first commit
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<script setup lang="ts">
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import Button from '@/components/ui/Button.vue';
|
||||
import Input from '@/components/ui/Input.vue';
|
||||
import Textarea from '@/components/ui/Textarea.vue';
|
||||
import { useTranslations } from '@/composables/useVanguard';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
|
||||
interface Permission {
|
||||
id: number;
|
||||
name: string;
|
||||
display_name: string | null;
|
||||
description: string | null;
|
||||
}
|
||||
|
||||
const props = defineProps<{ edit: boolean; permission?: Permission | null }>();
|
||||
|
||||
const { __ } = useTranslations();
|
||||
|
||||
const form = useForm({
|
||||
name: props.permission?.name ?? '',
|
||||
display_name: props.permission?.display_name ?? '',
|
||||
description: props.permission?.description ?? '',
|
||||
});
|
||||
|
||||
function submit() {
|
||||
if (props.edit && props.permission) {
|
||||
form.put(route('permissions.update', props.permission.id));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
form.post(route('permissions.store'));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout
|
||||
:title="__('Permissions')"
|
||||
:heading="edit && permission ? permission.name : __('Create New Permission')"
|
||||
:breadcrumbs="[
|
||||
{ label: __('Permissions'), href: route('permissions.index') },
|
||||
{ label: edit ? __('Edit') : __('Create') },
|
||||
]"
|
||||
>
|
||||
<form @submit.prevent="submit">
|
||||
<div class="rounded-lg border border-slate-200 bg-white p-6 shadow-sm">
|
||||
<div class="grid grid-cols-1 gap-6 md:grid-cols-4">
|
||||
<div class="md:col-span-1">
|
||||
<h5 class="font-medium text-slate-800">{{ __('Permission Details') }}</h5>
|
||||
<p class="font-light text-slate-500">
|
||||
{{ __('A general permission information.') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4 md:col-span-3">
|
||||
<div>
|
||||
<label for="name" class="mb-1 block text-slate-700">{{ __('Name') }}</label>
|
||||
<Input
|
||||
id="name"
|
||||
v-model="form.name"
|
||||
class="w-full"
|
||||
:placeholder="__('Permission Name')"
|
||||
:invalid="Boolean(form.errors.name)"
|
||||
/>
|
||||
<small v-if="form.errors.name" class="text-red-600">{{ form.errors.name }}</small>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="display_name" class="mb-1 block text-slate-700">
|
||||
{{ __('Display Name') }}
|
||||
</label>
|
||||
<Input
|
||||
id="display_name"
|
||||
v-model="form.display_name"
|
||||
class="w-full"
|
||||
:placeholder="__('Display Name')"
|
||||
:invalid="Boolean(form.errors.display_name)"
|
||||
/>
|
||||
<small v-if="form.errors.display_name" class="text-red-600">
|
||||
{{ form.errors.display_name }}
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="description" class="mb-1 block text-slate-700">
|
||||
{{ __('Description') }}
|
||||
</label>
|
||||
<Textarea
|
||||
id="description"
|
||||
v-model="form.description"
|
||||
class="w-full"
|
||||
:rows="3"
|
||||
:invalid="Boolean(form.errors.description)"
|
||||
/>
|
||||
<small v-if="form.errors.description" class="text-red-600">
|
||||
{{ form.errors.description }}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
:label="edit ? __('Update Permission') : __('Create Permission')"
|
||||
class="mt-4"
|
||||
:loading="form.processing"
|
||||
/>
|
||||
</form>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,160 @@
|
||||
<script setup lang="ts">
|
||||
import { Link, useForm } from '@inertiajs/vue3';
|
||||
import Button from '@/components/ui/Button.vue';
|
||||
import Checkbox from '@/components/ui/Checkbox.vue';
|
||||
import Tooltip from '@/components/ui/Tooltip.vue';
|
||||
import { useConfirmDelete } from '@/composables/useConfirmDelete';
|
||||
import { useTranslations } from '@/composables/useVanguard';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
|
||||
interface Role {
|
||||
id: number;
|
||||
display_name: string | null;
|
||||
}
|
||||
|
||||
interface Permission {
|
||||
id: number;
|
||||
name: string;
|
||||
display_name: string | null;
|
||||
removable: boolean;
|
||||
editUrl: string;
|
||||
deleteUrl: string;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
roles: Role[];
|
||||
permissions: Permission[];
|
||||
/** Permission ids currently granted, keyed by role id. */
|
||||
granted: Record<number, number[]>;
|
||||
}>();
|
||||
|
||||
const { __ } = useTranslations();
|
||||
const { confirmDelete } = useConfirmDelete();
|
||||
|
||||
/**
|
||||
* Mirrors the old roles[{roleId}][] checkbox matrix: each role maps to the
|
||||
* list of permission ids it holds, and RolePermissionsController replaces the
|
||||
* whole set for every role on save.
|
||||
*/
|
||||
const form = useForm<{ roles: Record<number, number[]> }>({
|
||||
roles: Object.fromEntries(
|
||||
props.roles.map((role) => [role.id, [...(props.granted[role.id] ?? [])]]),
|
||||
),
|
||||
});
|
||||
|
||||
function remove(permission: Permission) {
|
||||
confirmDelete({
|
||||
url: permission.deleteUrl,
|
||||
message: __('Are you sure that you want to delete this permission?'),
|
||||
});
|
||||
}
|
||||
|
||||
function submit() {
|
||||
form.post(route('permissions.save'), { preserveScroll: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout
|
||||
:title="__('Permissions')"
|
||||
:heading="__('Permissions')"
|
||||
:breadcrumbs="[{ label: __('Permissions') }]"
|
||||
>
|
||||
<form @submit.prevent="submit">
|
||||
<div class="rounded-lg border border-slate-200 bg-white p-6 shadow-sm">
|
||||
<div class="mb-4 flex justify-end border-b border-slate-100 pb-4">
|
||||
<Link :href="route('permissions.create')">
|
||||
<Button :label="__('Add Permission')" icon="fas fa-plus" rounded />
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full min-w-3xl text-left">
|
||||
<thead>
|
||||
<tr class="border-b border-slate-100">
|
||||
<th class="px-4 py-3 font-medium">{{ __('Name') }}</th>
|
||||
<th
|
||||
v-for="role in roles"
|
||||
:key="role.id"
|
||||
class="px-4 py-3 text-center font-medium"
|
||||
>
|
||||
{{ role.display_name }}
|
||||
</th>
|
||||
<th class="px-4 py-3 text-center font-medium">{{ __('Action') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="permission in permissions"
|
||||
:key="permission.id"
|
||||
class="odd:bg-body border-b border-slate-50"
|
||||
>
|
||||
<td class="px-4 py-3">
|
||||
{{ permission.display_name || permission.name }}
|
||||
</td>
|
||||
|
||||
<td
|
||||
v-for="role in roles"
|
||||
:key="role.id"
|
||||
class="px-4 py-3 text-center"
|
||||
>
|
||||
<!--
|
||||
Checkbox renders a flex box, which the
|
||||
cell's text-center cannot reach, so it
|
||||
has to centre itself.
|
||||
-->
|
||||
<Checkbox
|
||||
v-model="form.roles[role.id]"
|
||||
:value="permission.id"
|
||||
:id="`cb-${role.id}-${permission.id}`"
|
||||
class="mx-auto"
|
||||
/>
|
||||
</td>
|
||||
|
||||
<td class="px-4 py-3 text-center">
|
||||
<Tooltip :text="__('Edit Permission')">
|
||||
<Link :href="permission.editUrl">
|
||||
<Button
|
||||
icon="fas fa-edit"
|
||||
text
|
||||
rounded
|
||||
severity="secondary"
|
||||
:aria-label="__('Edit Permission')"
|
||||
/>
|
||||
</Link>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip v-if="permission.removable" :text="__('Delete Permission')">
|
||||
<Button
|
||||
icon="fas fa-trash"
|
||||
text
|
||||
rounded
|
||||
severity="secondary"
|
||||
:aria-label="__('Delete Permission')"
|
||||
@click="remove(permission)"
|
||||
/>
|
||||
</Tooltip>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr v-if="!permissions.length">
|
||||
<td :colspan="roles.length + 2" class="px-4 py-3">
|
||||
<em class="text-slate-500">{{ __('No records found.') }}</em>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
v-if="permissions.length"
|
||||
type="submit"
|
||||
:label="__('Save Permissions')"
|
||||
class="mt-4"
|
||||
:loading="form.processing"
|
||||
/>
|
||||
</form>
|
||||
</AppLayout>
|
||||
</template>
|
||||
Reference in New Issue
Block a user