Timewindow: optimize false properties deletion
This commit is contained in:
parent
6d509ca5d9
commit
d95a00e4af
@ -197,6 +197,23 @@ export function deleteNullProperties(obj: any) {
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteFalseProperties(obj: any) {
|
||||
if (isUndefinedOrNull(obj)) {
|
||||
return;
|
||||
}
|
||||
Object.keys(obj).forEach((propName) => {
|
||||
if (obj[propName] === false || isUndefinedOrNull(obj[propName])) {
|
||||
delete obj[propName];
|
||||
} else if (isObject(obj[propName])) {
|
||||
deleteFalseProperties(obj[propName]);
|
||||
} else if (Array.isArray(obj[propName])) {
|
||||
(obj[propName] as any[]).forEach((elem) => {
|
||||
deleteFalseProperties(elem);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function objToBase64(obj: any): string {
|
||||
const json = JSON.stringify(obj);
|
||||
return btoa(encodeURIComponent(json).replace(/%([0-9A-F]{2})/g,
|
||||
|
||||
@ -36,7 +36,15 @@ import { Store } from '@ngrx/store';
|
||||
import { AppState } from '@core/core.state';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { TimeService } from '@core/services/time.service';
|
||||
import { deepClean, deepClone, isDefined, isDefinedAndNotNull, isEmpty, mergeDeepIgnoreArray } from '@core/utils';
|
||||
import {
|
||||
deepClean,
|
||||
deepClone,
|
||||
deleteFalseProperties,
|
||||
isDefined,
|
||||
isDefinedAndNotNull,
|
||||
isEmpty,
|
||||
mergeDeepIgnoreArray
|
||||
} from '@core/utils';
|
||||
import { ToggleHeaderOption } from '@shared/components/toggle-header.component';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
@ -472,54 +480,11 @@ export class TimewindowConfigDialogComponent extends PageComponent implements On
|
||||
delete this.timewindow.allowedAggTypes;
|
||||
}
|
||||
|
||||
if (!this.timewindow.realtime.disableCustomInterval) {
|
||||
delete this.timewindow.realtime.disableCustomInterval;
|
||||
}
|
||||
if (!this.timewindow.realtime.disableCustomGroupInterval) {
|
||||
delete this.timewindow.realtime.disableCustomGroupInterval;
|
||||
}
|
||||
if (!this.timewindow.history.disableCustomInterval) {
|
||||
delete this.timewindow.history.disableCustomInterval;
|
||||
}
|
||||
if (!this.timewindow.history.disableCustomGroupInterval) {
|
||||
delete this.timewindow.history.disableCustomGroupInterval;
|
||||
}
|
||||
|
||||
if (!this.timewindow.hideAggregation) {
|
||||
delete this.timewindow.hideAggregation;
|
||||
}
|
||||
if (!this.timewindow.hideAggInterval) {
|
||||
delete this.timewindow.hideAggInterval;
|
||||
}
|
||||
if (!this.timewindow.hideTimezone) {
|
||||
delete this.timewindow.hideTimezone;
|
||||
}
|
||||
|
||||
if (!this.timewindow.realtime.hideInterval) {
|
||||
delete this.timewindow.realtime.hideInterval;
|
||||
}
|
||||
if (!this.timewindow.realtime.hideLastInterval) {
|
||||
delete this.timewindow.realtime.hideLastInterval;
|
||||
}
|
||||
if (!this.timewindow.realtime.hideQuickInterval) {
|
||||
delete this.timewindow.realtime.hideQuickInterval;
|
||||
}
|
||||
if (!this.timewindow.history.hideInterval) {
|
||||
delete this.timewindow.history.hideInterval;
|
||||
}
|
||||
if (!this.timewindow.history.hideLastInterval) {
|
||||
delete this.timewindow.history.hideLastInterval;
|
||||
}
|
||||
if (!this.timewindow.history.hideFixedInterval) {
|
||||
delete this.timewindow.history.hideFixedInterval;
|
||||
}
|
||||
if (!this.timewindow.history.hideQuickInterval) {
|
||||
delete this.timewindow.history.hideQuickInterval;
|
||||
}
|
||||
|
||||
if (!this.aggregation) {
|
||||
delete this.timewindow.aggregation;
|
||||
}
|
||||
|
||||
deleteFalseProperties(this.timewindow);
|
||||
this.dialogRef.close(deepClean(this.timewindow));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user