forked from verdnatura/salix-front
fix(AccountAcls): fix and optimization
This commit is contained in:
parent
9ed297207b
commit
a56df46678
|
@ -4,7 +4,7 @@ import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import FormModel from 'components/FormModel.vue';
|
import FormModel from 'components/FormModel.vue';
|
||||||
|
|
||||||
const emit = defineEmits(['onDataSaved']);
|
const emit = defineEmits(['onDataSaved', 'onDataCanceled']);
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
title: {
|
title: {
|
||||||
|
@ -15,26 +15,6 @@ defineProps({
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
url: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
model: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
filter: {
|
|
||||||
type: Object,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
urlCreate: {
|
|
||||||
type: String,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
formInitialData: {
|
|
||||||
type: Object,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
@ -43,8 +23,8 @@ const formModelRef = ref(null);
|
||||||
const closeButton = ref(null);
|
const closeButton = ref(null);
|
||||||
|
|
||||||
const onDataSaved = (formData, requestResponse) => {
|
const onDataSaved = (formData, requestResponse) => {
|
||||||
emit('onDataSaved', formData, requestResponse);
|
|
||||||
closeForm();
|
closeForm();
|
||||||
|
emit('onDataSaved', formData, requestResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isLoading = computed(() => formModelRef.value?.isLoading);
|
const isLoading = computed(() => formModelRef.value?.isLoading);
|
||||||
|
@ -61,12 +41,9 @@ defineExpose({
|
||||||
<template>
|
<template>
|
||||||
<FormModel
|
<FormModel
|
||||||
ref="formModelRef"
|
ref="formModelRef"
|
||||||
:form-initial-data="formInitialData"
|
|
||||||
:observe-form-changes="false"
|
:observe-form-changes="false"
|
||||||
:default-actions="false"
|
:default-actions="false"
|
||||||
:url-create="urlCreate"
|
v-bind="$attrs"
|
||||||
:url="url"
|
|
||||||
:model="model"
|
|
||||||
@on-data-saved="onDataSaved"
|
@on-data-saved="onDataSaved"
|
||||||
>
|
>
|
||||||
<template #form="{ data, validate }">
|
<template #form="{ data, validate }">
|
||||||
|
@ -85,6 +62,7 @@ defineExpose({
|
||||||
flat
|
flat
|
||||||
:disabled="isLoading"
|
:disabled="isLoading"
|
||||||
:loading="isLoading"
|
:loading="isLoading"
|
||||||
|
@click="emit('onDataCanceled')"
|
||||||
v-close-popup
|
v-close-popup
|
||||||
/>
|
/>
|
||||||
<QBtn
|
<QBtn
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
import FetchData from 'components/FetchData.vue';
|
||||||
|
|
||||||
import VnPaginate from 'components/ui/VnPaginate.vue';
|
import VnPaginate from 'components/ui/VnPaginate.vue';
|
||||||
import VnSearchbar from 'components/ui/VnSearchbar.vue';
|
import VnSearchbar from 'components/ui/VnSearchbar.vue';
|
||||||
|
@ -24,12 +25,12 @@ defineProps({
|
||||||
|
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const router = useRouter();
|
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
const { openConfirmationModal } = useVnConfirm();
|
const { openConfirmationModal } = useVnConfirm();
|
||||||
|
|
||||||
const paginateRef = ref(null);
|
const paginateRef = ref();
|
||||||
const formDialog = ref(false);
|
const formDialog = ref(false);
|
||||||
|
const rolesOptions = ref([]);
|
||||||
|
|
||||||
const exprBuilder = (param, value) => {
|
const exprBuilder = (param, value) => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
|
@ -50,19 +51,21 @@ const deleteAcl = async (id) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function showFormDialog(id = null) {
|
function showFormDialog(data) {
|
||||||
formDialog.value = {
|
formDialog.value = {
|
||||||
show: true,
|
show: true,
|
||||||
id,
|
formInitialData: data,
|
||||||
ur: `ACLs/${id}`,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const redirectToAclsForm = (id = undefined) => showFormDialog(id);
|
|
||||||
// router.push({ name: 'AccountAclForm', query: { id } });
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<FetchData
|
||||||
|
url="VnRoles"
|
||||||
|
:filter="{ fields: ['name'], order: 'name ASC' }"
|
||||||
|
@on-fetch="(data) => (rolesOptions = data)"
|
||||||
|
auto-load
|
||||||
|
/>
|
||||||
<template v-if="stateStore.isHeaderMounted()">
|
<template v-if="stateStore.isHeaderMounted()">
|
||||||
<Teleport to="#searchbar">
|
<Teleport to="#searchbar">
|
||||||
<VnSearchbar
|
<VnSearchbar
|
||||||
|
@ -86,7 +89,6 @@ const redirectToAclsForm = (id = undefined) => showFormDialog(id);
|
||||||
ref="paginateRef"
|
ref="paginateRef"
|
||||||
data-key="AccountAcls"
|
data-key="AccountAcls"
|
||||||
url="ACLs"
|
url="ACLs"
|
||||||
auto-load
|
|
||||||
:expr-builder="exprBuilder"
|
:expr-builder="exprBuilder"
|
||||||
>
|
>
|
||||||
<template #body="{ rows }">
|
<template #body="{ rows }">
|
||||||
|
@ -95,7 +97,7 @@ const redirectToAclsForm = (id = undefined) => showFormDialog(id);
|
||||||
:id="row.id"
|
:id="row.id"
|
||||||
:key="row.id"
|
:key="row.id"
|
||||||
:title="`${row.model}.${row.property}`"
|
:title="`${row.model}.${row.property}`"
|
||||||
@click="redirectToAclsForm(row.id)"
|
@click="showFormDialog(row)"
|
||||||
>
|
>
|
||||||
<template #list-items>
|
<template #list-items>
|
||||||
<VnLv :label="t('acls.role')" :value="row.principalId" />
|
<VnLv :label="t('acls.role')" :value="row.principalId" />
|
||||||
|
@ -128,7 +130,11 @@ const redirectToAclsForm = (id = undefined) => showFormDialog(id);
|
||||||
transition-show="scale"
|
transition-show="scale"
|
||||||
transition-hide="scale"
|
transition-hide="scale"
|
||||||
>
|
>
|
||||||
<AclFormView :id="formDialog.id" />
|
<AclFormView
|
||||||
|
:form-initial-data="formDialog.formInitialData"
|
||||||
|
@on-data-change="paginateRef.fetch()"
|
||||||
|
:roles-options="rolesOptions"
|
||||||
|
/>
|
||||||
</QDialog>
|
</QDialog>
|
||||||
<QPageSticky position="bottom-right" :offset="[18, 18]">
|
<QPageSticky position="bottom-right" :offset="[18, 18]">
|
||||||
<QBtn fab icon="add" color="primary" @click="showFormDialog()">
|
<QBtn fab icon="add" color="primary" @click="showFormDialog()">
|
||||||
|
|
|
@ -1,103 +1,86 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { ref, onBeforeMount, onMounted, toRefs } from 'vue';
|
import { ref, onBeforeMount, onMounted } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
import VnRow from 'components/ui/VnRow.vue';
|
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
import FormModelPopup from 'components/FormModelPopup.vue';
|
import FormModelPopup from 'components/FormModelPopup.vue';
|
||||||
|
|
||||||
import { useValidator } from 'src/composables/useValidator';
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
import { useArrayData } from 'src/composables/useArrayData';
|
import { useArrayData } from 'src/composables/useArrayData';
|
||||||
|
|
||||||
|
const emit = defineEmits(['onDataChange']);
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const router = useRouter();
|
|
||||||
const arrayData = useArrayData('aclCreate');
|
|
||||||
const { store } = arrayData;
|
|
||||||
const validationsStore = useValidator();
|
const validationsStore = useValidator();
|
||||||
const { models } = validationsStore;
|
const { models } = validationsStore;
|
||||||
|
const arrayData = useArrayData('aclCreate');
|
||||||
|
const { store } = arrayData;
|
||||||
|
|
||||||
const defaultFormData = ref(null);
|
|
||||||
|
|
||||||
const rolesOptions = ref([]);
|
|
||||||
const accessTypes = [{ name: '*' }, { name: 'READ' }, { name: 'WRITE' }];
|
const accessTypes = [{ name: '*' }, { name: 'READ' }, { name: 'WRITE' }];
|
||||||
const permissions = [{ name: 'ALLOW' }, { name: 'DENY' }];
|
const permissions = [{ name: 'ALLOW' }, { name: 'DENY' }];
|
||||||
const validations = ref([]);
|
const validations = ref([]);
|
||||||
|
|
||||||
const url = ref(null);
|
const url = ref();
|
||||||
const urlCreate = ref(null);
|
const urlCreate = ref('ACLs');
|
||||||
const urlUpdate = ref(null);
|
const urlUpdate = ref();
|
||||||
const action = ref('New');
|
const action = ref('New');
|
||||||
|
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
id: {
|
formInitialData: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: null,
|
default: () => {
|
||||||
|
return {
|
||||||
|
property: '*',
|
||||||
|
principalType: 'ROLE',
|
||||||
|
accessType: 'READ',
|
||||||
|
permission: 'ALLOW',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rolesOptions: {
|
||||||
|
type: Array,
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { id } = toRefs($props);
|
|
||||||
const redirectToAclList = () => router.push({ name: 'AccountAcls' });
|
|
||||||
|
|
||||||
const onDataSaved = () => {
|
|
||||||
store.data = undefined;
|
|
||||||
redirectToAclList();
|
|
||||||
};
|
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
for (let model in models) validations.value.push({ name: model });
|
for (let model in models) validations.value.push({ name: model });
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
url.value = id.value ? `ACLs/${id.value}` : null;
|
store.data = $props.formInitialData;
|
||||||
|
if ($props.formInitialData.id) {
|
||||||
if (url.value) {
|
urlCreate.value = null;
|
||||||
urlUpdate.value = 'ACLs';
|
urlUpdate.value = 'ACLs';
|
||||||
action.value = 'Edit';
|
action.value = 'Edit';
|
||||||
} else {
|
|
||||||
url.value = null;
|
|
||||||
defaultFormData.value = {
|
|
||||||
property: '*',
|
|
||||||
principalType: 'ROLE',
|
|
||||||
accessType: 'READ',
|
|
||||||
permission: 'ALLOW',
|
|
||||||
};
|
|
||||||
urlCreate.value = 'ACLs';
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
url="VnRoles"
|
|
||||||
:filter="{ fields: ['name'], order: 'name ASC' }"
|
|
||||||
@on-fetch="(data) => (rolesOptions = data)"
|
|
||||||
auto-load
|
|
||||||
/>
|
|
||||||
<FormModelPopup
|
<FormModelPopup
|
||||||
v-if="urlCreate || urlUpdate"
|
v-if="urlCreate || urlUpdate"
|
||||||
:title="t(`${action} ACL`)"
|
:title="t(`${action} ACL`)"
|
||||||
:url="url"
|
:url="url"
|
||||||
:url-update="urlUpdate"
|
:url-update="urlUpdate"
|
||||||
:url-create="urlCreate"
|
:url-create="urlCreate"
|
||||||
:form-initial-data="defaultFormData"
|
:form-initial-data="formInitialData"
|
||||||
auto-load
|
auto-load
|
||||||
model="aclCreate"
|
model="aclCreate"
|
||||||
@on-data-saved="onDataSaved()"
|
@on-data-saved="emit('onDataChange')"
|
||||||
|
@on-data-canceled="emit('onDataChange')"
|
||||||
>
|
>
|
||||||
<template #form-inputs="{ data }">
|
<template #form-inputs="{ data }">
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
<div class="column q-gutter-y-md">
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('acls.aclFilter.principalId')"
|
:label="t('acls.aclFilter.principalId')"
|
||||||
v-model="data.principalId"
|
v-model="data.principalId"
|
||||||
:options="rolesOptions"
|
:options="$props.rolesOptions"
|
||||||
option-value="name"
|
option-value="name"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
use-input
|
use-input
|
||||||
rounded
|
rounded
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('acls.aclFilter.model')"
|
:label="t('acls.aclFilter.model')"
|
||||||
v-model="data.model"
|
v-model="data.model"
|
||||||
|
@ -107,8 +90,7 @@ onMounted(() => {
|
||||||
use-input
|
use-input
|
||||||
rounded
|
rounded
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
|
||||||
<VnInput
|
<VnInput
|
||||||
:label="t('acls.aclFilter.property')"
|
:label="t('acls.aclFilter.property')"
|
||||||
v-model="data.property"
|
v-model="data.property"
|
||||||
|
@ -120,8 +102,6 @@ onMounted(() => {
|
||||||
</QIcon>
|
</QIcon>
|
||||||
</template></VnInput
|
</template></VnInput
|
||||||
>
|
>
|
||||||
</VnRow>
|
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('acls.aclFilter.accessType')"
|
:label="t('acls.aclFilter.accessType')"
|
||||||
v-model="data.accessType"
|
v-model="data.accessType"
|
||||||
|
@ -131,8 +111,6 @@ onMounted(() => {
|
||||||
use-input
|
use-input
|
||||||
rounded
|
rounded
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
|
||||||
<VnRow class="row q-gutter-md q-mb-md">
|
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('acls.aclFilter.permission')"
|
:label="t('acls.aclFilter.permission')"
|
||||||
v-model="data.permission"
|
v-model="data.permission"
|
||||||
|
@ -142,7 +120,7 @@ onMounted(() => {
|
||||||
use-input
|
use-input
|
||||||
rounded
|
rounded
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</FormModelPopup>
|
</FormModelPopup>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue