Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
volar committed Dec 5, 2023
1 parent d382c72 commit 388f88b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ASystemEntityScope from '@/components/form/ASystemEntityScope.vue'
import AssetCustomMetadataFormMassOperations from '@/components/damImage/uploadQueue/components/AssetCustomMetadataFormMassOperations.vue'
import AuthorRemoteAutocompleteWithCached from '@/components/damImage/uploadQueue/author/AuthorRemoteAutocompleteWithCached.vue'
import KeywordRemoteAutocompleteWithCached from '@/components/damImage/uploadQueue/keyword/KeywordRemoteAutocompleteWithCached.vue'
import { useUploadQueueMassOperations } from '@/components/damImage/uploadQueue/composables/uploadQueueMassOperations'
const props = withDefaults(
defineProps<{
Expand All @@ -25,68 +26,69 @@ const panels = ref<Array<string>>(['general'])
const uploadQueuesStore = useUploadQueuesStore()
// eslint-disable-next-line vue/no-setup-props-reactivity-loss
const { replaceEmptyCustomDataValue, replaceEmptyAuthors, replaceEmptyKeywords } = useUploadQueueMassOperations(
props.queueKey
)
const fillEmptyField = (data: { assetType: DamAssetType; elementProperty: string; value: any }) => {
// uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(props.queueId, data)
replaceEmptyCustomDataValue(data)
}
const replaceField = (data: { assetType: DamAssetType; elementProperty: string; value: any }) => {
// uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(props.queueId, data, true)
replaceEmptyCustomDataValue(data, true)
}
const fillEmptyKeywords = () => {
// uploadQueuesStore.queueItemsReplaceEmptyKeywords(props.queueId, massOperationsKeywords.value)
replaceEmptyKeywords(massOperationsKeywords.value)
}
const replaceKeywords = () => {
// uploadQueuesStore.queueItemsReplaceEmptyKeywords(props.queueId, massOperationsKeywords.value, true)
replaceEmptyKeywords(massOperationsKeywords.value, true)
}
const fillEmptyAuthors = () => {
// uploadQueuesStore.queueItemsReplaceEmptyAuthors(props.queueId, massOperationsAuthors.value)
replaceEmptyAuthors(massOperationsAuthors.value)
}
const replaceAuthors = () => {
// uploadQueuesStore.queueItemsReplaceEmptyAuthors(props.queueId, massOperationsAuthors.value, true)
replaceEmptyAuthors(massOperationsAuthors.value, true)
}
const fillAll = (forceReplace = false) => {
for (const [elementProperty, value] of Object.entries(massOperationsData.value.image)) {
// uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(
// props.queueId,
// {
// assetType: DamAssetType.Image,
// elementProperty,
// value,
// },
// forceReplace
// )
replaceEmptyCustomDataValue(
{
assetType: DamAssetType.Image,
elementProperty,
value,
},
forceReplace
)
}
for (const [elementProperty, value] of Object.entries(massOperationsData.value.video)) {
// uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(
// props.queueId,
// {
// assetType: DamAssetType.Video,
// elementProperty,
// value,
// },
// forceReplace
// )
replaceEmptyCustomDataValue(
{
assetType: DamAssetType.Video,
elementProperty,
value,
},
forceReplace
)
}
for (const [elementProperty, value] of Object.entries(massOperationsData.value.audio)) {
// uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(
// props.queueId,
// {
// assetType: DamAssetType.Audio,
// elementProperty,
// value,
// },
// forceReplace
// )
replaceEmptyCustomDataValue(
{
assetType: DamAssetType.Audio,
elementProperty,
value,
},
forceReplace
)
}
for (const [elementProperty, value] of Object.entries(massOperationsData.value.document)) {
// uploadQueuesStore.queueItemsReplaceEmptyCustomDataValue(
// props.queueId,
// {
// assetType: DamAssetType.Document,
// elementProperty,
// value,
// },
// forceReplace
// )
replaceEmptyCustomDataValue(
{
assetType: DamAssetType.Document,
elementProperty,
value,
},
forceReplace
)
}
if (forceReplace) {
replaceAuthors()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { UploadQueueKey } from '@/types/coreDam/UploadQueue'
import { useUploadQueuesStore } from '@/components/damImage/uploadQueue/composables/uploadQueuesStore'
import type { DamAssetType } from '@/types/coreDam/Asset'
import { isUndefined } from '@/utils/common'

export function useUploadQueueMassOperations(queueKey: UploadQueueKey) {
const uploadQueuesStore = useUploadQueuesStore()

const replaceEmptyCustomDataValue = (
data: { assetType: DamAssetType; elementProperty: string; value: any },
forceReplace = false
) => {
const items = uploadQueuesStore.getQueueItems(queueKey)
for (let i = 0; i < items.length; i++) {
const item = items[i]
if (item.assetType !== data.assetType) continue
if (
forceReplace ||
isUndefined(item.customData[data.elementProperty]) ||
item.customData[data.elementProperty] === ''
) {
item.customData[data.elementProperty] = data.value
}
}
}

const replaceEmptyKeywords = (value: any, forceReplace = false) => {
const items = uploadQueuesStore.getQueueItems(queueKey)
for (let i = 0; i < items.length; i++) {
const item = items[i]
if (forceReplace || isUndefined(item.keywords) || item.keywords.length === 0) {
item.keywords = value
}
}
}

const replaceEmptyAuthors = (value: any, forceReplace = false) => {
const items = uploadQueuesStore.getQueueItems(queueKey)
for (let i = 0; i < items.length; i++) {
const item = items[i]
if (forceReplace || isUndefined(item.authors) || item.authors.length === 0) {
item.authors = value
}
}
}

return {
replaceEmptyCustomDataValue,
replaceEmptyKeywords,
replaceEmptyAuthors,
}
}

0 comments on commit 388f88b

Please sign in to comment.