-
Notifications
You must be signed in to change notification settings - Fork 270
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
Showing
7 changed files
with
324 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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 |
---|---|---|
@@ -1,9 +1,47 @@ | ||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types' | ||
import { createXapiStoreConfig } from '@/stores/xen-api/create-xapi-store-config' | ||
import { useVdiStore } from '@/stores/xen-api/vdi.store' | ||
import { createSubscribableStoreContext } from '@core/utils/create-subscribable-store-context.util' | ||
import { defineStore } from 'pinia' | ||
import { computed } from 'vue' | ||
|
||
export const useSrStore = defineStore('xen-api-sr', () => { | ||
const config = createXapiStoreConfig('sr') | ||
const deps = { | ||
vdiStore: useVdiStore(), | ||
} | ||
|
||
return createSubscribableStoreContext(config, {}) | ||
const vdiContext = deps.vdiStore.getContext() | ||
|
||
const { context: baseContext, ...configRest } = createXapiStoreConfig('sr') | ||
|
||
const srs = computed(() => baseContext.records.value) | ||
const srsName = (ref: XenApiSr['$ref']) => baseContext.getByOpaqueRef(ref)?.name_label | ||
|
||
const getSrWithISO = computed(() => srs.value.filter(sr => sr.type === 'iso')) | ||
|
||
const concatVidsArray = computed(() => getSrWithISO.value.flatMap(sr => sr.VDIs || [])) | ||
|
||
const vdisGroupedBySrName = computed(() => { | ||
const groupedVdis: Record<string, XenApiSr[]> = {} | ||
|
||
concatVidsArray.value.forEach(vdiRef => { | ||
const vdi = vdiContext.getByOpaqueRef(vdiRef) | ||
if (vdi) { | ||
const srName = srsName(vdi.SR) || 'Unknown SR' | ||
if (!groupedVdis[srName]) { | ||
groupedVdis[srName] = [] | ||
} | ||
groupedVdis[srName].push(vdi) | ||
} | ||
}) | ||
|
||
return groupedVdis | ||
}) | ||
|
||
const context = { | ||
...baseContext, | ||
vdisGroupedBySrName, | ||
} | ||
|
||
return createSubscribableStoreContext({ context, ...configRest }, deps) | ||
}) |
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,9 @@ | ||
import { createXapiStoreConfig } from '@/stores/xen-api/create-xapi-store-config' | ||
import { createSubscribableStoreContext } from '@core/utils/create-subscribable-store-context.util' | ||
import { defineStore } from 'pinia' | ||
|
||
export const useVdiStore = defineStore('xen-api-vdi', () => { | ||
const config = createXapiStoreConfig('vdi') | ||
|
||
return createSubscribableStoreContext(config, {}) | ||
}) |
Oops, something went wrong.