Added dialog for creation latest telemetry key value
This commit is contained in:
parent
91b0b0aead
commit
0f5841e9cb
@ -17,7 +17,7 @@
|
||||
-->
|
||||
<form [formGroup]="attributeFormGroup" (ngSubmit)="add()" style="min-width: 400px;">
|
||||
<mat-toolbar color="primary">
|
||||
<h2>{{ 'attribute.add' | translate }}</h2>
|
||||
<h2>{{ title | translate }}</h2>
|
||||
<span fxFlex></span>
|
||||
<button mat-icon-button
|
||||
(click)="cancel()"
|
||||
|
||||
@ -19,16 +19,17 @@ 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 { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms';
|
||||
import { FormGroupDirective, NgForm, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
|
||||
import { EntityId } from '@shared/models/id/entity-id';
|
||||
import { Router } from '@angular/router';
|
||||
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 { Observable } from 'rxjs';
|
||||
|
||||
export interface AddAttributeDialogData {
|
||||
entityId: EntityId;
|
||||
attributeScope: AttributeScope;
|
||||
attributeScope: TelemetryType;
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -44,6 +45,8 @@ export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDia
|
||||
|
||||
submitted = false;
|
||||
|
||||
title = '';
|
||||
|
||||
constructor(protected store: Store<AppState>,
|
||||
protected router: Router,
|
||||
@Inject(MAT_DIALOG_DATA) public data: AddAttributeDialogData,
|
||||
@ -59,6 +62,8 @@ export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDia
|
||||
key: ['', [Validators.required, Validators.maxLength(255)]],
|
||||
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 {
|
||||
@ -78,11 +83,15 @@ export class AddAttributeDialogComponent extends DialogComponent<AddAttributeDia
|
||||
key: this.attributeFormGroup.get('key').value.trim(),
|
||||
value: this.attributeFormGroup.get('value').value
|
||||
};
|
||||
this.attributeService.saveEntityAttributes(this.data.entityId,
|
||||
this.data.attributeScope, [attribute]).subscribe(
|
||||
() => {
|
||||
this.dialogRef.close(true);
|
||||
}
|
||||
);
|
||||
let task: Observable<any>;
|
||||
if (this.data.attributeScope === LatestTelemetry.LATEST_TELEMETRY) {
|
||||
task = this.attributeService.saveEntityTimeseries(this.data.entityId,
|
||||
this.data.attributeScope, [attribute]);
|
||||
}
|
||||
if (this.data.attributeScope in AttributeScope) {
|
||||
task = this.attributeService.saveEntityAttributes(this.data.entityId,
|
||||
this.data.attributeScope as AttributeScope, [attribute]);
|
||||
}
|
||||
task.subscribe(() => this.dialogRef.close(true));
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
</div>
|
||||
<span fxFlex></span>
|
||||
<button mat-icon-button
|
||||
*ngIf="!isClientSideTelemetryTypeMap.get(attributeScope)"
|
||||
*ngIf="!isClientSideTelemetryTypeMap.get(attributeScope) || attributeScope === latestTelemetryTypes.LATEST_TELEMETRY"
|
||||
[disabled]="isLoading$ | async"
|
||||
(click)="addAttribute($event)"
|
||||
matTooltip="{{ 'action.add' | translate }}"
|
||||
|
||||
@ -313,7 +313,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
|
||||
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
||||
data: {
|
||||
entityId: this.entityIdValue,
|
||||
attributeScope: this.attributeScope as AttributeScope
|
||||
attributeScope: this.attributeScope
|
||||
}
|
||||
}).afterClosed().subscribe(
|
||||
(res) => {
|
||||
|
||||
@ -718,7 +718,8 @@
|
||||
"no-attributes-text": "No attributes found",
|
||||
"no-telemetry-text": "No telemetry found",
|
||||
"copy-key": "Copy key",
|
||||
"copy-value": "Copy value"
|
||||
"copy-value": "Copy value",
|
||||
"add-telemetry": "Add telemetry"
|
||||
},
|
||||
"api-usage": {
|
||||
"api-features": "API features",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user