Browse Source

Merge pull request #11586 from ArtemDzhereleiko/AD/imp/minor-improvement-for-scada

Improvements for SCADA system
pull/11611/head
Igor Kulikov 2 years ago
committed by GitHub
parent
commit
a87a6cb118
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      ui-ngx/src/app/modules/home/components/widget/lib/scada/scada-symbol.models.ts
  2. 1
      ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-property-panel.component.html
  3. 1
      ui-ngx/src/app/modules/home/pages/widget/save-widget-type-as-dialog.component.html
  4. 4
      ui-ngx/src/app/modules/home/pages/widget/widget-library.module.ts
  5. 53
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-dialog.component.html
  6. 22
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-dialog.component.scss
  7. 78
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-dialog.component.ts
  8. 2
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle.component.html
  9. 9
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle.component.ts
  10. 12
      ui-ngx/src/app/shared/components/image/image-gallery.component.ts
  11. 7
      ui-ngx/src/app/shared/components/widgets-bundle-select.component.html
  12. 57
      ui-ngx/src/app/shared/components/widgets-bundle-select.component.ts
  13. 3
      ui-ngx/src/app/shared/models/widgets-bundle.model.ts
  14. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

18
ui-ngx/src/app/modules/home/components/widget/lib/scada/scada-symbol.models.ts

@ -191,10 +191,10 @@ export interface ScadaSymbolMetadata {
properties: ScadaSymbolProperty[]; properties: ScadaSymbolProperty[];
} }
export const emptyMetadata = (): ScadaSymbolMetadata => ({ export const emptyMetadata = (width?: number, height?: number): ScadaSymbolMetadata => ({
title: '', title: '',
widgetSizeX: 3, widgetSizeX: width ? width/100 : 3,
widgetSizeY: 3, widgetSizeY: height ? height/100 : 3,
tags: [], tags: [],
behavior: [], behavior: [],
properties: [] properties: []
@ -255,7 +255,17 @@ const parseScadaSymbolMetadataFromDom = (svgDoc: Document): ScadaSymbolMetadata
if (elements.length) { if (elements.length) {
return JSON.parse(elements[0].textContent); return JSON.parse(elements[0].textContent);
} else { } else {
return emptyMetadata(); const svg = svgDoc.getElementsByTagName('svg')[0];
let width = null;
let height = null;
if (svg.viewBox.baseVal.width && svg.viewBox.baseVal.height) {
width = svg.viewBox.baseVal.width;
height = svg.viewBox.baseVal.height;
} else if (svg.width.baseVal.value && svg.height.baseVal.value) {
width = svg.width.baseVal.value;
height = svg.height.baseVal.value;
}
return emptyMetadata(width, height);
} }
} catch (_e) { } catch (_e) {
console.error(_e); console.error(_e);

1
ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-property-panel.component.html

@ -136,6 +136,7 @@
<div class="fixed-title-width" translate>scada.property.disable-on-property</div> <div class="fixed-title-width" translate>scada.property.disable-on-property</div>
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> <mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic">
<mat-select formControlName="disableOnProperty" placeholder="{{ 'widget-config.set' | translate }}"> <mat-select formControlName="disableOnProperty" placeholder="{{ 'widget-config.set' | translate }}">
<mat-option [value]="null"></mat-option>
<mat-option *ngFor="let prop of booleanPropertyIds" [value]="prop"> <mat-option *ngFor="let prop of booleanPropertyIds" [value]="prop">
{{ prop }} {{ prop }}
</mat-option> </mat-option>

1
ui-ngx/src/app/modules/home/pages/widget/save-widget-type-as-dialog.component.html

@ -39,6 +39,7 @@
</mat-form-field> </mat-form-field>
<tb-widgets-bundle-select <tb-widgets-bundle-select
formControlName="widgetsBundle" formControlName="widgetsBundle"
createNew
bundlesScope="{{bundlesScope}}"> bundlesScope="{{bundlesScope}}">
</tb-widgets-bundle-select> </tb-widgets-bundle-select>
</div> </div>

4
ui-ngx/src/app/modules/home/pages/widget/widget-library.module.ts

@ -28,6 +28,7 @@ import { WidgetTypeComponent } from '@home/pages/widget/widget-type.component';
import { WidgetTypeTabsComponent } from '@home/pages/widget/widget-type-tabs.component'; import { WidgetTypeTabsComponent } from '@home/pages/widget/widget-type-tabs.component';
import { WidgetsBundleWidgetsComponent } from '@home/pages/widget/widgets-bundle-widgets.component'; import { WidgetsBundleWidgetsComponent } from '@home/pages/widget/widgets-bundle-widgets.component';
import { WidgetTypeAutocompleteComponent } from '@home/pages/widget/widget-type-autocomplete.component'; import { WidgetTypeAutocompleteComponent } from '@home/pages/widget/widget-type-autocomplete.component';
import { WidgetsBundleDialogComponent } from '@home/pages/widget/widgets-bundle-dialog.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -39,7 +40,8 @@ import { WidgetTypeAutocompleteComponent } from '@home/pages/widget/widget-type-
SelectWidgetTypeDialogComponent, SelectWidgetTypeDialogComponent,
SaveWidgetTypeAsDialogComponent, SaveWidgetTypeAsDialogComponent,
WidgetTypeTabsComponent, WidgetTypeTabsComponent,
WidgetsBundleTabsComponent WidgetsBundleTabsComponent,
WidgetsBundleDialogComponent
], ],
imports: [ imports: [
CommonModule, CommonModule,

53
ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-dialog.component.html

@ -0,0 +1,53 @@
<!--
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.
-->
<form (ngSubmit)="save()" style="width: 650px;">
<mat-toolbar color="primary">
<h2 translate>widgets-bundle.add</h2>
<span fxFlex></span>
<button mat-icon-button
(click)="cancel()"
type="button">
<mat-icon class="material-icons">close</mat-icon>
</button>
</mat-toolbar>
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async">
</mat-progress-bar>
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div>
<div mat-dialog-content>
<tb-widgets-bundle
#widgetsBundleComponent
[isEdit]="true"
[entity]="widgetsBundle"
[standalone]="true">
</tb-widgets-bundle>
</div>
<div mat-dialog-actions fxLayoutAlign="end center">
<button mat-button color="primary"
type="button"
cdkFocusInitial
[disabled]="(isLoading$ | async)"
(click)="cancel()">
{{ 'action.cancel' | translate }}
</button>
<button mat-raised-button color="primary"
type="submit"
[disabled]="(isLoading$ | async) || widgetsBundleComponent.entityForm?.invalid || !widgetsBundleComponent.entityForm?.dirty">
{{ 'action.add' | translate }}
</button>
</div>
</form>

22
ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-dialog.component.scss

@ -0,0 +1,22 @@
/**
* 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.
*/
:host ::ng-deep {
tb-widgets-bundle {
.mat-padding {
padding: 0;
}
}
}

78
ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-dialog.component.ts

@ -0,0 +1,78 @@
///
/// 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 { Component, Inject, SkipSelf, ViewChild } from '@angular/core';
import { ErrorStateMatcher } from '@angular/material/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { FormGroupDirective, NgForm, UntypedFormControl } from '@angular/forms';
import { DialogComponent } from '@shared/components/dialog.component';
import { Router } from '@angular/router';
import { WidgetsBundle } from '@shared/models/widgets-bundle.model';
import { WidgetsBundleComponent } from '@home/pages/widget/widgets-bundle.component';
import { WidgetService } from '@core/http/widget.service';
export interface WidgetsBundleDialogData {
widgetsBundle: WidgetsBundle;
}
@Component({
selector: 'tb-widgets-bundle-dialog',
templateUrl: './widgets-bundle-dialog.component.html',
providers: [{provide: ErrorStateMatcher, useExisting: WidgetsBundleDialogComponent}],
styleUrls: ['widgets-bundle-dialog.component.scss']
})
export class WidgetsBundleDialogComponent extends
DialogComponent<WidgetsBundleDialogComponent, WidgetsBundle> implements ErrorStateMatcher {
widgetsBundle: WidgetsBundle;
submitted = false;
@ViewChild('widgetsBundleComponent', {static: true}) widgetsBundleComponent: WidgetsBundleComponent;
constructor(protected store: Store<AppState>,
protected router: Router,
@Inject(MAT_DIALOG_DATA) public data: WidgetsBundleDialogData,
public dialogRef: MatDialogRef<WidgetsBundleDialogComponent, WidgetsBundle>,
@SkipSelf() private errorStateMatcher: ErrorStateMatcher,
private widgetsService: WidgetService) {
super(store, router, dialogRef);
this.widgetsBundle = this.data.widgetsBundle;
}
isErrorState(control: UntypedFormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const originalErrorState = this.errorStateMatcher.isErrorState(control, form);
const customErrorState = !!(control && control.invalid && this.submitted);
return originalErrorState || customErrorState;
}
cancel(): void {
this.dialogRef.close(null);
}
save(): void {
this.submitted = true;
if (this.widgetsBundleComponent.entityForm.valid) {
this.widgetsBundle = {...this.widgetsBundle, ...this.widgetsBundleComponent.entityFormValue()};
this.widgetsService.saveWidgetsBundle(this.widgetsBundle).subscribe((widgetBundle) => {
this.dialogRef.close(widgetBundle);
});
}
}
}

2
ui-ngx/src/app/modules/home/pages/widget/widgets-bundle.component.html

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
--> -->
<div class="tb-details-buttons" fxLayout.xs="column"> <div class="tb-details-buttons" fxLayout.xs="column" *ngIf="!standalone">
<button mat-raised-button color="primary" <button mat-raised-button color="primary"
[disabled]="(isLoading$ | async)" [disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'open')" (click)="onEntityAction($event, 'open')"

9
ui-ngx/src/app/modules/home/pages/widget/widgets-bundle.component.ts

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { ChangeDetectorRef, Component, Inject } from '@angular/core'; import { ChangeDetectorRef, Component, Inject, Input, Optional } from '@angular/core';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { EntityComponent } from '../../components/entity/entity.component'; import { EntityComponent } from '../../components/entity/entity.component';
@ -29,9 +29,12 @@ import { EntityTableConfig } from '@home/models/entity/entities-table-config.mod
}) })
export class WidgetsBundleComponent extends EntityComponent<WidgetsBundle> { export class WidgetsBundleComponent extends EntityComponent<WidgetsBundle> {
@Input()
standalone = false;
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
@Inject('entity') protected entityValue: WidgetsBundle, @Optional() @Inject('entity') protected entityValue: WidgetsBundle,
@Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig<WidgetsBundle>, @Optional() @Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig<WidgetsBundle>,
public fb: UntypedFormBuilder, public fb: UntypedFormBuilder,
protected cd: ChangeDetectorRef) { protected cd: ChangeDetectorRef) {
super(store, fb, entityValue, entitiesTableConfigValue, cd); super(store, fb, entityValue, entitiesTableConfigValue, cd);

12
ui-ngx/src/app/shared/components/image/image-gallery.component.ts

@ -639,11 +639,15 @@ export class ImageGalleryComponent extends PageComponent implements OnInit, OnDe
} }
rowClick($event, image: ImageResourceInfo) { rowClick($event, image: ImageResourceInfo) {
if (this.selectionMode) { if (this.isScada) {
this.selectImage($event, image); this.editImage($event, image);
} else { } else {
if (this.deleteEnabled(image)) { if (this.selectionMode) {
this.dataSource.selection.toggle(image); this.selectImage($event, image);
} else {
if (this.deleteEnabled(image)) {
this.dataSource.selection.toggle(image);
}
} }
} }
} }

7
ui-ngx/src/app/shared/components/widgets-bundle-select.component.html

@ -22,6 +22,7 @@
panelClass="tb-widgets-bundle-select" panelClass="tb-widgets-bundle-select"
placeholder="{{ 'widget.select-widgets-bundle' | translate }}" placeholder="{{ 'widget.select-widgets-bundle' | translate }}"
(blur)="onTouched()" (blur)="onTouched()"
[compareWith]="compareById"
(ngModelChange)="widgetsBundleChanged()"> (ngModelChange)="widgetsBundleChanged()">
<mat-select-trigger> <mat-select-trigger>
<div class="tb-bundle-item"> <div class="tb-bundle-item">
@ -29,8 +30,12 @@
<span translate class="tb-bundle-system" *ngIf="isSystem(widgetsBundle)">widgets-bundle.system</span> <span translate class="tb-bundle-system" *ngIf="isSystem(widgetsBundle)">widgets-bundle.system</span>
</div> </div>
</mat-select-trigger> </mat-select-trigger>
<mat-option [value]="null" *ngIf="!required"> <mat-option *ngIf="createNew; else empty" [value]="null" (click)="openWidgetsBundleDialog($event)">
<a translate>widgets-bundle.create-new</a>
</mat-option> </mat-option>
<ng-template #empty>
<mat-option [value]="null" *ngIf="!required"></mat-option>
</ng-template>
<mat-option *ngFor="let widgetsBundle of widgetsBundles$ | async" [value]="widgetsBundle"> <mat-option *ngFor="let widgetsBundle of widgetsBundles$ | async" [value]="widgetsBundle">
<div class="tb-bundle-item"> <div class="tb-bundle-item">
<span>{{widgetsBundle.title}}</span> <span>{{widgetsBundle.title}}</span>

57
ui-ngx/src/app/shared/components/widgets-bundle-select.component.ts

@ -14,9 +14,18 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, forwardRef, Input, OnChanges, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core'; import {
ChangeDetectorRef,
Component,
forwardRef,
Input,
OnChanges,
OnInit,
SimpleChanges,
ViewEncapsulation
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Observable } from 'rxjs'; import { Observable, of } from 'rxjs';
import { map, share, tap } from 'rxjs/operators'; import { map, share, tap } from 'rxjs/operators';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@app/core/core.state'; import { AppState } from '@app/core/core.state';
@ -26,6 +35,11 @@ import { isDefined } from '@core/utils';
import { NULL_UUID } from '@shared/models/id/has-uuid'; import { NULL_UUID } from '@shared/models/id/has-uuid';
import { getCurrentAuthState } from '@core/auth/auth.selectors'; import { getCurrentAuthState } from '@core/auth/auth.selectors';
import { coerceBoolean } from '@shared/decorators/coercion'; import { coerceBoolean } from '@shared/decorators/coercion';
import { MatDialog } from '@angular/material/dialog';
import {
WidgetsBundleDialogComponent,
WidgetsBundleDialogData
} from '@home/pages/widget/widgets-bundle-dialog.component';
@Component({ @Component({
selector: 'tb-widgets-bundle-select', selector: 'tb-widgets-bundle-select',
@ -60,6 +74,10 @@ export class WidgetsBundleSelectComponent implements ControlValueAccessor, OnIni
@Input() @Input()
excludeBundleIds: Array<string>; excludeBundleIds: Array<string>;
@Input()
@coerceBoolean()
createNew: boolean;
widgetsBundles$: Observable<Array<WidgetsBundle>>; widgetsBundles$: Observable<Array<WidgetsBundle>>;
widgetsBundles: Array<WidgetsBundle>; widgetsBundles: Array<WidgetsBundle>;
@ -70,7 +88,9 @@ export class WidgetsBundleSelectComponent implements ControlValueAccessor, OnIni
private propagateChange: (value: any) => void = () => {}; private propagateChange: (value: any) => void = () => {};
constructor(private store: Store<AppState>, constructor(private store: Store<AppState>,
private widgetService: WidgetService) { private widgetService: WidgetService,
private dialog: MatDialog,
private cd: ChangeDetectorRef) {
} }
registerOnChange(fn: any): void { registerOnChange(fn: any): void {
@ -171,4 +191,35 @@ export class WidgetsBundleSelectComponent implements ControlValueAccessor, OnIni
return widgetsBundlesObservable; return widgetsBundlesObservable;
} }
compareById(f1: WidgetsBundle, f2: WidgetsBundle): boolean {
return f1 && f2 && f1.id.id === f2.id.id;
}
openWidgetsBundleDialog($event) {
$event.preventDefault();
const widgetsBundle: WidgetsBundle = {
title: '',
image: '',
description: '',
scada: true,
order: null
};
this.dialog.open<WidgetsBundleDialogComponent, WidgetsBundleDialogData,
WidgetsBundle>(WidgetsBundleDialogComponent, {
disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
widgetsBundle
}
}).afterClosed().subscribe(
(savedWidgetBundle) => {
if (savedWidgetBundle) {
this.widgetsBundles$ = of([...this.widgetsBundles, savedWidgetBundle]);
this.widgetsBundle = savedWidgetBundle;
this.widgetsBundleChanged();
}
}
);
}
} }

3
ui-ngx/src/app/shared/models/widgets-bundle.model.ts

@ -20,8 +20,7 @@ import { WidgetsBundleId } from '@shared/models/id/widgets-bundle-id';
import { HasTenantId, HasVersion } from '@shared/models/entity.models'; import { HasTenantId, HasVersion } from '@shared/models/entity.models';
export interface WidgetsBundle extends BaseData<WidgetsBundleId>, HasTenantId, HasVersion, ExportableEntity<WidgetsBundleId> { export interface WidgetsBundle extends BaseData<WidgetsBundleId>, HasTenantId, HasVersion, ExportableEntity<WidgetsBundleId> {
tenantId: TenantId; alias?: string;
alias: string;
title: string; title: string;
image: string; image: string;
scada: boolean; scada: boolean;

3
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -5951,7 +5951,8 @@
"search": "Search widget bundles", "search": "Search widget bundles",
"selected-widgets-bundles": "{ count, plural, =1 {1 widgets bundle} other {# widgets bundles} } selected", "selected-widgets-bundles": "{ count, plural, =1 {1 widgets bundle} other {# widgets bundles} } selected",
"open-widgets-bundle": "Open widgets bundle", "open-widgets-bundle": "Open widgets bundle",
"loading-widgets-bundles": "Loading widgets bundles..." "loading-widgets-bundles": "Loading widgets bundles...",
"create-new": "Create new widget bundle"
}, },
"widget-config": { "widget-config": {
"data": "Data", "data": "Data",

Loading…
Cancel
Save