@c8y/ngx-components 1023.80.2 → 1023.81.2
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/datapoint-explorer/view/index.d.ts +1 -0
- package/datapoint-explorer/view/index.d.ts.map +1 -1
- package/echart/index.d.ts +2 -1
- package/echart/index.d.ts.map +1 -1
- package/fesm2022/c8y-ngx-components-datapoint-explorer-view.mjs +10 -2
- package/fesm2022/c8y-ngx-components-datapoint-explorer-view.mjs.map +1 -1
- package/fesm2022/c8y-ngx-components-echart.mjs +26 -14
- package/fesm2022/c8y-ngx-components-echart.mjs.map +1 -1
- package/fesm2022/c8y-ngx-components-static-assets-data.mjs +9 -5
- package/fesm2022/c8y-ngx-components-static-assets-data.mjs.map +1 -1
- package/fesm2022/c8y-ngx-components-widgets-implementations-asset-table.mjs +17 -10
- package/fesm2022/c8y-ngx-components-widgets-implementations-asset-table.mjs.map +1 -1
- package/fesm2022/c8y-ngx-components-widgets-implementations-datapoints-graph.mjs +11 -3
- package/fesm2022/c8y-ngx-components-widgets-implementations-datapoints-graph.mjs.map +1 -1
- package/fesm2022/c8y-ngx-components.mjs +83 -63
- package/fesm2022/c8y-ngx-components.mjs.map +1 -1
- package/index.d.ts +33 -29
- package/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/static-assets/data/index.d.ts.map +1 -1
- package/widgets/implementations/asset-table/index.d.ts.map +1 -1
- package/widgets/implementations/datapoints-graph/index.d.ts +1 -0
- package/widgets/implementations/datapoints-graph/index.d.ts.map +1 -1
|
@@ -140,12 +140,16 @@ class StaticAssetsService {
|
|
|
140
140
|
* Gets the static assets app for the given type.
|
|
141
141
|
*/
|
|
142
142
|
async getAppForTenant(type) {
|
|
143
|
-
const
|
|
144
|
-
const { data:
|
|
145
|
-
if (!
|
|
146
|
-
throw Error(`No app with
|
|
143
|
+
const contextPath = this.getContextPath(type);
|
|
144
|
+
const { data: manifest } = await this.appService.getManifestOfContextPath(contextPath);
|
|
145
|
+
if (!manifest.id) {
|
|
146
|
+
throw Error(`No app with path ${contextPath} found.`);
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
const { data: app } = await this.appService.detail(manifest.id);
|
|
149
|
+
if (app.owner?.tenant.id !== this.appstate.currentTenant.value?.name) {
|
|
150
|
+
throw Error(`No app with path ${contextPath} found that is owned by the current tenant.`);
|
|
151
|
+
}
|
|
152
|
+
return app;
|
|
149
153
|
}
|
|
150
154
|
getContentJSONForType(type, appendTenantId) {
|
|
151
155
|
const path = this.getPathForContent(type, appendTenantId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c8y-ngx-components-static-assets-data.mjs","sources":["../../static-assets/data/static-assets.service.ts","../../static-assets/data/c8y-ngx-components-static-assets-data.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { ApplicationAvailability, ApplicationType, FetchClient, IApplication } from '@c8y/client';\nimport { ApplicationService } from '@c8y/client';\nimport { AppStateService, DroppedFile, FilesService, ZipService } from '@c8y/ngx-components';\nimport { StaticAsset, StaticAssetType } from './static-assets.model';\n\n@Injectable({ providedIn: 'root' })\nexport class StaticAssetsService {\n readonly fileNames = {\n contents: 'contents.json',\n manifest: 'cumulocity.json',\n exportZipName: 'static-assets.zip'\n } as const;\n private listFilesCachePromises: Record<string, Promise<StaticAsset[]>> = {};\n\n constructor(\n private appstate: AppStateService,\n private appService: ApplicationService,\n private fetchClient: FetchClient,\n private fileService: FilesService,\n private zip: ZipService\n ) {}\n\n /**\n * Lists all files of the given type.\n * Forces a cache renewal.\n */\n async listFiles<T extends string = StaticAssetType>(type: T): Promise<StaticAsset[]> {\n return this.listFilesCached(type, true);\n }\n\n /**\n * Lists all files of the given type.\n * Uses a cache.\n */\n async listFilesCached<T extends string = StaticAssetType>(\n type: T,\n forceCacheRenewal = false\n ): Promise<StaticAsset[]> {\n if (!this.listFilesCachePromises[type] || forceCacheRenewal) {\n this.listFilesCachePromises[type] = this._listFiles(type);\n }\n\n return await this.listFilesCachePromises[type];\n }\n\n /**\n * Clones all assets of the given type from parent tenants into the current tenant.\n */\n async cloneAssetsIntoTenant<T extends string = StaticAssetType>(type: T) {\n const { data: apps } = await this.appService.list({\n availability: ApplicationAvailability.SHARED,\n type: ApplicationType.HOSTED,\n pageSize: 2000\n });\n\n const tenantIdsFromOtherAssetApps = apps\n .filter(app => {\n const result =\n app.owner?.tenant?.id &&\n app.owner?.tenant?.id !== this.appstate.currentTenant.value?.name &&\n app.contextPath === this.getContextPath(type, app.owner?.tenant?.id);\n return result;\n })\n .map(app => app.owner?.tenant?.id);\n\n let filesOfCurrentTenant = await this._listFiles(type);\n\n let filesToUpload = new Array<File>();\n\n const oldAssets = new Array<StaticAsset>();\n\n for (const tenantId of tenantIdsFromOtherAssetApps) {\n try {\n const filesOfApp = await this.getContentJSONForType(type, tenantId);\n oldAssets.push(...filesOfApp);\n for (const file of filesOfApp) {\n try {\n const response = await this.fetchClient.fetch(file.path);\n if (response.status !== 200) {\n console.warn(`Failed to get file \"${file.fileName}\" from path ${file.path}`);\n continue;\n }\n const fileContent = await response.blob();\n\n // remove existing file with same name\n filesOfCurrentTenant = filesOfCurrentTenant.filter(\n existingFile => existingFile.fileName !== file.fileName\n );\n filesToUpload = filesToUpload.filter(\n existingFile => existingFile.name !== file.fileName\n );\n\n filesToUpload.push(new File([fileContent], file.fileName, { type: file.type }));\n } catch (e) {\n console.warn(`Failed to add file \"${file.fileName}\" from tenant ${tenantId}`, e);\n }\n }\n } catch (e) {\n console.warn(`Failed to get asset files from tenant ${tenantId}`);\n }\n }\n\n if (!filesToUpload.length) {\n return;\n }\n\n const newAssets = await this.addFilesToStaticAssets(type, filesToUpload, filesOfCurrentTenant);\n\n return { oldAssets, newAssets };\n }\n\n /**\n * Adds the given files to the static assets of the given type.\n */\n async addFilesToStaticAssets<T extends string = StaticAssetType>(\n type: T,\n files: DroppedFile[] | File[],\n existingFiles: StaticAsset[],\n throwErrorOnExistingFiles = true\n ) {\n const app = await this.getAppForTenant(type);\n const filesToAddToContents = new Array<StaticAsset>();\n const addedAt = new Date().toISOString();\n const filesToUpload: {\n path: string;\n contents: Blob;\n }[] = [];\n for (const droppedFile of files) {\n const file = droppedFile instanceof File ? droppedFile : droppedFile.file;\n const fileName = file.name.toLowerCase().replace(/[^a-zA-Z0-9\\-\\_\\.]/g, '');\n const newFile = new File([file], fileName, {\n type: file.type,\n lastModified: file.lastModified\n });\n if (existingFiles.find(existingFile => existingFile.fileName === fileName)) {\n if (throwErrorOnExistingFiles) {\n throw Error(`File with name \"${fileName}\" is already existing.`);\n }\n existingFiles = existingFiles.filter(existingFile => existingFile.fileName !== fileName);\n }\n const fileExtension = file.name.split('.').pop();\n filesToAddToContents.push({\n addedAt,\n lastModified: file.lastModified,\n extension: fileExtension,\n fileName: fileName,\n originalFileName: file.name,\n path: `/apps/public/${app.contextPath}/${fileName}`,\n size: newFile.size,\n type: newFile.type,\n hashSum: await this.fileService.getHashSumOfFile(newFile)\n });\n filesToUpload.push({\n contents: newFile,\n path: fileName\n });\n }\n\n const newFiles: StaticAsset[] = [...existingFiles, ...filesToAddToContents];\n filesToUpload.push({\n contents: new File([JSON.stringify(newFiles)], this.fileNames.contents, {\n type: 'application/json'\n }),\n path: this.fileNames.contents\n });\n await this.appService.binary(app).updateFiles(filesToUpload);\n await this.ensureAddedFilesArePresent(filesToAddToContents);\n return newFiles;\n }\n\n /**\n * Gets the static assets app for the given type.\n */\n async getAppForTenant<T extends string = StaticAssetType>(type: T): Promise<IApplication> {\n const appName = this.getContextPath(type, false);\n const { data: apps } = await this.appService.listByName(appName);\n if (!apps.length) {\n throw Error(`No app with name ${appName} found.`);\n }\n return apps[0];\n }\n\n private getContentJSONForType<T extends string = StaticAssetType>(\n type: T,\n appendTenantId?: string | null | undefined\n ) {\n const path = this.getPathForContent(type, appendTenantId);\n return this.getContentJSONFromPath(path);\n }\n\n private async getContentJSONFromPath(path: string): Promise<StaticAsset[]> {\n const response = await this.fetchClient.fetch(path);\n if (response.status !== 200) {\n throw Error(`Failed to retrieve ${path}`);\n }\n\n const content = await response.json();\n return content;\n }\n\n private async ensureAddedFilesArePresent(files: StaticAsset[]) {\n for (const file of files) {\n await this.ensureFileIsPresent(file);\n }\n }\n\n private async ensureFileIsPresent(file: StaticAsset) {\n for (let i = 0; i < 12; i++) {\n try {\n const currentDate = new Date();\n const response = await this.fetchClient.fetch(\n `${file.path}?nocache=${currentDate.getTime()}`\n );\n if (response.status !== 200) {\n await this.sleep(5_000);\n continue;\n }\n\n const blob = await response.blob();\n const hashSum = await this.fileService.getHashSumOfFile(blob);\n if (hashSum !== file.hashSum) {\n await this.sleep(5_000);\n continue;\n }\n return;\n } catch (e) {\n console.warn(e);\n continue;\n }\n }\n throw Error(`Unable to retrieve file from ${file.path}`);\n }\n\n private sleep(duration: number): Promise<void> {\n return new Promise<void>(resolve => setTimeout(() => resolve(), duration));\n }\n\n private async _listFiles<T extends string = StaticAssetType>(type: T) {\n try {\n const files = await this.getContentJSONForType(type);\n return files;\n } catch (e) {\n console.warn(e);\n }\n\n return await this.createEmptyApp(type);\n }\n\n private getPathForContent<T extends string = StaticAssetType>(\n type: T,\n appendTenantId?: string | null | undefined\n ): string {\n const currentDate = new Date();\n const contextPath = this.getContextPath(type, appendTenantId);\n return `/apps/public/${contextPath}/${\n this.fileNames.contents\n }?nocache=${currentDate.getTime()}`;\n }\n\n private getContextPath<T extends string = StaticAssetType>(\n type: T,\n appendTenantId?: string | false | undefined\n ) {\n let contextPath: string = type + '-assets';\n const tenantId =\n appendTenantId === undefined ? this.appstate.currentTenant.value?.name : appendTenantId;\n if (tenantId) {\n contextPath = `${contextPath}-${tenantId}`;\n }\n return contextPath;\n }\n\n private async createEmptyApp<T extends string = StaticAssetType>(\n type: T,\n appendTenantId?: string | null | undefined\n ): Promise<StaticAsset[]> {\n const name = this.getContextPath(type, false);\n const contextPath = this.getContextPath(type, appendTenantId);\n const key = `${contextPath}-key`;\n const manifest: IApplication = {\n name,\n contextPath,\n key,\n description: `Application containing static assets used for ${type}.`,\n noAppSwitcher: true,\n type: ApplicationType.HOSTED,\n availability: ApplicationAvailability.MARKET\n };\n\n const content = [];\n const zipFile = await this.zip.createZip([\n {\n fileName: `${this.fileNames.manifest}`,\n blob: new Blob([JSON.stringify(manifest)])\n },\n {\n fileName: `${this.fileNames.contents}`,\n blob: new Blob([JSON.stringify(content)])\n }\n ]);\n const { data: app } = await this.appService.create(manifest);\n const { data: appBinary } = await this.appService\n .binary(app)\n .upload(zipFile, `empty-${name}.zip`);\n await this.appService.update({ id: app.id, activeVersionId: appBinary.id as string });\n return [];\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAOa,mBAAmB,CAAA;IAQ9B,WAAA,CACU,QAAyB,EACzB,UAA8B,EAC9B,WAAwB,EACxB,WAAyB,EACzB,GAAe,EAAA;QAJf,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,GAAG,GAAH,GAAG;AAZJ,QAAA,IAAA,CAAA,SAAS,GAAG;AACnB,YAAA,QAAQ,EAAE,eAAe;AACzB,YAAA,QAAQ,EAAE,iBAAiB;AAC3B,YAAA,aAAa,EAAE;SACP;QACF,IAAA,CAAA,sBAAsB,GAA2C,EAAE;IAQxE;AAEH;;;AAGG;IACH,MAAM,SAAS,CAAqC,IAAO,EAAA;QACzD,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC;IACzC;AAEA;;;AAGG;AACH,IAAA,MAAM,eAAe,CACnB,IAAO,EACP,iBAAiB,GAAG,KAAK,EAAA;QAEzB,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,iBAAiB,EAAE;AAC3D,YAAA,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC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AAA,IAAA,EAAA,mBAAmB,cADN,MAAM,EAAA,CAAA,CAAA;;4FACnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACNlC;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"c8y-ngx-components-static-assets-data.mjs","sources":["../../static-assets/data/static-assets.service.ts","../../static-assets/data/c8y-ngx-components-static-assets-data.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport {\n ApplicationAvailability,\n ApplicationService,\n ApplicationType,\n FetchClient,\n IApplication\n} from '@c8y/client';\nimport { AppStateService, DroppedFile, FilesService, ZipService } from '@c8y/ngx-components';\nimport { StaticAsset, StaticAssetType } from './static-assets.model';\n\n@Injectable({ providedIn: 'root' })\nexport class StaticAssetsService {\n readonly fileNames = {\n contents: 'contents.json',\n manifest: 'cumulocity.json',\n exportZipName: 'static-assets.zip'\n } as const;\n private listFilesCachePromises: Record<string, Promise<StaticAsset[]>> = {};\n\n constructor(\n private appstate: AppStateService,\n private appService: ApplicationService,\n private fetchClient: FetchClient,\n private fileService: FilesService,\n private zip: ZipService\n ) {}\n\n /**\n * Lists all files of the given type.\n * Forces a cache renewal.\n */\n async listFiles<T extends string = StaticAssetType>(type: T): Promise<StaticAsset[]> {\n return this.listFilesCached(type, true);\n }\n\n /**\n * Lists all files of the given type.\n * Uses a cache.\n */\n async listFilesCached<T extends string = StaticAssetType>(\n type: T,\n forceCacheRenewal = false\n ): Promise<StaticAsset[]> {\n if (!this.listFilesCachePromises[type] || forceCacheRenewal) {\n this.listFilesCachePromises[type] = this._listFiles(type);\n }\n\n return await this.listFilesCachePromises[type];\n }\n\n /**\n * Clones all assets of the given type from parent tenants into the current tenant.\n */\n async cloneAssetsIntoTenant<T extends string = StaticAssetType>(type: T) {\n const { data: apps } = await this.appService.list({\n availability: ApplicationAvailability.SHARED,\n type: ApplicationType.HOSTED,\n pageSize: 2000\n });\n\n const tenantIdsFromOtherAssetApps = apps\n .filter(app => {\n const result =\n app.owner?.tenant?.id &&\n app.owner?.tenant?.id !== this.appstate.currentTenant.value?.name &&\n app.contextPath === this.getContextPath(type, app.owner?.tenant?.id);\n return result;\n })\n .map(app => app.owner?.tenant?.id);\n\n let filesOfCurrentTenant = await this._listFiles(type);\n\n let filesToUpload = new Array<File>();\n\n const oldAssets = new Array<StaticAsset>();\n\n for (const tenantId of tenantIdsFromOtherAssetApps) {\n try {\n const filesOfApp = await this.getContentJSONForType(type, tenantId);\n oldAssets.push(...filesOfApp);\n for (const file of filesOfApp) {\n try {\n const response = await this.fetchClient.fetch(file.path);\n if (response.status !== 200) {\n console.warn(`Failed to get file \"${file.fileName}\" from path ${file.path}`);\n continue;\n }\n const fileContent = await response.blob();\n\n // remove existing file with same name\n filesOfCurrentTenant = filesOfCurrentTenant.filter(\n existingFile => existingFile.fileName !== file.fileName\n );\n filesToUpload = filesToUpload.filter(\n existingFile => existingFile.name !== file.fileName\n );\n\n filesToUpload.push(new File([fileContent], file.fileName, { type: file.type }));\n } catch (e) {\n console.warn(`Failed to add file \"${file.fileName}\" from tenant ${tenantId}`, e);\n }\n }\n } catch (e) {\n console.warn(`Failed to get asset files from tenant ${tenantId}`);\n }\n }\n\n if (!filesToUpload.length) {\n return;\n }\n\n const newAssets = await this.addFilesToStaticAssets(type, filesToUpload, filesOfCurrentTenant);\n\n return { oldAssets, newAssets };\n }\n\n /**\n * Adds the given files to the static assets of the given type.\n */\n async addFilesToStaticAssets<T extends string = StaticAssetType>(\n type: T,\n files: DroppedFile[] | File[],\n existingFiles: StaticAsset[],\n throwErrorOnExistingFiles = true\n ) {\n const app = await this.getAppForTenant(type);\n const filesToAddToContents = new Array<StaticAsset>();\n const addedAt = new Date().toISOString();\n const filesToUpload: {\n path: string;\n contents: Blob;\n }[] = [];\n for (const droppedFile of files) {\n const file = droppedFile instanceof File ? droppedFile : droppedFile.file;\n const fileName = file.name.toLowerCase().replace(/[^a-zA-Z0-9\\-\\_\\.]/g, '');\n const newFile = new File([file], fileName, {\n type: file.type,\n lastModified: file.lastModified\n });\n if (existingFiles.find(existingFile => existingFile.fileName === fileName)) {\n if (throwErrorOnExistingFiles) {\n throw Error(`File with name \"${fileName}\" is already existing.`);\n }\n existingFiles = existingFiles.filter(existingFile => existingFile.fileName !== fileName);\n }\n const fileExtension = file.name.split('.').pop();\n filesToAddToContents.push({\n addedAt,\n lastModified: file.lastModified,\n extension: fileExtension,\n fileName: fileName,\n originalFileName: file.name,\n path: `/apps/public/${app.contextPath}/${fileName}`,\n size: newFile.size,\n type: newFile.type,\n hashSum: await this.fileService.getHashSumOfFile(newFile)\n });\n filesToUpload.push({\n contents: newFile,\n path: fileName\n });\n }\n\n const newFiles: StaticAsset[] = [...existingFiles, ...filesToAddToContents];\n filesToUpload.push({\n contents: new File([JSON.stringify(newFiles)], this.fileNames.contents, {\n type: 'application/json'\n }),\n path: this.fileNames.contents\n });\n await this.appService.binary(app).updateFiles(filesToUpload);\n await this.ensureAddedFilesArePresent(filesToAddToContents);\n return newFiles;\n }\n\n /**\n * Gets the static assets app for the given type.\n */\n async getAppForTenant<T extends string = StaticAssetType>(type: T): Promise<IApplication> {\n const contextPath = this.getContextPath(type);\n\n const { data: manifest } = await this.appService.getManifestOfContextPath(contextPath);\n if (!manifest.id) {\n throw Error(`No app with path ${contextPath} found.`);\n }\n const { data: app } = await this.appService.detail(manifest.id);\n if (app.owner?.tenant.id !== this.appstate.currentTenant.value?.name) {\n throw Error(`No app with path ${contextPath} found that is owned by the current tenant.`);\n }\n return app;\n }\n\n private getContentJSONForType<T extends string = StaticAssetType>(\n type: T,\n appendTenantId?: string | null | undefined\n ) {\n const path = this.getPathForContent(type, appendTenantId);\n return this.getContentJSONFromPath(path);\n }\n\n private async getContentJSONFromPath(path: string): Promise<StaticAsset[]> {\n const response = await this.fetchClient.fetch(path);\n if (response.status !== 200) {\n throw Error(`Failed to retrieve ${path}`);\n }\n\n const content = await response.json();\n return content;\n }\n\n private async ensureAddedFilesArePresent(files: StaticAsset[]) {\n for (const file of files) {\n await this.ensureFileIsPresent(file);\n }\n }\n\n private async ensureFileIsPresent(file: StaticAsset) {\n for (let i = 0; i < 12; i++) {\n try {\n const currentDate = new Date();\n const response = await this.fetchClient.fetch(\n `${file.path}?nocache=${currentDate.getTime()}`\n );\n if (response.status !== 200) {\n await this.sleep(5_000);\n continue;\n }\n\n const blob = await response.blob();\n const hashSum = await this.fileService.getHashSumOfFile(blob);\n if (hashSum !== file.hashSum) {\n await this.sleep(5_000);\n continue;\n }\n return;\n } catch (e) {\n console.warn(e);\n continue;\n }\n }\n throw Error(`Unable to retrieve file from ${file.path}`);\n }\n\n private sleep(duration: number): Promise<void> {\n return new Promise<void>(resolve => setTimeout(() => resolve(), duration));\n }\n\n private async _listFiles<T extends string = StaticAssetType>(type: T) {\n try {\n const files = await this.getContentJSONForType(type);\n return files;\n } catch (e) {\n console.warn(e);\n }\n\n return await this.createEmptyApp(type);\n }\n\n private getPathForContent<T extends string = StaticAssetType>(\n type: T,\n appendTenantId?: string | null | undefined\n ): string {\n const currentDate = new Date();\n const contextPath = this.getContextPath(type, appendTenantId);\n return `/apps/public/${contextPath}/${\n this.fileNames.contents\n }?nocache=${currentDate.getTime()}`;\n }\n\n private getContextPath<T extends string = StaticAssetType>(\n type: T,\n appendTenantId?: string | false | undefined\n ) {\n let contextPath: string = type + '-assets';\n const tenantId =\n appendTenantId === undefined ? this.appstate.currentTenant.value?.name : appendTenantId;\n if (tenantId) {\n contextPath = `${contextPath}-${tenantId}`;\n }\n return contextPath;\n }\n\n private async createEmptyApp<T extends string = StaticAssetType>(\n type: T,\n appendTenantId?: string | null | undefined\n ): Promise<StaticAsset[]> {\n const name = this.getContextPath(type, false);\n const contextPath = this.getContextPath(type, appendTenantId);\n const key = `${contextPath}-key`;\n const manifest: IApplication = {\n name,\n contextPath,\n key,\n description: `Application containing static assets used for ${type}.`,\n noAppSwitcher: true,\n type: ApplicationType.HOSTED,\n availability: ApplicationAvailability.MARKET\n };\n\n const content = [];\n const zipFile = await this.zip.createZip([\n {\n fileName: `${this.fileNames.manifest}`,\n blob: new Blob([JSON.stringify(manifest)])\n },\n {\n fileName: `${this.fileNames.contents}`,\n blob: new Blob([JSON.stringify(content)])\n }\n ]);\n const { data: app } = await this.appService.create(manifest);\n const { data: appBinary } = await this.appService\n .binary(app)\n .upload(zipFile, `empty-${name}.zip`);\n await this.appService.update({ id: app.id, activeVersionId: appBinary.id as string });\n return [];\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAYa,mBAAmB,CAAA;IAQ9B,WAAA,CACU,QAAyB,EACzB,UAA8B,EAC9B,WAAwB,EACxB,WAAyB,EACzB,GAAe,EAAA;QAJf,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,UAAU,GAAV,UAAU;QACV,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,WAAW,GAAX,WAAW;QACX,IAAA,CAAA,GAAG,GAAH,GAAG;AAZJ,QAAA,IAAA,CAAA,SAAS,GAAG;AACnB,YAAA,QAAQ,EAAE,eAAe;AACzB,YAAA,QAAQ,EAAE,iBAAiB;AAC3B,YAAA,aAAa,EAAE;SACP;QACF,IAAA,CAAA,sBAAsB,GAA2C,EAAE;IAQxE;AAEH;;;AAGG;IACH,MAAM,SAAS,CAAqC,IAAO,EAAA;QACzD,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC;IACzC;AAEA;;;AAGG;AACH,IAAA,MAAM,eAAe,CACnB,IAAO,EACP,iBAAiB,GAAG,KAAK,EAAA;QAEzB,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,iBAAiB,EAAE;AAC3D,YAAA,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAC3D;AAEA,QAAA,OAAO,MAAM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AA,EAAA,CAAA,UAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAnB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,cADN,MAAM,EAAA,CAAA,CAAA;;4FACnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACXlC;;AAEG;;;;"}
|
|
@@ -202,7 +202,8 @@ class IconCellRendererComponent {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
getComputedValue(property, context) {
|
|
205
|
-
|
|
205
|
+
const propertyName = property.computedConfig?.__propertyName || property.name;
|
|
206
|
+
return from(this.computedPropertyService.getByName(propertyName)).pipe(switchMap(definition => {
|
|
206
207
|
let value = '-';
|
|
207
208
|
runInInjectionContext(definition.injector, () => {
|
|
208
209
|
if (property.computedConfig?.dp?.length > 0) {
|
|
@@ -882,16 +883,20 @@ class AssetTableService {
|
|
|
882
883
|
if (idx === -1)
|
|
883
884
|
continue;
|
|
884
885
|
const type = this.getColumnType(selectedProperties[idx]);
|
|
885
|
-
|
|
886
|
+
// extract to a helper
|
|
887
|
+
if (this.checkIfColumnIsLinkable(type)) {
|
|
886
888
|
return idx;
|
|
887
889
|
}
|
|
888
890
|
}
|
|
889
891
|
}
|
|
890
892
|
return selectedProperties.findIndex(prop => {
|
|
891
893
|
const type = this.getColumnType(prop);
|
|
892
|
-
return type
|
|
894
|
+
return this.checkIfColumnIsLinkable(type);
|
|
893
895
|
});
|
|
894
896
|
}
|
|
897
|
+
checkIfColumnIsLinkable(type) {
|
|
898
|
+
return type !== 'computed' && type !== 'alarm' && type !== 'date' && type !== 'icon';
|
|
899
|
+
}
|
|
895
900
|
getColumnType(prop) {
|
|
896
901
|
return prop.columnType
|
|
897
902
|
? prop.columnType
|
|
@@ -942,7 +947,7 @@ class AssetTableService {
|
|
|
942
947
|
path: prop.keyPath || prop.name,
|
|
943
948
|
header: prop.columnLabel || prop.label || prop.title,
|
|
944
949
|
iconConfig: prop.iconConfig || {},
|
|
945
|
-
computedConfig: prop.computed
|
|
950
|
+
computedConfig: prop.computed && prop.config ? prop.config : null,
|
|
946
951
|
showIconAndValue: config?.showIconAndValue,
|
|
947
952
|
visible: prop.visible ?? true
|
|
948
953
|
});
|
|
@@ -1821,17 +1826,19 @@ class AssetTableGridSettingsComponent {
|
|
|
1821
1826
|
}
|
|
1822
1827
|
applyFilter(column, dropdown) {
|
|
1823
1828
|
const formGroup = column.filteringConfig?.formGroup;
|
|
1824
|
-
this.existingColumnFilter[column.name]
|
|
1829
|
+
const newFilter = { ...this.existingColumnFilter, [column.name]: formGroup?.value };
|
|
1830
|
+
this.existingColumnFilter = newFilter;
|
|
1825
1831
|
column.filteringConfig.model = formGroup?.value;
|
|
1826
|
-
|
|
1827
|
-
// Update config and local copy
|
|
1828
|
-
this.widgetConfigService.updateConfig({ filterPredicate: this.existingColumnFilter });
|
|
1832
|
+
this.widgetConfigService.updateConfig({ filterPredicate: newFilter });
|
|
1829
1833
|
dropdown.hide();
|
|
1830
1834
|
}
|
|
1831
1835
|
resetFilter(column, dropdown) {
|
|
1832
|
-
|
|
1836
|
+
const newFilter = { ...this.existingColumnFilter };
|
|
1837
|
+
delete newFilter[column.name];
|
|
1838
|
+
this.existingColumnFilter = newFilter;
|
|
1833
1839
|
column.filteringConfig.formGroup.reset();
|
|
1834
|
-
|
|
1840
|
+
column.filteringConfig.model = {};
|
|
1841
|
+
this.widgetConfigService.updateConfig({ filterPredicate: newFilter });
|
|
1835
1842
|
dropdown.hide();
|
|
1836
1843
|
}
|
|
1837
1844
|
isColumnFiltered(column) {
|