@c8y/ngx-components
Version:
Angular modules for Cumulocity IoT applications
141 lines (134 loc) • 6.55 kB
JavaScript
import * as i0 from '@angular/core';
import { InjectionToken, Optional, Inject, Injectable, NgModule } from '@angular/core';
import * as i2 from '@c8y/ngx-components';
import { NavigatorNode, gettext, Status } from '@c8y/ngx-components';
import { omitBy, isNil, pickBy, has, without, difference, keys, assign, includes } from 'lodash-es';
import * as i1 from '@c8y/client';
import { OperationStatus } from '@c8y/client';
const DEVICE_CONTROL_NAVIGATOR_NODE_CONFIG = new InjectionToken('DEVICE_CONTROL_NAVIGATOR_NODE_CONFIG');
class OperationsNavigationFactory {
constructor(config) {
this.config = config;
this.navs = [];
}
async get() {
if (this.navs.length === 0) {
this.navs.push(new NavigatorNode({
...{
label: gettext('Device control'),
path: 'devicecontrol/single',
icon: 'c8y-icon c8y-icon-device-control',
parent: gettext('Overviews'),
priority: 1360
},
...omitBy(this.config, isNil)
}));
}
return this.navs;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OperationsNavigationFactory, deps: [{ token: DEVICE_CONTROL_NAVIGATOR_NODE_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OperationsNavigationFactory }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OperationsNavigationFactory, decorators: [{
type: Injectable
}], ctorParameters: () => [{ type: i2.NavigatorNode, decorators: [{
type: Optional
}, {
type: Inject,
args: [DEVICE_CONTROL_NAVIGATOR_NODE_CONFIG]
}] }] });
const OPERATION_STATUS_LABELS = {
PENDING: gettext('Pending'),
EXECUTING: gettext('Executing'),
FAILED: gettext('Failed'),
SUCCESSFUL: gettext('Successful')
};
const OPERATION_STATUS_OPTIONS_MAP = {
PENDING: {
label: OPERATION_STATUS_LABELS.PENDING,
status: OperationStatus.PENDING,
icon: 'clock-o',
styleClass: ''
},
EXECUTING: {
label: OPERATION_STATUS_LABELS.EXECUTING,
status: OperationStatus.EXECUTING,
icon: 'refresh',
styleClass: 'text-info'
},
SUCCESSFUL: {
label: OPERATION_STATUS_LABELS.SUCCESSFUL,
status: OperationStatus.SUCCESSFUL,
icon: 'check-circle',
styleClass: 'text-success'
},
FAILED: {
label: OPERATION_STATUS_LABELS.FAILED,
status: OperationStatus.FAILED,
icon: 'exclamation-circle',
styleClass: 'text-danger'
}
};
const CLEAN_KEYS = ['creationTime', 'deviceExternalIDs', 'id', 'self'];
const CLEAN_KEYS_UPDATE = ['deviceId', 'deviceName', 'bulkOperationId'];
const RESERVED_KEYS = CLEAN_KEYS.concat(['deviceId', 'deviceName', 'bulkOperationId']);
const STANDARD_KEYS = {
failureReason: gettext('Failure reason'),
description: gettext('Description'),
status: gettext('Status')
};
class OperationsService {
constructor(operationService, modal, alertService) {
this.operationService = operationService;
this.modal = modal;
this.alertService = alertService;
}
getStandardKeys(operation) {
return pickBy(STANDARD_KEYS, (_, key) => has(operation, key));
}
getNonStandardKeys(operation, excluding = []) {
return without(difference(this.getKeys(operation), keys(this.getStandardKeys(operation))), ...excluding);
}
async cancel(operation) {
try {
await this.modal.confirm(gettext('Cancel operation'), gettext('You are about to cancel the operation. Do you want to proceed?'), Status.DANGER);
const operationAfterUpdate = (await this.operationService.update({
id: operation.id,
status: OperationStatus.FAILED,
failureReason: gettext('Operation cancelled by user.')
})).data;
assign(operation, operationAfterUpdate);
this.alertService.success(gettext('Operation cancelled.'));
}
catch (er) {
if (er) {
this.alertService.addServerFailure(er);
}
}
}
getKeys(managedObject) {
return Object.keys({ ...managedObject }).filter(key => !includes(RESERVED_KEYS, key));
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OperationsService, deps: [{ token: i1.OperationService }, { token: i2.ModalService }, { token: i2.AlertService }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OperationsService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OperationsService, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}], ctorParameters: () => [{ type: i1.OperationService }, { type: i2.ModalService }, { type: i2.AlertService }] });
class OperationsSharedModule {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OperationsSharedModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: OperationsSharedModule }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OperationsSharedModule, providers: [OperationsService] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: OperationsSharedModule, decorators: [{
type: NgModule,
args: [{
providers: [OperationsService]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { CLEAN_KEYS, CLEAN_KEYS_UPDATE, DEVICE_CONTROL_NAVIGATOR_NODE_CONFIG, OPERATION_STATUS_LABELS, OPERATION_STATUS_OPTIONS_MAP, OperationsNavigationFactory, OperationsService, OperationsSharedModule, RESERVED_KEYS, STANDARD_KEYS };
//# sourceMappingURL=c8y-ngx-components-operations-shared.mjs.map