UNPKG

@c8y/ngx-components

Version:

Angular modules for Cumulocity IoT applications

108 lines (102 loc) 4.85 kB
import * as i0 from '@angular/core'; import { Injectable, NgModule } from '@angular/core'; import * as i1 from '@c8y/client'; import { OperationStatus } from '@c8y/client'; import * as i2 from '@c8y/ngx-components'; import { gettext, Status } from '@c8y/ngx-components'; import { pickBy, has, without, difference, keys, assign, includes } from 'lodash-es'; 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: "18.2.13", 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: "18.2.13", ngImport: i0, type: OperationsService, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", 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: "18.2.13", ngImport: i0, type: OperationsSharedModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.13", ngImport: i0, type: OperationsSharedModule }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: OperationsSharedModule, providers: [OperationsService] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: OperationsSharedModule, decorators: [{ type: NgModule, args: [{ providers: [OperationsService] }] }] }); /** * Generated bundle index. Do not edit. */ export { CLEAN_KEYS, CLEAN_KEYS_UPDATE, OPERATION_STATUS_LABELS, OPERATION_STATUS_OPTIONS_MAP, OperationsService, OperationsSharedModule, RESERVED_KEYS, STANDARD_KEYS }; //# sourceMappingURL=c8y-ngx-components-operations-shared.mjs.map