Browse Source

Merge pull request #9003 from rusikv/feature/create-latest-telemetry-key-value

Added dialog for creation latest telemetry key value
pull/9071/head
Igor Kulikov 3 years ago
committed by GitHub
parent
commit
2595466cf3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ui-ngx/src/app/modules/home/components/attribute/add-attribute-dialog.component.html
  2. 32
      ui-ngx/src/app/modules/home/components/attribute/add-attribute-dialog.component.ts
  3. 2
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.html
  4. 3
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts
  5. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

2
ui-ngx/src/app/modules/home/components/attribute/add-attribute-dialog.component.html

@ -17,7 +17,7 @@
--> -->
<form [formGroup]="attributeFormGroup" (ngSubmit)="add()" style="min-width: 400px;"> <form [formGroup]="attributeFormGroup" (ngSubmit)="add()" style="min-width: 400px;">
<mat-toolbar color="primary"> <mat-toolbar color="primary">
<h2>{{ 'attribute.add' | translate }}</h2> <h2>{{ title | translate }}</h2>
<span fxFlex></span> <span fxFlex></span>
<button mat-icon-button <button mat-icon-button
(click)="cancel()" (click)="cancel()"

32
ui-ngx/src/app/modules/home/components/attribute/add-attribute-dialog.component.ts

@ -19,16 +19,17 @@ import { ErrorStateMatcher } from '@angular/material/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms'; import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms';
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { DialogComponent } from '@app/shared/components/dialog.component'; import { DialogComponent } from '@app/shared/components/dialog.component';
import { AttributeData, AttributeScope } from '@shared/models/telemetry/telemetry.models'; import { AttributeData, AttributeScope, LatestTelemetry, TelemetryType } from '@shared/models/telemetry/telemetry.models';
import { AttributeService } from '@core/http/attribute.service'; import { AttributeService } from '@core/http/attribute.service';
import { Observable } from 'rxjs';
export interface AddAttributeDialogData { export interface AddAttributeDialogData {
entityId: EntityId; entityId: EntityId;
attributeScope: AttributeScope; attributeScope: TelemetryType;
} }
@Component({ @Component({
@ -40,17 +41,19 @@ export interface AddAttributeDialogData {
export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDialogComponent, boolean> export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDialogComponent, boolean>
implements OnInit, ErrorStateMatcher { implements OnInit, ErrorStateMatcher {
attributeFormGroup: UntypedFormGroup; attributeFormGroup: FormGroup;
submitted = false; submitted = false;
title = '';
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
protected router: Router, protected router: Router,
@Inject(MAT_DIALOG_DATA) public data: AddAttributeDialogData, @Inject(MAT_DIALOG_DATA) public data: AddAttributeDialogData,
private attributeService: AttributeService, private attributeService: AttributeService,
@SkipSelf() private errorStateMatcher: ErrorStateMatcher, @SkipSelf() private errorStateMatcher: ErrorStateMatcher,
public dialogRef: MatDialogRef<AddAttributeDialogComponent, boolean>, public dialogRef: MatDialogRef<AddAttributeDialogComponent, boolean>,
public fb: UntypedFormBuilder) { public fb: FormBuilder) {
super(store, router, dialogRef); super(store, router, dialogRef);
} }
@ -59,9 +62,11 @@ export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDia
key: ['', [Validators.required, Validators.maxLength(255)]], key: ['', [Validators.required, Validators.maxLength(255)]],
value: [null, [Validators.required]] value: [null, [Validators.required]]
}); });
this.title = this.data.attributeScope === LatestTelemetry.LATEST_TELEMETRY ?
'attribute.add-telemetry' : 'attribute.add'
} }
isErrorState(control: UntypedFormControl | null, form: FormGroupDirective | NgForm | null): boolean { isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const originalErrorState = this.errorStateMatcher.isErrorState(control, form); const originalErrorState = this.errorStateMatcher.isErrorState(control, form);
const customErrorState = !!(control && control.invalid && this.submitted); const customErrorState = !!(control && control.invalid && this.submitted);
return originalErrorState || customErrorState; return originalErrorState || customErrorState;
@ -78,11 +83,14 @@ export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDia
key: this.attributeFormGroup.get('key').value.trim(), key: this.attributeFormGroup.get('key').value.trim(),
value: this.attributeFormGroup.get('value').value value: this.attributeFormGroup.get('value').value
}; };
this.attributeService.saveEntityAttributes(this.data.entityId, let task: Observable<any>;
this.data.attributeScope, [attribute]).subscribe( if (this.data.attributeScope === LatestTelemetry.LATEST_TELEMETRY) {
() => { task = this.attributeService.saveEntityTimeseries(this.data.entityId,
this.dialogRef.close(true); this.data.attributeScope, [attribute]);
} } else {
); task = this.attributeService.saveEntityAttributes(this.data.entityId,
this.data.attributeScope as AttributeScope, [attribute]);
}
task.subscribe(() => this.dialogRef.close(true));
} }
} }

2
ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.html

@ -34,7 +34,7 @@
</div> </div>
<span fxFlex></span> <span fxFlex></span>
<button mat-icon-button <button mat-icon-button
*ngIf="!isClientSideTelemetryTypeMap.get(attributeScope)" *ngIf="attributeScope !== attributeScopeTypes.CLIENT_SCOPE"
[disabled]="isLoading$ | async" [disabled]="isLoading$ | async"
(click)="addAttribute($event)" (click)="addAttribute($event)"
matTooltip="{{ 'action.add' | translate }}" matTooltip="{{ 'action.add' | translate }}"

3
ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts

@ -100,6 +100,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
isClientSideTelemetryTypeMap = isClientSideTelemetryType; isClientSideTelemetryTypeMap = isClientSideTelemetryType;
latestTelemetryTypes = LatestTelemetry; latestTelemetryTypes = LatestTelemetry;
attributeScopeTypes = AttributeScope;
mode: 'default' | 'widget' = 'default'; mode: 'default' | 'widget' = 'default';
@ -313,7 +314,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: { data: {
entityId: this.entityIdValue, entityId: this.entityIdValue,
attributeScope: this.attributeScope as AttributeScope attributeScope: this.attributeScope
} }
}).afterClosed().subscribe( }).afterClosed().subscribe(
(res) => { (res) => {

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

@ -725,7 +725,8 @@
"no-attributes-text": "No attributes found", "no-attributes-text": "No attributes found",
"no-telemetry-text": "No telemetry found", "no-telemetry-text": "No telemetry found",
"copy-key": "Copy key", "copy-key": "Copy key",
"copy-value": "Copy value" "copy-value": "Copy value",
"add-telemetry": "Add telemetry"
}, },
"api-usage": { "api-usage": {
"api-features": "API features", "api-features": "API features",

Loading…
Cancel
Save