@anzusystems/common-admin 2.0.0-rc.28 → 2.0.0-rc.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/domains/dam/api/damAssetApi.d.ts +12 -1
- package/dist/domains/dam/api/damAssetApi.js +151 -95
- package/dist/domains/dam/api/damAssetApi.js.map +1 -1
- package/dist/domains/dam/api/damMetadataOnServer.d.ts +35 -0
- package/dist/domains/dam/api/damMetadataOnServer.js +28 -0
- package/dist/domains/dam/api/damMetadataOnServer.js.map +1 -0
- package/dist/domains/dam/assetDetail/components/AssetDetailSidebarMetadata.vue.js +26 -25
- package/dist/domains/dam/assetDetail/components/AssetDetailSidebarMetadata.vue.js.map +1 -1
- package/dist/domains/dam/assetDetail/store/assetDetailStore.js +40 -39
- package/dist/domains/dam/assetDetail/store/assetDetailStore.js.map +1 -1
- package/dist/domains/dam/cropper/components/ACropper.vue.d.ts +1 -1
- package/dist/domains/dam/cropper/components/ACropper.vue.js +153 -136
- package/dist/domains/dam/cropper/components/ACropper.vue.js.map +1 -1
- package/dist/domains/dam/imageWidget/components/AImageMediaWidget.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/AImagePublicInput.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/AImageWidget.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/AImageWidgetMultiple.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/ImageMediaWidgetInner.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/ImageWidgetInner.vue.d.ts +1 -1
- package/dist/domains/dam/imageWidget/components/ImageWidgetMultipleInner.vue.d.ts +1 -1
- package/dist/domains/dam/uploadQueue/components/UploadQueueDialog.vue.js +106 -106
- package/dist/domains/dam/uploadQueue/components/UploadQueueDialog.vue.js.map +1 -1
- package/dist/domains/dam/uploadQueue/components/UploadQueueDialogSingle.vue.js +13 -13
- package/dist/domains/dam/uploadQueue/components/UploadQueueDialogSingle.vue.js.map +1 -1
- package/dist/domains/dam/uploadQueue/settlement/uploadSettle.js +115 -114
- package/dist/domains/dam/uploadQueue/settlement/uploadSettle.js.map +1 -1
- package/dist/domains/dam/uploadQueue/store/uploadQueuesStore.js +147 -143
- package/dist/domains/dam/uploadQueue/store/uploadQueuesStore.js.map +1 -1
- package/dist/domains/filters/components/FiltersSelected.vue.js +5 -5
- package/dist/domains/filters/components/FiltersSelected.vue.js.map +1 -1
- package/dist/domains/filters/composables/filterFactory.js +41 -38
- package/dist/domains/filters/composables/filterFactory.js.map +1 -1
- package/dist/domains/remoteAutocomplete/components/AFormRemoteAutocomplete.vue.js +46 -38
- package/dist/domains/remoteAutocomplete/components/AFormRemoteAutocomplete.vue.js.map +1 -1
- package/dist/domains/system/composables/alerts.js +8 -2
- package/dist/domains/system/composables/alerts.js.map +1 -1
- package/dist/domains/system/systemBar/utils/appReload.d.ts +9 -1
- package/dist/domains/system/systemBar/utils/appReload.js +3 -3
- package/dist/domains/system/systemBar/utils/appReload.js.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadQueuesStore.js","names":["requestedUrl","apiErrorIsReported","apiErrorStatus","mapApiError","report","useCommonAdminCoreDamOptions","ENTITY","fetchAsset","fetchAssetByFileId","fetchAssetListByIds","SYSTEM_CORE_DAM","useDamCachedAuthors","useUploadQueueItemFactory","useAssetSuggestions","useDamConfigState","useDamNotifications","useDamNotificationsConnection","DamNotificationName","getAssetTypeByMimeType","UPLOAD_QUEUE_ITEM_CHUNK_SIZE","createUploadQueueCore","libraryQueuePreset","UploadRowRole","useDamCachedKeywords","damFileTypeFix","DamAssetType","UploadQueueItemStatus","UploadQueueItemType","AnzuApiResponseCodeError","cloneDeep","isArray","isString","isUndefined","commonT","defineStore","getCurrentScope","ref","editableFieldsOf","item","sameValue","one","other","writeUnchanged","was","saved","kept","unchanged","field","customData","now","then","key","takeWrite","note","entry","written","noted","useUploadQueuesStore","queues","createDefault","configNames","configOf","queueKey","damOf","profile","row","target","assetId","options","damClient","endPointAsset","error","licenceId","assetIds","failure","answer","url","context","originFileId","ids","core","settlement","addRowUnder","configName","known","storeScope","toSettlementEvent","event","addDamNotificationListener","listening","listenToNotifications","listen","origin","settlementEvent","addByCopyToLicence","extSystem","assetLicence","assets","getDamConfigExtSystem","configExtSystem","queueItem","added","addByFiles","files","file","type","targetOf","of","queueItemProcessed","queueItemFullyProcessed","queueItemDuplicate","originAssetFile","assetType","queueItemFailed","failReason","refreshAsset","stopItemUpload","_index","detailWrites","detailWriteKey","lastDetailWrite","openNotes","noteRowsOfAsset","rows","queue","forgetRowsNote","othersTakeWrite","own","updateFromDetail","asset","mainFileSingleUse","rowsAtSave","updateNewNames","getAuthorConflicts","dam","addToCachedKeywords","fetchCachedKeywords","addToCachedAuthors","fetchCachedAuthors","queuesOfConfig","before","turn","writeKey","isLatest","assetRes"],"sources":["../../../../../src/domains/dam/uploadQueue/store/uploadQueuesStore.ts"],"sourcesContent":["import { requestedUrl } from '@/domains/api/composables/request'\nimport { apiErrorIsReported, apiErrorStatus, mapApiError, report } from '@/domains/api/utils/apiErrors'\nimport { useCommonAdminCoreDamOptions } from '@/domains/dam/composables/commonAdminCoreDamOptions'\nimport { ENTITY, fetchAsset, fetchAssetByFileId, fetchAssetListByIds } from '@/domains/dam/api/damAssetApi'\nimport { SYSTEM_CORE_DAM } from '@/domains/dam/api/damConstants'\nimport { useDamCachedAuthors } from '@/domains/dam/author/composables/cachedAuthors'\nimport { useUploadQueueItemFactory } from '@/domains/dam/uploadQueue/factory/UploadQueueItemFactory'\nimport { useAssetSuggestions } from '@/domains/dam/uploadQueue/composables/assetSuggestions'\nimport { useDamConfigState } from '@/domains/dam/config/composables/damConfigState'\nimport { useDamNotifications } from '@/domains/dam/composables/damNotifications'\nimport { useDamNotificationsConnection } from '@/domains/dam/composables/damNotificationsConnection'\nimport { type DamNotification, DamNotificationName } from '@/domains/dam/composables/damNotificationsEventBus'\nimport { getAssetTypeByMimeType } from '@/domains/dam/uploadQueue/utils/mimeTypeHelper'\nimport { createUploadQueueCore, UPLOAD_QUEUE_ITEM_CHUNK_SIZE } from '@/domains/dam/uploadQueue/core/uploadQueueCore'\nimport type { UploadQueueSettlementProfile } from '@/domains/dam/uploadQueue/core/uploadQueueCoreTypes'\nimport { libraryQueuePreset } from '@/domains/dam/uploadQueue/presets/queuePresets'\nimport {\n type UploadReadOptions,\n type UploadRefreshOutcome,\n UploadRowRole,\n type UploadSettlementEvent,\n} from '@/domains/dam/uploadQueue/settlement/uploadSettlementTypes'\nimport { useDamCachedKeywords } from '@/domains/dam/keyword/composables/cachedKeywords'\nimport { damFileTypeFix } from '@/domains/ui/file/utils/fileType'\nimport type { AxiosRequestConfig } from 'axios'\nimport type { DocId, DocIdNullable, IntegerId } from '@/shared/types/common'\nimport { type AssetDetailItemDto, DamAssetType, type DamAssetTypeType } from '@/domains/dam/types/Asset'\nimport type { AssetFileFailReasonType } from '@/domains/dam/types/AssetFile'\nimport {\n type UploadQueue,\n type UploadQueueItem,\n UploadQueueItemStatus,\n UploadQueueItemType,\n type UploadQueueKey,\n} from '@/domains/dam/types/UploadQueue'\nimport { AnzuApiResponseCodeError } from '@/shared/error/AnzuApiResponseCodeError'\nimport { cloneDeep, isArray, isString, isUndefined } from '@/shared/utils/common'\nimport { commonT } from '@/plugins/i18n'\nimport { defineStore } from 'pinia'\nimport { getCurrentScope, ref } from 'vue'\n\n/** Fields the user edits and a detail save writes. */\nexport interface EditableFields {\n keywords: DocId[]\n authors: DocId[]\n sources: DocId[]\n customData: UploadQueueItem['customData']\n mainFileSingleUse: boolean | null | undefined\n}\n\nconst editableFieldsOf = (item: UploadQueueItem): EditableFields =>\n cloneDeep({\n keywords: item.keywords,\n authors: item.authors,\n sources: item.sources,\n customData: item.customData,\n mainFileSingleUse: item.mainFileSingleUse,\n })\n\nconst sameValue = (one: unknown, other: unknown) => JSON.stringify(one) === JSON.stringify(other)\n\n/** Field-by-field snapshot of an asset's rows (`noteRowsOfAsset`). */\nexport interface RowsNote {\n assetId: DocId\n /** DAM configuration of the queues the rows are in. */\n configName: string\n rows: Map<UploadQueueItem, EditableFields>\n}\n\n/**\n * Which rows a settle function targets: queues of the named DAM configuration, or of the configuration of `queueKey`.\n * Required because two DAMs may share an asset id.\n */\nexport type UploadQueueRowsOf = string | { queueKey: UploadQueueKey }\n\n/** What a write left as the user had changed it: these fields and these custom data keys. */\ninterface KeptByWrite {\n fields: Set<'keywords' | 'authors' | 'sources' | 'mainFileSingleUse'>\n customKeys: Set<string>\n}\n\n/**\n * Writes the saved detail into a row of its asset. Each row gets its own copies.\n * A field the user changed since `was` (the row when save was pressed)\n * keeps the user's value. Custom data keys are compared one by one.\n * A row unknown to `was` (it became a row of the asset meanwhile)\n * takes everything. `mainFileSingleUse` undefined is left as is.\n * Returns what it kept.\n */\nconst writeUnchanged = (item: UploadQueueItem, was: EditableFields | undefined, saved: EditableFields) => {\n const kept: KeptByWrite = { fields: new Set(), customKeys: new Set() }\n const unchanged = (field: 'keywords' | 'authors' | 'sources' | 'mainFileSingleUse') => {\n if (!was || sameValue(item[field], was[field])) return true\n kept.fields.add(field)\n return false\n }\n if (unchanged('keywords')) item.keywords = [...saved.keywords]\n if (unchanged('authors')) item.authors = [...saved.authors]\n if (unchanged('sources')) item.sources = [...(saved.sources ?? [])]\n const customData = cloneDeep(saved.customData)\n if (was && customData) {\n const now = item.customData ?? {}\n const then = was.customData ?? {}\n new Set([...Object.keys(now), ...Object.keys(then)]).forEach((key) => {\n if (sameValue(now[key], then[key])) return\n kept.customKeys.add(key)\n if (key in now) customData[key] = cloneDeep(now[key])\n else delete customData[key]\n })\n }\n item.customData = customData\n if (isUndefined(saved.mainFileSingleUse)) kept.fields.add('mainFileSingleUse')\n else if (unchanged('mainFileSingleUse')) item.mainFileSingleUse = saved.mainFileSingleUse\n return kept\n}\n\n/**\n * Another pending save of the same asset takes over what a write just put into `item`.\n * That value is not a user change. Otherwise the later save would keep the earlier save's values.\n */\nconst takeWrite = (note: RowsNote, item: UploadQueueItem, kept: KeptByWrite) => {\n const entry = note.rows.get(item)\n if (!entry) return\n if (!kept.fields.has('keywords')) entry.keywords = [...item.keywords]\n if (!kept.fields.has('authors')) entry.authors = [...item.authors]\n if (!kept.fields.has('sources')) entry.sources = [...(item.sources ?? [])]\n if (!kept.fields.has('mainFileSingleUse')) entry.mainFileSingleUse = item.mainFileSingleUse\n const written = item.customData ?? {}\n const noted = (entry.customData = { ...entry.customData })\n new Set([...Object.keys(written), ...Object.keys(noted)]).forEach((key) => {\n if (kept.customKeys.has(key)) return\n if (key in written) noted[key] = cloneDeep(written[key])\n else delete noted[key]\n })\n}\n\nexport const useUploadQueuesStore = defineStore('commonAdminUploadQueuesStore', () => {\n const queues = ref<Map<UploadQueueKey, UploadQueue>>(new Map())\n\n const { createDefault } = useUploadQueueItemFactory()\n\n // The DAM configuration each queue was created under. Its files are sent\n // and its rows read with that configuration's client and endpoints.\n // A queue without a given name uses `default`.\n const configNames = new Map<UploadQueueKey, string>()\n const configOf = (queueKey?: UploadQueueKey) =>\n (isUndefined(queueKey) ? undefined : configNames.get(queueKey)) ?? 'default'\n // Resolved per request, from the queue it is for.\n const damOf = (queueKey?: UploadQueueKey) => useCommonAdminCoreDamOptions(configOf(queueKey))\n\n // The poll repeats while a row waits. The settlement decides per request\n // whether a failure starts a streak, and only that one is reported.\n\n // A missing asset is an answer the settlement counts. Anything else is a failed read.\n const readAsset = async (assetId: DocId, options?: UploadReadOptions) => {\n const { damClient, endPointAsset } = damOf(options?.queueKey)\n try {\n return options?.report === false\n ? await fetchAsset(damClient, endPointAsset, assetId, { report: false })\n : await fetchAsset(damClient, endPointAsset, assetId)\n } catch (error) {\n if (apiErrorStatus(error) === 404) return null\n throw error\n }\n }\n\n // The list request reports nothing by itself. A reported failure is\n // rethrown as reported, so the settlement can check whether it was logged.\n const readAssets = async (licenceId: IntegerId, assetIds: DocId[], options?: UploadReadOptions) => {\n const { damClient, endPointAsset } = damOf(options?.queueKey)\n try {\n return await fetchAssetListByIds(damClient, endPointAsset, assetIds, licenceId)\n } catch (failure) {\n if (options?.report) {\n // An answer without an asset list is rejected like the failed answers.\n const answer = isArray<{ status?: number; config?: AxiosRequestConfig }>(failure) ? failure.at(-1) : undefined\n const url = `${endPointAsset}/licence/${licenceId}/ids/${assetIds.join(',')}`\n const context = {\n system: SYSTEM_CORE_DAM,\n entity: ENTITY,\n // The URL as sent, with the client's base address, when axios kept the config.\n url: requestedUrl(damClient, url, {}, failure, answer?.config),\n }\n const error = isArray(failure) ? new AnzuApiResponseCodeError(answer?.status ?? 0) : failure\n throw report(mapApiError(error, context), context)\n }\n throw failure\n }\n }\n\n // Handles a row once its file is on the server. The queue poll,\n // notifications and the refresh button all go through here.\n // The core counts the queue, starts the next row after a final\n // state, and keeps failed rows a refresh may still change.\n const profile: UploadQueueSettlementProfile = {\n roleOf: (row) => (row.type === UploadQueueItemType.Asset ? UploadRowRole.Copy : UploadRowRole.Upload),\n policyFor: () => ({ reader: 'asset', settleOn: 'read', duplicate: 'becomeOriginal', metadata: 'load' }),\n // Matched by asset only, whatever file an event names.\n matches: (row, target) => row.assetId === target.assetId,\n readers: {\n asset: readAsset,\n assets: readAssets,\n duplicateOriginAsset: async (originFileId, options) => {\n const { damClient, endPointAsset } = damOf(options?.queueKey)\n return fetchAssetByFileId(damClient, endPointAsset, originFileId)\n },\n failureReported: apiErrorIsReported,\n },\n // Two DAMs may use the same asset id, so rows are settled only within the queues of their configuration.\n configOf,\n // Names of a queue's rows come from the DAM of its configuration.\n caches: {\n addAuthors: (ids, queueKey) => useDamCachedAuthors(configOf(queueKey)).addToCachedAuthors(ids),\n addKeywords: (ids, queueKey) => useDamCachedKeywords(configOf(queueKey)).addToCachedKeywords(ids),\n fetchAuthors: (queueKey) => useDamCachedAuthors(configOf(queueKey)).fetchCachedAuthors(),\n fetchKeywords: (queueKey) => useDamCachedKeywords(configOf(queueKey)).fetchCachedKeywords(),\n },\n messages: {\n processingTooLong: () => commonT('common.damImage.uploadErrors.processingTooLong'),\n readFailed: () => commonT('common.damImage.uploadErrors.readFailed'),\n assetMissing: () => commonT('common.damImage.uploadErrors.unknownError'),\n assetGone: () => commonT('common.damImage.queueItem.assetGone'),\n },\n // Uses the socket of the queue's configuration. A configuration without a socket is polled more often.\n connection: {\n isPushAlive: (queueKey) => useDamNotificationsConnection(configOf(queueKey)).isPushAlive(),\n onChange: useDamNotificationsConnection().onChange,\n },\n }\n\n // Created in the store's scope, so a disposed store leaves no poll timer and no tab or socket listener.\n const core = createUploadQueueCore(libraryQueuePreset({ queues, settlement: profile, configOf }))\n const { settlement } = core\n\n // A queue key belongs to one widget and so to one configuration. A queue with\n // rows refuses another configuration name instead of sending under its own.\n // The name is set together with the row, with no await in between.\n // Of two overlapping adds, the first row in the queue sets the name.\n function addRowUnder(queueKey: UploadQueueKey, configName: string, item: UploadQueueItem) {\n const known = configNames.get(queueKey)\n if (!isUndefined(known) && known !== configName && core.getQueueItems(queueKey).length > 0) {\n throw new Error(\n `useUploadQueuesStore: the queue \"${queueKey}\" has rows under the DAM configuration \"${known}\", none is added under \"${configName}\".`\n )\n }\n configNames.set(queueKey, configName)\n core.addRow(queueKey, item)\n }\n\n const storeScope = getCurrentScope()\n\n // The file a notification names is dropped. Rows match by asset only,\n // and a read for a non-main file would take that file's state unchecked.\n // `configNames`: configurations of the socket it came through. Only their queues are affected.\n const toSettlementEvent = (event: DamNotification, configNames: string[]): UploadSettlementEvent | null => {\n switch (event.name) {\n case DamNotificationName.AssetFileProcessed:\n return { kind: 'processed', assetId: event.data.asset, fileId: null, configNames }\n case DamNotificationName.AssetFileFailed:\n return {\n kind: 'failed',\n assetId: event.data.asset,\n fileId: null,\n failReason: event.data.failReason,\n configNames,\n }\n case DamNotificationName.AssetFileDuplicate:\n return {\n kind: 'duplicate',\n assetId: event.data.asset,\n fileId: null,\n originAssetFile: event.data.originAssetFile,\n assetType: event.data.assetType,\n configNames,\n }\n case DamNotificationName.AssetMetadataProcessed:\n return { kind: 'metadata', assetId: event.data.asset, fileId: null, configNames }\n case DamNotificationName.AssetFileCopied:\n return { kind: 'copied', assetId: event.data.asset, fileId: null, configNames }\n }\n return null\n }\n\n const { addDamNotificationListener } = useDamNotifications()\n // Starts with the first row, not with the store. An application with its own queue store\n // keeps this one alive too, and both would answer every notification. Never removed.\n let listening = false\n function listenToNotifications() {\n if (listening) return\n listening = true\n // Listens on every socket of the page. An event concerns only the queues of its socket's configurations.\n const listen = () =>\n addDamNotificationListener(\n (event, origin) => {\n const settlementEvent = toSettlementEvent(event, origin)\n // Not awaited: the read it triggers happens later.\n if (settlementEvent) void settlement.notify(settlementEvent)\n },\n { all: true }\n )\n // Run in the store's scope. The first row is added from a component,\n // and a listener in that component's scope would be disposed with it.\n if (storeScope) storeScope.run(listen)\n else listen()\n }\n\n async function addByCopyToLicence(\n queueKey: UploadQueueKey,\n extSystem: IntegerId,\n assetLicence: IntegerId,\n assets: DocId[],\n configName: string\n ) {\n // Throws here for an unknown configuration, before anything is done, so its DAM config store is not created.\n useCommonAdminCoreDamOptions(configName)\n const { getDamConfigExtSystem } = useDamConfigState(undefined, configName)\n\n const configExtSystem = getDamConfigExtSystem(extSystem)\n if (isUndefined(configExtSystem)) {\n throw new Error('useUploadQueuesStore.addByCopyToLicence: Ext system must be initialised.')\n }\n listenToNotifications()\n for (const assetId of assets) {\n const queueItem = createDefault(\n core.uniqueKey('asset_' + assetId),\n UploadQueueItemType.Asset,\n UploadQueueItemStatus.Processing,\n DamAssetType.Image, // only image now\n UPLOAD_QUEUE_ITEM_CHUNK_SIZE,\n assetLicence\n )\n queueItem.assetId = assetId\n addRowUnder(queueKey, configName, queueItem)\n // Nothing is uploaded for a copy. It waits for the server from the start.\n const added = core.getQueueItems(queueKey).at(-1)\n if (added) core.track(queueKey, added)\n }\n }\n\n async function addByFiles(\n queueKey: UploadQueueKey,\n extSystem: IntegerId,\n assetLicence: IntegerId,\n files: File[],\n configName: string\n ) {\n // Throws here for an unknown configuration, before anything is done, so its DAM config store is not created.\n useCommonAdminCoreDamOptions(configName)\n const { getDamConfigExtSystem } = useDamConfigState(undefined, configName)\n\n const configExtSystem = getDamConfigExtSystem(extSystem)\n if (isUndefined(configExtSystem)) {\n throw new Error('useUploadQueuesStore.addByFiles: Ext system must be initialised.')\n }\n listenToNotifications()\n for await (const file of files) {\n const type = getAssetTypeByMimeType(damFileTypeFix(file), configExtSystem)\n if (!type || type !== DamAssetType.Image) continue // only image now\n const queueItem = createDefault(\n core.uniqueKey('file_' + file.name),\n UploadQueueItemType.File,\n UploadQueueItemStatus.Waiting,\n type,\n UPLOAD_QUEUE_ITEM_CHUNK_SIZE,\n assetLicence\n )\n queueItem.file = file\n queueItem.displayTitle = file.name\n addRowUnder(queueKey, configName, queueItem)\n }\n }\n\n // Legacy names kept for callers until the queues are unified. `of`:\n // whose rows they settle, read with that configuration's client.\n\n const targetOf = (assetId: DocId, of: UploadQueueRowsOf) => ({\n assetId,\n fileId: null,\n configNames: [isString(of) ? of : configOf(of.queueKey)],\n })\n\n function queueItemProcessed(assetId: DocId, of: UploadQueueRowsOf) {\n return settlement.notify({ kind: 'processed', ...targetOf(assetId, of) })\n }\n\n function queueItemFullyProcessed(assetId: DocId, of: UploadQueueRowsOf) {\n return settlement.settleKnownProcessed(targetOf(assetId, of), { withMetadata: true })\n }\n\n function queueItemDuplicate(\n assetId: DocId,\n originAssetFile: DocIdNullable,\n assetType: DamAssetTypeType | null,\n of: UploadQueueRowsOf\n ) {\n return settlement.settleKnownDuplicate(targetOf(assetId, of), originAssetFile, assetType)\n }\n\n async function queueItemFailed(assetId: DocId, failReason: AssetFileFailReasonType, of: UploadQueueRowsOf) {\n settlement.settleKnownFailed(targetOf(assetId, of), failReason)\n }\n\n /** Row refresh button: reads the file's current state and settles the asset's rows by it. */\n function refreshAsset(assetId: DocId, of: UploadQueueRowsOf): Promise<UploadRefreshOutcome> {\n return settlement.refreshAsset(targetOf(assetId, of))\n }\n\n async function stopItemUpload(queueKey: UploadQueueKey, queueItem: UploadQueueItem, _index?: number) {\n core.stopItemUpload(queueKey, queueItem)\n }\n\n // Pending detail-save writes per configuration and asset. Only the latest one writes.\n // Otherwise overlapping saves left rows with whichever read\n // answered last, and the later save kept the earlier values.\n // Two DAMs may share an asset id, so saves under two configurations concern two assets.\n const detailWrites = new Map<string, number>()\n const detailWriteKey = (configName: string, assetId: DocId) => `${configName}\\u0000${assetId}`\n // Write numbers come from one global counter and are never reused.\n // A per-asset counter let a third save reuse the first save's\n // number, and the first save's late read wrote over the third.\n let lastDetailWrite = 0\n\n // Notes of pending detail saves. A write updates the other notes.\n const openNotes = new Set<RowsNote>()\n\n /**\n * Snapshots the rows of `assetId` in every queue of `configName`, field by field, when a detail save is pressed.\n * Pass it to `updateFromDetail` on success or to `forgetRowsNote` on failure.\n */\n function noteRowsOfAsset(assetId: DocId, configName: string): RowsNote {\n const rows = new Map<UploadQueueItem, EditableFields>()\n queues.value.forEach((queue, queueKey) => {\n if (configOf(queueKey) !== configName) return\n queue.items.forEach((item) => {\n if (item.assetId === assetId && item.type) rows.set(item, editableFieldsOf(item))\n })\n })\n const note = { assetId, configName, rows }\n openNotes.add(note)\n return note\n }\n\n /** The save for this note failed. Nothing is written from it. */\n function forgetRowsNote(note: RowsNote) {\n openNotes.delete(note)\n }\n\n /**\n * `kept`: what the write into `item` left as the user had it.\n * Every other note of that asset and configuration takes the rest.\n */\n const othersTakeWrite = (own: RowsNote, item: UploadQueueItem, kept: KeptByWrite) => {\n openNotes.forEach((note) => {\n if (note === own || note.assetId !== own.assetId) return\n if (note.configName === own.configName) takeWrite(note, item, kept)\n })\n }\n\n /**\n * `configName`: the DAM configuration the detail was saved under.\n * Only its queues are written, and names go to its caches.\n * `mainFileSingleUse`: the switch saved with the detail. `rowsAtSave`: the\n * rows when save was pressed (`noteRowsOfAsset`); current rows if omitted.\n * A field the user changed since keeps the user's value, custom data\n * keys each on their own. Unchanged fields take the saved values.\n * Of two concurrent writes of one asset under one configuration, only the later one writes.\n */\n async function updateFromDetail(\n asset: AssetDetailItemDto,\n configName: string,\n mainFileSingleUse?: boolean | null,\n rowsAtSave?: RowsNote\n ) {\n const { updateNewNames, getAuthorConflicts } = useAssetSuggestions()\n let dam: ReturnType<typeof useCommonAdminCoreDamOptions>\n try {\n dam = useCommonAdminCoreDamOptions(configName)\n } catch (e) {\n // Unknown configuration name: rows are left alone silently.\n return\n }\n const { addToCachedKeywords, fetchCachedKeywords } = useDamCachedKeywords(configName)\n const { addToCachedAuthors, fetchCachedAuthors } = useDamCachedAuthors(configName)\n // Only this configuration's queues: another DAM may have an asset with the same id.\n const queuesOfConfig = () =>\n Array.from(queues.value.entries()).filter(([queueKey]) => configOf(queueKey) === configName)\n // A detail opened from a row keeps notifying the queue even when no queue has a row of the\n // asset. Then there is nothing to write, and the save would wait for the read in vain.\n const rows = queuesOfConfig().flatMap(([, queue]) => queue.items)\n const isRowOfAsset = (item: UploadQueueItem) => item.assetId === asset.id && !!item.type\n // A processing row may become a row of the asset during the read,\n // when its file turns out to be a duplicate of the asset's file.\n // It gets the write like any row of the asset, since the asset was not read while no row had it.\n // The DAM detects duplicates only within the file's licence, so rows of another licence are excluded.\n const mayBecomeRowOfAsset = (item: UploadQueueItem) =>\n !!item.type && item.status === UploadQueueItemStatus.Processing && item.licenceId === asset.licence\n if (!rows.some(isRowOfAsset) && !rows.some(mayBecomeRowOfAsset)) {\n if (rowsAtSave) forgetRowsNote(rowsAtSave)\n return\n }\n const note = rowsAtSave ?? noteRowsOfAsset(asset.id, configName)\n const before = note.rows\n const turn = ++lastDetailWrite\n const writeKey = detailWriteKey(configName, asset.id)\n detailWrites.set(writeKey, turn)\n // A later save of this asset under this configuration started its write since. That one writes.\n const isLatest = () => detailWrites.get(writeKey) === turn\n try {\n const assetRes = await fetchAsset(dam.damClient, dam.endPointAsset, asset.id)\n if (!isLatest()) return\n // One answer serves the asset's rows in every queue of the configuration, but each row gets its own copies.\n // Filling a custom field writes into custom data in place, so a shared\n // object would change another queue's row and that queue would send it.\n queuesOfConfig().forEach(([queueKey, queue]) => {\n queue.items.forEach((item) => {\n if (item.assetId === assetRes.id && item.type) {\n // The detail saves the switch too. Left unchanged, the next queue save would send the old value.\n const kept = writeUnchanged(item, before.get(item), {\n keywords: assetRes.keywords,\n authors: assetRes.authors,\n sources: assetRes.sources,\n customData: assetRes.metadata.customData,\n mainFileSingleUse: assetRes.mainFileSingleUse,\n })\n othersTakeWrite(note, item, kept)\n updateNewNames(assetRes.metadata.authorSuggestions, queue.suggestions.newAuthorNames)\n updateNewNames(assetRes.metadata.keywordSuggestions, queue.suggestions.newKeywordNames)\n item.authorConflicts = getAuthorConflicts(assetRes.metadata.authorSuggestions)\n addToCachedKeywords(item.keywords)\n addToCachedAuthors(item.authors)\n addToCachedAuthors(item.sources)\n addToCachedAuthors(item.authorConflicts)\n }\n })\n core.recalculateQueueCounts(queueKey)\n fetchCachedAuthors()\n fetchCachedKeywords()\n })\n } catch (e) {\n if (!isLatest()) return\n // The detail is saved anyway. Unchanged rows would send their\n // old values with the next queue save, over the detail's values.\n // Each row gets its own copies, not the detail's lists.\n // Suggestions come from the server and stay as the rows have them.\n queuesOfConfig().forEach(([, queue]) => {\n queue.items.forEach((item) => {\n if (item.assetId === asset.id && item.type) {\n const kept = writeUnchanged(item, before.get(item), {\n keywords: asset.keywords,\n authors: asset.authors,\n sources: asset.sources,\n customData: asset.metadata.customData,\n mainFileSingleUse: isUndefined(mainFileSingleUse) ? undefined : mainFileSingleUse,\n })\n othersTakeWrite(note, item, kept)\n addToCachedKeywords(item.keywords)\n addToCachedAuthors(item.authors)\n addToCachedAuthors(item.sources)\n }\n })\n })\n fetchCachedAuthors()\n fetchCachedKeywords()\n } finally {\n forgetRowsNote(note)\n if (isLatest()) detailWrites.delete(writeKey)\n }\n }\n\n return {\n getQueue: core.getQueue,\n getQueueItems: core.getQueueItems,\n addByFiles,\n addByCopyToLicence,\n queueItemProcessed,\n queueItemFullyProcessed,\n queueItemDuplicate,\n queueItemFailed,\n refreshAsset,\n /**\n * Whether a refresh may still change a failed row. True when its finish request went out before the client gave\n * up and the server has said nothing final since, or when it is a duplicate whose original could not be read.\n */\n refreshMayHelp: core.refreshMayHelp,\n /** The row failed because its asset was missing from enough reads (\"Asset už neexistuje.\"). */\n isGivenUpMissing: (item: UploadQueueItem) => settlement.isGivenUpMissing(item),\n removeByIndex: core.removeByIndex,\n stopItemUpload,\n getQueueTotalCount: core.getQueueTotalCount,\n getQueueProcessedCount: core.getQueueProcessedCount,\n stopUpload: core.stopUpload,\n getQueueItemsTypes: core.getQueueItemsTypes,\n updateFromDetail,\n noteRowsOfAsset,\n forgetRowsNote,\n forceReloadFileInput: core.forceReloadFileInput,\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,IAAMqC,MAAoBC,MACxBT,EAAU;CACR,UAAUS,EAAK;CACf,SAASA,EAAK;CACd,SAASA,EAAK;CACd,YAAYA,EAAK;CACjB,mBAAmBA,EAAK;AAC1B,CAAC,GAEGC,KAAaC,GAAcC,MAAmB,KAAK,UAAUD,CAAG,MAAM,KAAK,UAAUC,CAAK,GA8B1FC,KAAkBJ,GAAuBK,GAAiCC,MAA0B;CACxG,IAAMC,IAAoB;EAAE,wBAAQ,IAAI,IAAI;EAAG,4BAAY,IAAI,IAAI;CAAE,GAC/DC,KAAaC,MACb,CAACJ,KAAOJ,EAAUD,EAAKS,IAAQJ,EAAII,EAAM,IAAU,MACvDF,EAAK,OAAO,IAAIE,CAAK,GACd;CAELD,EAAU,UAAU,MAAGR,EAAK,WAAW,CAAC,GAAGM,EAAM,QAAQ,IACzDE,EAAU,SAAS,MAAGR,EAAK,UAAU,CAAC,GAAGM,EAAM,OAAO,IACtDE,EAAU,SAAS,MAAGR,EAAK,UAAU,CAAC,GAAIM,EAAM,WAAW,CAAC,CAAE;CAClE,IAAMI,IAAanB,EAAUe,EAAM,UAAU;CAC7C,IAAID,KAAOK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B,mBAAmBjG,EAAYkG,CAAiB,IAAI,KAAA,IAAYA;MAClE,CAAC;MACDJ,EAAgBzE,GAAMf,GAAMO,CAAI,GAChC0F,EAAoBjG,EAAK,QAAQ,GACjCmG,EAAmBnG,EAAK,OAAO,GAC/BmG,EAAmBnG,EAAK,OAAO;KACjC;IACF,CAAC;GACH,CAAC,GACDoG,EAAmB,GACnBF,EAAoB;EACtB,UAAU;GACRX,EAAexE,CAAI,GACf0F,EAAS,KAAGzB,EAAa,OAAOwB,CAAQ;EAC9C;CACF;CAEA,OAAO;EACL,UAAU9D,EAAK;EACf,eAAeA,EAAK;EACpBsB;EACAR;EACAc;EACAC;EACAC;EACAG;EACAE;EAKA,gBAAgBnC,EAAK;EAErB,mBAAmB1C,MAA0B2C,EAAW,iBAAiB3C,CAAI;EAC7E,eAAe0C,EAAK;EACpBoC;EACA,oBAAoBpC,EAAK;EACzB,wBAAwBA,EAAK;EAC7B,YAAYA,EAAK;EACjB,oBAAoBA,EAAK;EACzBgD;EACAN;EACAG;EACA,sBAAsB7C,EAAK;CAC7B;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"uploadQueuesStore.js","names":["requestedUrl","apiErrorIsReported","apiErrorStatus","mapApiError","report","useCommonAdminCoreDamOptions","ENTITY","fetchAsset","fetchAssetByFileId","fetchAssetListByIds","metadataOfAsset","metadataOnServer","setMetadataOnServer","SYSTEM_CORE_DAM","useDamCachedAuthors","useUploadQueueItemFactory","useAssetSuggestions","useDamConfigState","useDamNotifications","useDamNotificationsConnection","DamNotificationName","getAssetTypeByMimeType","UPLOAD_QUEUE_ITEM_CHUNK_SIZE","createUploadQueueCore","libraryQueuePreset","UploadRowRole","useDamCachedKeywords","damFileTypeFix","DamAssetType","UploadQueueItemStatus","UploadQueueItemType","AnzuApiResponseCodeError","cloneDeep","isArray","isString","isUndefined","commonT","defineStore","getCurrentScope","ref","editableFieldsOf","item","sameValue","one","other","writeUnchanged","was","saved","kept","unchanged","field","customData","now","then","key","takeWrite","note","entry","written","noted","useUploadQueuesStore","queues","createDefault","configNames","configOf","queueKey","damOf","profile","row","target","assetId","options","damClient","endPointAsset","error","licenceId","assetIds","failure","answer","url","context","originFileId","ids","core","settlement","addRowUnder","configName","known","storeScope","toSettlementEvent","event","addDamNotificationListener","listening","listenToNotifications","listen","origin","settlementEvent","addByCopyToLicence","extSystem","assetLicence","assets","getDamConfigExtSystem","configExtSystem","queueItem","added","addByFiles","files","file","type","targetOf","of","queueItemProcessed","queueItemFullyProcessed","queueItemDuplicate","originAssetFile","assetType","queueItemFailed","failReason","refreshAsset","stopItemUpload","_index","detailWrites","detailWriteKey","lastDetailWrite","openNotes","noteRowsOfAsset","rows","queue","forgetRowsNote","othersTakeWrite","own","updateFromDetail","asset","mainFileSingleUse","rowsAtSave","updateNewNames","getAuthorConflicts","dam","addToCachedKeywords","fetchCachedKeywords","addToCachedAuthors","fetchCachedAuthors","queuesOfConfig","before","turn","writeKey","isLatest","assetRes"],"sources":["../../../../../src/domains/dam/uploadQueue/store/uploadQueuesStore.ts"],"sourcesContent":["import { requestedUrl } from '@/domains/api/composables/request'\nimport { apiErrorIsReported, apiErrorStatus, mapApiError, report } from '@/domains/api/utils/apiErrors'\nimport { useCommonAdminCoreDamOptions } from '@/domains/dam/composables/commonAdminCoreDamOptions'\nimport { ENTITY, fetchAsset, fetchAssetByFileId, fetchAssetListByIds } from '@/domains/dam/api/damAssetApi'\nimport { metadataOfAsset, metadataOnServer, setMetadataOnServer } from '@/domains/dam/api/damMetadataOnServer'\nimport { SYSTEM_CORE_DAM } from '@/domains/dam/api/damConstants'\nimport { useDamCachedAuthors } from '@/domains/dam/author/composables/cachedAuthors'\nimport { useUploadQueueItemFactory } from '@/domains/dam/uploadQueue/factory/UploadQueueItemFactory'\nimport { useAssetSuggestions } from '@/domains/dam/uploadQueue/composables/assetSuggestions'\nimport { useDamConfigState } from '@/domains/dam/config/composables/damConfigState'\nimport { useDamNotifications } from '@/domains/dam/composables/damNotifications'\nimport { useDamNotificationsConnection } from '@/domains/dam/composables/damNotificationsConnection'\nimport { type DamNotification, DamNotificationName } from '@/domains/dam/composables/damNotificationsEventBus'\nimport { getAssetTypeByMimeType } from '@/domains/dam/uploadQueue/utils/mimeTypeHelper'\nimport { createUploadQueueCore, UPLOAD_QUEUE_ITEM_CHUNK_SIZE } from '@/domains/dam/uploadQueue/core/uploadQueueCore'\nimport type { UploadQueueSettlementProfile } from '@/domains/dam/uploadQueue/core/uploadQueueCoreTypes'\nimport { libraryQueuePreset } from '@/domains/dam/uploadQueue/presets/queuePresets'\nimport {\n type UploadReadOptions,\n type UploadRefreshOutcome,\n UploadRowRole,\n type UploadSettlementEvent,\n} from '@/domains/dam/uploadQueue/settlement/uploadSettlementTypes'\nimport { useDamCachedKeywords } from '@/domains/dam/keyword/composables/cachedKeywords'\nimport { damFileTypeFix } from '@/domains/ui/file/utils/fileType'\nimport type { AxiosRequestConfig } from 'axios'\nimport type { DocId, DocIdNullable, IntegerId } from '@/shared/types/common'\nimport { type AssetDetailItemDto, DamAssetType, type DamAssetTypeType } from '@/domains/dam/types/Asset'\nimport type { AssetFileFailReasonType } from '@/domains/dam/types/AssetFile'\nimport {\n type UploadQueue,\n type UploadQueueItem,\n UploadQueueItemStatus,\n UploadQueueItemType,\n type UploadQueueKey,\n} from '@/domains/dam/types/UploadQueue'\nimport { AnzuApiResponseCodeError } from '@/shared/error/AnzuApiResponseCodeError'\nimport { cloneDeep, isArray, isString, isUndefined } from '@/shared/utils/common'\nimport { commonT } from '@/plugins/i18n'\nimport { defineStore } from 'pinia'\nimport { getCurrentScope, ref } from 'vue'\n\n/** Fields the user edits and a detail save writes. */\nexport interface EditableFields {\n keywords: DocId[]\n authors: DocId[]\n sources: DocId[]\n customData: UploadQueueItem['customData']\n mainFileSingleUse: boolean | null | undefined\n}\n\nconst editableFieldsOf = (item: UploadQueueItem): EditableFields =>\n cloneDeep({\n keywords: item.keywords,\n authors: item.authors,\n sources: item.sources,\n customData: item.customData,\n mainFileSingleUse: item.mainFileSingleUse,\n })\n\nconst sameValue = (one: unknown, other: unknown) => JSON.stringify(one) === JSON.stringify(other)\n\n/** Field-by-field snapshot of an asset's rows (`noteRowsOfAsset`). */\nexport interface RowsNote {\n assetId: DocId\n /** DAM configuration of the queues the rows are in. */\n configName: string\n rows: Map<UploadQueueItem, EditableFields>\n}\n\n/**\n * Which rows a settle function targets: queues of the named DAM configuration, or of the configuration of `queueKey`.\n * Required because two DAMs may share an asset id.\n */\nexport type UploadQueueRowsOf = string | { queueKey: UploadQueueKey }\n\n/** What a write left as the user had changed it: these fields and these custom data keys. */\ninterface KeptByWrite {\n fields: Set<'keywords' | 'authors' | 'sources' | 'mainFileSingleUse'>\n customKeys: Set<string>\n}\n\n/**\n * Writes the saved detail into a row of its asset. Each row gets its own copies.\n * A field the user changed since `was` (the row when save was pressed)\n * keeps the user's value. Custom data keys are compared one by one.\n * A row unknown to `was` (it became a row of the asset meanwhile)\n * takes everything. `mainFileSingleUse` undefined is left as is.\n * Returns what it kept.\n */\nconst writeUnchanged = (item: UploadQueueItem, was: EditableFields | undefined, saved: EditableFields) => {\n const kept: KeptByWrite = { fields: new Set(), customKeys: new Set() }\n const unchanged = (field: 'keywords' | 'authors' | 'sources' | 'mainFileSingleUse') => {\n if (!was || sameValue(item[field], was[field])) return true\n kept.fields.add(field)\n return false\n }\n if (unchanged('keywords')) item.keywords = [...saved.keywords]\n if (unchanged('authors')) item.authors = [...saved.authors]\n if (unchanged('sources')) item.sources = [...(saved.sources ?? [])]\n const customData = cloneDeep(saved.customData)\n if (was && customData) {\n const now = item.customData ?? {}\n const then = was.customData ?? {}\n new Set([...Object.keys(now), ...Object.keys(then)]).forEach((key) => {\n if (sameValue(now[key], then[key])) return\n kept.customKeys.add(key)\n if (key in now) customData[key] = cloneDeep(now[key])\n else delete customData[key]\n })\n }\n item.customData = customData\n if (isUndefined(saved.mainFileSingleUse)) kept.fields.add('mainFileSingleUse')\n else if (unchanged('mainFileSingleUse')) item.mainFileSingleUse = saved.mainFileSingleUse\n return kept\n}\n\n/**\n * Another pending save of the same asset takes over what a write just put into `item`.\n * That value is not a user change. Otherwise the later save would keep the earlier save's values.\n */\nconst takeWrite = (note: RowsNote, item: UploadQueueItem, kept: KeptByWrite) => {\n const entry = note.rows.get(item)\n if (!entry) return\n if (!kept.fields.has('keywords')) entry.keywords = [...item.keywords]\n if (!kept.fields.has('authors')) entry.authors = [...item.authors]\n if (!kept.fields.has('sources')) entry.sources = [...(item.sources ?? [])]\n if (!kept.fields.has('mainFileSingleUse')) entry.mainFileSingleUse = item.mainFileSingleUse\n const written = item.customData ?? {}\n const noted = (entry.customData = { ...entry.customData })\n new Set([...Object.keys(written), ...Object.keys(noted)]).forEach((key) => {\n if (kept.customKeys.has(key)) return\n if (key in written) noted[key] = cloneDeep(written[key])\n else delete noted[key]\n })\n}\n\nexport const useUploadQueuesStore = defineStore('commonAdminUploadQueuesStore', () => {\n const queues = ref<Map<UploadQueueKey, UploadQueue>>(new Map())\n\n const { createDefault } = useUploadQueueItemFactory()\n\n // The DAM configuration each queue was created under. Its files are sent\n // and its rows read with that configuration's client and endpoints.\n // A queue without a given name uses `default`.\n const configNames = new Map<UploadQueueKey, string>()\n const configOf = (queueKey?: UploadQueueKey) =>\n (isUndefined(queueKey) ? undefined : configNames.get(queueKey)) ?? 'default'\n // Resolved per request, from the queue it is for.\n const damOf = (queueKey?: UploadQueueKey) => useCommonAdminCoreDamOptions(configOf(queueKey))\n\n // The poll repeats while a row waits. The settlement decides per request\n // whether a failure starts a streak, and only that one is reported.\n\n // A missing asset is an answer the settlement counts. Anything else is a failed read.\n const readAsset = async (assetId: DocId, options?: UploadReadOptions) => {\n const { damClient, endPointAsset } = damOf(options?.queueKey)\n try {\n return options?.report === false\n ? await fetchAsset(damClient, endPointAsset, assetId, { report: false })\n : await fetchAsset(damClient, endPointAsset, assetId)\n } catch (error) {\n if (apiErrorStatus(error) === 404) return null\n throw error\n }\n }\n\n // The list request reports nothing by itself. A reported failure is\n // rethrown as reported, so the settlement can check whether it was logged.\n const readAssets = async (licenceId: IntegerId, assetIds: DocId[], options?: UploadReadOptions) => {\n const { damClient, endPointAsset } = damOf(options?.queueKey)\n try {\n return await fetchAssetListByIds(damClient, endPointAsset, assetIds, licenceId)\n } catch (failure) {\n if (options?.report) {\n // An answer without an asset list is rejected like the failed answers.\n const answer = isArray<{ status?: number; config?: AxiosRequestConfig }>(failure) ? failure.at(-1) : undefined\n const url = `${endPointAsset}/licence/${licenceId}/ids/${assetIds.join(',')}`\n const context = {\n system: SYSTEM_CORE_DAM,\n entity: ENTITY,\n // The URL as sent, with the client's base address, when axios kept the config.\n url: requestedUrl(damClient, url, {}, failure, answer?.config),\n }\n const error = isArray(failure) ? new AnzuApiResponseCodeError(answer?.status ?? 0) : failure\n throw report(mapApiError(error, context), context)\n }\n throw failure\n }\n }\n\n // Handles a row once its file is on the server. The queue poll,\n // notifications and the refresh button all go through here.\n // The core counts the queue, starts the next row after a final\n // state, and keeps failed rows a refresh may still change.\n const profile: UploadQueueSettlementProfile = {\n roleOf: (row) => (row.type === UploadQueueItemType.Asset ? UploadRowRole.Copy : UploadRowRole.Upload),\n policyFor: () => ({ reader: 'asset', settleOn: 'read', duplicate: 'becomeOriginal', metadata: 'load' }),\n // Matched by asset only, whatever file an event names.\n matches: (row, target) => row.assetId === target.assetId,\n readers: {\n asset: readAsset,\n assets: readAssets,\n duplicateOriginAsset: async (originFileId, options) => {\n const { damClient, endPointAsset } = damOf(options?.queueKey)\n return fetchAssetByFileId(damClient, endPointAsset, originFileId)\n },\n failureReported: apiErrorIsReported,\n },\n // Two DAMs may use the same asset id, so rows are settled only within the queues of their configuration.\n configOf,\n // Names of a queue's rows come from the DAM of its configuration.\n caches: {\n addAuthors: (ids, queueKey) => useDamCachedAuthors(configOf(queueKey)).addToCachedAuthors(ids),\n addKeywords: (ids, queueKey) => useDamCachedKeywords(configOf(queueKey)).addToCachedKeywords(ids),\n fetchAuthors: (queueKey) => useDamCachedAuthors(configOf(queueKey)).fetchCachedAuthors(),\n fetchKeywords: (queueKey) => useDamCachedKeywords(configOf(queueKey)).fetchCachedKeywords(),\n },\n messages: {\n processingTooLong: () => commonT('common.damImage.uploadErrors.processingTooLong'),\n readFailed: () => commonT('common.damImage.uploadErrors.readFailed'),\n assetMissing: () => commonT('common.damImage.uploadErrors.unknownError'),\n assetGone: () => commonT('common.damImage.queueItem.assetGone'),\n },\n // Uses the socket of the queue's configuration. A configuration without a socket is polled more often.\n connection: {\n isPushAlive: (queueKey) => useDamNotificationsConnection(configOf(queueKey)).isPushAlive(),\n onChange: useDamNotificationsConnection().onChange,\n },\n }\n\n // Created in the store's scope, so a disposed store leaves no poll timer and no tab or socket listener.\n const core = createUploadQueueCore(libraryQueuePreset({ queues, settlement: profile, configOf }))\n const { settlement } = core\n\n // A queue key belongs to one widget and so to one configuration. A queue with\n // rows refuses another configuration name instead of sending under its own.\n // The name is set together with the row, with no await in between.\n // Of two overlapping adds, the first row in the queue sets the name.\n function addRowUnder(queueKey: UploadQueueKey, configName: string, item: UploadQueueItem) {\n const known = configNames.get(queueKey)\n if (!isUndefined(known) && known !== configName && core.getQueueItems(queueKey).length > 0) {\n throw new Error(\n `useUploadQueuesStore: the queue \"${queueKey}\" has rows under the DAM configuration \"${known}\", none is added under \"${configName}\".`\n )\n }\n configNames.set(queueKey, configName)\n core.addRow(queueKey, item)\n }\n\n const storeScope = getCurrentScope()\n\n // The file a notification names is dropped. Rows match by asset only,\n // and a read for a non-main file would take that file's state unchecked.\n // `configNames`: configurations of the socket it came through. Only their queues are affected.\n const toSettlementEvent = (event: DamNotification, configNames: string[]): UploadSettlementEvent | null => {\n switch (event.name) {\n case DamNotificationName.AssetFileProcessed:\n return { kind: 'processed', assetId: event.data.asset, fileId: null, configNames }\n case DamNotificationName.AssetFileFailed:\n return {\n kind: 'failed',\n assetId: event.data.asset,\n fileId: null,\n failReason: event.data.failReason,\n configNames,\n }\n case DamNotificationName.AssetFileDuplicate:\n return {\n kind: 'duplicate',\n assetId: event.data.asset,\n fileId: null,\n originAssetFile: event.data.originAssetFile,\n assetType: event.data.assetType,\n configNames,\n }\n case DamNotificationName.AssetMetadataProcessed:\n return { kind: 'metadata', assetId: event.data.asset, fileId: null, configNames }\n case DamNotificationName.AssetFileCopied:\n return { kind: 'copied', assetId: event.data.asset, fileId: null, configNames }\n }\n return null\n }\n\n const { addDamNotificationListener } = useDamNotifications()\n // Starts with the first row, not with the store. An application with its own queue store\n // keeps this one alive too, and both would answer every notification. Never removed.\n let listening = false\n function listenToNotifications() {\n if (listening) return\n listening = true\n // Listens on every socket of the page. An event concerns only the queues of its socket's configurations.\n const listen = () =>\n addDamNotificationListener(\n (event, origin) => {\n const settlementEvent = toSettlementEvent(event, origin)\n // Not awaited: the read it triggers happens later.\n if (settlementEvent) void settlement.notify(settlementEvent)\n },\n { all: true }\n )\n // Run in the store's scope. The first row is added from a component,\n // and a listener in that component's scope would be disposed with it.\n if (storeScope) storeScope.run(listen)\n else listen()\n }\n\n async function addByCopyToLicence(\n queueKey: UploadQueueKey,\n extSystem: IntegerId,\n assetLicence: IntegerId,\n assets: DocId[],\n configName: string\n ) {\n // Throws here for an unknown configuration, before anything is done, so its DAM config store is not created.\n useCommonAdminCoreDamOptions(configName)\n const { getDamConfigExtSystem } = useDamConfigState(undefined, configName)\n\n const configExtSystem = getDamConfigExtSystem(extSystem)\n if (isUndefined(configExtSystem)) {\n throw new Error('useUploadQueuesStore.addByCopyToLicence: Ext system must be initialised.')\n }\n listenToNotifications()\n for (const assetId of assets) {\n const queueItem = createDefault(\n core.uniqueKey('asset_' + assetId),\n UploadQueueItemType.Asset,\n UploadQueueItemStatus.Processing,\n DamAssetType.Image, // only image now\n UPLOAD_QUEUE_ITEM_CHUNK_SIZE,\n assetLicence\n )\n queueItem.assetId = assetId\n addRowUnder(queueKey, configName, queueItem)\n // Nothing is uploaded for a copy. It waits for the server from the start.\n const added = core.getQueueItems(queueKey).at(-1)\n if (added) core.track(queueKey, added)\n }\n }\n\n async function addByFiles(\n queueKey: UploadQueueKey,\n extSystem: IntegerId,\n assetLicence: IntegerId,\n files: File[],\n configName: string\n ) {\n // Throws here for an unknown configuration, before anything is done, so its DAM config store is not created.\n useCommonAdminCoreDamOptions(configName)\n const { getDamConfigExtSystem } = useDamConfigState(undefined, configName)\n\n const configExtSystem = getDamConfigExtSystem(extSystem)\n if (isUndefined(configExtSystem)) {\n throw new Error('useUploadQueuesStore.addByFiles: Ext system must be initialised.')\n }\n listenToNotifications()\n for await (const file of files) {\n const type = getAssetTypeByMimeType(damFileTypeFix(file), configExtSystem)\n if (!type || type !== DamAssetType.Image) continue // only image now\n const queueItem = createDefault(\n core.uniqueKey('file_' + file.name),\n UploadQueueItemType.File,\n UploadQueueItemStatus.Waiting,\n type,\n UPLOAD_QUEUE_ITEM_CHUNK_SIZE,\n assetLicence\n )\n queueItem.file = file\n queueItem.displayTitle = file.name\n addRowUnder(queueKey, configName, queueItem)\n }\n }\n\n // Legacy names kept for callers until the queues are unified. `of`:\n // whose rows they settle, read with that configuration's client.\n\n const targetOf = (assetId: DocId, of: UploadQueueRowsOf) => ({\n assetId,\n fileId: null,\n configNames: [isString(of) ? of : configOf(of.queueKey)],\n })\n\n function queueItemProcessed(assetId: DocId, of: UploadQueueRowsOf) {\n return settlement.notify({ kind: 'processed', ...targetOf(assetId, of) })\n }\n\n function queueItemFullyProcessed(assetId: DocId, of: UploadQueueRowsOf) {\n return settlement.settleKnownProcessed(targetOf(assetId, of), { withMetadata: true })\n }\n\n function queueItemDuplicate(\n assetId: DocId,\n originAssetFile: DocIdNullable,\n assetType: DamAssetTypeType | null,\n of: UploadQueueRowsOf\n ) {\n return settlement.settleKnownDuplicate(targetOf(assetId, of), originAssetFile, assetType)\n }\n\n async function queueItemFailed(assetId: DocId, failReason: AssetFileFailReasonType, of: UploadQueueRowsOf) {\n settlement.settleKnownFailed(targetOf(assetId, of), failReason)\n }\n\n /** Row refresh button: reads the file's current state and settles the asset's rows by it. */\n function refreshAsset(assetId: DocId, of: UploadQueueRowsOf): Promise<UploadRefreshOutcome> {\n return settlement.refreshAsset(targetOf(assetId, of))\n }\n\n async function stopItemUpload(queueKey: UploadQueueKey, queueItem: UploadQueueItem, _index?: number) {\n core.stopItemUpload(queueKey, queueItem)\n }\n\n // Pending detail-save writes per configuration and asset. Only the latest one writes.\n // Otherwise overlapping saves left rows with whichever read\n // answered last, and the later save kept the earlier values.\n // Two DAMs may share an asset id, so saves under two configurations concern two assets.\n const detailWrites = new Map<string, number>()\n const detailWriteKey = (configName: string, assetId: DocId) => `${configName}\\u0000${assetId}`\n // Write numbers come from one global counter and are never reused.\n // A per-asset counter let a third save reuse the first save's\n // number, and the first save's late read wrote over the third.\n let lastDetailWrite = 0\n\n // Notes of pending detail saves. A write updates the other notes.\n const openNotes = new Set<RowsNote>()\n\n /**\n * Snapshots the rows of `assetId` in every queue of `configName`, field by field, when a detail save is pressed.\n * Pass it to `updateFromDetail` on success or to `forgetRowsNote` on failure.\n */\n function noteRowsOfAsset(assetId: DocId, configName: string): RowsNote {\n const rows = new Map<UploadQueueItem, EditableFields>()\n queues.value.forEach((queue, queueKey) => {\n if (configOf(queueKey) !== configName) return\n queue.items.forEach((item) => {\n if (item.assetId === assetId && item.type) rows.set(item, editableFieldsOf(item))\n })\n })\n const note = { assetId, configName, rows }\n openNotes.add(note)\n return note\n }\n\n /** The save for this note failed. Nothing is written from it. */\n function forgetRowsNote(note: RowsNote) {\n openNotes.delete(note)\n }\n\n /**\n * `kept`: what the write into `item` left as the user had it.\n * Every other note of that asset and configuration takes the rest.\n */\n const othersTakeWrite = (own: RowsNote, item: UploadQueueItem, kept: KeptByWrite) => {\n openNotes.forEach((note) => {\n if (note === own || note.assetId !== own.assetId) return\n if (note.configName === own.configName) takeWrite(note, item, kept)\n })\n }\n\n /**\n * `configName`: the DAM configuration the detail was saved under.\n * Only its queues are written, and names go to its caches.\n * `mainFileSingleUse`: the switch saved with the detail. `rowsAtSave`: the\n * rows when save was pressed (`noteRowsOfAsset`); current rows if omitted.\n * A field the user changed since keeps the user's value, custom data\n * keys each on their own. Unchanged fields take the saved values.\n * Of two concurrent writes of one asset under one configuration, only the later one writes.\n */\n async function updateFromDetail(\n asset: AssetDetailItemDto,\n configName: string,\n mainFileSingleUse?: boolean | null,\n rowsAtSave?: RowsNote\n ) {\n const { updateNewNames, getAuthorConflicts } = useAssetSuggestions()\n let dam: ReturnType<typeof useCommonAdminCoreDamOptions>\n try {\n dam = useCommonAdminCoreDamOptions(configName)\n } catch (e) {\n // Unknown configuration name: rows are left alone silently.\n return\n }\n const { addToCachedKeywords, fetchCachedKeywords } = useDamCachedKeywords(configName)\n const { addToCachedAuthors, fetchCachedAuthors } = useDamCachedAuthors(configName)\n // Only this configuration's queues: another DAM may have an asset with the same id.\n const queuesOfConfig = () =>\n Array.from(queues.value.entries()).filter(([queueKey]) => configOf(queueKey) === configName)\n // A detail opened from a row keeps notifying the queue even when no queue has a row of the\n // asset. Then there is nothing to write, and the save would wait for the read in vain.\n const rows = queuesOfConfig().flatMap(([, queue]) => queue.items)\n const isRowOfAsset = (item: UploadQueueItem) => item.assetId === asset.id && !!item.type\n // A processing row may become a row of the asset during the read,\n // when its file turns out to be a duplicate of the asset's file.\n // It gets the write like any row of the asset, since the asset was not read while no row had it.\n // The DAM detects duplicates only within the file's licence, so rows of another licence are excluded.\n const mayBecomeRowOfAsset = (item: UploadQueueItem) =>\n !!item.type && item.status === UploadQueueItemStatus.Processing && item.licenceId === asset.licence\n if (!rows.some(isRowOfAsset) && !rows.some(mayBecomeRowOfAsset)) {\n if (rowsAtSave) forgetRowsNote(rowsAtSave)\n return\n }\n const note = rowsAtSave ?? noteRowsOfAsset(asset.id, configName)\n const before = note.rows\n const turn = ++lastDetailWrite\n const writeKey = detailWriteKey(configName, asset.id)\n detailWrites.set(writeKey, turn)\n // A later save of this asset under this configuration started its write since. That one writes.\n const isLatest = () => detailWrites.get(writeKey) === turn\n try {\n const assetRes = await fetchAsset(dam.damClient, dam.endPointAsset, asset.id)\n if (!isLatest()) return\n // One answer serves the asset's rows in every queue of the configuration, but each row gets its own copies.\n // Filling a custom field writes into custom data in place, so a shared\n // object would change another queue's row and that queue would send it.\n queuesOfConfig().forEach(([queueKey, queue]) => {\n queue.items.forEach((item) => {\n if (item.assetId === assetRes.id && item.type) {\n // The detail saves the switch too. Left unchanged, the next queue save would send the old value.\n const kept = writeUnchanged(item, before.get(item), {\n keywords: assetRes.keywords,\n authors: assetRes.authors,\n sources: assetRes.sources,\n customData: assetRes.metadata.customData,\n mainFileSingleUse: assetRes.mainFileSingleUse,\n })\n // What the DAM has now. A field the row kept as the user changed it differs and goes with its save.\n setMetadataOnServer(item, metadataOfAsset(assetRes))\n othersTakeWrite(note, item, kept)\n updateNewNames(assetRes.metadata.authorSuggestions, queue.suggestions.newAuthorNames)\n updateNewNames(assetRes.metadata.keywordSuggestions, queue.suggestions.newKeywordNames)\n item.authorConflicts = getAuthorConflicts(assetRes.metadata.authorSuggestions)\n addToCachedKeywords(item.keywords)\n addToCachedAuthors(item.authors)\n addToCachedAuthors(item.sources)\n addToCachedAuthors(item.authorConflicts)\n }\n })\n core.recalculateQueueCounts(queueKey)\n fetchCachedAuthors()\n fetchCachedKeywords()\n })\n } catch (e) {\n if (!isLatest()) return\n // The detail is saved anyway. Unchanged rows would send their\n // old values with the next queue save, over the detail's values.\n // Each row gets its own copies, not the detail's lists.\n // Suggestions come from the server and stay as the rows have them.\n queuesOfConfig().forEach(([, queue]) => {\n queue.items.forEach((item) => {\n if (item.assetId === asset.id && item.type) {\n const kept = writeUnchanged(item, before.get(item), {\n keywords: asset.keywords,\n authors: asset.authors,\n sources: asset.sources,\n customData: asset.metadata.customData,\n mainFileSingleUse: isUndefined(mainFileSingleUse) ? undefined : mainFileSingleUse,\n })\n // The row took the detail's values as the DAM's, so its save does not send them back.\n const known = metadataOnServer(item)\n if (known) {\n setMetadataOnServer(item, {\n ...metadataOfAsset(asset),\n mainFileSingleUse: isUndefined(mainFileSingleUse) ? known.mainFileSingleUse : mainFileSingleUse,\n })\n }\n othersTakeWrite(note, item, kept)\n addToCachedKeywords(item.keywords)\n addToCachedAuthors(item.authors)\n addToCachedAuthors(item.sources)\n }\n })\n })\n fetchCachedAuthors()\n fetchCachedKeywords()\n } finally {\n forgetRowsNote(note)\n if (isLatest()) detailWrites.delete(writeKey)\n }\n }\n\n return {\n getQueue: core.getQueue,\n getQueueItems: core.getQueueItems,\n addByFiles,\n addByCopyToLicence,\n queueItemProcessed,\n queueItemFullyProcessed,\n queueItemDuplicate,\n queueItemFailed,\n refreshAsset,\n /**\n * Whether a refresh may still change a failed row. True when its finish request went out before the client gave\n * up and the server has said nothing final since, or when it is a duplicate whose original could not be read.\n */\n refreshMayHelp: core.refreshMayHelp,\n /** The row failed because its asset was missing from enough reads (\"Asset už neexistuje.\"). */\n isGivenUpMissing: (item: UploadQueueItem) => settlement.isGivenUpMissing(item),\n removeByIndex: core.removeByIndex,\n stopItemUpload,\n getQueueTotalCount: core.getQueueTotalCount,\n getQueueProcessedCount: core.getQueueProcessedCount,\n stopUpload: core.stopUpload,\n getQueueItemsTypes: core.getQueueItemsTypes,\n updateFromDetail,\n noteRowsOfAsset,\n forgetRowsNote,\n forceReloadFileInput: core.forceReloadFileInput,\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,IAAMwC,MAAoBC,MACxBT,EAAU;CACR,UAAUS,EAAK;CACf,SAASA,EAAK;CACd,SAASA,EAAK;CACd,YAAYA,EAAK;CACjB,mBAAmBA,EAAK;AAC1B,CAAC,GAEGC,KAAaC,GAAcC,MAAmB,KAAK,UAAUD,CAAG,MAAM,KAAK,UAAUC,CAAK,GA8B1FC,KAAkBJ,GAAuBK,GAAiCC,MAA0B;CACxG,IAAMC,IAAoB;EAAE,wBAAQ,IAAI,IAAI;EAAG,4BAAY,IAAI,IAAI;CAAE,GAC/DC,KAAaC,MACb,CAACJ,KAAOJ,EAAUD,EAAKS,IAAQJ,E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C = { class: "a-selected-filters__label text-body-small" }, w = /*@__PURE__*
|
|
|
21
21
|
title: O(e),
|
|
22
22
|
options: t
|
|
23
23
|
})).sort((t, n) => e.indexOf(t.name) - e.indexOf(n.name));
|
|
24
|
-
}), { clearOneFilterSelected: A, isClearable: j } = b(), M = (e) => {
|
|
24
|
+
}), { clearOneFilterSelected: A, isClearable: j } = b(), M = (e, t) => _(t) && t.length > 0 && e.length === t.length && e.every((e) => t.includes(e)), N = (e) => {
|
|
25
25
|
if (!j(e, w)) return !1;
|
|
26
26
|
let t = w.fields[e];
|
|
27
27
|
if (t.type === "timeInterval" && t.related) {
|
|
@@ -29,8 +29,8 @@ var C = { class: "a-selected-filters__label text-body-small" }, w = /*@__PURE__*
|
|
|
29
29
|
if (T[t.related] !== e.default) return !0;
|
|
30
30
|
}
|
|
31
31
|
let n = T[e];
|
|
32
|
-
return _(n) ? !
|
|
33
|
-
},
|
|
32
|
+
return _(n) ? !M(n, t.default) : n !== t.default;
|
|
33
|
+
}, P = (e, t) => {
|
|
34
34
|
A(e, t, T, w, E), w.touched = !0;
|
|
35
35
|
};
|
|
36
36
|
return (t, s) => (l(!0), r(e, null, u(k.value, (t) => (l(), r("div", {
|
|
@@ -39,13 +39,13 @@ var C = { class: "a-selected-filters__label text-body-small" }, w = /*@__PURE__*
|
|
|
39
39
|
}, [i("div", C, d(t.title) + ":", 1), (l(!0), r(e, null, u(t.options, (e) => (l(), r("div", {
|
|
40
40
|
key: e.value,
|
|
41
41
|
class: "a-selected-filters__chips"
|
|
42
|
-
}, [
|
|
42
|
+
}, [N(t.name) ? (l(), n(x, {
|
|
43
43
|
key: 0,
|
|
44
44
|
closable: "",
|
|
45
45
|
"close-label": "common.button.remove",
|
|
46
46
|
size: "small",
|
|
47
47
|
class: "a-selected-filters__chip",
|
|
48
|
-
"onClick:close": p((n) =>
|
|
48
|
+
"onClick:close": p((n) => P(t.name, e.value), ["stop"])
|
|
49
49
|
}, {
|
|
50
50
|
close: f(() => [o(S, {
|
|
51
51
|
size: "16",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiltersSelected.vue.js","names":["_openBlock","_createElementBlock","_Fragment","_renderList","_createElementVNode","_toDisplayString","_createBlock","_component_VChip","_withModifiers","_withCtx","_createVNode","_component_VIcon","_createTextVNode","Fragment","computed","createBlock","createElementBlock","createElementVNode","createTextVNode","createVNode","defineComponent","inject","openBlock","renderList","toDisplayString","withCtx","withModifiers","FilterConfigKey","FilterDataKey","FilterSelectedKey","isArray","isUndefined","useI18n","useFilterClearHelpers","VChip","VIcon","_hoisted_1","FiltersSelected_vue_vue_type_script_setup_true_lang_default","__props","filterConfig","filterData","filterSelected","t","getTitleFromConfig","name","titleT","selectedArray","fieldOrder","key","valueArray","a","b","clearOneFilterSelected","isClearable","canClear","config","related","
|
|
1
|
+
{"version":3,"file":"FiltersSelected.vue.js","names":["_openBlock","_createElementBlock","_Fragment","_renderList","_createElementVNode","_toDisplayString","_createBlock","_component_VChip","_withModifiers","_withCtx","_createVNode","_component_VIcon","_createTextVNode","Fragment","computed","createBlock","createElementBlock","createElementVNode","createTextVNode","createVNode","defineComponent","inject","openBlock","renderList","toDisplayString","withCtx","withModifiers","FilterConfigKey","FilterDataKey","FilterSelectedKey","isArray","isUndefined","useI18n","useFilterClearHelpers","VChip","VIcon","_hoisted_1","FiltersSelected_vue_vue_type_script_setup_true_lang_default","__props","filterConfig","filterData","filterSelected","t","getTitleFromConfig","name","titleT","selectedArray","fieldOrder","key","valueArray","a","b","clearOneFilterSelected","isClearable","isArrayDefault","value","defaultValue","item","canClear","config","related","clickClose","optionValue","_ctx","_cache","option","$event"],"sources":["../../../../src/domains/filters/components/FiltersSelected.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { computed, inject } from 'vue'\nimport { FilterConfigKey, FilterDataKey, FilterSelectedKey } from '@/domains/filters/utils/filterInjectionKeys'\nimport { isArray, isUndefined } from '@/shared/utils/common'\nimport { useI18n } from 'vue-i18n'\nimport { useFilterClearHelpers } from '@/domains/filters/composables/filterFactory'\n\nconst filterConfig = inject(FilterConfigKey)\nconst filterData = inject(FilterDataKey)\nconst filterSelected = inject(FilterSelectedKey)\n\nif (isUndefined(filterConfig) || isUndefined(filterData) || isUndefined(filterSelected)) {\n throw new Error('Incorrect provide/inject config.')\n}\n\nconst { t } = useI18n()\n\nconst getTitleFromConfig = (name: string) => {\n const titleT = filterConfig.fields?.[name]?.titleT\n if (titleT) return t(titleT)\n return name\n}\n\nconst selectedArray = computed(() => {\n const fieldOrder = Object.keys(filterConfig.fields)\n return Array.from(filterSelected.value)\n .filter(([key]) => filterConfig.fields?.[key]?.render?.selected !== false)\n .map(([key, valueArray]) => ({\n name: key,\n title: getTitleFromConfig(key),\n options: valueArray,\n }))\n .sort((a, b) => fieldOrder.indexOf(a.name) - fieldOrder.indexOf(b.name))\n})\n\nconst { clearOneFilterSelected, isClearable } = useFilterClearHelpers()\n\n// In any order. An empty default has no chip to keep.\nconst isArrayDefault = (value: unknown[], defaultValue: unknown) =>\n isArray(defaultValue) &&\n defaultValue.length > 0 &&\n value.length === defaultValue.length &&\n value.every((item) => defaultValue.includes(item))\n\n/**\n * Clearing restores the default. On a field already at its non-null default, the close\n * button would drop the chip, write the same value, and the chip would come back.\n * Arrays differ: closing one chip removes one option. An array holding exactly its default shows the default view and\n * has no close button either: closing removed a default option, as `status: [with_file]` of admin-dam's asset list\n * (#87746). Once it holds another option, every chip can be closed again.\n */\nconst canClear = (name: string) => {\n if (!isClearable(name, filterConfig)) return false\n // `isClearable` has just read this same config, so it is there.\n const config = filterConfig.fields[name]!\n // A time interval is a pair sharing one chip, and clearing writes the default into both.\n // Only `until` may differ, because the custom dialog opens prefilled. The button still has work then.\n if (config.type === 'timeInterval' && config.related) {\n // `createFilter` checked that the related field is configured.\n const related = filterConfig.fields[config.related]!\n if (filterData[config.related] !== related.default) return true\n }\n const value = filterData[name]\n if (isArray(value)) return !isArrayDefault(value, config.default)\n return value !== config.default\n}\n\nconst clickClose = (name: string, optionValue: number | string) => {\n clearOneFilterSelected(name, optionValue, filterData, filterConfig, filterSelected)\n filterConfig.touched = true\n}\n</script>\n\n<template>\n <div\n v-for=\"item in selectedArray\"\n :key=\"item.name\"\n class=\"a-selected-filters\"\n >\n <div class=\"a-selected-filters__label text-body-small\">{{ item.title }}:</div>\n <div\n v-for=\"option in item.options\"\n :key=\"option.value\"\n class=\"a-selected-filters__chips\"\n >\n <VChip\n v-if=\"canClear(item.name)\"\n closable\n close-label=\"common.button.remove\"\n size=\"small\"\n class=\"a-selected-filters__chip\"\n @click:close.stop=\"clickClose(item.name, option.value)\"\n >\n <template #close>\n <VIcon\n size=\"16\"\n icon=\"mdi-close-circle\"\n />\n </template>\n {{ option.title }}\n </VChip>\n <VChip\n v-else\n size=\"small\"\n class=\"a-selected-filters__chip\"\n >\n {{ option.title }}\n </VChip>\n </div>\n </div>\n</template>\n\n<style lang=\"scss\">\n.a-selected-filters {\n display: inline-flex;\n align-items: center;\n background: #f5f5f5;\n border-radius: 20px;\n padding: 4px 4px 4px 12px;\n margin: 0 4px 2px 0;\n gap: 8px;\n max-width: 100%;\n\n &__label {\n white-space: nowrap;\n }\n\n &__chips {\n display: flex;\n gap: 4px;\n flex-wrap: wrap;\n }\n\n &__chip {\n background: white;\n box-shadow: none;\n\n .v-chip__content {\n max-width: 40vw;\n }\n\n &:hover .v-chip__close {\n opacity: 0.8;\n }\n }\n\n .v-chip__close {\n opacity: 0.3;\n transition: opacity 0.2s;\n }\n}\n\n// Values above are hardcoded light, which renders white-on-white in dark theme.\n.v-theme--dark .a-selected-filters {\n background: rgb(var(--v-theme-on-surface), 0.08);\n\n .a-selected-filters__chip {\n background: rgb(var(--v-theme-on-surface), 0.16);\n color: rgb(var(--v-theme-on-surface));\n }\n}\n</style>\n"],"mappings":";;;;;;;;;;;EAOA,IAAMuC,IAAelB,EAAOM,CAAe,GACrCa,IAAanB,EAAOO,CAAa,GACjCa,IAAiBpB,EAAOQ,CAAiB;EAE/C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GACjEV,EAAuBR,GAAMkB,GAAatB,GAAYD,GAAcE,CAAc,GAClFF,EAAa,UAAU;EACzB;E,kBAIEvC,EAAA,EAAA,GAAAC,EAmCMC,GAAA,MAAAC,EAlCW2C,EAAA,QAARW,OADTzD,EAAA,GAAAC,EAmCM,OAAA;GAjCH,KAAKwD,EAAK;GACX,OAAM;E,IAENrD,EAA8E,OAA9EgC,GAA8E/B,EAApBoD,EAAK,KAAK,IAAG,KAAC,CAAA,IACxEzD,EAAA,EAAA,GAAAC,EA4BMC,GAAA,MAAAC,EA3BasD,EAAK,UAAfQ,OADTjE,EAAA,GAAAC,EA4BM,OAAA;GA1BH,KAAKgE,EAAO;GACb,OAAM;E,IAGEP,EAASD,EAAK,IAAI,KAD1BzD,EAAA,GAAAM,EAeQC,GAAA;;GAbN,UAAA;GACA,eAAY;GACZ,MAAK;GACL,OAAM;GACL,iBAAWC,GAAA0D,MAAOL,EAAWJ,EAAK,MAAMQ,EAAO,KAAK,GAAA,CAAA,MAAA,CAAA;;GAE1C,OAAKxD,QAIZ,CAHFC,EAGEC,GAAA;IAFA,MAAK;IACL,MAAK;;GAEE,SAAAF,QACX,CADWG,EAAA,MACXP,EAAG4D,EAAO,KAAK,GAAA,CAAA,C;;E,gCAEjBjE,EAAA,GAAAM,EAMQC,GAAA;;GAJN,MAAK;GACL,OAAM;;GAEN,SAAAE,QAAkB,CAAfG,EAAAP,EAAA4D,EAAO,KAAK,GAAA,CAAA,C"}
|
|
@@ -135,11 +135,11 @@ function B() {
|
|
|
135
135
|
isClearable: a
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
-
var re = {
|
|
138
|
+
var V = /* @__PURE__ */ new WeakMap(), re = {
|
|
139
139
|
storeFiltersLocalStorage: !0,
|
|
140
140
|
populateUrlParams: !0
|
|
141
141
|
};
|
|
142
|
-
function
|
|
142
|
+
function H(t, r, i = {}) {
|
|
143
143
|
let a = {
|
|
144
144
|
...re,
|
|
145
145
|
...i
|
|
@@ -147,37 +147,37 @@ function V(t, r, i = {}) {
|
|
|
147
147
|
x(a.storeFiltersLocalStorage) ? u = a.storeFiltersLocalStorage : h(a.storeFiltersLocalStorage) && !0 === a.storeFiltersLocalStorage && x(r.general.system) && x(r.general.subject) && (u = "tableFilter_" + r.general.system + "_" + r.general.subject);
|
|
148
148
|
let d = a.pageStoreKey ?? (x(a.storeFiltersLocalStorage) ? a.storeFiltersLocalStorage : o(r.general.system, r.general.subject));
|
|
149
149
|
e() && (n(l, d), n(c, (e) => L(e)));
|
|
150
|
-
let { consumeStoredPage: f, getStoredRowsPerPage: m, getStoredView: y, setStoredPage: A } = s(), P = (e) => N(
|
|
150
|
+
let { consumeStoredPage: f, getStoredRowsPerPage: m, getStoredView: y, setStoredPage: A } = s(), P = (e) => N(W(), e), F, I = (e) => {
|
|
151
151
|
F = e, A(d, e.value.page, e.value.rowsPerPage, P(e.value.sortBy));
|
|
152
152
|
}, L = (e) => {
|
|
153
153
|
if (e !== F || e.value.page === 1 && !ce()) return;
|
|
154
|
-
let t =
|
|
155
|
-
|
|
154
|
+
let t = W();
|
|
155
|
+
X(q(t, e, !0, !0)), ue(t) && Z(q(t, e, !0, !0));
|
|
156
156
|
}, R = a.populateUrlParams || !S(u), z = (e) => {
|
|
157
157
|
let t = f(d);
|
|
158
158
|
if (t === null || R) return t;
|
|
159
159
|
let n = y(d);
|
|
160
160
|
return n === null || n === P(e) ? t : null;
|
|
161
|
-
},
|
|
161
|
+
}, H = (e, t) => t === null ? e.value.rowsPerPage : m(d) ?? e.value.rowsPerPage, { clearAll: U } = B(), W = () => {
|
|
162
162
|
let e = {};
|
|
163
163
|
for (let n in t) try {
|
|
164
164
|
let i = n, a = t[i];
|
|
165
165
|
S(a) || v(a) || g(a) || M(a, r.fields[i].default) || (e[n] = a);
|
|
166
166
|
} catch {}
|
|
167
167
|
return e;
|
|
168
|
-
},
|
|
169
|
-
let t =
|
|
168
|
+
}, G = () => Object.values(r.fields).filter((e) => e.persist === !1).map((e) => e.name), K = (e) => {
|
|
169
|
+
let t = G();
|
|
170
170
|
if (t.length === 0) return e;
|
|
171
171
|
let n = { ...e };
|
|
172
172
|
for (let e of t) delete n[e];
|
|
173
173
|
return n;
|
|
174
174
|
}, ie = (e) => {
|
|
175
|
-
for (let n of
|
|
175
|
+
for (let n of G()) {
|
|
176
176
|
if (e && !S(e[n])) continue;
|
|
177
177
|
let i = n;
|
|
178
178
|
t[i] = p(r.fields[i].default);
|
|
179
179
|
}
|
|
180
|
-
},
|
|
180
|
+
}, q = (e, t, n, r = !1) => N(e, n ? t.value.sortBy : void 0, r ? t.value : void 0), J = (e) => {
|
|
181
181
|
if (!e) return null;
|
|
182
182
|
e.startsWith("#") && (e = e.substring(1));
|
|
183
183
|
let t = e.indexOf(O);
|
|
@@ -211,52 +211,53 @@ function V(t, r, i = {}) {
|
|
|
211
211
|
filters: i,
|
|
212
212
|
sortBy: a
|
|
213
213
|
};
|
|
214
|
-
},
|
|
214
|
+
}, Y = (e) => {
|
|
215
215
|
let t = window.location.pathname + window.location.search + e, n = window.history.state, r = b(n) && x(n.current) ? {
|
|
216
216
|
...n,
|
|
217
217
|
current: (n.current.split("#")[0] ?? "") + e
|
|
218
218
|
} : n;
|
|
219
219
|
window.history.replaceState(r, "", t);
|
|
220
|
-
},
|
|
221
|
-
a.populateUrlParams !== !1 &&
|
|
220
|
+
}, X = (e) => {
|
|
221
|
+
a.populateUrlParams !== !1 && Y("#" + e);
|
|
222
222
|
}, ae = () => {
|
|
223
|
-
a.populateUrlParams !== !1 &&
|
|
224
|
-
}, oe = () => a.populateUrlParams === !1 ? null :
|
|
223
|
+
a.populateUrlParams !== !1 && Y("");
|
|
224
|
+
}, oe = () => a.populateUrlParams === !1 ? null : J(window.location.hash), Z = (e) => {
|
|
225
225
|
u && localStorage && localStorage.setItem(u, e);
|
|
226
|
-
},
|
|
226
|
+
}, Q = () => {
|
|
227
227
|
if (!u || !localStorage) return null;
|
|
228
228
|
let e = localStorage.getItem(u);
|
|
229
229
|
if (!e || !x(e)) return null;
|
|
230
|
-
let t =
|
|
230
|
+
let t = G(), n = e.indexOf(O);
|
|
231
231
|
if (t.length === 0 || n === -1) return e;
|
|
232
232
|
let r = new URLSearchParams(e.slice(0, n));
|
|
233
233
|
if (!t.some((e) => r.has(e))) return e;
|
|
234
234
|
for (let e of t) r.delete(e);
|
|
235
235
|
return r.size === 0 ? "" : j(r.toString()) + O;
|
|
236
236
|
}, se = () => {
|
|
237
|
-
let e =
|
|
238
|
-
return e ?
|
|
239
|
-
}, ce = () => a.populateUrlParams !== !1 && D.test(window.location.hash) || !S(u) && !!localStorage && D.test(localStorage.getItem(u) ?? ""),
|
|
237
|
+
let e = Q();
|
|
238
|
+
return e ? J(e) : null;
|
|
239
|
+
}, ce = () => a.populateUrlParams !== !1 && D.test(window.location.hash) || !S(u) && !!localStorage && D.test(localStorage.getItem(u) ?? ""), $ = (e) => G().some((t) => !S(e[t])), le = (e) => {
|
|
240
240
|
let t = e.indexOf(O), n = new URLSearchParams(t === -1 ? e : e.slice(0, t));
|
|
241
241
|
return n.delete(w), n.delete(T), n.delete(E), n.sort(), n.toString();
|
|
242
|
-
},
|
|
243
|
-
if (
|
|
244
|
-
let t =
|
|
245
|
-
return !t || !t.includes(O) ||
|
|
242
|
+
}, ue = (e) => {
|
|
243
|
+
if ($(e)) return !1;
|
|
244
|
+
let t = Q();
|
|
245
|
+
return !t || !t.includes(O) || le(t) === le(N(e));
|
|
246
246
|
};
|
|
247
247
|
return {
|
|
248
248
|
loadStoredFilters: (e, n) => {
|
|
249
|
+
V.has(e) || V.set(e, p(e.value.sortBy));
|
|
249
250
|
let i = "hash", a = oe();
|
|
250
251
|
if (v(a) && (i = "localStorage", a = se()), ie(i === "hash" && a ? a.filters : void 0), v(a) || _(a.filters) && v(a.sortBy) && S(a.page)) {
|
|
251
252
|
let t = z(e.value.sortBy);
|
|
252
253
|
return t !== null && (e.value = {
|
|
253
254
|
...e.value,
|
|
254
255
|
page: t,
|
|
255
|
-
rowsPerPage:
|
|
256
|
+
rowsPerPage: H(e, t)
|
|
256
257
|
}), I(e), n && n(), !1;
|
|
257
258
|
}
|
|
258
259
|
let o = i === "hash" && !_(a.filters);
|
|
259
|
-
o &&
|
|
260
|
+
o && U(t, r);
|
|
260
261
|
for (let e in t) {
|
|
261
262
|
let n = e, r = a.filters[n];
|
|
262
263
|
if (!S(r)) {
|
|
@@ -272,41 +273,43 @@ function V(t, r, i = {}) {
|
|
|
272
273
|
}
|
|
273
274
|
}
|
|
274
275
|
if (i === "localStorage") {
|
|
275
|
-
let e =
|
|
276
|
-
e &&
|
|
276
|
+
let e = Q();
|
|
277
|
+
e && X(e);
|
|
277
278
|
}
|
|
278
279
|
let s = a.sortBy ?? e.value.sortBy, c = z(s), l = c === null ? a.page : void 0;
|
|
279
280
|
if (e.value = {
|
|
280
281
|
...e.value,
|
|
281
282
|
sortBy: s,
|
|
282
283
|
page: c ?? l ?? (i === "hash" ? 1 : e.value.page),
|
|
283
|
-
rowsPerPage: S(l) ?
|
|
284
|
+
rowsPerPage: S(l) ? H(e, c) : a.rowsPerPage ?? e.value.rowsPerPage
|
|
284
285
|
}, I(e), o) {
|
|
285
|
-
let t =
|
|
286
|
-
|
|
286
|
+
let t = W();
|
|
287
|
+
Z(q(K(t), e, !0, !$(t)));
|
|
287
288
|
}
|
|
288
289
|
return n && n(), !0;
|
|
289
290
|
},
|
|
290
291
|
resetFilter: (e, t) => {
|
|
292
|
+
let n = R && V.has(e) ? p(V.get(e)) : e.value.sortBy;
|
|
291
293
|
e.value = {
|
|
292
294
|
...e.value,
|
|
295
|
+
sortBy: n,
|
|
293
296
|
page: 1
|
|
294
297
|
}, I(e), u && localStorage && localStorage.removeItem(u), ae(), r.touched = !1, t && t();
|
|
295
298
|
},
|
|
296
299
|
submitFilter: (e, t) => {
|
|
297
|
-
let n =
|
|
298
|
-
|
|
300
|
+
let n = W();
|
|
301
|
+
X(q(n, e, !0)), Z(q(K(n), e, !0)), e.value = {
|
|
299
302
|
...e.value,
|
|
300
303
|
page: 1
|
|
301
304
|
}, I(e), r.touched = !1, t && t();
|
|
302
305
|
},
|
|
303
|
-
serializeFilters:
|
|
304
|
-
deserializeFilters:
|
|
306
|
+
serializeFilters: q,
|
|
307
|
+
deserializeFilters: J
|
|
305
308
|
};
|
|
306
309
|
}
|
|
307
|
-
function
|
|
310
|
+
function U(e, r, i, o, s = {}) {
|
|
308
311
|
n(d, r), n(f, e), n(u, i);
|
|
309
|
-
let { resetFilter: c, submitFilter: l, loadStoredFilters: p } =
|
|
312
|
+
let { resetFilter: c, submitFilter: l, loadStoredFilters: p } = H(e, r, s), m = a(() => o(i, e, r)), h = () => l(i, m);
|
|
310
313
|
return t(() => p(i, m)), {
|
|
311
314
|
getList: m,
|
|
312
315
|
sortByChange: h,
|
|
@@ -314,6 +317,6 @@ function H(e, r, i, o, s = {}) {
|
|
|
314
317
|
resetFilterAction: () => c(i, m)
|
|
315
318
|
};
|
|
316
319
|
}
|
|
317
|
-
export { P as buildFilterHash, R as createFilter, L as createFilterStore, F as isRouterSafeHash,
|
|
320
|
+
export { P as buildFilterHash, R as createFilter, L as createFilterStore, F as isRouterSafeHash, U as useDatatableList, B as useFilterClearHelpers, H as useFilterHelpers };
|
|
318
321
|
|
|
319
322
|
//# sourceMappingURL=filterFactory.js.map
|