Browse Source

added rewrite param to delete latest timeseries, enabled single selection deletion (#8933)

pull/9020/head
Ruslan Vasylkiv 3 years ago
committed by GitHub
parent
commit
32c2d44b0c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      ui-ngx/src/app/core/http/attribute.service.ts
  2. 2
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.html
  3. 11
      ui-ngx/src/app/modules/home/components/attribute/attribute-table.component.ts
  4. 2
      ui-ngx/src/app/modules/home/components/attribute/delete-timeseries-panel.component.html
  5. 6
      ui-ngx/src/app/modules/home/components/attribute/delete-timeseries-panel.component.ts

10
ui-ngx/src/app/core/http/attribute.service.ts

@ -50,7 +50,7 @@ export class AttributeService {
} }
public deleteEntityTimeseries(entityId: EntityId, timeseries: Array<AttributeData>, deleteAllDataForKeys = false, public deleteEntityTimeseries(entityId: EntityId, timeseries: Array<AttributeData>, deleteAllDataForKeys = false,
startTs?: number, endTs?: number, rewriteLatestIfDeleted = false, deleteLatest = false, startTs?: number, endTs?: number, rewriteLatestIfDeleted = false, deleteLatest = true,
config?: RequestConfig): Observable<any> { config?: RequestConfig): Observable<any> {
const keys = timeseries.map(attribute => encodeURIComponent(attribute.key)).join(','); const keys = timeseries.map(attribute => encodeURIComponent(attribute.key)).join(',');
let url = `/api/plugins/telemetry/${entityId.entityType}/${entityId.id}/timeseries/delete` + let url = `/api/plugins/telemetry/${entityId.entityType}/${entityId.id}/timeseries/delete` +
@ -64,9 +64,11 @@ export class AttributeService {
return this.http.delete(url, defaultHttpOptionsFromConfig(config)); return this.http.delete(url, defaultHttpOptionsFromConfig(config));
} }
public deleteEntityLatestTimeseries(entityId: EntityId, timeseries: Array<AttributeData>, config?: RequestConfig): Observable<any> { public deleteEntityLatestTimeseries(entityId: EntityId, timeseries: Array<AttributeData>, rewrite = true,
config?: RequestConfig): Observable<any> {
const keys = timeseries.map(attribute => encodeURIComponent(attribute.key)).join(','); const keys = timeseries.map(attribute => encodeURIComponent(attribute.key)).join(',');
let url = `/api/plugins/telemetry/${entityId.entityType}/${entityId.id}/timeseries/latest/delete?keys=${keys}`; let url = `/api/plugins/telemetry/${entityId.entityType}/${entityId.id}/timeseries/latest/delete?keys=${keys}` +
`$rewrite=${rewrite}`;
return this.http.delete(url, defaultHttpOptionsFromConfig(config)); return this.http.delete(url, defaultHttpOptionsFromConfig(config));
} }
@ -111,7 +113,7 @@ export class AttributeService {
let deleteEntityTimeseriesObservable: Observable<any>; let deleteEntityTimeseriesObservable: Observable<any>;
if (deleteTimeseries.length) { if (deleteTimeseries.length) {
deleteEntityTimeseriesObservable = this.deleteEntityTimeseries(entityId, deleteTimeseries, true, deleteEntityTimeseriesObservable = this.deleteEntityTimeseries(entityId, deleteTimeseries, true,
null, null, false, false, config); null, null, false, true, config);
} else { } else {
deleteEntityTimeseriesObservable = of(null); deleteEntityTimeseriesObservable = of(null);
} }

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

@ -93,7 +93,7 @@
(click)="deleteAttributes($event)"> (click)="deleteAttributes($event)">
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
</button> </button>
<button [fxShow]="attributeScope === latestTelemetryTypes.LATEST_TELEMETRY && dataSource.selection.selected.length > 1" <button [fxShow]="attributeScope === latestTelemetryTypes.LATEST_TELEMETRY"
class="button-widget-action" class="button-widget-action"
mat-icon-button [disabled]="isLoading$ | async" mat-icon-button [disabled]="isLoading$ | async"
matTooltip="{{ 'action.delete' | translate }}" matTooltip="{{ 'action.delete' | translate }}"

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

@ -386,7 +386,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
const isMultipleDeletion = isUndefinedOrNull(attribute); const isMultipleDeletion = isUndefinedOrNull(attribute) && this.dataSource.selection.selected.length > 1;
const target = $event.target || $event.srcElement || $event.currentTarget; const target = $event.target || $event.srcElement || $event.currentTarget;
const config = new OverlayConfig(); const config = new OverlayConfig();
config.backdropClass = 'cdk-overlay-transparent-backdrop'; config.backdropClass = 'cdk-overlay-transparent-backdrop';
@ -424,22 +424,23 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
componentRef.onDestroy(() => { componentRef.onDestroy(() => {
if (componentRef.instance.result !== null) { if (componentRef.instance.result !== null) {
const strategy = componentRef.instance.result; const strategy = componentRef.instance.result;
const timeseries = isMultipleDeletion ? this.dataSource.selection.selected : [attribute]; const timeseries = attribute ? [attribute]: this.dataSource.selection.selected;
let deleteAllDataForKeys = false; let deleteAllDataForKeys = false;
let rewriteLatestIfDeleted = false; let rewriteLatestIfDeleted = false;
let startTs = null; let startTs = null;
let endTs = null; let endTs = null;
let deleteLatest = false; let deleteLatest = true;
let task: Observable<any>; let task: Observable<any>;
if (strategy === TimeseriesDeleteStrategy.DELETE_ALL_DATA_INCLUDING_KEY) { if (strategy === TimeseriesDeleteStrategy.DELETE_ALL_DATA_INCLUDING_KEY) {
deleteAllDataForKeys = true; deleteAllDataForKeys = true;
deleteLatest = true;
} }
if (strategy === TimeseriesDeleteStrategy.DELETE_OLD_DATA_EXCEPT_LATEST_VALUE) { if (strategy === TimeseriesDeleteStrategy.DELETE_OLD_DATA_EXCEPT_LATEST_VALUE) {
deleteAllDataForKeys = true; deleteAllDataForKeys = true;
deleteLatest = false;
} }
if (strategy === TimeseriesDeleteStrategy.DELETE_LATEST_VALUE) { if (strategy === TimeseriesDeleteStrategy.DELETE_LATEST_VALUE) {
task = this.attributeService.deleteEntityLatestTimeseries(this.entityIdValue, timeseries); rewriteLatestIfDeleted = componentRef.instance.rewriteLatestIfDeleted;
task = this.attributeService.deleteEntityLatestTimeseries(this.entityIdValue, timeseries, rewriteLatestIfDeleted);
} }
if (strategy === TimeseriesDeleteStrategy.DELETE_DATA_FOR_TIME_PERIOD) { if (strategy === TimeseriesDeleteStrategy.DELETE_DATA_FOR_TIME_PERIOD) {
startTs = componentRef.instance.startDateTime.getTime(); startTs = componentRef.instance.startDateTime.getTime();

2
ui-ngx/src/app/modules/home/components/attribute/delete-timeseries-panel.component.html

@ -52,6 +52,8 @@
(ngModelChange)="onEndDateTimeChange($event)"> (ngModelChange)="onEndDateTimeChange($event)">
</mat-form-field> </mat-form-field>
</div> </div>
</div>
<div *ngIf="isPeriodStrategy() || isDeleteLatestStrategy()">
<mat-slide-toggle [(ngModel)]="rewriteLatestIfDeleted"> <mat-slide-toggle [(ngModel)]="rewriteLatestIfDeleted">
{{ "attribute.delete-timeseries.rewrite-latest-value-if-deleted" | translate }} {{ "attribute.delete-timeseries.rewrite-latest-value-if-deleted" | translate }}
</mat-slide-toggle> </mat-slide-toggle>

6
ui-ngx/src/app/modules/home/components/attribute/delete-timeseries-panel.component.ts

@ -43,7 +43,7 @@ export class DeleteTimeseriesPanelComponent implements OnInit {
endDateTime: Date; endDateTime: Date;
rewriteLatestIfDeleted: boolean = false; rewriteLatestIfDeleted: boolean = true;
strategiesTranslationsMap = timeseriesDeleteStrategyTranslations; strategiesTranslationsMap = timeseriesDeleteStrategyTranslations;
@ -80,6 +80,10 @@ export class DeleteTimeseriesPanelComponent implements OnInit {
return this.strategy === TimeseriesDeleteStrategy.DELETE_DATA_FOR_TIME_PERIOD; return this.strategy === TimeseriesDeleteStrategy.DELETE_DATA_FOR_TIME_PERIOD;
} }
isDeleteLatestStrategy(): boolean {
return this.strategy === TimeseriesDeleteStrategy.DELETE_LATEST_VALUE;
}
onStartDateTimeChange(newStartDateTime: Date) { onStartDateTimeChange(newStartDateTime: Date) {
const endDateTimeTs = this.endDateTime.getTime(); const endDateTimeTs = this.endDateTime.getTime();
if (newStartDateTime.getTime() >= endDateTimeTs) { if (newStartDateTime.getTime() >= endDateTimeTs) {

Loading…
Cancel
Save