2024-05-09 18:56:31 +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.
|
|
|
|
|
///
|
|
|
|
|
|
2024-05-20 18:08:25 +03:00
|
|
|
import {
|
|
|
|
|
AfterViewInit,
|
|
|
|
|
ChangeDetectorRef,
|
|
|
|
|
Component,
|
|
|
|
|
HostBinding,
|
|
|
|
|
OnDestroy,
|
|
|
|
|
OnInit,
|
|
|
|
|
ViewChild,
|
|
|
|
|
ViewEncapsulation
|
|
|
|
|
} from '@angular/core';
|
2024-05-09 18:56:31 +03:00
|
|
|
import { PageComponent } from '@shared/components/page.component';
|
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
import { AppState } from '@core/core.state';
|
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
|
import { ScadaSymbolData } from '@home/pages/scada-symbol/scada-symbol.models';
|
2024-05-17 19:31:35 +03:00
|
|
|
import { IotSvgMetadata, parseIotSvgMetadataFromContent } from '@home/components/widget/lib/svg/iot-svg.models';
|
2024-05-20 18:08:25 +03:00
|
|
|
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
|
|
|
|
import { deepClone } from '@core/utils';
|
|
|
|
|
import {
|
|
|
|
|
ScadaSymbolEditorComponent,
|
|
|
|
|
ScadaSymbolEditorData
|
|
|
|
|
} from '@home/pages/scada-symbol/scada-symbol-editor.component';
|
2024-05-09 18:56:31 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'tb-scada-symbol',
|
|
|
|
|
templateUrl: './scada-symbol.component.html',
|
|
|
|
|
styleUrls: ['./scada-symbol.component.scss'],
|
|
|
|
|
encapsulation: ViewEncapsulation.None
|
|
|
|
|
})
|
|
|
|
|
export class ScadaSymbolComponent extends PageComponent implements OnInit, OnDestroy, AfterViewInit {
|
|
|
|
|
|
|
|
|
|
@HostBinding('style.width') width = '100%';
|
|
|
|
|
@HostBinding('style.height') height = '100%';
|
|
|
|
|
|
2024-05-20 18:08:25 +03:00
|
|
|
@ViewChild('symbolEditor')
|
|
|
|
|
symbolEditor: ScadaSymbolEditorComponent;
|
|
|
|
|
|
2024-05-09 18:56:31 +03:00
|
|
|
symbolData: ScadaSymbolData;
|
2024-05-20 18:08:25 +03:00
|
|
|
symbolEditorData: ScadaSymbolEditorData;
|
2024-05-09 18:56:31 +03:00
|
|
|
metadata: IotSvgMetadata;
|
|
|
|
|
|
2024-05-20 18:08:25 +03:00
|
|
|
previewMode = false;
|
|
|
|
|
|
|
|
|
|
scadaSymbolFormGroup: UntypedFormGroup;
|
|
|
|
|
|
2024-05-09 18:56:31 +03:00
|
|
|
private destroy$ = new Subject<void>();
|
|
|
|
|
|
2024-05-20 18:08:25 +03:00
|
|
|
private origSymbolData: ScadaSymbolData;
|
|
|
|
|
|
2024-05-09 18:56:31 +03:00
|
|
|
constructor(protected store: Store<AppState>,
|
|
|
|
|
private router: Router,
|
2024-05-20 18:08:25 +03:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
|
private fb: UntypedFormBuilder,
|
|
|
|
|
private cd: ChangeDetectorRef) {
|
2024-05-09 18:56:31 +03:00
|
|
|
super(store);
|
2024-05-20 18:08:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.scadaSymbolFormGroup = this.fb.group({
|
|
|
|
|
metadata: [null]
|
|
|
|
|
});
|
2024-05-09 18:56:31 +03:00
|
|
|
this.route.data.pipe(
|
|
|
|
|
takeUntil(this.destroy$)
|
|
|
|
|
).subscribe(
|
|
|
|
|
() => {
|
|
|
|
|
this.reset();
|
2024-05-20 18:08:25 +03:00
|
|
|
this.init(this.route.snapshot.data.symbolData);
|
2024-05-09 18:56:31 +03:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
super.ngOnDestroy();
|
|
|
|
|
this.destroy$.next();
|
|
|
|
|
this.destroy$.complete();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 18:08:25 +03:00
|
|
|
onApplyScadaSymbolConfig() {
|
|
|
|
|
if (this.scadaSymbolFormGroup.valid) {
|
|
|
|
|
const svgContent = this.symbolEditor.getContent();
|
|
|
|
|
console.log(svgContent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onRevertScadaSymbolConfig() {
|
|
|
|
|
this.init(this.origSymbolData);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-09 18:56:31 +03:00
|
|
|
private reset(): void {
|
2024-05-20 18:08:25 +03:00
|
|
|
this.previewMode = false;
|
2024-05-09 18:56:31 +03:00
|
|
|
}
|
|
|
|
|
|
2024-05-20 18:08:25 +03:00
|
|
|
private init(data: ScadaSymbolData) {
|
|
|
|
|
this.origSymbolData = data;
|
|
|
|
|
this.symbolData = deepClone(data);
|
|
|
|
|
this.symbolEditorData = {
|
|
|
|
|
svgContent: this.symbolData.svgContent
|
|
|
|
|
};
|
2024-05-09 18:56:31 +03:00
|
|
|
this.metadata = parseIotSvgMetadataFromContent(this.symbolData.svgContent);
|
2024-05-20 18:08:25 +03:00
|
|
|
this.scadaSymbolFormGroup.patchValue({
|
|
|
|
|
metadata: this.metadata
|
|
|
|
|
}, {emitEvent: false});
|
|
|
|
|
this.scadaSymbolFormGroup.markAsPristine();
|
|
|
|
|
this.cd.markForCheck();
|
2024-05-09 18:56:31 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|