Skip to content

Commit

Permalink
input dam author to image widget multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
volar committed Dec 12, 2024
1 parent 4b147a2 commit 6bd6a76
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 42 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"@kyvg/vue3-notification": "^3.4.1",
"@mdi/font": "^7.4.47",
"@shikijs/vitepress-twoslash": "^1.24.2",
"@stylistic/eslint-plugin": "^2.12.0",
"@stylistic/eslint-plugin": "^2.12.1",
"@tsconfig/node18": "^18.2.4",
"@types/node": "^22.10.1",
"@types/node": "^22.10.2",
"@types/rusha": "^0.8.3",
"@types/sortablejs": "^1.15.8",
"@types/webfontloader": "^1.6.38",
Expand Down Expand Up @@ -77,7 +77,7 @@
"stylelint-config-recommended-vue": "^1.5.0",
"stylelint-config-standard-scss": "^14.0.0",
"typescript": "5.6.3",
"unplugin": "2.0.0",
"unplugin": "2.1.0",
"uuid": "^11.0.3",
"vite": "6.0.3",
"vite-plugin-dts": "4.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,33 @@ import AFormTextarea from '@/components/form/AFormTextarea.vue'
import { computed, ref } from 'vue'
import useVuelidate from '@vuelidate/core'
import { useValidate } from '@/validators/vuelidate/useValidate'
import { useImageStore } from '@/components/damImage/uploadQueue/composables/imageStore'
import ASystemEntityScope from '@/components/form/ASystemEntityScope.vue'
import AuthorRemoteAutocompleteWithCached from '@/components/damImage/uploadQueue/author/AuthorRemoteAutocompleteWithCached.vue'
import { useExtSystemIdForCached } from '@/components/damImage/uploadQueue/composables/extSystemIdForCached'
import { storeToRefs } from 'pinia'
const texts = ref({ description: '', source: '' })
const texts = ref({ description: '', source: '', authors: [] })
const { replaceEmptyDescription, replaceEmptySource } = useImageMassOperations()
const imageStore = useImageStore()
const { images } = storeToRefs(imageStore)
const { replaceEmptyDescription, replaceEmptySource, replaceEmptyAuthors } = useImageMassOperations()
const { t } = useI18n()
const fillAll = (forceReplace: boolean) => {
replaceEmptyDescription(texts.value.description, forceReplace)
replaceEmptySource(texts.value.source, forceReplace)
replaceEmptyAuthors(texts.value.authors, forceReplace)
}
const clearForm = () => {
texts.value.description = ''
texts.value.source = ''
texts.value.authors = []
}
const { cachedExtSystemId } = useExtSystemIdForCached()
const { maxLength } = useValidate()
const rules = computed(() => ({
Expand All @@ -34,6 +45,14 @@ const rules = computed(() => ({
},
}))
const v$ = useVuelidate(rules, { texts }, { $scope: false })
const showDamAuthorsAtLeastOne = computed(() => {
if (images.value.length === 0) return false
return (
images.value.length &&
images.value.some((item) => item?.showDamAuthors)
)
})
</script>

<template>
Expand Down Expand Up @@ -84,6 +103,61 @@ const v$ = useVuelidate(rules, { texts }, { $scope: false })
<VRow
dense
class="mt-1"
v-if="showDamAuthorsAtLeastOne"
>
<VCol>
<ASystemEntityScope
subject="keyword"
system="dam"
>
<div class="d-flex">
<div style="flex-grow: 1">
<AuthorRemoteAutocompleteWithCached
v-model="texts.authors"
:ext-system="cachedExtSystemId"
:label="t('common.damImage.asset.model.authors')"
clearable
multiple
:validation-scope="false"
/>
</div>
<VBtn
icon
size="small"
variant="text"
class="mr-1"
@click.stop="replaceEmptyAuthors(texts.authors, false)"
>
<VIcon icon="mdi-file-arrow-left-right-outline" />
<VTooltip
activator="parent"
location="bottom"
>
{{ t('common.damImage.asset.massOperations.fillOneEmpty') }}
</VTooltip>
</VBtn>
<VBtn
icon
size="small"
variant="text"
@click.stop="replaceEmptyAuthors(texts.authors, true)"
>
<VIcon icon="mdi-file-replace-outline" />
<VTooltip
activator="parent"
location="bottom"
>
{{ t('common.damImage.asset.massOperations.replaceOne') }}
</VTooltip>
</VBtn>
</div>
</ASystemEntityScope>
</VCol>
</VRow>
<VRow
v-else
dense
class="mt-1"
>
<VCol>
<div class="d-flex">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const fetchImagesOnLoad = async () => {
...imageRes,
...{
damAuthors: found ? found.authors : [],
showDamAuthors: found ? found.authors.length > 0 : false,
showDamAuthors: found ? found.authors.length === 0 : false,
},
}
})
Expand Down Expand Up @@ -213,7 +213,8 @@ const assetSelectConfirmMap = async (items: AssetSearchListItemDto[]): Promise<I
return items.map((asset) => {
maxPosition.value++
const description = assetMetadataMap.get(asset.id)?.description
const authorIds = assetMetadataMap.get(asset.id)?.authorIds || []
const description = assetMetadataMap.get(asset.id)?.description ?? ''
const authorNames: string[] = []
assetMetadataMap.get(asset.id)?.authorIds.forEach((authorId) => {
const name = authorsMap.get(authorId)
Expand All @@ -225,7 +226,7 @@ const assetSelectConfirmMap = async (items: AssetSearchListItemDto[]): Promise<I
return {
key: generateUUIDv1(),
texts: {
description: description ?? '',
description: description,
source: authorNames.join(', '),
},
dam: {
Expand All @@ -234,8 +235,8 @@ const assetSelectConfirmMap = async (items: AssetSearchListItemDto[]): Promise<I
licenceId: asset.licence,
},
position: maxPosition.value,
damAuthors: asset.authors,
showDamAuthors: asset.authors.length > 0,
damAuthors: authorIds,
showDamAuthors: authorIds.length === 0,
}
})
}
Expand Down Expand Up @@ -316,7 +317,7 @@ const saveImages = async () => {
return {
...item,
damAuthors: found ? found.damAuthors : item.damAuthors,
showDamAuthors: found ? found.damAuthors.length > 0 : item.damAuthors.length > 0,
showDamAuthors: found ? found.damAuthors.length === 0 : item.damAuthors.length === 0,
}
})
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const { cachedExtSystemId } = useExtSystemIdForCached()
const authorConflicts = ref<DocId[]>([])
const image = computed(() => imageStore.images[props.index])
const imageSourceRequired = computed(() => {
return !image.value.showDamAuthors
if (isNull(image.value) || isUndefined(image.value)) return true
return image.value.showDamAuthors === false
})
const { v$ } = useImageValidation(image, imageSourceRequired)
Expand Down Expand Up @@ -97,15 +98,6 @@ const removeItem = () => {
/>
</VCol>
</VRow>
<VRow dense>
<VCol>
<AFormTextarea
v-model="image.texts.source"
:label="t('common.damImage.image.model.texts.source')"
:v="v$.image.texts.source"
/>
</VCol>
</VRow>
<VRow dense v-if="image.showDamAuthors">
<VCol>
<ASystemEntityScope
Expand All @@ -125,6 +117,15 @@ const removeItem = () => {
</ASystemEntityScope>
</VCol>
</VRow>
<VRow dense v-else>
<VCol>
<AFormTextarea
v-model="image.texts.source"
:label="t('common.damImage.image.model.texts.source')"
:v="v$.image.texts.source"
/>
</VCol>
</VRow>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const metadataMap = async (
},
position: maxPosition.value,
damAuthors: authorIds || [],
showDamAuthors: !!(authorIds && authorIds.length > 0),
showDamAuthors: authorIds && authorIds.length === 0,
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { isUndefined } from '@/utils/common'
import { useImageStore } from '@/components/damImage/uploadQueue/composables/imageStore'
import type { DocId } from '@/types/common'
import { fetchAuthorListByIds } from '@/components/damImage/uploadQueue/api/authorApi'
import { useCommonAdminCoreDamOptions } from '@/components/dam/assetSelect/composables/commonAdminCoreDamOptions'
import { useExtSystemIdForCached } from '@/components/damImage/uploadQueue/composables/extSystemIdForCached'

export function useImageMassOperations() {
const imageStore = useImageStore()

const replaceEmptyDescription = (value: any, forceReplace = false) => {
const replaceEmptyDescription = (value: string, forceReplace = false) => {
const items = imageStore.images
for (let i = 0; i < items.length; i++) {
const item = items[i]
Expand All @@ -14,7 +18,7 @@ export function useImageMassOperations() {
}
}

const replaceEmptySource = (value: any, forceReplace = false) => {
const replaceEmptySource = (value: string, forceReplace = false) => {
const items = imageStore.images
for (let i = 0; i < items.length; i++) {
const item = items[i]
Expand All @@ -24,8 +28,37 @@ export function useImageMassOperations() {
}
}

const { damClient } = useCommonAdminCoreDamOptions()
const { cachedExtSystemId } = useExtSystemIdForCached()

const replaceEmptyAuthors = async (value: DocId[], forceReplace = false) => {
const authorsMap = new Map<DocId, string>()
const authorNames: string[] = []
const authorsRes = await fetchAuthorListByIds(damClient, cachedExtSystemId.value, [
...value,
])
authorsRes.forEach((author) => {
authorsMap.set(author.id, author.name)
})
value.forEach((authorId) => {
const name = authorsMap.get(authorId)
if (!isUndefined(name) && name.trim().length > 0) {
authorNames.push(name)
}
})
const items = imageStore.images
for (let i = 0; i < items.length; i++) {
const item = items[i]
if (forceReplace || isUndefined(item.damAuthors) || item.damAuthors.length === 0) {
item.damAuthors = value
item.texts.source = authorNames.join(', ')
}
}
}

return {
replaceEmptyDescription,
replaceEmptySource,
replaceEmptyAuthors,
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { computed, ref } from 'vue'
import type { ImageCreateUpdateAware, ImageStoreItem } from '@/types/ImageAware'
import { cloneDeep, isNull } from '@/utils/common'

Expand Down
2 changes: 0 additions & 2 deletions src/types/coreDam/Asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export interface AssetSearchListItemDto extends AnzuUserAndTimeTrackingAware, Re
flags: Flags
licence: IntegerId
mainFile: null | AssetFile
keywords: DocId[]
authors: DocId[]
podcasts: DocId[]
assetFileProperties: AssetFileProperties
mainFileSingleUse: Readonly<boolean | null>
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ __metadata:
"@kyvg/vue3-notification": "npm:^3.4.1"
"@mdi/font": "npm:^7.4.47"
"@shikijs/vitepress-twoslash": "npm:^1.24.2"
"@stylistic/eslint-plugin": "npm:^2.12.0"
"@stylistic/eslint-plugin": "npm:^2.12.1"
"@tsconfig/node18": "npm:^18.2.4"
"@types/node": "npm:^22.10.1"
"@types/node": "npm:^22.10.2"
"@types/rusha": "npm:^0.8.3"
"@types/sortablejs": "npm:^1.15.8"
"@types/webfontloader": "npm:^1.6.38"
Expand Down Expand Up @@ -229,7 +229,7 @@ __metadata:
stylelint-config-recommended-vue: "npm:^1.5.0"
stylelint-config-standard-scss: "npm:^14.0.0"
typescript: "npm:5.6.3"
unplugin: "npm:2.0.0"
unplugin: "npm:2.1.0"
uuid: "npm:^11.0.3"
vite: "npm:6.0.3"
vite-plugin-dts: "npm:4.3.0"
Expand Down Expand Up @@ -1649,9 +1649,9 @@ __metadata:
languageName: node
linkType: hard

"@stylistic/eslint-plugin@npm:^2.12.0":
version: 2.12.0
resolution: "@stylistic/eslint-plugin@npm:2.12.0"
"@stylistic/eslint-plugin@npm:^2.12.1":
version: 2.12.1
resolution: "@stylistic/eslint-plugin@npm:2.12.1"
dependencies:
"@typescript-eslint/utils": "npm:^8.13.0"
eslint-visitor-keys: "npm:^4.2.0"
Expand All @@ -1660,7 +1660,7 @@ __metadata:
picomatch: "npm:^4.0.2"
peerDependencies:
eslint: ">=8.40.0"
checksum: 10/a0caebcfffdc32f5e2869547ca0a942d228413da822d4692d5c30083ed7ebcda94d5cd12865d500e9db88fb4362863d4f8b00de1bf5e4a6556e6a97b1abf6290
checksum: 10/acc6a7b7cddbd7b26a32b9aded5a49193b6e7df61169845a4130d60ce38a171b8a25365b2e500d8560d29d040d5850ddaa26150a65c22213891696652f0b8d91
languageName: node
linkType: hard

Expand Down Expand Up @@ -1757,12 +1757,12 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:*, @types/node@npm:^22.10.1":
version: 22.10.1
resolution: "@types/node@npm:22.10.1"
"@types/node@npm:*, @types/node@npm:^22.10.2":
version: 22.10.2
resolution: "@types/node@npm:22.10.2"
dependencies:
undici-types: "npm:~6.20.0"
checksum: 10/c802a526da2f3fa3ccefd00a71244e7cb825329951719e79e8fec62b1dbc2855388c830489770611584665ce10be23c05ed585982038b24924e1ba2c2cce03fd
checksum: 10/451adfefed4add58b069407173e616220fd4aaa3307cdde1bb701aa053b65b54ced8483db2f870dcedec7a58cb3b06101fbc19d85852716672ec1fd3660947fa
languageName: node
linkType: hard

Expand Down Expand Up @@ -7279,13 +7279,13 @@ __metadata:
languageName: node
linkType: hard

"unplugin@npm:2.0.0":
version: 2.0.0
resolution: "unplugin@npm:2.0.0"
"unplugin@npm:2.1.0":
version: 2.1.0
resolution: "unplugin@npm:2.1.0"
dependencies:
acorn: "npm:^8.14.0"
webpack-virtual-modules: "npm:^0.6.2"
checksum: 10/6772bd118e6faa9360dbc738ba6e930b371ab5b3664f3ce22b789c974ab9d07b25a308978243f8efa0c04bdd163e85a371edcbc5a1d24ebde0f048146c452afc
checksum: 10/b01041839c25ff5b0997677e00ffe8d98aa532443833968d652c0165eab3159702c3c3d1237afa58db35af5ccf25dd0a05782d78b7c22000742797e382362bcd
languageName: node
linkType: hard

Expand Down

0 comments on commit 6bd6a76

Please sign in to comment.