2024-05-17 19:31:35 +03:00
|
|
|
///
|
|
|
|
|
/// Copyright © 2016-2024 The Thingsboard Authors
|
|
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import {
|
2024-06-06 17:26:41 +03:00
|
|
|
AfterViewInit, ChangeDetectorRef,
|
2024-05-17 19:31:35 +03:00
|
|
|
Component,
|
2024-06-07 15:41:57 +03:00
|
|
|
ElementRef, EventEmitter,
|
2024-05-17 19:31:35 +03:00
|
|
|
Input,
|
|
|
|
|
OnChanges,
|
|
|
|
|
OnDestroy,
|
2024-06-07 15:41:57 +03:00
|
|
|
OnInit, Output,
|
2024-05-17 19:31:35 +03:00
|
|
|
SimpleChanges,
|
|
|
|
|
ViewChild,
|
|
|
|
|
ViewContainerRef,
|
|
|
|
|
ViewEncapsulation
|
|
|
|
|
} from '@angular/core';
|
2024-05-30 18:20:50 +03:00
|
|
|
import { ScadaSymbolEditObject, ScadaSymbolEditObjectCallbacks } from '@home/pages/scada-symbol/scada-symbol-editor.models';
|
2024-06-06 17:26:41 +03:00
|
|
|
import { TbAnchorComponent } from '@shared/components/tb-anchor.component';
|
2024-05-17 19:31:35 +03:00
|
|
|
|
2024-05-20 18:08:25 +03:00
|
|
|
export interface ScadaSymbolEditorData {
|
2024-05-30 18:20:50 +03:00
|
|
|
scadaSymbolContent: string;
|
2024-05-20 18:08:25 +03:00
|
|
|
}
|
|
|
|
|
|
2024-05-17 19:31:35 +03:00
|
|
|
@Component({
|
|
|
|
|
selector: 'tb-scada-symbol-editor',
|
|
|
|
|
templateUrl: './scada-symbol-editor.component.html',
|
|
|
|
|
styleUrls: ['./scada-symbol-editor.component.scss'],
|
|
|
|
|
encapsulation: ViewEncapsulation.None
|
|
|
|
|
})
|
|
|
|
|
export class ScadaSymbolEditorComponent implements OnInit, OnDestroy, AfterViewInit, OnChanges {
|
|
|
|
|
|
2024-05-30 18:20:50 +03:00
|
|
|
@ViewChild('scadaSymbolShape', {static: false})
|
|
|
|
|
scadaSymbolShape: ElementRef<HTMLElement>;
|
2024-05-17 19:31:35 +03:00
|
|
|
|
2024-06-06 17:26:41 +03:00
|
|
|
@ViewChild('tooltipsContainer', {static: false})
|
|
|
|
|
tooltipsContainer: ElementRef<HTMLElement>;
|
|
|
|
|
|
|
|
|
|
@ViewChild('tooltipsContainerComponent', {static: true})
|
|
|
|
|
tooltipsContainerComponent: TbAnchorComponent;
|
|
|
|
|
|
2024-05-17 19:31:35 +03:00
|
|
|
@Input()
|
2024-05-20 18:08:25 +03:00
|
|
|
data: ScadaSymbolEditorData;
|
2024-05-17 19:31:35 +03:00
|
|
|
|
2024-05-23 12:20:37 +03:00
|
|
|
@Input()
|
|
|
|
|
editObjectCallbacks: ScadaSymbolEditObjectCallbacks;
|
2024-05-22 19:40:49 +03:00
|
|
|
|
2024-05-31 14:23:41 +03:00
|
|
|
@Input()
|
|
|
|
|
readonly: boolean;
|
|
|
|
|
|
2024-06-07 15:41:57 +03:00
|
|
|
@Output()
|
|
|
|
|
updateScadaSymbol = new EventEmitter();
|
|
|
|
|
|
|
|
|
|
@Output()
|
|
|
|
|
downloadScadaSymbol = new EventEmitter();
|
|
|
|
|
|
2024-05-17 19:31:35 +03:00
|
|
|
scadaSymbolEditObject: ScadaSymbolEditObject;
|
|
|
|
|
|
2024-06-06 17:26:41 +03:00
|
|
|
zoomInDisabled = false;
|
|
|
|
|
zoomOutDisabled = false;
|
|
|
|
|
|
|
|
|
|
constructor(private cd: ChangeDetectorRef) {
|
2024-05-17 19:31:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
2024-06-06 17:26:41 +03:00
|
|
|
this.editObjectCallbacks.onZoom = () => {
|
|
|
|
|
this.updateZoomButtonsState();
|
|
|
|
|
};
|
2024-05-30 18:20:50 +03:00
|
|
|
this.scadaSymbolEditObject = new ScadaSymbolEditObject(this.scadaSymbolShape.nativeElement,
|
2024-06-06 17:26:41 +03:00
|
|
|
this.tooltipsContainer.nativeElement,
|
|
|
|
|
this.tooltipsContainerComponent.viewContainerRef, this.editObjectCallbacks, this.readonly);
|
2024-05-20 18:08:25 +03:00
|
|
|
if (this.data) {
|
2024-06-06 17:26:41 +03:00
|
|
|
this.updateContent(this.data.scadaSymbolContent);
|
2024-05-17 19:31:35 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
|
for (const propName of Object.keys(changes)) {
|
|
|
|
|
const change = changes[propName];
|
|
|
|
|
if (!change.firstChange && change.currentValue !== change.previousValue) {
|
2024-05-20 18:08:25 +03:00
|
|
|
if (propName === 'data') {
|
2024-05-17 19:31:35 +03:00
|
|
|
if (this.scadaSymbolEditObject) {
|
2024-05-20 18:08:25 +03:00
|
|
|
setTimeout(() => {
|
2024-06-06 17:26:41 +03:00
|
|
|
this.updateContent(this.data.scadaSymbolContent);
|
2024-05-20 18:08:25 +03:00
|
|
|
});
|
2024-05-17 19:31:35 +03:00
|
|
|
}
|
2024-05-31 14:23:41 +03:00
|
|
|
} else if (propName === 'readonly') {
|
|
|
|
|
this.scadaSymbolEditObject.setReadOnly(this.readonly);
|
2024-05-17 19:31:35 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
this.scadaSymbolEditObject.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 18:08:25 +03:00
|
|
|
getContent(): string {
|
|
|
|
|
return this.scadaSymbolEditObject?.getContent();
|
|
|
|
|
}
|
2024-06-06 17:26:41 +03:00
|
|
|
|
|
|
|
|
zoomIn() {
|
|
|
|
|
this.scadaSymbolEditObject.zoomIn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zoomOut() {
|
|
|
|
|
this.scadaSymbolEditObject.zoomOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updateContent(content: string) {
|
|
|
|
|
this.scadaSymbolEditObject.setContent(content);
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.updateZoomButtonsState();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updateZoomButtonsState() {
|
|
|
|
|
this.zoomInDisabled = this.scadaSymbolEditObject.zoomInDisabled();
|
|
|
|
|
this.zoomOutDisabled = this.scadaSymbolEditObject.zoomOutDisabled();
|
|
|
|
|
this.cd.markForCheck();
|
|
|
|
|
}
|
2024-05-17 19:31:35 +03:00
|
|
|
}
|
|
|
|
|
|