thingsboard/ui-ngx/src/app/modules/home/pages/rulechain/debug-config-button.component.ts

103 lines
3.5 KiB
TypeScript
Raw Normal View History

///
/// 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,
2024-11-12 17:13:58 +02:00
ChangeDetectorRef,
EventEmitter,
Output
} from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule } from '@shared/shared.module';
import { DebugDurationLeftPipe } from '@home/pages/rulechain/debug-duration-left.pipe';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { TbPopoverService } from '@shared/components/popover.service';
import { MatButton } from '@angular/material/button';
2024-11-12 17:13:58 +02:00
import { DebugConfigPanelComponent } from '@home/pages/rulechain/debug-config-panel.component';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { interval } from 'rxjs';
2024-11-12 17:13:58 +02:00
import { SECOND } from '@shared/models/time/time.models';
import { RuleNodeDebugConfig } from '@shared/models/rule-node.models';
@Component({
2024-11-12 17:13:58 +02:00
selector: 'tb-debug-config-button',
templateUrl: './debug-config-button.component.html',
standalone: true,
imports: [
CommonModule,
SharedModule,
DebugDurationLeftPipe,
],
changeDetection: ChangeDetectionStrategy.OnPush
})
2024-11-12 17:13:58 +02:00
export class DebugConfigButtonComponent {
2024-11-12 17:13:58 +02:00
@Input() debugFailures = false;
@Input() debugAll = false;
@Input() debugAllUntil = 0;
@Input() disabled = false;
2024-11-12 17:13:58 +02:00
@Output() onDebugConfigChanged = new EventEmitter<RuleNodeDebugConfig>()
constructor(protected store: Store<AppState>,
private popoverService: TbPopoverService,
private renderer: Renderer2,
private viewContainerRef: ViewContainerRef,
private destroyRef: DestroyRef,
private cdr: ChangeDetectorRef
) {
2024-11-12 17:13:58 +02:00
interval(SECOND)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => this.cdr.markForCheck());
}
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,
2024-11-12 17:13:58 +02:00
this.viewContainerRef, DebugConfigPanelComponent, 'bottom', true, null,
{
debugFailures: this.debugFailures,
debugAll: this.debugAll,
debugAllUntil: this.debugAllUntil,
},
{},
{}, {}, true);
debugStrategyPopover.tbComponentRef.instance.popover = debugStrategyPopover;
2024-11-12 17:13:58 +02:00
debugStrategyPopover.tbComponentRef.instance.onConfigApplied.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((config: RuleNodeDebugConfig) => {
this.onDebugConfigChanged.emit(config);
this.cdr.markForCheck();
debugStrategyPopover.hide();
});
}
}
2024-11-12 17:13:58 +02:00
isDebugAllActive(): boolean {
return this.debugAllUntil > new Date().getTime();
}
}