|
|
|
@ -14,13 +14,15 @@ |
|
|
|
/// limitations under the License.
|
|
|
|
///
|
|
|
|
|
|
|
|
import { Component, Inject, InjectionToken, OnInit } from '@angular/core'; |
|
|
|
import { Component, Inject, InjectionToken, OnDestroy, OnInit } from '@angular/core'; |
|
|
|
import { OverlayRef } from '@angular/cdk/overlay'; |
|
|
|
import { |
|
|
|
TimeseriesDeleteStrategy, |
|
|
|
timeseriesDeleteStrategyTranslations |
|
|
|
} from '@shared/models/telemetry/telemetry.models'; |
|
|
|
import { MINUTE } from '@shared/models/time/time.models'; |
|
|
|
import { AbstractControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; |
|
|
|
import { Subscription } from 'rxjs'; |
|
|
|
|
|
|
|
export const DELETE_TIMESERIES_PANEL_DATA = new InjectionToken<any>('DeleteTimeseriesPanelData'); |
|
|
|
|
|
|
|
@ -33,17 +35,15 @@ export interface DeleteTimeseriesPanelData { |
|
|
|
templateUrl: './delete-timeseries-panel.component.html', |
|
|
|
styleUrls: ['./delete-timeseries-panel.component.scss'] |
|
|
|
}) |
|
|
|
export class DeleteTimeseriesPanelComponent implements OnInit { |
|
|
|
export class DeleteTimeseriesPanelComponent implements OnInit, OnDestroy { |
|
|
|
|
|
|
|
strategy: string = TimeseriesDeleteStrategy.DELETE_ALL_DATA; |
|
|
|
deleteTimeseriesFormGroup: UntypedFormGroup; |
|
|
|
|
|
|
|
result: string = null; |
|
|
|
|
|
|
|
startDateTime: Date; |
|
|
|
startDateTimeSubscription: Subscription; |
|
|
|
|
|
|
|
endDateTime: Date; |
|
|
|
endDateTimeSubscription: Subscription; |
|
|
|
|
|
|
|
rewriteLatestIfDeleted: boolean = true; |
|
|
|
result: string = null; |
|
|
|
|
|
|
|
strategiesTranslationsMap = timeseriesDeleteStrategyTranslations; |
|
|
|
|
|
|
|
@ -53,22 +53,40 @@ export class DeleteTimeseriesPanelComponent implements OnInit { |
|
|
|
]; |
|
|
|
|
|
|
|
constructor(@Inject(DELETE_TIMESERIES_PANEL_DATA) public data: DeleteTimeseriesPanelData, |
|
|
|
public overlayRef: OverlayRef) { } |
|
|
|
public overlayRef: OverlayRef, |
|
|
|
public fb: UntypedFormBuilder) { } |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
let today = new Date(); |
|
|
|
this.startDateTime = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate()); |
|
|
|
this.endDateTime = today; |
|
|
|
const today = new Date(); |
|
|
|
if (this.data.isMultipleDeletion) { |
|
|
|
this.strategiesTranslationsMap = new Map(Array.from(this.strategiesTranslationsMap.entries()) |
|
|
|
.filter(([strategy]) => { |
|
|
|
return this.multipleDeletionStrategies.includes(strategy); |
|
|
|
})) |
|
|
|
} |
|
|
|
this.deleteTimeseriesFormGroup = this.fb.group({ |
|
|
|
strategy: [TimeseriesDeleteStrategy.DELETE_ALL_DATA], |
|
|
|
startDateTime: [new Date(today.getFullYear(), today.getMonth() - 1, today.getDate())], |
|
|
|
endDateTime: [today], |
|
|
|
rewriteLatest: [true] |
|
|
|
}) |
|
|
|
this.startDateTimeSubscription = this.getStartDateTimeFormControl().valueChanges.subscribe( |
|
|
|
value => this.onStartDateTimeChange(value) |
|
|
|
) |
|
|
|
this.endDateTimeSubscription = this.getEndDateTimeFormControl().valueChanges.subscribe( |
|
|
|
value => this.onEndDateTimeChange(value) |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
|
this.startDateTimeSubscription.unsubscribe(); |
|
|
|
this.startDateTimeSubscription = null; |
|
|
|
this.endDateTimeSubscription.unsubscribe(); |
|
|
|
this.endDateTimeSubscription = null; |
|
|
|
} |
|
|
|
|
|
|
|
delete(): void { |
|
|
|
this.result = this.strategy; |
|
|
|
this.result = this.getStrategyFormControl().value; |
|
|
|
this.overlayRef.dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -77,28 +95,50 @@ export class DeleteTimeseriesPanelComponent implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
isPeriodStrategy(): boolean { |
|
|
|
return this.strategy === TimeseriesDeleteStrategy.DELETE_ALL_DATA_FOR_TIME_PERIOD; |
|
|
|
return this.getStrategyFormControl().value === TimeseriesDeleteStrategy.DELETE_ALL_DATA_FOR_TIME_PERIOD; |
|
|
|
} |
|
|
|
|
|
|
|
isDeleteLatestStrategy(): boolean { |
|
|
|
return this.strategy === TimeseriesDeleteStrategy.DELETE_LATEST_VALUE; |
|
|
|
return this.getStrategyFormControl().value === TimeseriesDeleteStrategy.DELETE_LATEST_VALUE; |
|
|
|
} |
|
|
|
|
|
|
|
getStrategyFormControl(): AbstractControl { |
|
|
|
return this.deleteTimeseriesFormGroup.get('strategy'); |
|
|
|
} |
|
|
|
|
|
|
|
getStartDateTimeFormControl(): AbstractControl { |
|
|
|
return this.deleteTimeseriesFormGroup.get('startDateTime'); |
|
|
|
} |
|
|
|
|
|
|
|
getEndDateTimeFormControl(): AbstractControl { |
|
|
|
return this.deleteTimeseriesFormGroup.get('endDateTime'); |
|
|
|
} |
|
|
|
|
|
|
|
getRewriteLatestFormControl(): AbstractControl { |
|
|
|
return this.deleteTimeseriesFormGroup.get('rewriteLatest'); |
|
|
|
} |
|
|
|
|
|
|
|
onStartDateTimeChange(newStartDateTime: Date) { |
|
|
|
const endDateTimeTs = this.endDateTime.getTime(); |
|
|
|
if (newStartDateTime.getTime() >= endDateTimeTs) { |
|
|
|
this.startDateTime = new Date(endDateTimeTs - MINUTE); |
|
|
|
} else { |
|
|
|
this.startDateTime = newStartDateTime; |
|
|
|
if (newStartDateTime) { |
|
|
|
const endDateTimeTs = this.deleteTimeseriesFormGroup.get('endDateTime').value.getTime(); |
|
|
|
const startDateTimeControl = this.getStartDateTimeFormControl(); |
|
|
|
if (newStartDateTime.getTime() >= endDateTimeTs) { |
|
|
|
startDateTimeControl.patchValue(new Date(endDateTimeTs - MINUTE), {onlySelf: true, emitEvent: false}); |
|
|
|
} else { |
|
|
|
startDateTimeControl.patchValue(newStartDateTime, {onlySelf: true, emitEvent: false}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onEndDateTimeChange(newEndDateTime: Date) { |
|
|
|
const startDateTimeTs = this.startDateTime.getTime(); |
|
|
|
if (newEndDateTime.getTime() <= startDateTimeTs) { |
|
|
|
this.endDateTime = new Date(startDateTimeTs + MINUTE); |
|
|
|
} else { |
|
|
|
this.endDateTime = newEndDateTime; |
|
|
|
if (newEndDateTime) { |
|
|
|
const startDateTimeTs = this.deleteTimeseriesFormGroup.get('startDateTime').value.getTime(); |
|
|
|
const endDateTimeControl = this.getEndDateTimeFormControl(); |
|
|
|
if (newEndDateTime.getTime() <= startDateTimeTs) { |
|
|
|
endDateTimeControl.patchValue(new Date(startDateTimeTs + MINUTE), {onlySelf: true, emitEvent: false}); |
|
|
|
} else { |
|
|
|
endDateTimeControl.patchValue(newEndDateTime, {onlySelf: true, emitEvent: false}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|