Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/cfe #145

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const props = withDefaults(
defineProps<{
modelValue: any
config: DamConfigAssetCustomFormElement
elementKey: string
elementProperty: string
validationScope?: ValidationScope
}>(),
{
validationScope: undefined,
}
)
const emit = defineEmits<{
(e: 'update:modelValue', data: { key: string; value: any }): void
(e: 'update:modelValue', data: { property: string; value: any }): void
(e: 'blur', data: any): void
}>()

Expand All @@ -31,7 +31,7 @@ const fixValue = (value: any) => {
}

const updateModelValue = (value: any) => {
emit('update:modelValue', { key: props.elementKey, value: fixValue(value) })
emit('update:modelValue', { property: props.elementProperty, value: fixValue(value) })
}

const modelValueComputed = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const emit = defineEmits<{

const { showAllMetadata, toggleShowAllMetadata } = useAssetCustomMetadataForm()

const updateModelValue = (data: { key: string; value: any }) => {
const updateModelValue = (data: { property: string; value: any }) => {
const updated = {} as { [key: string]: any }
updated[data.key] = data.value
updated[data.property] = data.value
emit('update:modelValue', { ...props.modelValue, ...updated })
emit('anyChange')
}
Expand Down Expand Up @@ -73,8 +73,8 @@ const enableShowHide = computed(() => {
<VCol>
<AssetCustomMetadataElement
:config="element"
:element-key="element.key"
:model-value="modelValue[element.key]"
:element-property="element.property"
:model-value="modelValue[element.property]"
:validation-scope="AssetMetadataValidationScopeSymbol"
@update:model-value="updateModelValue"
/>
Expand All @@ -95,8 +95,8 @@ const enableShowHide = computed(() => {
<VCol>
<AssetCustomMetadataElement
:config="element"
:element-key="element.key"
:model-value="modelValue[element.key]"
:element-property="element.property"
:model-value="modelValue[element.property]"
@update:model-value="updateModelValue"
/>
</VCol>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ const props = withDefaults(
)
const emit = defineEmits<{
(e: 'update:modelValue', data: any): void
(e: 'fillEmptyField', data: { assetType: AssetType; elementKey: string; value: any }): void
(e: 'replaceField', data: { assetType: AssetType; elementKey: string; value: any }): void
(e: 'fillEmptyField', data: { assetType: AssetType; elementProperty: string; value: any }): void
(e: 'replaceField', data: { assetType: AssetType; elementProperty: string; value: any }): void
}>()

const updateModelValue = (data: { key: string; value: any }) => {
const updateModelValue = (data: { property: string; value: any }) => {
const updated = {} as { [key: string]: any }
updated[data.key] = data.value
updated[data.property] = data.value
emit('update:modelValue', { ...props.modelValue, ...updated })
}

const fillEmptyField = (elementKey: string, value: any) => {
emit('fillEmptyField', { assetType: props.assetType, elementKey, value })
const fillEmptyField = (elementProperty: string, value: any) => {
emit('fillEmptyField', { assetType: props.assetType, elementProperty, value })
}
const replaceField = (elementKey: string, value: any) => {
emit('replaceField', { assetType: props.assetType, elementKey, value })
const replaceField = (elementProperty: string, value: any) => {
emit('replaceField', { assetType: props.assetType, elementProperty, value })
}

const elements = computed(() => {
Expand All @@ -50,16 +50,16 @@ const elements = computed(() => {
<div class="d-flex">
<AssetCustomMetadataElement
:config="element"
:element-key="element.key"
:model-value="modelValue[element.key]"
:element-property="element.property"
:model-value="modelValue[element.property]"
@update:model-value="updateModelValue"
/>
<VBtn
icon
size="small"
variant="text"
class="mr-1"
@click.stop="fillEmptyField(element.key, modelValue[element.key])"
@click.stop="fillEmptyField(element.property, modelValue[element.property])"
>
<VIcon icon="mdi-file-arrow-left-right-outline" />
<VTooltip
Expand All @@ -73,7 +73,7 @@ const elements = computed(() => {
icon
size="small"
variant="text"
@click.stop="replaceField(element.key, modelValue[element.key])"
@click.stop="replaceField(element.property, modelValue[element.property])"
>
<VIcon icon="mdi-file-replace-outline" />
<VTooltip
Expand Down
13 changes: 7 additions & 6 deletions src/services/DamConfigAssetCustomFormService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ref } from 'vue'
import type { DamConfigAssetCustomFormElement } from '@/types/coreDam/DamConfigAssetCustomForm'
import type { DamConfigAssetCustomFormElement, DamConfigAssetCustomFormElementTemp } from '@/types/coreDam/DamConfigAssetCustomForm'
import { fetchAssetCustomFormElements } from '@/services/api/coreDam/assetCustomFormApi'
import { AssetType } from '@/model/coreDam/valueObject/AssetType'
import { useCurrentExtSystem } from '@/composables/system/currentExtSystem'
import { mapElementsWithKeyToProperty } from '@/services/TempMapCustomFormElementHelper'

export const damConfigAssetCustomFormElementsInitialized = ref(false)

Expand All @@ -15,12 +16,12 @@ export const damConfigAssetCustomFormElements: {
document: [],
}

const setDamConfigAssetCustomFormElements = (responses: Awaited<{ data: DamConfigAssetCustomFormElement[] }>[]) => {
const setDamConfigAssetCustomFormElements = (responses: Awaited<{ data: DamConfigAssetCustomFormElementTemp[] }>[]) => {
try {
damConfigAssetCustomFormElements.image = responses[0].data
damConfigAssetCustomFormElements.audio = responses[1].data
damConfigAssetCustomFormElements.video = responses[2].data
damConfigAssetCustomFormElements.document = responses[3].data
damConfigAssetCustomFormElements.image = mapElementsWithKeyToProperty(responses[0].data)
damConfigAssetCustomFormElements.audio = mapElementsWithKeyToProperty(responses[1].data)
damConfigAssetCustomFormElements.video = mapElementsWithKeyToProperty(responses[2].data)
damConfigAssetCustomFormElements.document = mapElementsWithKeyToProperty(responses[3].data)

damConfigAssetCustomFormElementsInitialized.value = true
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion src/services/DamConfigDistributionCustomFormService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type Ref, ref } from 'vue'
import { fetchDistributionCustomFormElements } from '@/services/api/coreDam/assetCustomFormApi'
import type { DistributionServiceName } from '@/types/coreDam/DamConfig'
import { mapElementsWithKeyToProperty } from '@/services/TempMapCustomFormElementHelper'

export const damConfigDistributionCustomFormElements: Ref<Record<DistributionServiceName, any>> = ref({})

Expand All @@ -12,7 +13,7 @@ export const loadDamConfigDistributionCustomFormElements = (distributionServiceN
}
fetchDistributionCustomFormElements(distributionServiceName)
.then((res) => {
damConfigDistributionCustomFormElements.value[distributionServiceName] = res.data
damConfigDistributionCustomFormElements.value[distributionServiceName] = mapElementsWithKeyToProperty(res.data)
resolve(true)
return
})
Expand Down
28 changes: 28 additions & 0 deletions src/services/TempMapCustomFormElementHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// todo will be removed once rename key => property will be implemented

import type {
DamConfigAssetCustomFormElement,
DamConfigAssetCustomFormElementTemp
} from '@/types/coreDam/DamConfigAssetCustomForm'
import { isDefined } from '@anzusystems/common-admin'

export function mapElementsWithKeyToProperty
(items: Array<DamConfigAssetCustomFormElementTemp>
): Array<DamConfigAssetCustomFormElement> {
return items.map(item => {
return {
id: item.id,
property: isDefined(item.property) ? item.property as string : item.key as string,
name: item.name,
position: item.position,
attributes: item.attributes,
createdAt: item.createdAt,
modifiedAt: item.modifiedAt,
createdBy: item.createdBy,
modifiedBy: item.modifiedBy,
_system: item._system,
_resourceName: item._resourceName,
}
})

}
2 changes: 1 addition & 1 deletion src/services/api/coreDam/assetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const handleMetadataValidationError = (error: any, assetType: AssetType) => {
const items = [] as ValidationError[]
for (const [key, values] of Object.entries(data.fields)) {
const field = key.split('.').pop()
const found = damConfigAssetCustomFormElements[assetType].find((item) => item.key === field)
const found = damConfigAssetCustomFormElements[assetType].find((item) => item.property === field)
if (found) {
items.push({
field: found.name,
Expand Down
6 changes: 3 additions & 3 deletions src/services/api/coreDam/assetCustomFormApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { apiFetchOne } from '@anzusystems/common-admin'
import { damClient } from '@/services/api/clients/damClient'
import { SYSTEM_CORE_DAM } from '@/model/systems'
import type { AssetType } from '@/model/coreDam/valueObject/AssetType'
import type { DamConfigAssetCustomFormElement } from '@/types/coreDam/DamConfigAssetCustomForm'
import type { DamConfigAssetCustomFormElementTemp } from '@/types/coreDam/DamConfigAssetCustomForm'
import type { DistributionServiceName } from '@/types/coreDam/DamConfig'

const END_POINT = '/adm/v1/asset-custom-form'
const ENTITY = 'assetCustomForm'

// todo limit set to 100 for now, add load for pagination?
export const fetchAssetCustomFormElements = (extSystem: IntegerId, assetType: AssetType) =>
apiFetchOne<{ data: DamConfigAssetCustomFormElement[] }>(
apiFetchOne<{ data: DamConfigAssetCustomFormElementTemp[] }>(
damClient,
END_POINT + '/ext-system/:extSystem/type/:assetType/element?order[position]=asc&limit=100',
{ extSystem, assetType },
Expand All @@ -21,7 +21,7 @@ export const fetchAssetCustomFormElements = (extSystem: IntegerId, assetType: As

// todo limit set to 100 for now, add load for pagination?
export const fetchDistributionCustomFormElements = (distributionService: DistributionServiceName) =>
apiFetchOne<{ data: DamConfigAssetCustomFormElement[] }>(
apiFetchOne<{ data: DamConfigAssetCustomFormElementTemp[] }>(
damClient,
END_POINT + '/distribution-service/:distributionService/element?order[position]=asc&limit=100',
{ distributionService },
Expand Down
13 changes: 8 additions & 5 deletions src/stores/coreDam/uploadQueuesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { UploadQueue, UploadQueueItem } from '@/types/coreDam/UploadQueue'
import { QueueItemStatus, QueueItemType } from '@/types/coreDam/UploadQueue'
import type { AssetFileNullable } from '@/types/coreDam/File'
import { LinkType } from '@/types/coreDam/File'
import type { AssetSearchListItemDto } from '@/types/coreDam/Asset'
import type { AssetDetailItemDto, AssetSearchListItemDto } from '@/types/coreDam/Asset'
import { AssetStatus } from '@/model/coreDam/valueObject/AssetStatus'
import { getAssetTypeByMimeType } from '@/services/upload/mimeTypeService'
import { AssetType } from '@/model/coreDam/valueObject/AssetType'
Expand All @@ -25,7 +25,6 @@ import { useCachedAuthors } from '@/views/coreDam/author/composables/cachedAutho
import { useCachedKeywords } from '@/views/coreDam/keyword/composables/cachedKeywords'
import { getAuthorConflicts, updateNewNames } from '@/services/AssetSuggestionsService'
import { useAssetDetailStore } from '@/stores/coreDam/assetDetailStore'
import type { AssetDetailItemDto } from '@/types/coreDam/Asset'
import { fileTypeFix } from '@/services/fileType'

interface State {
Expand Down Expand Up @@ -474,15 +473,19 @@ export const useUploadQueuesStore = defineStore('damUploadQueuesStore', {
},
queueItemsReplaceEmptyCustomDataValue(
queueId: string,
data: { assetType: AssetType; elementKey: string; value: any },
data: { assetType: AssetType; elementProperty: string; value: any },
forceReplace = false
) {
const items = this.queues[queueId].items
for (let i = 0; i < items.length; i++) {
const item = items[i]
if (item.assetType !== data.assetType) continue
if (forceReplace || isUndefined(item.customData[data.elementKey]) || item.customData[data.elementKey] === '') {
item.customData[data.elementKey] = data.value
if (
forceReplace ||
isUndefined(item.customData[data.elementProperty]) ||
item.customData[data.elementProperty] === ''
) {
item.customData[data.elementProperty] = data.value
}
}
},
Expand Down
11 changes: 10 additions & 1 deletion src/types/coreDam/DamConfigAssetCustomForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ export interface DamConfigAssetCustomFormAttributes {

export interface DamConfigAssetCustomFormElement extends AnzuUserAndTimeTrackingAware, ResourceNameSystemAware {
id: DocId
key: string
property: string
name: string
position: number
attributes: DamConfigAssetCustomFormAttributes
}

export interface DamConfigAssetCustomFormElementTemp extends AnzuUserAndTimeTrackingAware, ResourceNameSystemAware {
id: DocId
key?: string
property?: string
name: string
position: number
attributes: DamConfigAssetCustomFormAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const panels = ref<Array<string>>(['general'])

const uploadQueuesStore = useUploadQueuesStore()

const fillEmptyField = (data: { assetType: AssetType; elementKey: string; value: any }) => {
const fillEmptyField = (data: { assetType: AssetType; elementProperty: string; value: any }) => {
uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(props.queueId, data)
}
const replaceField = (data: { assetType: AssetType; elementKey: string; value: any }) => {
const replaceField = (data: { assetType: AssetType; elementProperty: string; value: any }) => {
uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(props.queueId, data, true)
}
const fillEmptyKeywords = () => {
Expand All @@ -44,45 +44,45 @@ const replaceAuthors = () => {
uploadQueuesStore.queueItemsReplaceEmptyAuthors(props.queueId, massOperationsAuthors.value, true)
}
const fillAll = (forceReplace = false) => {
for (const [elementKey, value] of Object.entries(massOperationsData.value.image)) {
for (const [elementProperty, value] of Object.entries(massOperationsData.value.image)) {
uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(
props.queueId,
{
assetType: AssetType.Image,
elementKey,
elementProperty,
value,
},
forceReplace
)
}
for (const [elementKey, value] of Object.entries(massOperationsData.value.video)) {
for (const [elementProperty, value] of Object.entries(massOperationsData.value.video)) {
uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(
props.queueId,
{
assetType: AssetType.Video,
elementKey,
elementProperty,
value,
},
forceReplace
)
}
for (const [elementKey, value] of Object.entries(massOperationsData.value.audio)) {
for (const [elementProperty, value] of Object.entries(massOperationsData.value.audio)) {
uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(
props.queueId,
{
assetType: AssetType.Audio,
elementKey,
elementProperty,
value,
},
forceReplace
)
}
for (const [elementKey, value] of Object.entries(massOperationsData.value.document)) {
for (const [elementProperty, value] of Object.entries(massOperationsData.value.document)) {
uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(
props.queueId,
{
assetType: AssetType.Document,
elementKey,
elementProperty,
value,
},
forceReplace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const emit = defineEmits<{
(e: 'anyChange'): void
}>()

const updateModelValue = (data: { key: string; value: any }) => {
const updateModelValue = (data: { property: string; value: any }) => {
const updated = {} as { [key: string]: any }
updated[data.key] = data.value
updated[data.property] = data.value
emit('update:modelValue', { ...props.modelValue, ...updated })
emit('anyChange')
}
Expand All @@ -42,8 +42,8 @@ const elements = computed(() => {
<VCol>
<AssetCustomMetadataElement
:config="element"
:element-key="element.key"
:model-value="modelValue[element.key]"
:element-property="element.property"
:model-value="modelValue[element.property]"
:validation-scope="AssetMetadataValidationScopeSymbol"
@update:model-value="updateModelValue"
/>
Expand Down
Loading