-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
volar
committed
Dec 5, 2023
1 parent
d382c72
commit 388f88b
Showing
2 changed files
with
96 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/components/damImage/uploadQueue/composables/uploadQueueMassOperations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |