diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tag.component.html b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tag.component.html index 830a629764..e3e0b82d82 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tag.component.html +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tag.component.html @@ -40,14 +40,15 @@
- + {{ 'scada.state-render-function' | translate }} - @@ -55,14 +56,15 @@
- + {{ 'scada.on-click-action' | translate }} - diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tag.component.ts b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tag.component.ts index 7ca3c909d4..f074955776 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tag.component.ts +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tag.component.ts @@ -16,12 +16,15 @@ import { ChangeDetectorRef, - Component, EventEmitter, + Component, + EventEmitter, forwardRef, Input, OnChanges, - OnInit, Output, - SimpleChanges, ViewChild, + OnInit, + Output, + SimpleChanges, + ViewChild, ViewEncapsulation } from '@angular/core'; import { @@ -33,6 +36,7 @@ import { } from '@angular/forms'; import { IotSvgTag } from '@home/components/widget/lib/svg/iot-svg.models'; import { MatExpansionPanel } from '@angular/material/expansion'; +import { JsFuncComponent } from '@shared/components/js-func.component'; @Component({ selector: 'tb-scada-symbol-metadata-tag', @@ -52,6 +56,18 @@ export class ScadaSymbolMetadataTagComponent implements ControlValueAccessor, On @ViewChild('expansionPanel') expansionPanel: MatExpansionPanel; + @ViewChild('renderFunctionExpansionPanel') + renderFunctionExpansionPanel: MatExpansionPanel; + + @ViewChild('clickActionExpansionPanel') + clickActionExpansionPanel: MatExpansionPanel; + + @ViewChild('stateRenderFunction') + stateRenderFunction: JsFuncComponent; + + @ViewChild('clickAction') + clickAction: JsFuncComponent; + @Input() disabled: boolean; @@ -131,6 +147,36 @@ export class ScadaSymbolMetadataTagComponent implements ControlValueAccessor, On ); } + editTagStateRenderFunction(): void { + this.openPanelWithCallback(this.expansionPanel, () => { + this.openPanelWithCallback(this.renderFunctionExpansionPanel, () => { + this.stateRenderFunction.focus(); + }); + }); + } + + editClickAction(): void { + this.openPanelWithCallback(this.expansionPanel, () => { + this.openPanelWithCallback(this.clickActionExpansionPanel, () => { + this.clickAction.focus(); + }); + }); + } + + private openPanelWithCallback(panel: MatExpansionPanel, callback: () => void) { + if (!panel.expanded) { + const s = panel.afterExpand.subscribe(() => { + s.unsubscribe(); + setTimeout(() => { + callback(); + }); + }); + panel.open(); + } else { + callback(); + } + } + private updateModel() { const value = this.tagFormGroup.value; if (value.tag && !this.modelValue?.tag) { diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tags.component.scss b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tags.component.scss index 1e2ce80fce..d4a1366a27 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tags.component.scss +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tags.component.scss @@ -14,7 +14,10 @@ * limitations under the License. */ .tb-scada-symbol-metadata-tags { + flex: 1; + margin: 12px; .tb-scada-symbol-metadata-tags-list { + overflow: auto; display: flex; flex-direction: column; gap: 8px; diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tags.component.ts b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tags.component.ts index d30c33aa0f..13bebfe72d 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tags.component.ts +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tags.component.ts @@ -14,7 +14,16 @@ /// limitations under the License. /// -import { Component, forwardRef, Input, OnChanges, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core'; +import { + Component, + forwardRef, HostBinding, + Input, + OnChanges, + OnInit, QueryList, + SimpleChanges, + ViewChildren, + ViewEncapsulation +} from '@angular/core'; import { AbstractControl, ControlValueAccessor, @@ -28,6 +37,9 @@ import { Validator } from '@angular/forms'; import { IotSvgTag } from '@home/components/widget/lib/svg/iot-svg.models'; +import { + ScadaSymbolMetadataTagComponent +} from '@home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tag.component'; const tagValidator = (control: AbstractControl): ValidationErrors | null => { const tag: IotSvgTag = control.value; @@ -59,6 +71,12 @@ const tagValidator = (control: AbstractControl): ValidationErrors | null => { }) export class ScadaSymbolMetadataTagsComponent implements ControlValueAccessor, OnInit, Validator, OnChanges { + @HostBinding('style.display') styleDisplay = 'flex'; + @HostBinding('style.overflow') styleOverflow = 'hidden'; + + @ViewChildren(ScadaSymbolMetadataTagComponent) + metadataTags: QueryList; + @Input() disabled: boolean; @@ -140,13 +158,44 @@ export class ScadaSymbolMetadataTagsComponent implements ControlValueAccessor, O return tagControl; } - removeTag(index: number) { - (this.tagsFormGroup.get('tags') as UntypedFormArray).removeAt(index); + removeTag(index: number, emitEvent = true) { + (this.tagsFormGroup.get('tags') as UntypedFormArray).removeAt(index, {emitEvent}); } addTag() { + this.addNewTag(null); + } + + editTagStateRenderFunction(tag: string): void { + this.addTagIfNotPresent(tag); + setTimeout(() => { + const tags: IotSvgTag[] = this.tagsFormGroup.get('tags').value; + const index = tags.findIndex(t => t.tag === tag); + const tagComponent = this.metadataTags.get(index); + tagComponent?.editTagStateRenderFunction(); + }); + } + + editTagClickAction(tag: string): void { + this.addTagIfNotPresent(tag); + setTimeout(() => { + const tags: IotSvgTag[] = this.tagsFormGroup.get('tags').value; + const index = tags.findIndex(t => t.tag === tag); + const tagComponent = this.metadataTags.get(index); + tagComponent?.editClickAction(); + }); + } + + private addTagIfNotPresent(tag: string) { + const tags: IotSvgTag[] = this.tagsFormGroup.get('tags').value; + if (!tags || !tags.find(t => t.tag === tag)) { + this.addNewTag(tag); + } + } + + private addNewTag(tagLabel: string) { const tag: IotSvgTag = { - tag: null + tag: tagLabel }; const tagsArray = this.tagsFormGroup.get('tags') as UntypedFormArray; const tagControl = this.fb.control(tag, [tagValidator]); @@ -164,6 +213,15 @@ export class ScadaSymbolMetadataTagsComponent implements ControlValueAccessor, O } private updateAvailableTags() { + if (this.tags) { + for (const c of this.tagsFormArray().controls) { + const svgTag: IotSvgTag = c.value; + if (svgTag.tag && !this.tags.includes(svgTag.tag)) { + const index = this.tagsFormArray().controls.indexOf(c); + this.removeTag(index, false); + } + } + } const svgTags: IotSvgTag[] = this.tagsFormGroup.get('tags').value; const usedTags = (svgTags || []).filter(t => !!t.tag).map(t => t.tag); this.availableTags = (this.tags || []).filter(t => !usedTags.includes(t)); diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.html b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.html index 13348302d0..16573951a7 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.html +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.html @@ -51,8 +51,9 @@
-
+
diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.scss b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.scss index bfaf8b0529..7b923e1688 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.scss +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.scss @@ -41,6 +41,7 @@ } } .tb-scada-symbol-metadata-content { + display: flex; & > .mat-content { padding-top: 8px; @media #{$mat-xs} { @@ -60,6 +61,9 @@ @media #{$mat-xs} { gap: 8px; } + &.overflow-hidden { + overflow: hidden; + } } .tb-form-panel { .mat-expansion-panel.tb-settings { diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.ts b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.ts index 966115c44e..d8b6267a8f 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.ts +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-metadata.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { Component, forwardRef, Input, OnInit, ViewEncapsulation } from '@angular/core'; +import { Component, forwardRef, Input, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; import { ControlValueAccessor, NG_VALIDATORS, @@ -29,9 +29,11 @@ import { PageComponent } from '@shared/components/page.component'; import { IotSvgMetadata } from '@home/components/widget/lib/svg/iot-svg.models'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; -import { WidgetConfigMode, widgetType } from '@shared/models/widget.models'; import { ToggleHeaderOption } from '@shared/components/toggle-header.component'; import { TranslateService } from '@ngx-translate/core'; +import { + ScadaSymbolMetadataTagsComponent +} from '@home/pages/scada-symbol/metadata-components/scada-symbol-metadata-tags.component'; @Component({ selector: 'tb-scada-symbol-metadata', @@ -53,6 +55,9 @@ import { TranslateService } from '@ngx-translate/core'; }) export class ScadaSymbolMetadataComponent extends PageComponent implements OnInit, ControlValueAccessor, Validator { + @ViewChild('symbolMetadataTags') + symbolMetadataTags: ScadaSymbolMetadataTagsComponent; + @Input() disabled: boolean; @@ -130,6 +135,16 @@ export class ScadaSymbolMetadataComponent extends PageComponent implements OnIni ); } + editTagStateRenderFunction(tag: string): void { + this.selectedOption = 'tags'; + this.symbolMetadataTags.editTagStateRenderFunction(tag); + } + + editTagClickAction(tag: string): void { + this.selectedOption = 'tags'; + this.symbolMetadataTags.editTagClickAction(tag); + } + public validate(c: UntypedFormControl) { const valid = this.metadataFormGroup.valid; return valid ? null : { @@ -144,7 +159,4 @@ export class ScadaSymbolMetadataComponent extends PageComponent implements OnIni this.modelValue = metadata; this.propagateChange(this.modelValue); } - - protected readonly WidgetConfigMode = WidgetConfigMode; - protected readonly widgetType = widgetType; } diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-editor.component.ts b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-editor.component.ts index cd25aa7063..10c2b3f7f0 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-editor.component.ts +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-editor.component.ts @@ -17,17 +17,17 @@ import { AfterViewInit, Component, - ElementRef, EventEmitter, + ElementRef, Input, OnChanges, OnDestroy, - OnInit, Output, + OnInit, SimpleChanges, ViewChild, ViewContainerRef, ViewEncapsulation } from '@angular/core'; -import { ScadaSymbolEditObject } from '@home/pages/scada-symbol/scada-symbol.models'; +import { ScadaSymbolEditObject, ScadaSymbolEditObjectCallbacks } from '@home/pages/scada-symbol/scada-symbol.models'; export interface ScadaSymbolEditorData { svgContent: string; @@ -47,8 +47,8 @@ export class ScadaSymbolEditorComponent implements OnInit, OnDestroy, AfterViewI @Input() data: ScadaSymbolEditorData; - @Output() - tags = new EventEmitter(); + @Input() + editObjectCallbacks: ScadaSymbolEditObjectCallbacks; scadaSymbolEditObject: ScadaSymbolEditObject; @@ -60,8 +60,7 @@ export class ScadaSymbolEditorComponent implements OnInit, OnDestroy, AfterViewI ngAfterViewInit() { this.scadaSymbolEditObject = new ScadaSymbolEditObject(this.iotSvgShape.nativeElement, - this.viewContainerRef); - this.scadaSymbolEditObject.tagsUpdated.subscribe(tags => this.tags.emit(tags)); + this.viewContainerRef, this.editObjectCallbacks); if (this.data) { this.scadaSymbolEditObject.setContent(this.data.svgContent); } @@ -86,13 +85,8 @@ export class ScadaSymbolEditorComponent implements OnInit, OnDestroy, AfterViewI this.scadaSymbolEditObject.destroy(); } - get dirty(): boolean { - return this.scadaSymbolEditObject?.dirty; - } - getContent(): string { return this.scadaSymbolEditObject?.getContent(); } - } diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-tooltip.component.scss b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-tooltip.component.scss index 1ea820b6a2..43613b6d40 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-tooltip.component.scss +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-tooltip.component.scss @@ -21,6 +21,9 @@ &.column { flex-direction: column; } + &.flex-start { + align-items: start; + } .tb-confirm-text { font-size: 14px; diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-tooltip.components.ts b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-tooltip.components.ts index faf091c5b7..813a652af1 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-tooltip.components.ts +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol-tooltip.components.ts @@ -189,6 +189,12 @@ class ScadaSymbolTagInputPanelComponent extends ScadaSymbolPanelComponent implem (click)="onUpdateTag()"> edit + + +
scada.on-click-action
+ + +
`, + styleUrls: ['./scada-symbol-tooltip.component.scss'], + encapsulation: ViewEncapsulation.None +}) +class ScadaSymbolTagSettingsComponent extends ScadaSymbolPanelComponent implements OnInit, AfterViewInit { + + hasStateRenderFunction = false; + + hasClickAction = false; + + constructor(public element: ElementRef) { + super(element); + } + + ngOnInit() { + } + + updateFunctionsState() { + this.hasStateRenderFunction = this.symbolElement.hasStateRenderFunction(); + this.hasClickAction = this.symbolElement.hasClickAction(); + } + + editStateRenderFunction() { + this.symbolElement.editStateRenderFunction(); + } + + editClickAction() { + this.symbolElement.editClickAction(); + } +} + @NgModule({ declarations: [ ScadaSymbolAddTagPanelComponent, ScadaSymbolTagInputPanelComponent, ScadaSymbolTagPanelComponent, - ScadaSymbolRemoveTagConfirmComponent + ScadaSymbolRemoveTagConfirmComponent, + ScadaSymbolTagSettingsComponent ], imports: [ CommonModule, diff --git a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol.component.html b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol.component.html index 82b415e570..449bf95bc7 100644 --- a/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol.component.html +++ b/ui-ngx/src/app/modules/home/pages/scada-symbol/scada-symbol.component.html @@ -64,6 +64,7 @@