UNPKG

@c8y/ngx-components

Version:

Angular modules for Cumulocity IoT applications

119 lines (113 loc) 7.26 kB
import { AssetPropertyService, gettext, C8yTranslatePipe, EmptyStateComponent, DataGridComponent, IconDirective, ViewContext, hookRoute } from '@c8y/ngx-components'; import * as i0 from '@angular/core'; import { inject, Component, Injectable } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ActivatedRoute } from '@angular/router'; import { difference } from 'lodash-es'; import * as i1 from '@c8y/client'; class DeviceParametersListComponent { constructor() { this.route = inject(ActivatedRoute); this.assetPropertyService = inject(AssetPropertyService); this.device = this.route.snapshot.parent?.data?.contextData; this.rows = []; this.pagination = { currentPage: 1, pageSize: 25 }; this.columns = [ { name: 'Title', path: 'title', header: gettext('Title') }, { name: 'Key', path: 'key', header: gettext('Key') }, { name: 'Value', path: 'value', header: gettext('Value') }, { name: 'Type', path: 'type', header: gettext('Type') } ]; } async ngOnInit() { await this.loadData(); } async loadData() { const paramKeys = this.getParameterKeys(this.device); if (!paramKeys.length) { return { data: [], res: {}, size: 0, filteredSize: 0 }; } const result = await this.assetPropertyService.list({ identifiers: paramKeys }); const definitions = result.data || []; this.rows = paramKeys.map(key => { const def = definitions.find(d => d.identifier === key); const value = this.device[key]; return { title: def?.jsonSchema?.title || '', key, value: typeof value === 'object' ? JSON.stringify(value) : value, type: def?.jsonSchema?.type || typeof value }; }); } getParameterKeys(device) { const excluded = [ 'id', 'self', 'owner', 'name', 'type', 'lastUpdated', 'creationTime', 'childDevices', 'childAssets', 'childAdditions', 'deviceParents', 'assetParents', 'additionParents', 'c8y_IsDevice', 'com_cumulocity_model_Agent' ]; return difference(Object.keys(device), excluded); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DeviceParametersListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.14", type: DeviceParametersListComponent, isStandalone: true, selector: "c8y-device-parameters-list", ngImport: i0, template: "<div class=\"content-fullpage\">\n <c8y-data-grid\n [title]=\"'Parameters' | translate\"\n [columns]=\"columns\"\n [rows]=\"rows\"\n [pagination]=\"pagination\"\n (onReload)=\"loadData()\"\n >\n <c8y-ui-empty-state\n icon=\"search\"\n [title]=\"'No parameters to display.' | translate\"\n [subtitle]=\"'Parameters used in the device will be displayed here' | translate\"\n horizontal\n ></c8y-ui-empty-state>\n </c8y-data-grid>\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }, { kind: "component", type: EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "component", type: DataGridComponent, selector: "c8y-data-grid", inputs: ["title", "loadMoreItemsLabel", "loadingItemsLabel", "showSearch", "refresh", "columns", "rows", "pagination", "childNodePagination", "infiniteScroll", "serverSideDataCallback", "selectable", "singleSelection", "selectionPrimaryKey", "displayOptions", "actionControls", "bulkActionControls", "headerActionControls", "searchText", "configureColumnsEnabled", "showCounterWarning", "activeClassName", "expandableRows", "treeGrid", "hideReload", "childNodesProperty", "parentNodeLabelProperty"], outputs: ["rowMouseOver", "rowMouseLeave", "rowClick", "onConfigChange", "onBeforeFilter", "onBeforeSearch", "onFilter", "itemsSelect", "onReload", "onAddCustomColumn", "onRemoveCustomColumn", "onColumnFilterReset", "onSort", "onPageSizeChange", "onColumnReordered", "onColumnVisibilityChange"] }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DeviceParametersListComponent, decorators: [{ type: Component, args: [{ standalone: true, selector: 'c8y-device-parameters-list', imports: [CommonModule, IconDirective, C8yTranslatePipe, EmptyStateComponent, DataGridComponent], template: "<div class=\"content-fullpage\">\n <c8y-data-grid\n [title]=\"'Parameters' | translate\"\n [columns]=\"columns\"\n [rows]=\"rows\"\n [pagination]=\"pagination\"\n (onReload)=\"loadData()\"\n >\n <c8y-ui-empty-state\n icon=\"search\"\n [title]=\"'No parameters to display.' | translate\"\n [subtitle]=\"'Parameters used in the device will be displayed here' | translate\"\n horizontal\n ></c8y-ui-empty-state>\n </c8y-data-grid>\n</div>\n" }] }] }); const DEVICE_PARAMETERS_MICROSERVICE = 'device-parameters'; const DTM_MICROSERVICE = 'dtm'; class DeviceParametersTabGuard { constructor(applicationService) { this.applicationService = applicationService; } async canActivate() { const deviceParametersAvailable = await this.applicationService .isAvailable(DEVICE_PARAMETERS_MICROSERVICE) .then(({ data }) => data) .catch(() => false); const dtmAvailable = await this.applicationService .isAvailable(DTM_MICROSERVICE) .then(({ data }) => data) .catch(() => false); return deviceParametersAvailable && dtmAvailable; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DeviceParametersTabGuard, deps: [{ token: i1.ApplicationService }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DeviceParametersTabGuard, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DeviceParametersTabGuard, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: i1.ApplicationService }] }); const DEVICE_PARAMETERS_ROUTE = { path: 'parameters', context: ViewContext.Device, component: DeviceParametersListComponent, label: gettext('Parameters'), icon: 'sliders', priority: 650, canActivate: [DeviceParametersTabGuard] }; const deviceParametersFeatureProvider = [hookRoute(DEVICE_PARAMETERS_ROUTE)]; /** * Generated bundle index. Do not edit. */ export { deviceParametersFeatureProvider }; //# sourceMappingURL=c8y-ngx-components-device-parameters.mjs.map