Browse Source
Debug settings changed approach to object (ControlValueAccessor) and refactoringpull/12138/head
committed by
GitHub
19 changed files with 383 additions and 357 deletions
@ -1,46 +0,0 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 The Thingsboard Authors |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
|
|||
--> |
|||
<button mat-stroked-button |
|||
*ngIf="!minifyMode else minifiedButton" |
|||
class="tb-rounded-btn flex-1 w-36" |
|||
color="primary" |
|||
#matButton |
|||
[class.active]="((isDebugAllActive$ | async) || debugFailures) && !disabled" |
|||
[disabled]="disabled" |
|||
(click)="openDebugStrategyPanel($event, matButton)"> |
|||
<mat-icon [color]="disabled ? 'inherit' : 'primary'">bug_report</mat-icon> |
|||
<span *ngIf="!debugFailures && !(isDebugAllActive$ | async)" translate>common.disabled</span> |
|||
<span *ngIf="(isDebugAllActive$ | async) && debugFailures" translate>debug-config.all</span> |
|||
<span *ngIf="(isDebugAllActive$ | async) && !debugFailures"> |
|||
{{ !debugAll ? (debugAllUntil | durationLeft) : ('debug-config.min' | translate: { number: maxDebugModeDurationMinutes }) }} |
|||
</span> |
|||
<span *ngIf="!(isDebugAllActive$ | async) && debugFailures" translate>debug-config.failures</span> |
|||
</button> |
|||
<ng-template #minifiedButton> |
|||
<button mat-icon-button |
|||
class="mini-debug-btn" |
|||
[disabled]="disabled" |
|||
#matButton |
|||
[matTooltip]="(isDebugAllActive$ | async) ? (debugAllUntil | durationLeft) : null" |
|||
matTooltipPosition="above" |
|||
(click)="openDebugStrategyPanel($event, matButton)"> |
|||
<mat-icon class="material-icons" [color]="((isDebugAllActive$ | async) || debugFailures) && !disabled ? 'primary' : 'inherit'"> |
|||
bug_report |
|||
</mat-icon> |
|||
</button> |
|||
</ng-template> |
|||
@ -1,20 +0,0 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
:host { |
|||
.mini-debug-btn { |
|||
color: rgba(0, 0, 0, 0.6); |
|||
} |
|||
} |
|||
@ -1,102 +0,0 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { |
|||
Component, |
|||
Input, |
|||
Renderer2, |
|||
ViewContainerRef, |
|||
DestroyRef, |
|||
ChangeDetectionStrategy, |
|||
EventEmitter, |
|||
Output |
|||
} from '@angular/core'; |
|||
import { CommonModule } from '@angular/common'; |
|||
import { SharedModule } from '@shared/shared.module'; |
|||
import { DurationLeftPipe } from '@shared/pipe/duration-left.pipe'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { DebugConfigPanelComponent } from './debug-config-panel.component'; |
|||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|||
import { shareReplay, timer } from 'rxjs'; |
|||
import { SECOND } from '@shared/models/time/time.models'; |
|||
import { HasDebugConfig } from '@shared/models/entity.models'; |
|||
import { map } from 'rxjs/operators'; |
|||
import { getCurrentAuthState } from '@core/auth/auth.selectors'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { Store } from '@ngrx/store'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-debug-config-button', |
|||
templateUrl: './debug-config-button.component.html', |
|||
styleUrls: ['./debug-config-button.component.scss'], |
|||
standalone: true, |
|||
imports: [ |
|||
CommonModule, |
|||
SharedModule, |
|||
DurationLeftPipe, |
|||
], |
|||
changeDetection: ChangeDetectionStrategy.OnPush |
|||
}) |
|||
export class DebugConfigButtonComponent { |
|||
|
|||
@Input() debugFailures = false; |
|||
@Input() debugAll = false; |
|||
@Input() debugAllUntil = 0; |
|||
@Input() disabled = false; |
|||
@Input() minifyMode = false; |
|||
@Input() debugLimitsConfiguration: string; |
|||
|
|||
@Output() onDebugConfigChanged = new EventEmitter<HasDebugConfig>(); |
|||
|
|||
isDebugAllActive$ = timer(0, SECOND).pipe(map(() => this.debugAllUntil > new Date().getTime() || this.debugAll), shareReplay(1)); |
|||
|
|||
readonly maxDebugModeDurationMinutes = getCurrentAuthState(this.store).maxDebugModeDurationMinutes; |
|||
|
|||
constructor(private popoverService: TbPopoverService, |
|||
private renderer: Renderer2, |
|||
private store: Store<AppState>, |
|||
private viewContainerRef: ViewContainerRef, |
|||
private destroyRef: DestroyRef, |
|||
) {} |
|||
|
|||
openDebugStrategyPanel($event: Event, matButton: MatButton): void { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
const trigger = matButton._elementRef.nativeElement; |
|||
if (this.popoverService.hasPopover(trigger)) { |
|||
this.popoverService.hidePopover(trigger); |
|||
} else { |
|||
const debugStrategyPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, DebugConfigPanelComponent, 'bottom', true, null, |
|||
{ |
|||
debugFailures: this.debugFailures, |
|||
debugAll: this.debugAll, |
|||
debugAllUntil: this.debugAllUntil, |
|||
maxDebugModeDurationMinutes: this.maxDebugModeDurationMinutes, |
|||
debugLimitsConfiguration: this.debugLimitsConfiguration |
|||
}, |
|||
{}, |
|||
{}, {}, true); |
|||
debugStrategyPopover.tbComponentRef.instance.popover = debugStrategyPopover; |
|||
debugStrategyPopover.tbComponentRef.instance.onConfigApplied.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((config: HasDebugConfig) => { |
|||
this.onDebugConfigChanged.emit(config); |
|||
debugStrategyPopover.hide(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,112 +0,0 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { |
|||
ChangeDetectionStrategy, |
|||
ChangeDetectorRef, |
|||
Component, |
|||
EventEmitter, |
|||
Input, |
|||
OnInit |
|||
} from '@angular/core'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|||
import { UntypedFormBuilder } from '@angular/forms'; |
|||
import { CommonModule } from '@angular/common'; |
|||
import { SharedModule } from '@shared/shared.module'; |
|||
import { MINUTE, SECOND } from '@shared/models/time/time.models'; |
|||
import { DurationLeftPipe } from '@shared/pipe/duration-left.pipe'; |
|||
import { shareReplay, timer } from 'rxjs'; |
|||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|||
import { HasDebugConfig } from '@shared/models/entity.models'; |
|||
import { distinctUntilChanged, map, tap } from 'rxjs/operators'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-debug-config-panel', |
|||
templateUrl: './debug-config-panel.component.html', |
|||
standalone: true, |
|||
imports: [ |
|||
SharedModule, |
|||
CommonModule, |
|||
DurationLeftPipe |
|||
], |
|||
changeDetection: ChangeDetectionStrategy.OnPush |
|||
}) |
|||
export class DebugConfigPanelComponent extends PageComponent implements OnInit { |
|||
|
|||
@Input() popover: TbPopoverComponent<DebugConfigPanelComponent>; |
|||
@Input() debugFailures = false; |
|||
@Input() debugAll = false; |
|||
@Input() debugAllUntil = 0; |
|||
@Input() maxDebugModeDurationMinutes: number; |
|||
@Input() debugLimitsConfiguration: string; |
|||
|
|||
onFailuresControl = this.fb.control(false); |
|||
debugAllControl = this.fb.control(false); |
|||
|
|||
maxMessagesCount: string; |
|||
maxTimeFrameSec: string; |
|||
|
|||
isDebugAllActive$ = timer(0, SECOND).pipe( |
|||
map(() => { |
|||
this.cd.markForCheck(); |
|||
return this.debugAllUntil > new Date().getTime() || this.debugAll; |
|||
}), |
|||
distinctUntilChanged(), |
|||
tap(isDebugOn => this.debugAllControl.patchValue(isDebugOn, { emitEvent: false })), |
|||
shareReplay(1), |
|||
); |
|||
|
|||
onConfigApplied = new EventEmitter<HasDebugConfig>(); |
|||
|
|||
constructor(private fb: UntypedFormBuilder, private cd: ChangeDetectorRef) { |
|||
super(); |
|||
|
|||
this.observeDebugAllChange(); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.maxMessagesCount = this.debugLimitsConfiguration?.split(':')[0]; |
|||
this.maxTimeFrameSec = this.debugLimitsConfiguration?.split(':')[1]; |
|||
this.onFailuresControl.patchValue(this.debugFailures); |
|||
} |
|||
|
|||
onCancel(): void { |
|||
this.popover?.hide(); |
|||
} |
|||
|
|||
onApply(): void { |
|||
this.onConfigApplied.emit({ |
|||
debugAll: this.debugAll, |
|||
debugFailures: this.onFailuresControl.value, |
|||
debugAllUntil: this.debugAllUntil |
|||
}); |
|||
} |
|||
|
|||
onReset(): void { |
|||
this.debugAll = true; |
|||
this.debugAllUntil = new Date().getTime() + this.maxDebugModeDurationMinutes * MINUTE; |
|||
this.cd.markForCheck(); |
|||
} |
|||
|
|||
private observeDebugAllChange(): void { |
|||
this.debugAllControl.valueChanges.pipe(takeUntilDestroyed()).subscribe(value => { |
|||
this.debugAllUntil = value? new Date().getTime() + this.maxDebugModeDurationMinutes * MINUTE : 0; |
|||
this.debugAll = value; |
|||
this.cd.markForCheck(); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 The Thingsboard Authors |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
|
|||
--> |
|||
<button mat-stroked-button |
|||
class="tb-rounded-btn w-36 flex-1" |
|||
color="primary" |
|||
#matButton |
|||
[class.active]="((isDebugAllActive$ | async) || failuresEnabled) && !disabled" |
|||
[disabled]="disabled" |
|||
(click)="openDebugStrategyPanel($event, matButton)"> |
|||
<mat-icon [color]="debugSettingsFormGroup.disabled ? 'inherit' : 'primary'">bug_report</mat-icon> |
|||
<span *ngIf="!failuresEnabled && !(isDebugAllActive$ | async)" translate>common.disabled</span> |
|||
<span *ngIf="(isDebugAllActive$ | async) && failuresEnabled" translate>debug-config.all</span> |
|||
<span *ngIf="(isDebugAllActive$ | async) && !failuresEnabled"> |
|||
{{ !allEnabled ? (allEnabledUntil | durationLeft) : ('debug-config.min' | translate: { number: maxDebugModeDurationMinutes }) }} |
|||
</span> |
|||
<span *ngIf="!(isDebugAllActive$ | async) && failuresEnabled" translate>debug-config.failures</span> |
|||
</button> |
|||
@ -0,0 +1,155 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { ChangeDetectionStrategy, Component, forwardRef, Input, Renderer2, ViewContainerRef } from '@angular/core'; |
|||
import { CommonModule } from '@angular/common'; |
|||
import { SharedModule } from '@shared/shared.module'; |
|||
import { DurationLeftPipe } from '@shared/pipe/duration-left.pipe'; |
|||
import { TbPopoverService } from '@shared/components/popover.service'; |
|||
import { MatButton } from '@angular/material/button'; |
|||
import { DebugSettingsPanelComponent } from './debug-settings-panel.component'; |
|||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|||
import { of, shareReplay, timer } from 'rxjs'; |
|||
import { SECOND } from '@shared/models/time/time.models'; |
|||
import { DebugSettings } from '@shared/models/entity.models'; |
|||
import { map, startWith, switchMap, takeWhile } from 'rxjs/operators'; |
|||
import { getCurrentAuthState } from '@core/auth/auth.selectors'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { ControlValueAccessor, FormBuilder, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-debug-settings-button', |
|||
templateUrl: './debug-settings-button.component.html', |
|||
standalone: true, |
|||
imports: [ |
|||
CommonModule, |
|||
SharedModule, |
|||
DurationLeftPipe, |
|||
], |
|||
providers: [ |
|||
{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => DebugSettingsButtonComponent), |
|||
multi: true |
|||
}, |
|||
], |
|||
changeDetection: ChangeDetectionStrategy.OnPush |
|||
}) |
|||
export class DebugSettingsButtonComponent implements ControlValueAccessor { |
|||
|
|||
@Input() debugLimitsConfiguration: string; |
|||
|
|||
debugSettingsFormGroup = this.fb.group({ |
|||
failuresEnabled: [false], |
|||
allEnabled: [false], |
|||
allEnabledUntil: [] |
|||
}); |
|||
|
|||
disabled = false; |
|||
|
|||
isDebugAllActive$ = this.debugSettingsFormGroup.get('allEnabled').valueChanges.pipe( |
|||
startWith(this.debugSettingsFormGroup.get('allEnabled').value), |
|||
switchMap(value => { |
|||
if (value) { |
|||
return of(true); |
|||
} else { |
|||
return timer(0, SECOND).pipe( |
|||
map(() => this.allEnabledUntil > new Date().getTime()), |
|||
takeWhile(value => value, true) |
|||
); |
|||
} |
|||
}), |
|||
takeUntilDestroyed(), |
|||
shareReplay(1) |
|||
); |
|||
|
|||
readonly maxDebugModeDurationMinutes = getCurrentAuthState(this.store).maxDebugModeDurationMinutes; |
|||
|
|||
private propagateChange: (settings: DebugSettings) => void; |
|||
|
|||
constructor(private popoverService: TbPopoverService, |
|||
private renderer: Renderer2, |
|||
private store: Store<AppState>, |
|||
private viewContainerRef: ViewContainerRef, |
|||
private fb: FormBuilder, |
|||
) { |
|||
this.debugSettingsFormGroup.valueChanges.pipe( |
|||
takeUntilDestroyed() |
|||
).subscribe(value => { |
|||
this.propagateChange(value); |
|||
}) |
|||
} |
|||
|
|||
get failuresEnabled(): boolean { |
|||
return this.debugSettingsFormGroup.get('failuresEnabled').value; |
|||
} |
|||
|
|||
get allEnabled(): boolean { |
|||
return this.debugSettingsFormGroup.get('allEnabled').value; |
|||
} |
|||
|
|||
get allEnabledUntil(): number { |
|||
return this.debugSettingsFormGroup.get('allEnabledUntil').value; |
|||
} |
|||
|
|||
openDebugStrategyPanel($event: Event, matButton: MatButton): void { |
|||
if ($event) { |
|||
$event.stopPropagation(); |
|||
} |
|||
const trigger = matButton._elementRef.nativeElement; |
|||
const debugSettings = this.debugSettingsFormGroup.value; |
|||
|
|||
if (this.popoverService.hasPopover(trigger)) { |
|||
this.popoverService.hidePopover(trigger); |
|||
} else { |
|||
const debugStrategyPopover = this.popoverService.displayPopover(trigger, this.renderer, |
|||
this.viewContainerRef, DebugSettingsPanelComponent, 'bottom', true, null, |
|||
{ |
|||
...debugSettings, |
|||
maxDebugModeDurationMinutes: this.maxDebugModeDurationMinutes, |
|||
debugLimitsConfiguration: this.debugLimitsConfiguration |
|||
}, |
|||
{}, |
|||
{}, {}, true); |
|||
debugStrategyPopover.tbComponentRef.instance.popover = debugStrategyPopover; |
|||
debugStrategyPopover.tbComponentRef.instance.onSettingsApplied.subscribe((settings: DebugSettings) => { |
|||
this.debugSettingsFormGroup.patchValue(settings); |
|||
debugStrategyPopover.hide(); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
registerOnChange(fn: (settings: DebugSettings) => void): void { |
|||
this.propagateChange = fn; |
|||
} |
|||
|
|||
registerOnTouched(_: () => void): void {} |
|||
|
|||
writeValue(settings: DebugSettings): void { |
|||
this.debugSettingsFormGroup.patchValue(settings, {emitEvent: false}); |
|||
this.debugSettingsFormGroup.get('allEnabled').updateValueAndValidity({onlySelf: true}); |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
if (isDisabled) { |
|||
this.debugSettingsFormGroup.disable({emitEvent: false}); |
|||
} else { |
|||
this.debugSettingsFormGroup.enable({emitEvent: false}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,133 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { |
|||
booleanAttribute, |
|||
ChangeDetectionStrategy, |
|||
ChangeDetectorRef, |
|||
Component, |
|||
EventEmitter, |
|||
Input, |
|||
OnInit |
|||
} from '@angular/core'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { TbPopoverComponent } from '@shared/components/popover.component'; |
|||
import { FormBuilder } from '@angular/forms'; |
|||
import { CommonModule } from '@angular/common'; |
|||
import { SharedModule } from '@shared/shared.module'; |
|||
import { SECOND } from '@shared/models/time/time.models'; |
|||
import { DurationLeftPipe } from '@shared/pipe/duration-left.pipe'; |
|||
import { of, shareReplay, timer } from 'rxjs'; |
|||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|||
import { DebugSettings } from '@shared/models/entity.models'; |
|||
import { distinctUntilChanged, map, startWith, switchMap, takeWhile } from 'rxjs/operators'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-debug-settings-panel', |
|||
templateUrl: './debug-settings-panel.component.html', |
|||
standalone: true, |
|||
imports: [ |
|||
SharedModule, |
|||
CommonModule, |
|||
DurationLeftPipe |
|||
], |
|||
changeDetection: ChangeDetectionStrategy.OnPush |
|||
}) |
|||
export class DebugSettingsPanelComponent extends PageComponent implements OnInit { |
|||
|
|||
@Input() popover: TbPopoverComponent<DebugSettingsPanelComponent>; |
|||
@Input({ transform: booleanAttribute }) failuresEnabled = false; |
|||
@Input({ transform: booleanAttribute }) allEnabled = false; |
|||
@Input() allEnabledUntil = 0; |
|||
@Input() maxDebugModeDurationMinutes: number; |
|||
@Input() debugLimitsConfiguration: string; |
|||
|
|||
onFailuresControl = this.fb.control(false); |
|||
debugAllControl = this.fb.control(false); |
|||
|
|||
maxMessagesCount: string; |
|||
maxTimeFrameSec: string; |
|||
initialAllEnabled: boolean; |
|||
|
|||
isDebugAllActive$ = this.debugAllControl.valueChanges.pipe( |
|||
startWith(this.debugAllControl.value), |
|||
switchMap(value => { |
|||
if (value) { |
|||
return of(true); |
|||
} else { |
|||
return timer(0, SECOND).pipe( |
|||
map(() => this.allEnabledUntil > new Date().getTime()), |
|||
takeWhile(value => value, true) |
|||
); |
|||
} |
|||
}), |
|||
takeUntilDestroyed(), |
|||
shareReplay(1), |
|||
); |
|||
|
|||
onSettingsApplied = new EventEmitter<DebugSettings>(); |
|||
|
|||
constructor(private fb: FormBuilder, |
|||
private cd: ChangeDetectorRef) { |
|||
super(); |
|||
|
|||
this.debugAllControl.valueChanges.pipe( |
|||
takeUntilDestroyed() |
|||
).subscribe(value => { |
|||
this.allEnabled = value; |
|||
this.cd.markForCheck(); |
|||
}); |
|||
|
|||
this.isDebugAllActive$.pipe( |
|||
distinctUntilChanged(), |
|||
takeUntilDestroyed() |
|||
).subscribe(isDebugOn => this.debugAllControl.patchValue(isDebugOn, {emitEvent: false})) |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.maxMessagesCount = this.debugLimitsConfiguration?.split(':')[0]; |
|||
this.maxTimeFrameSec = this.debugLimitsConfiguration?.split(':')[1]; |
|||
this.onFailuresControl.patchValue(this.failuresEnabled); |
|||
this.debugAllControl.patchValue(this.allEnabled); |
|||
this.initialAllEnabled = this.allEnabled || this.allEnabledUntil > new Date().getTime(); |
|||
} |
|||
|
|||
onCancel(): void { |
|||
this.popover?.hide(); |
|||
} |
|||
|
|||
onApply(): void { |
|||
const isDebugAllChanged = this.initialAllEnabled !== this.debugAllControl.value || this.initialAllEnabled !== this.allEnabledUntil > new Date().getTime(); |
|||
if (isDebugAllChanged) { |
|||
this.onSettingsApplied.emit({ |
|||
allEnabled: this.allEnabled, |
|||
failuresEnabled: this.onFailuresControl.value, |
|||
allEnabledUntil: 0, |
|||
}); |
|||
} else { |
|||
this.onSettingsApplied.emit({ |
|||
allEnabled: false, |
|||
failuresEnabled: this.onFailuresControl.value, |
|||
}); |
|||
} |
|||
} |
|||
|
|||
onReset(): void { |
|||
this.debugAllControl.patchValue(true); |
|||
this.allEnabledUntil = 0; |
|||
this.cd.markForCheck(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue