Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
volar committed Nov 21, 2023
1 parent f2e8917 commit e1087e1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 137 deletions.
103 changes: 45 additions & 58 deletions src/composables/system/appNotificationListeners.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,57 @@
import { useNotification } from '@/composables/system/notifications'
import { useUploadQueuesStore } from '@/stores/coreDam/uploadQueuesStore'
import { updateCurrentUser } from '@/composables/system/currentUser'
import { useDistributionListStore } from '@/stores/coreDam/distributionListStore'
import { DamDistributionStatus } from '@anzusystems/common-admin'
import {
DamDistributionStatus,
DamNotificationName,
initDamNotifications,
useDamNotifications
} from '@anzusystems/common-admin'

export const initAppNotificationListeners = () => {
const { openConnection, addNotificationListener } = useNotification()
const { openConnection } = initDamNotifications()
const { addDamNotificationListener } = useDamNotifications()
openConnection()

// Asset
const uploadQueuesStore = useUploadQueuesStore()
addNotificationListener('asset_file_processed', (message: Event) => {
if (message instanceof CustomEvent) {
uploadQueuesStore.queueItemProcessed(message.detail.asset)
}
})
addNotificationListener('asset_file_failed', (message: Event) => {
if (message instanceof CustomEvent<unknown>) {
uploadQueuesStore.queueItemFailed(message.detail.asset, message.detail.failReason)
}
})
addNotificationListener('asset_file_duplicate', (message: Event) => {
if (message instanceof CustomEvent) {
uploadQueuesStore.queueItemDuplicate(
message.detail.asset,
message.detail.originAssetFile,
message.detail.assetType
)
}
})
addNotificationListener('asset_metadata_processed', (message: Event) => {
if (message instanceof CustomEvent) {
uploadQueuesStore.queueItemMetadataProcessed(message.detail.asset)
}
})

// Distribution
const distributionListStore = useDistributionListStore()
addNotificationListener('distribution_distributing', (message: Event) => {
if (message instanceof CustomEvent) {
distributionListStore.listItemMessageUpdate(message.detail.id, DamDistributionStatus.Distributing)
}
})
addNotificationListener('distribution_remote_processing', (message: Event) => {
if (message instanceof CustomEvent) {
distributionListStore.listItemMessageUpdate(message.detail.id, DamDistributionStatus.RemoteProcessing)
}
})
addNotificationListener('distribution_distributed', (message: Event) => {
if (message instanceof CustomEvent) {
distributionListStore.listItemMessageUpdate(message.detail.id, DamDistributionStatus.Distributed)
}
})
addNotificationListener('distribution_failed', (message: Event) => {
if (message instanceof CustomEvent) {
distributionListStore.listItemMessageUpdate(message.detail.id, DamDistributionStatus.Failed)
}
})
addNotificationListener('distribution_authorized', (message: Event) => {
if (message instanceof CustomEvent) {
distributionListStore.authorizationMessage(message.detail.distributionService, message.detail.success)
}
})

// User
addNotificationListener('user_updated', () => {
updateCurrentUser()
addDamNotificationListener((event) => {
switch (event.name) {
case DamNotificationName.AssetFileProcessed:
uploadQueuesStore.queueItemProcessed(event.data.asset)
break
case DamNotificationName.AssetFileFailed:
uploadQueuesStore.queueItemFailed(event.data.asset, event.data.failReason)
break
case DamNotificationName.AssetFileDuplicate:
uploadQueuesStore.queueItemDuplicate(
event.data.asset,
event.data.originAssetFile,
event.data.assetType
)
break
case DamNotificationName.AssetMetadataProcessed:
uploadQueuesStore.queueItemMetadataProcessed(event.data.asset)
break
case DamNotificationName.DistributionDistributing:
distributionListStore.listItemMessageUpdate(event.data.id, DamDistributionStatus.Distributing)
break
case DamNotificationName.DistributionRemoteProcessing:
distributionListStore.listItemMessageUpdate(event.data.id, DamDistributionStatus.RemoteProcessing)
break
case DamNotificationName.DistributionDistributed:
distributionListStore.listItemMessageUpdate(event.data.id, DamDistributionStatus.Distributed)
break
case DamNotificationName.DistributionFailed:
distributionListStore.listItemMessageUpdate(event.data.id, DamDistributionStatus.Failed)
break
case DamNotificationName.DistributionAuthorized:
distributionListStore.authorizationMessage(event.data.distributionService, event.data.success)
break
case DamNotificationName.UserUpdated:
updateCurrentUser()
break
}
})
}
51 changes: 0 additions & 51 deletions src/composables/system/notifications.ts

This file was deleted.

10 changes: 8 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AppLayoutBlank from '@/layouts/AppLayoutBlank.vue'
import AppLayoutFullscreen from '@/layouts/AppLayoutFullscreen.vue'
import { vuetify } from '@/plugins/vuetify'
import { router } from '@/router'
import { loadEnvConfig } from '@/services/EnvConfigService'
import { envConfig, loadEnvConfig } from '@/services/EnvConfigService'
import { initErrorHandler } from '@/services/ErrorHandlerApiService'
import { createPinia } from 'pinia'
import { createApp } from 'vue'
Expand Down Expand Up @@ -48,9 +48,15 @@ loadEnvConfig(() => {
coreDam: {
configs: {
default: {
client: damClient,
damClient: damClient,
},
},
apiTimeout: envConfig.dam.apiTimeout,
uploadStatusFallback: true,
notification: {
enabled: envConfig.notification.enabled,
webSocketUrl: envConfig.notification.webSocketUrl,
},
},
})
.component('AppLayoutLoader', AppLayoutLoader)
Expand Down
22 changes: 0 additions & 22 deletions src/services/AssetSuggestionsService.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/stores/coreDam/assetDetailStore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { acceptHMRUpdate, defineStore } from 'pinia'
import type { AssetDetailItemDto } from '@anzusystems/common-admin'
import { type AssetDetailItemDto, useAssetSuggestions } from '@anzusystems/common-admin'
import { DamAssetStatus } from '@anzusystems/common-admin'
import type { DocId, DocIdNullable } from '@anzusystems/common-admin'
import { useCachedAuthors } from '@/views/coreDam/author/composables/cachedAuthors'
import { useCachedKeywords } from '@/views/coreDam/keyword/composables/cachedKeywords'
import { getAuthorConflicts } from '@/services/AssetSuggestionsService'

interface State {
asset: AssetDetailItemDto | null
Expand Down Expand Up @@ -48,6 +47,7 @@ export const useAssetDetailStore = defineStore('damAssetDetailStore', {
this.loader = false
},
setAsset(asset: AssetDetailItemDto) {
const { getAuthorConflicts } = useAssetSuggestions()
this.metadataAreTouched = false // todo check
this.authorConflicts = getAuthorConflicts(asset.metadata.authorSuggestions)
this.prefetchLazyData(asset) // todo check
Expand Down
5 changes: 3 additions & 2 deletions src/stores/coreDam/uploadQueuesStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { acceptHMRUpdate, defineStore } from 'pinia'
import type { UploadQueue } from '@anzusystems/common-admin'
import { type UploadQueue, useAssetSuggestions } from '@anzusystems/common-admin'
import {
type AssetDetailItemDto,
type AssetFileFailReason,
Expand Down Expand Up @@ -31,7 +31,6 @@ import { useExternalProviders } from '@/composables/system/externalProviders'
import { useCurrentAssetLicence } from '@/composables/system/currentExtSystem'
import { useCachedAuthors } from '@/views/coreDam/author/composables/cachedAuthors'
import { useCachedKeywords } from '@/views/coreDam/keyword/composables/cachedKeywords'
import { getAuthorConflicts, updateNewNames } from '@/services/AssetSuggestionsService'
import { useAssetDetailStore } from '@/stores/coreDam/assetDetailStore'

interface State {
Expand Down Expand Up @@ -235,6 +234,7 @@ export const useUploadQueuesStore = defineStore('damUploadQueuesStore', {
this.queues[queueId].fileInputKey++
},
async fetchLazyAdditionalMetadata(queueId: string, licenceId: number, assetIds: DocId[]) {
const { getAuthorConflicts } = useAssetSuggestions()
const res = await fetchAssetListByIds(assetIds, licenceId)
for (let i = 0; i < res.length; i++) {
const foundIndex = this.queues[queueId].items.findIndex((item) => item.assetId === res[i].id)
Expand Down Expand Up @@ -383,6 +383,7 @@ export const useUploadQueuesStore = defineStore('damUploadQueuesStore', {
}
},
async queueItemMetadataProcessed(assetId: DocId) {
const { updateNewNames, getAuthorConflicts } = useAssetSuggestions()
const assetDetailStore = useAssetDetailStore()
const asset = await fetchAsset(assetId)
for (const queueId in this.queues) {
Expand Down

0 comments on commit e1087e1

Please sign in to comment.