-
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 1, 2024
1 parent
c3b180f
commit 109653e
Showing
5 changed files
with
188 additions
and
5 deletions.
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
src/components/damImage/uploadQueue/components/ImageMassOperations.vue
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,149 @@ | ||
<script lang="ts" setup> | ||
import { useI18n } from 'vue-i18n' | ||
import { useImageMassOperations } from '@/components/damImage/uploadQueue/composables/imageMassOperations' | ||
import AFormTextarea from '@/components/form/AFormTextarea.vue' | ||
import { computed, ref } from 'vue' | ||
import useVuelidate from '@vuelidate/core' | ||
import { useValidate } from '@/validators/vuelidate/useValidate' | ||
const texts = ref({ description: '', source: '' }) | ||
const { replaceEmptyDescription, replaceEmptySource } = useImageMassOperations() | ||
const { t } = useI18n() | ||
const fillAll = (forceReplace: boolean) => { | ||
replaceEmptyDescription(texts.value.description, forceReplace) | ||
replaceEmptySource(texts.value.source, forceReplace) | ||
} | ||
const clearForm = () => { | ||
texts.value.description = '' | ||
texts.value.source = '' | ||
} | ||
const { maxLength } = useValidate() | ||
const rules = computed(() => ({ | ||
texts: { | ||
description: { | ||
maxLength: maxLength(2000), | ||
}, | ||
source: { | ||
maxLength: maxLength(255), | ||
}, | ||
}, | ||
})) | ||
const v$ = useVuelidate(rules, { texts }, { $scope: false }) | ||
</script> | ||
|
||
<template> | ||
<div class="w-100"> | ||
<VRow | ||
dense | ||
class="mt-1" | ||
> | ||
<VCol> | ||
<div class="d-flex"> | ||
<AFormTextarea | ||
:v="v$" | ||
:label="t('common.damImage.image.model.texts.description')" | ||
v-model="texts.description" | ||
/> | ||
<VBtn | ||
icon | ||
size="small" | ||
variant="text" | ||
class="mr-1" | ||
@click.stop="replaceEmptyDescription(texts.description, 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="replaceEmptyDescription(texts.description, true)" | ||
> | ||
<VIcon icon="mdi-file-replace-outline" /> | ||
<VTooltip | ||
activator="parent" | ||
location="bottom" | ||
> | ||
{{ t('common.damImage.asset.massOperations.replaceOne') }} | ||
</VTooltip> | ||
</VBtn> | ||
</div> | ||
</VCol> | ||
</VRow> | ||
<VRow | ||
dense | ||
class="mt-1" | ||
> | ||
<VCol> | ||
<div class="d-flex"> | ||
<AFormTextarea v-model="texts.source" /> | ||
<VBtn | ||
icon | ||
size="small" | ||
variant="text" | ||
class="mr-1" | ||
@click.stop="replaceEmptySource(texts.source, 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="replaceEmptySource(texts.source, true)" | ||
> | ||
<VIcon icon="mdi-file-replace-outline" /> | ||
<VTooltip | ||
activator="parent" | ||
location="bottom" | ||
> | ||
{{ t('common.damImage.asset.massOperations.replaceOne') }} | ||
</VTooltip> | ||
</VBtn> | ||
</div> | ||
</VCol> | ||
</VRow> | ||
<div class="sidebar-info__actions pa-2 d-flex align-center justify-center"> | ||
<VBtn | ||
class="mr-2" | ||
variant="text" | ||
size="small" | ||
@click.stop="fillAll(false)" | ||
> | ||
{{ t('common.damImage.asset.massOperations.fillAllEmpty') }} | ||
</VBtn> | ||
<VBtn | ||
class="mr-2" | ||
variant="text" | ||
size="small" | ||
@click.stop="fillAll(true)" | ||
> | ||
{{ t('common.damImage.asset.massOperations.replaceAll') }} | ||
</VBtn> | ||
<VBtn | ||
variant="text" | ||
size="small" | ||
@click.stop="clearForm" | ||
> | ||
{{ t('common.damImage.asset.massOperations.clearForm') }} | ||
</VBtn> | ||
</div> | ||
</div> | ||
</template> |
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
31 changes: 31 additions & 0 deletions
31
src/components/damImage/uploadQueue/composables/imageMassOperations.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,31 @@ | ||
import { isUndefined } from '@/utils/common' | ||
import { useImageStore } from '@/components/damImage/uploadQueue/composables/imageStore' | ||
|
||
export function useImageMassOperations() { | ||
const imageStore = useImageStore() | ||
|
||
const replaceEmptyDescription = (value: any, forceReplace = false) => { | ||
const items = imageStore.images | ||
for (let i = 0; i < items.length; i++) { | ||
const item = items[i] | ||
if (forceReplace || isUndefined(item.texts.description) || item.texts.description.length === 0) { | ||
item.texts.description = value | ||
} | ||
} | ||
} | ||
|
||
const replaceEmptySource = (value: any, forceReplace = false) => { | ||
const items = imageStore.images | ||
for (let i = 0; i < items.length; i++) { | ||
const item = items[i] | ||
if (forceReplace || isUndefined(item.texts.source) || item.texts.source.length === 0) { | ||
item.texts.source = value | ||
} | ||
} | ||
} | ||
|
||
return { | ||
replaceEmptyDescription, | ||
replaceEmptySource, | ||
} | ||
} |
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
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