Browse Source

UI: Minor inmprovement for SCADA system

pull/11586/head
Artem Dzhereleiko 2 years ago
parent
commit
7c442b000a
  1. 9
      ui-ngx/src/app/modules/home/components/widget/lib/scada/scada-symbol.models.ts
  2. 3
      ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts
  3. 1
      ui-ngx/src/app/modules/home/pages/scada-symbol/metadata-components/scada-symbol-property-panel.component.html
  4. 1
      ui-ngx/src/app/modules/home/pages/widget/save-widget-type-as-dialog.component.html
  5. 4
      ui-ngx/src/app/modules/home/pages/widget/widget-library.module.ts
  6. 53
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-dialog.component.html
  7. 22
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-dialog.component.scss
  8. 95
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle-dialog.component.ts
  9. 2
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle.component.html
  10. 9
      ui-ngx/src/app/modules/home/pages/widget/widgets-bundle.component.ts
  11. 16
      ui-ngx/src/app/shared/components/image/image-gallery.component.ts
  12. 7
      ui-ngx/src/app/shared/components/widgets-bundle-select.component.html
  13. 57
      ui-ngx/src/app/shared/components/widgets-bundle-select.component.ts
  14. 3
      ui-ngx/src/app/shared/models/widgets-bundle.model.ts
  15. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

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

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

3
ui-ngx/src/app/modules/home/pages/admin/admin-routing.module.ts

@ -114,7 +114,8 @@ const routes: Routes = [
data: {
auth: [Authority.TENANT_ADMIN, Authority.SYS_ADMIN],
title: 'scada.symbols',
imageSubType: ResourceSubType.SCADA_SYMBOL
imageSubType: ResourceSubType.SCADA_SYMBOL,
editOnRowClick: true
}
},
{

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>
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic">
<mat-select formControlName="disableOnProperty" placeholder="{{ 'widget-config.set' | translate }}">
<mat-option [value]="null"></mat-option>
<mat-option *ngFor="let prop of booleanPropertyIds" [value]="prop">
{{ prop }}
</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>
<tb-widgets-bundle-select
formControlName="widgetsBundle"
createNew
bundlesScope="{{bundlesScope}}">
</tb-widgets-bundle-select>
</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 { WidgetsBundleWidgetsComponent } from '@home/pages/widget/widgets-bundle-widgets.component';
import { WidgetTypeAutocompleteComponent } from '@home/pages/widget/widget-type-autocomplete.component';
import { WidgetsBundleDialogComponent } from '@home/pages/widget/widgets-bundle-dialog.component';
@NgModule({
declarations: [
@ -39,7 +40,8 @@ import { WidgetTypeAutocompleteComponent } from '@home/pages/widget/widget-type-
SelectWidgetTypeDialogComponent,
SaveWidgetTypeAsDialogComponent,
WidgetTypeTabsComponent,
WidgetsBundleTabsComponent
WidgetsBundleTabsComponent,
WidgetsBundleDialogComponent
],
imports: [
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;
}
}
}

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

@ -0,0 +1,95 @@
///
/// 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 {
AfterViewInit,
Component,
ComponentFactoryResolver,
Inject,
Injector,
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 { TenantProfileService } from '@core/http/tenant-profile.service';
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, AfterViewInit {
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>,
private componentFactoryResolver: ComponentFactoryResolver,
private injector: Injector,
@SkipSelf() private errorStateMatcher: ErrorStateMatcher,
private widgetsService: WidgetService) {
super(store, router, dialogRef);
this.widgetsBundle = this.data.widgetsBundle;
}
ngAfterViewInit(): void {
setTimeout(() => {
this.widgetsBundleComponent.entityForm.markAsDirty();
}, 0);
}
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.
-->
<div class="tb-details-buttons" fxLayout.xs="column">
<div class="tb-details-buttons" fxLayout.xs="column" *ngIf="!standalone">
<button mat-raised-button color="primary"
[disabled]="(isLoading$ | async)"
(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.
///
import { ChangeDetectorRef, Component, Inject } from '@angular/core';
import { ChangeDetectorRef, Component, Inject, Input, Optional } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
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> {
@Input()
standalone = false;
constructor(protected store: Store<AppState>,
@Inject('entity') protected entityValue: WidgetsBundle,
@Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig<WidgetsBundle>,
@Optional() @Inject('entity') protected entityValue: WidgetsBundle,
@Optional() @Inject('entitiesTableConfig') protected entitiesTableConfigValue: EntityTableConfig<WidgetsBundle>,
public fb: UntypedFormBuilder,
protected cd: ChangeDetectorRef) {
super(store, fb, entityValue, entitiesTableConfigValue, cd);

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

@ -181,6 +181,8 @@ export class ImageGalleryComponent extends PageComponent implements OnInit, OnDe
return this.imageSubType === ResourceSubType.SCADA_SYMBOL;
}
private editOnRowClick = false;
private updateDataSubscription: Subscription;
private widgetResize$: ResizeObserver;
@ -217,6 +219,7 @@ export class ImageGalleryComponent extends PageComponent implements OnInit, OnDe
const routerQueryParams: PageQueryParam = this.route.snapshot.queryParams;
if (this.pageMode) {
this.imageSubType = this.route.snapshot.data.imageSubType || ResourceSubType.IMAGE;
this.editOnRowClick = this.route.snapshot.data.editOnRowClick || false;
if (routerQueryParams.hasOwnProperty('direction')
|| routerQueryParams.hasOwnProperty('property')) {
sortOrder = {
@ -639,11 +642,16 @@ export class ImageGalleryComponent extends PageComponent implements OnInit, OnDe
}
rowClick($event, image: ImageResourceInfo) {
if (this.selectionMode) {
this.selectImage($event, image);
if (this.editOnRowClick) {
this.editImage($event, image);
} else {
if (this.deleteEnabled(image)) {
this.dataSource.selection.toggle(image);
if (this.selectionMode) {
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"
placeholder="{{ 'widget.select-widgets-bundle' | translate }}"
(blur)="onTouched()"
[compareWith]="compareById"
(ngModelChange)="widgetsBundleChanged()">
<mat-select-trigger>
<div class="tb-bundle-item">
@ -29,8 +30,12 @@
<span translate class="tb-bundle-system" *ngIf="isSystem(widgetsBundle)">widgets-bundle.system</span>
</div>
</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>
<ng-template #empty>
<mat-option [value]="null" *ngIf="!required"></mat-option>
</ng-template>
<mat-option *ngFor="let widgetsBundle of widgetsBundles$ | async" [value]="widgetsBundle">
<div class="tb-bundle-item">
<span>{{widgetsBundle.title}}</span>

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

@ -14,9 +14,18 @@
/// 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 { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { map, share, tap } from 'rxjs/operators';
import { Store } from '@ngrx/store';
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 { getCurrentAuthState } from '@core/auth/auth.selectors';
import { coerceBoolean } from '@shared/decorators/coercion';
import { MatDialog } from '@angular/material/dialog';
import {
WidgetsBundleDialogComponent,
WidgetsBundleDialogData
} from '@home/pages/widget/widgets-bundle-dialog.component';
@Component({
selector: 'tb-widgets-bundle-select',
@ -60,6 +74,10 @@ export class WidgetsBundleSelectComponent implements ControlValueAccessor, OnIni
@Input()
excludeBundleIds: Array<string>;
@Input()
@coerceBoolean()
createNew: boolean;
widgetsBundles$: Observable<Array<WidgetsBundle>>;
widgetsBundles: Array<WidgetsBundle>;
@ -70,7 +88,9 @@ export class WidgetsBundleSelectComponent implements ControlValueAccessor, OnIni
private propagateChange: (value: any) => void = () => {};
constructor(private store: Store<AppState>,
private widgetService: WidgetService) {
private widgetService: WidgetService,
private dialog: MatDialog,
private cd: ChangeDetectorRef) {
}
registerOnChange(fn: any): void {
@ -171,4 +191,35 @@ export class WidgetsBundleSelectComponent implements ControlValueAccessor, OnIni
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';
export interface WidgetsBundle extends BaseData<WidgetsBundleId>, HasTenantId, HasVersion, ExportableEntity<WidgetsBundleId> {
tenantId: TenantId;
alias: string;
alias?: string;
title: string;
image: string;
scada: boolean;

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

@ -5935,7 +5935,8 @@
"search": "Search widget bundles",
"selected-widgets-bundles": "{ count, plural, =1 {1 widgets bundle} other {# widgets bundles} } selected",
"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": {
"data": "Data",

Loading…
Cancel
Save