UNPKG

@c8y/ngx-components

Version:

Angular modules for Cumulocity IoT applications

1 lines 7.9 kB
{"version":3,"file":"c8y-ngx-components-widgets-implementations-device-control-message.mjs","sources":["../../widgets/implementations/device-control-message/device-control-message-widget-view/device-control-message-widget-view.component.ts","../../widgets/implementations/device-control-message/device-control-message-widget-view/device-control-message-widget-view.component.html","../../widgets/implementations/device-control-message/c8y-ngx-components-widgets-implementations-device-control-message.ts"],"sourcesContent":["import { Component, Input, OnChanges, OnDestroy, OnInit, Optional } from '@angular/core';\nimport { gettext } from '@c8y/ngx-components/gettext';\nimport {\n AlertService,\n CoreModule,\n DynamicComponent,\n DynamicComponentAlert,\n DynamicComponentAlertAggregator\n} from '@c8y/ngx-components';\nimport { IManagedObject, OperationService } from '@c8y/client';\nimport { TranslateService } from '@ngx-translate/core';\nimport { BehaviorSubject, Observable, Subscription } from 'rxjs';\nimport { map, shareReplay } from 'rxjs/operators';\nimport { ContextDashboardComponent } from '@c8y/ngx-components/context-dashboard';\nimport { ReactiveFormsModule } from '@angular/forms';\n\nexport type DeviceControlMessageWidgetConfig = { device?: IManagedObject };\n\n@Component({\n selector: 'c8y-device-control-message-widget-view',\n templateUrl: './device-control-message-widget-view.component.html',\n standalone: true,\n imports: [CoreModule, ReactiveFormsModule]\n})\nexport class DeviceControlMessageWidgetViewComponent\n implements OnChanges, DynamicComponent, OnDestroy, OnInit\n{\n @Input() config: DeviceControlMessageWidgetConfig;\n operationSupportedByDevice$: Observable<boolean>;\n messageToBeSent = '';\n alerts: DynamicComponentAlertAggregator;\n private readonly operationAttribute = 'c8y_Message';\n private currentDevice = new BehaviorSubject<IManagedObject | null>(null);\n private operationSupportedByDeviceSubscription: Subscription;\n\n constructor(\n private alert: AlertService,\n private operation: OperationService,\n private translate: TranslateService,\n @Optional() private dashboard: ContextDashboardComponent\n ) {\n this.operationSupportedByDevice$ = this.currentDevice.pipe(\n map(device => {\n if (!device) {\n return false;\n }\n const supportedOperations = device.c8y_SupportedOperations;\n if (supportedOperations && Array.isArray(supportedOperations)) {\n return supportedOperations.includes(this.operationAttribute);\n }\n return false;\n }),\n shareReplay({ refCount: true, bufferSize: 1 })\n );\n }\n\n ngOnInit(): void {\n if (this.dashboard?.isDeviceTypeDashboard && this.dashboard?.context?.id) {\n this.currentDevice.next(this.dashboard.context);\n }\n this.operationSupportedByDeviceSubscription = this.operationSupportedByDevice$.subscribe(\n supported => {\n if (!supported) {\n this.alerts.addAlerts(\n new DynamicComponentAlert({\n type: 'warning',\n text: gettext('Operation not supported by this device')\n })\n );\n } else {\n this.alerts.clear();\n }\n }\n );\n }\n\n ngOnDestroy(): void {\n this.operationSupportedByDeviceSubscription?.unsubscribe();\n }\n\n ngOnChanges(): void {\n if (!this.dashboard?.isDeviceTypeDashboard && this.config.device) {\n this.currentDevice.next(this.config.device);\n }\n }\n\n async sendMessage() {\n const msg = this.messageToBeSent;\n const operationDescription = this.translate.instant(gettext('Send message \"{{msg}}\"'), { msg });\n try {\n await this.operation.create({\n deviceId: this.currentDevice.value?.id,\n description: operationDescription,\n [this.operationAttribute]: { text: msg }\n });\n this.alert.success(gettext('Message will be sent.'));\n this.messageToBeSent = '';\n } catch (e) {\n this.alert.addServerFailure(e);\n }\n }\n}\n","<div *ngIf=\"operationSupportedByDevice$ | async\" class=\"input-group p-16\">\n <input\n type=\"text\"\n class=\"form-control\"\n data-cy=\"c8y-device-control-message-widget-view--message-textbox\"\n [(ngModel)]=\"messageToBeSent\"\n placeholder=\"{{ 'Message' | translate }}\"\n />\n <span class=\"input-group-btn\">\n <button\n title=\"{{ 'Send' | translate }}\"\n class=\"btn btn-primary\"\n data-cy=\"c8y-device-control-message-widget-view--send-button\"\n (click)=\"sendMessage()\"\n [disabled]=\"!messageToBeSent\"\n translate\n >\n Send\n </button>\n </span>\n</div>\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;;;MAwBa,uCAAuC,CAAA;AAWlD,IAAA,WAAA,CACU,KA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