From cd99aee637f67d8a81329f8a9609016dca260f8f Mon Sep 17 00:00:00 2001 From: volar Date: Fri, 12 Apr 2024 11:23:16 +0200 Subject: [PATCH] dam user detail and edit - implement Asset Licence Groups --- src/locales/en/coreDam/user.json | 1 + src/locales/sk/coreDam/user.json | 1 + .../coreDam/filter/AssetLicenceGroupFilter.ts | 13 ++++ .../api/coreDam/assetLicenceGroupApi.ts | 9 +-- src/stores/coreDam/userStore.ts | 45 +++++++------ ...DamAssetLicenceGroupRemoteAutocomplete.vue | 67 +++++++++++++++++++ .../composables/assetLicenceGroupActions.ts | 31 ++++++++- .../coreDam/user/components/UserDetail.vue | 18 ++++- .../coreDam/user/components/UserEditForm.vue | 13 +++- .../coreDam/user/composables/userActions.ts | 4 +- .../user/composables/userValidation.ts | 4 +- 11 files changed, 173 insertions(+), 33 deletions(-) create mode 100644 src/views/coreDam/assetLicenceGroup/components/DamAssetLicenceGroupRemoteAutocomplete.vue diff --git a/src/locales/en/coreDam/user.json b/src/locales/en/coreDam/user.json index 29956e0f..2609ab10 100644 --- a/src/locales/en/coreDam/user.json +++ b/src/locales/en/coreDam/user.json @@ -12,6 +12,7 @@ "enabled": "Enabled", "plainPassword": "New password", "assetLicences": "Licences", + "licenceGroups": "Licence groups", "userToExtSystems": "User to External Systems", "adminToExtSystems": "Admin to External Systems", "superAdmin": "Super admin", diff --git a/src/locales/sk/coreDam/user.json b/src/locales/sk/coreDam/user.json index ed786997..9acd3607 100644 --- a/src/locales/sk/coreDam/user.json +++ b/src/locales/sk/coreDam/user.json @@ -12,6 +12,7 @@ "enabled": "Povolený", "plainPassword": "Nové heslo", "assetLicences": "Licencie", + "licenceGroups": "Skupiny licencií", "userToExtSystems": "Používateľ externých systémov", "adminToExtSystems": "Admin externých systémov", "superAdmin": "Super admin", diff --git a/src/model/coreDam/filter/AssetLicenceGroupFilter.ts b/src/model/coreDam/filter/AssetLicenceGroupFilter.ts index 268f0535..e44fd096 100644 --- a/src/model/coreDam/filter/AssetLicenceGroupFilter.ts +++ b/src/model/coreDam/filter/AssetLicenceGroupFilter.ts @@ -15,3 +15,16 @@ export function useAssetLicenceGroupListFilter() { return filter } +export function useAssetLicenceGroupFilter() { + return reactive({ + name: { + ...makeFilter({ name: 'name', variant: 'startsWith' }), + }, + extSystem: { + ...makeFilter({ name: 'extSystem', default: null }), + }, + extId: { + ...makeFilter({ name: 'extId', default: null }), + }, + }) +} diff --git a/src/services/api/coreDam/assetLicenceGroupApi.ts b/src/services/api/coreDam/assetLicenceGroupApi.ts index 1a838afb..759c9a71 100644 --- a/src/services/api/coreDam/assetLicenceGroupApi.ts +++ b/src/services/api/coreDam/assetLicenceGroupApi.ts @@ -9,13 +9,14 @@ import { type IntegerId, type Pagination } from '@anzusystems/common-admin' import type { AssetLicenceGroup } from '@/types/coreDam/AssetLicenceGroup' +import type { AxiosInstance } from 'axios' const END_POINT = '/adm/v1/asset-licence-group' export const ENTITY = 'assetLicenceGroup' -export const fetchAssetLicenceGroupListByIds = (ids: IntegerId[]) => +export const fetchAssetLicenceGroupListByIds = (client: () => AxiosInstance, ids: IntegerId[]) => apiFetchByIds( - damClient, + client, ids, END_POINT, {}, @@ -25,9 +26,9 @@ export const fetchAssetLicenceGroupListByIds = (ids: IntegerId[]) => true ) -export const fetchAssetLicenceGroupList = (pagination: Pagination, filterBag: FilterBag) => +export const fetchAssetLicenceGroupList = (client: () => AxiosInstance, pagination: Pagination, filterBag: FilterBag) => apiFetchList( - damClient, + client, END_POINT, {}, pagination, diff --git a/src/stores/coreDam/userStore.ts b/src/stores/coreDam/userStore.ts index 6d89fdb0..e7d36452 100644 --- a/src/stores/coreDam/userStore.ts +++ b/src/stores/coreDam/userStore.ts @@ -1,29 +1,34 @@ import type { DamUser, DamUserUpdateDto } from '@anzusystems/common-admin' import { useUserFactory } from '@/model/coreDam/factory/UserFactory' import { acceptHMRUpdate, defineStore } from 'pinia' +import { ref } from 'vue' +import type { AssetLicenceGroup } from '@/types/coreDam/AssetLicenceGroup' -const { createDefault, createDefaultForUpdate } = useUserFactory() +export const useUserOneStore = defineStore('damUserOneStore', () => { + const { createDefault, createDefaultForUpdate } = useUserFactory() -interface State { - user: DamUser - userUpdate: DamUserUpdateDto -} + const user = ref(createDefault()) + const userUpdate = ref(createDefaultForUpdate(createDefault())) + const userAssetLicenceGroups = ref([]) + + function setUser(userNew: DamUser) { + user.value = userNew + userUpdate.value = createDefaultForUpdate(userNew) + } + + function reset() { + user.value = createDefault() + userUpdate.value = createDefaultForUpdate(user.value) + userAssetLicenceGroups.value = [] + } -export const useUserOneStore = defineStore('damUserOneStore', { - state: (): State => ({ - user: createDefault(), - userUpdate: createDefaultForUpdate(createDefault()), - }), - actions: { - setUser(user: DamUser) { - this.user = user - this.userUpdate = createDefaultForUpdate(user) - }, - reset() { - this.user = createDefault() - this.userUpdate = createDefaultForUpdate(this.user) - }, - }, + return { + user, + userUpdate, + userAssetLicenceGroups, + setUser, + reset, + } }) if (import.meta.hot) { diff --git a/src/views/coreDam/assetLicenceGroup/components/DamAssetLicenceGroupRemoteAutocomplete.vue b/src/views/coreDam/assetLicenceGroup/components/DamAssetLicenceGroupRemoteAutocomplete.vue new file mode 100644 index 00000000..4203846c --- /dev/null +++ b/src/views/coreDam/assetLicenceGroup/components/DamAssetLicenceGroupRemoteAutocomplete.vue @@ -0,0 +1,67 @@ + + + diff --git a/src/views/coreDam/assetLicenceGroup/composables/assetLicenceGroupActions.ts b/src/views/coreDam/assetLicenceGroup/composables/assetLicenceGroupActions.ts index 628249c3..b1fcd6db 100644 --- a/src/views/coreDam/assetLicenceGroup/composables/assetLicenceGroupActions.ts +++ b/src/views/coreDam/assetLicenceGroup/composables/assetLicenceGroupActions.ts @@ -1,12 +1,13 @@ import { ref } from 'vue' -import type { FilterBag, Pagination } from '@anzusystems/common-admin' +import type { FilterBag, IntegerId, Pagination, ValueObjectOption } from '@anzusystems/common-admin' import { useAlerts } from '@anzusystems/common-admin' import { useAssetLicenceGroupOneStore } from '@/stores/coreDam/assetLicenceGroupStore' import { storeToRefs } from 'pinia' import { fetchAssetLicenceGroup, fetchAssetLicenceGroupList, - updateAssetLicenceGroup + fetchAssetLicenceGroupListByIds, + updateAssetLicenceGroup, } from '@/services/api/coreDam/assetLicenceGroupApi' import useVuelidate from '@vuelidate/core' import { useRouter } from 'vue-router' @@ -14,6 +15,8 @@ import { ROUTE } from '@/router/routes' import type { AssetLicenceGroup } from '@/types/coreDam/AssetLicenceGroup' import { useCachedAssetLicences } from '@/views/coreDam/assetLicence/composables/cachedAssetLicences' import { useCachedExtSystems } from '@/views/coreDam/extSystem/composables/cachedExtSystems' +import { damClient } from '@/services/api/clients/damClient' +import type { AxiosInstance } from 'axios' const { showValidationError, showRecordWas, showErrorsDefault } = useAlerts() @@ -31,7 +34,7 @@ export const useAssetLicenceGroupListActions = () => { const fetchList = async (pagination: Pagination, filterBag: FilterBag) => { listLoading.value = true try { - const res = await fetchAssetLicenceGroupList(pagination, filterBag) + const res = await fetchAssetLicenceGroupList(damClient, pagination, filterBag) res.forEach((item) => { addToCachedAssetLicences(item.licences) addToCachedExtSystems(item.extSystem) @@ -133,3 +136,25 @@ export const useAssetLicenceGroupEditActions = () => { resetStore: assetLicenceGroupOneStore.reset, } } + +export const useAssetLicenceGroupSelectActions = (client: () => AxiosInstance) => { + const mapToValueObjectOption = (assetLicenceGroups: AssetLicenceGroup[]): ValueObjectOption[] => { + return assetLicenceGroups.map((assetLicence: AssetLicenceGroup) => ({ + title: assetLicence.name, + value: assetLicence.id, + })) + } + + const fetchItems = async (pagination: Pagination, filterBag: FilterBag) => { + return mapToValueObjectOption(await fetchAssetLicenceGroupList(client, pagination, filterBag)) + } + + const fetchItemsByIds = async (ids: number[]) => { + return mapToValueObjectOption(await fetchAssetLicenceGroupListByIds(client, ids)) + } + + return { + fetchItems, + fetchItemsByIds, + } +} diff --git a/src/views/coreDam/user/components/UserDetail.vue b/src/views/coreDam/user/components/UserDetail.vue index 3950fdbb..05ebefdb 100644 --- a/src/views/coreDam/user/components/UserDetail.vue +++ b/src/views/coreDam/user/components/UserDetail.vue @@ -1,5 +1,5 @@ @@ -16,6 +17,19 @@ const { t } = useI18n()