forked from verdnatura/salix-front
103 lines
2.6 KiB
Vue
103 lines
2.6 KiB
Vue
<script setup>
|
|
import { useI18n } from 'vue-i18n';
|
|
import { computed, ref } from 'vue';
|
|
import VnTable from 'components/VnTable/VnTable.vue';
|
|
import { useRoute } from 'vue-router';
|
|
import VnSearchbar from 'components/ui/VnSearchbar.vue';
|
|
import { useStateStore } from 'stores/useStateStore';
|
|
import { useSummaryDialog } from 'src/composables/useSummaryDialog';
|
|
import RoleSummary from './Card/RoleSummary.vue';
|
|
const route = useRoute();
|
|
const stateStore = useStateStore();
|
|
const { t } = useI18n();
|
|
const $props = defineProps({
|
|
id: {
|
|
type: Number,
|
|
default: 0,
|
|
},
|
|
});
|
|
const tableRef = ref();
|
|
const entityId = computed(() => $props.id || route.params.id);
|
|
const { viewSummary } = useSummaryDialog();
|
|
const columns = computed(() => [
|
|
{
|
|
align: 'left',
|
|
name: 'id',
|
|
label: t('id'),
|
|
isId: true,
|
|
columnFilter: {
|
|
inWhere: true,
|
|
},
|
|
cardVisible: true,
|
|
},
|
|
{
|
|
align: 'left',
|
|
name: 'name',
|
|
label: t('name'),
|
|
cardVisible: true,
|
|
create: true,
|
|
},
|
|
{
|
|
align: 'left',
|
|
name: 'description',
|
|
label: t('description'),
|
|
cardVisible: true,
|
|
create: true,
|
|
},
|
|
{
|
|
align: 'right',
|
|
label: '',
|
|
name: 'tableActions',
|
|
actions: [
|
|
{
|
|
title: t('View Summary'),
|
|
icon: 'preview',
|
|
action: (row) => viewSummary(row.id, RoleSummary),
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
const exprBuilder = (param, value) => {
|
|
switch (param) {
|
|
case 'search':
|
|
return /^\d+$/.test(value)
|
|
? { id: value }
|
|
: {
|
|
or: [
|
|
{ name: { like: `%${value}%` } },
|
|
{ nickname: { like: `%${value}%` } },
|
|
],
|
|
};
|
|
case 'name':
|
|
case 'description':
|
|
return { [param]: { like: `%${value}%` } };
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<VnSearchbar
|
|
data-key="Roles"
|
|
:expr-builder="exprBuilder"
|
|
:label="t('role.searchRoles')"
|
|
:info="t('role.searchInfo')"
|
|
/>
|
|
<VnTable
|
|
ref="tableRef"
|
|
data-key="Roles"
|
|
:url="`VnRoles`"
|
|
:create="{
|
|
urlCreate: 'VnRoles',
|
|
title: t('Create rol'),
|
|
onDataSaved: ({ id }) => tableRef.redirect(id),
|
|
formInitialData: {
|
|
editorFk: entityId,
|
|
},
|
|
}"
|
|
order="id ASC"
|
|
:columns="columns"
|
|
default-mode="table"
|
|
redirect="account/role"
|
|
/>
|
|
</template>
|