Merge pull request #12212 from maxunbearable/fix/debug-settings-ui-fixes

Debug Settings fixes
This commit is contained in:
Igor Kulikov 2024-12-09 19:04:15 +02:00 committed by GitHub
commit 99cfdab78c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 86 additions and 77 deletions

View File

@ -305,7 +305,11 @@ export class ItemBufferService {
connectors: [],
additionalInfo: origNode.additionalInfo,
configuration: origNode.configuration,
debugMode: origNode.debugMode,
debugSettings: {
failuresEnabled: origNode.debugSettings?.failuresEnabled,
allEnabled: origNode.debugSettings?.allEnabled || origNode.debugSettings?.allEnabledUntil > new Date().getTime(),
allEnabledUntil: 0
},
x: origNode.x,
y: origNode.y,
name: origNode.name,

View File

@ -23,10 +23,9 @@
[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>
@if (isDebugAllActive$ | async) {
{{ !allEnabled() ? (allEnabledUntil | durationLeft) : (maxDebugModeDuration | milliSecondsToTimeString: true : true) }}
} @else {
{{ (failuresEnabled ? 'debug-config.failures' : 'common.disabled') | translate }}
}
</button>

View File

@ -14,18 +14,27 @@
/// limitations under the License.
///
import { ChangeDetectionStrategy, Component, forwardRef, Input, Renderer2, ViewContainerRef } from '@angular/core';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
forwardRef,
Input,
Renderer2,
signal,
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 { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
import { of, shareReplay, timer } from 'rxjs';
import { SECOND } from '@shared/models/time/time.models';
import { MINUTE, SECOND } from '@shared/models/time/time.models';
import { DebugSettings } from '@shared/models/entity.models';
import { map, startWith, switchMap, takeWhile } from 'rxjs/operators';
import { map, switchMap, takeWhile } from 'rxjs/operators';
import { getCurrentAuthState } from '@core/auth/auth.selectors';
import { AppState } from '@core/core.state';
import { Store } from '@ngrx/store';
@ -60,11 +69,11 @@ export class DebugSettingsButtonComponent implements ControlValueAccessor {
});
disabled = false;
allEnabled = signal(false);
isDebugAllActive$ = this.debugSettingsFormGroup.get('allEnabled').valueChanges.pipe(
startWith(null),
switchMap(() => {
if (this.allEnabled) {
isDebugAllActive$ = toObservable(this.allEnabled).pipe(
switchMap((value) => {
if (value) {
return of(true);
} else {
return timer(0, SECOND).pipe(
@ -77,7 +86,7 @@ export class DebugSettingsButtonComponent implements ControlValueAccessor {
shareReplay(1)
);
readonly maxDebugModeDurationMinutes = getCurrentAuthState(this.store).maxDebugModeDurationMinutes;
readonly maxDebugModeDuration = getCurrentAuthState(this.store).maxDebugModeDurationMinutes * MINUTE;
private propagateChange: (settings: DebugSettings) => void = () => {};
@ -86,22 +95,23 @@ export class DebugSettingsButtonComponent implements ControlValueAccessor {
private store: Store<AppState>,
private viewContainerRef: ViewContainerRef,
private fb: FormBuilder,
private cd : ChangeDetectorRef,
) {
this.debugSettingsFormGroup.valueChanges.pipe(
takeUntilDestroyed()
).subscribe(value => {
this.propagateChange(value);
})
});
this.debugSettingsFormGroup.get('allEnabled').valueChanges.pipe(
takeUntilDestroyed()
).subscribe(value => this.allEnabled.set(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;
}
@ -120,7 +130,7 @@ export class DebugSettingsButtonComponent implements ControlValueAccessor {
this.viewContainerRef, DebugSettingsPanelComponent, 'bottom', true, null,
{
...debugSettings,
maxDebugModeDurationMinutes: this.maxDebugModeDurationMinutes,
maxDebugModeDuration: this.maxDebugModeDuration,
debugLimitsConfiguration: this.debugLimitsConfiguration
},
{},
@ -128,6 +138,7 @@ export class DebugSettingsButtonComponent implements ControlValueAccessor {
debugStrategyPopover.tbComponentRef.instance.popover = debugStrategyPopover;
debugStrategyPopover.tbComponentRef.instance.onSettingsApplied.subscribe((settings: DebugSettings) => {
this.debugSettingsFormGroup.patchValue(settings);
this.cd.markForCheck();
debugStrategyPopover.hide();
});
}
@ -141,6 +152,7 @@ export class DebugSettingsButtonComponent implements ControlValueAccessor {
writeValue(settings: DebugSettings): void {
this.debugSettingsFormGroup.patchValue(settings, {emitEvent: false});
this.allEnabled.set(settings?.allEnabled);
this.debugSettingsFormGroup.get('allEnabled').updateValueAndValidity({onlySelf: true});
}

View File

@ -20,7 +20,7 @@
<div class="hint-container">
<div class="tb-form-hint tb-primary-fill tb-flex center">
@if (debugLimitsConfiguration) {
{{ 'debug-config.hint.main-limited' | translate: { msg: maxMessagesCount, sec: maxTimeFrameSec } }}
{{ 'debug-config.hint.main-limited' | translate: { msg: maxMessagesCount, time: (maxTimeFrameDuration | milliSecondsToTimeString: true : true) } }}
} @else {
{{ 'debug-config.hint.main' | translate }}
}
@ -35,7 +35,7 @@
<div class="align-center flex justify-between">
<mat-slide-toggle class="mat-slide" [formControl]="debugAllControl">
<div tb-hint-tooltip-icon="{{ 'debug-config.hint.all-messages' | translate }}">
{{ 'debug-config.all-messages' | translate: { time: (isDebugAllActive$ | async) && !allEnabled ? (allEnabledUntil | durationLeft) : ('debug-config.min' | translate: { number: maxDebugModeDurationMinutes }) } }}
{{ 'debug-config.all-messages' | translate: { time: (isDebugAllActive$ | async) && !allEnabled ? (allEnabledUntil | durationLeft) : (maxDebugModeDuration | milliSecondsToTimeString: true : true) } }}
</div>
</mat-slide-toggle>
<button mat-icon-button *ngIf="(isDebugAllActive$ | async) && !allEnabled"
@ -58,6 +58,7 @@
<button mat-raised-button
color="primary"
type="button"
[disabled]="(isLoading$ | async) || !onFailuresControl.dirty && !debugAllControl.dirty"
(click)="onApply()">
{{ 'action.apply' | translate }}
</button>

View File

@ -52,14 +52,14 @@ export class DebugSettingsPanelComponent extends PageComponent implements OnInit
@Input({ transform: booleanAttribute }) failuresEnabled = false;
@Input({ transform: booleanAttribute }) allEnabled = false;
@Input() allEnabledUntil = 0;
@Input() maxDebugModeDurationMinutes: number;
@Input() maxDebugModeDuration: number;
@Input() debugLimitsConfiguration: string;
onFailuresControl = this.fb.control(false);
debugAllControl = this.fb.control(false);
maxMessagesCount: string;
maxTimeFrameSec: string;
maxTimeFrameDuration: number;
initialAllEnabled: boolean;
isDebugAllActive$ = this.debugAllControl.valueChanges.pipe(
@ -99,7 +99,7 @@ export class DebugSettingsPanelComponent extends PageComponent implements OnInit
ngOnInit(): void {
this.maxMessagesCount = this.debugLimitsConfiguration?.split(':')[0];
this.maxTimeFrameSec = this.debugLimitsConfiguration?.split(':')[1];
this.maxTimeFrameDuration = parseInt(this.debugLimitsConfiguration?.split(':')[1]) * SECOND;
this.onFailuresControl.patchValue(this.failuresEnabled);
this.debugAllControl.patchValue(this.allEnabled);
this.initialAllEnabled = this.allEnabled || this.allEnabledUntil > new Date().getTime();
@ -128,6 +128,7 @@ export class DebugSettingsPanelComponent extends PageComponent implements OnInit
onReset(): void {
this.debugAllControl.patchValue(true);
this.debugAllControl.markAsDirty();
this.allEnabledUntil = 0;
this.cd.markForCheck();
}

View File

@ -239,10 +239,10 @@
matTooltipPosition="above">
<mat-icon>delete</mat-icon>
</button>
<button [disabled]="(isLoading$ | async) || !isDebugModeEnabled()"
<button [disabled]="(isLoading$ | async) || !isDebugSettingsEnabled()"
mat-fab color="accent" class="tb-btn-footer"
(click)="resetDebugModeInAllNodes()"
matTooltip="{{ 'rulenode.reset-debug-mode' | translate }}"
(click)="resetDebugSettingsInAllNodes()"
matTooltip="{{ 'rulenode.reset-debug-settings' | translate }}"
matTooltipPosition="above">
<mat-icon>bug_report</mat-icon>
</button>

View File

@ -95,6 +95,7 @@ import { ComponentClusteringMode } from '@shared/models/component-descriptor.mod
import { MatDrawer } from '@angular/material/sidenav';
import { HttpStatusCode } from '@angular/common/http';
import { TbContextMenuEvent } from '@shared/models/jquery-event.models';
import { DebugSettings } from '@shared/models/entity.models';
import Timeout = NodeJS.Timeout;
@Component({
@ -1415,17 +1416,20 @@ export class RuleChainPageComponent extends PageComponent
this.ruleChainCanvas.modelService.deleteSelected();
}
isDebugModeEnabled(): boolean {
const res = this.ruleChainModel.nodes.find((node) => node.debugMode);
isDebugSettingsEnabled(): boolean {
const res = this.ruleChainModel.nodes.find((node) => node?.debugSettings && this.isDebugSettingsActive(node.debugSettings));
return typeof res !== 'undefined';
}
resetDebugModeInAllNodes() {
resetDebugSettingsInAllNodes(): void {
let changed = false;
this.ruleChainModel.nodes.forEach((node) => {
if (node.component.type !== RuleNodeType.INPUT) {
changed = changed || node.debugMode;
node.debugMode = false;
const nodeHasActiveDebugSettings = node?.debugSettings && this.isDebugSettingsActive(node.debugSettings);
changed = changed || nodeHasActiveDebugSettings;
if (nodeHasActiveDebugSettings) {
node.debugSettings = { allEnabled: false, failuresEnabled: false, allEnabledUntil: 0 };
}
}
});
if (changed) {
@ -1433,6 +1437,10 @@ export class RuleChainPageComponent extends PageComponent
}
}
private isDebugSettingsActive(debugSettings: DebugSettings): boolean {
return debugSettings.allEnabled || debugSettings.failuresEnabled || debugSettings.allEnabledUntil > new Date().getTime();
}
validate() {
setTimeout(() => {
this.isInvalid = false;

View File

@ -16,7 +16,7 @@
import { Pipe, PipeTransform } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { DAY, HOUR, MINUTE, SECOND } from '@shared/models/time/time.models';
import { DAY, HOUR, MINUTE, SECOND, YEAR } from '@shared/models/time/time.models';
@Pipe({
name: 'milliSecondsToTimeString'
@ -27,19 +27,21 @@ export class MillisecondsToTimeStringPipe implements PipeTransform {
}
transform(milliSeconds: number, shortFormat = false, onlyFirstDigit = false): string {
const { days, hours, minutes, seconds } = this.extractTimeUnits(milliSeconds);
return this.formatTimeString(days, hours, minutes, seconds, shortFormat, onlyFirstDigit);
const { years, days, hours, minutes, seconds } = this.extractTimeUnits(milliSeconds);
return this.formatTimeString(years, days, hours, minutes, seconds, shortFormat, onlyFirstDigit);
}
private extractTimeUnits(milliseconds: number): { days: number; hours: number; minutes: number; seconds: number } {
const days = Math.floor(milliseconds / DAY);
private extractTimeUnits(milliseconds: number): { years: number; days: number; hours: number; minutes: number; seconds: number } {
const years = Math.floor(milliseconds / YEAR);
const days = Math.floor((milliseconds % YEAR) / DAY);
const hours = Math.floor((milliseconds % DAY) / HOUR);
const minutes = Math.floor((milliseconds % HOUR) / MINUTE);
const seconds = Math.floor((milliseconds % MINUTE) / SECOND);
return { days, hours, minutes, seconds };
return { years, days, hours, minutes, seconds };
}
private formatTimeString(
years: number,
days: number,
hours: number,
minutes: number,
@ -48,6 +50,7 @@ export class MillisecondsToTimeStringPipe implements PipeTransform {
onlyFirstDigit: boolean
): string {
const timeUnits = [
{ value: years, key: 'years', shortKey: 'short.years' },
{ value: days, key: 'days', shortKey: 'short.days' },
{ value: hours, key: 'hours', shortKey: 'short.hours' },
{ value: minutes, key: 'minutes', shortKey: 'short.minutes' },
@ -59,7 +62,7 @@ export class MillisecondsToTimeStringPipe implements PipeTransform {
if (value > 0) {
timeString += this.translate.instant(shortFormat ? `timewindow.${shortKey}` : `timewindow.${key}`, { [key]: value });
if (onlyFirstDigit) {
return timeString;
return timeString.trim();
}
}
}

View File

@ -4602,7 +4602,6 @@
"output": "الإخراج",
"test": "اختبار",
"help": "مساعدة",
"reset-debug-mode": "إعادة تعيين وضع التصحيح في جميع العقد",
"test-with-this-message": "{{test}} مع هذه الرسالة"
},
"role": {

View File

@ -3651,8 +3651,7 @@
"metadata-required": "Les entrades de metadades no poden estar buides.",
"output": "Sortida",
"test": "Test",
"help": "Ajuda",
"reset-debug-mode": "Restablir el mode de depuració a tots els nodes"
"help": "Ajuda"
},
"role": {
"role": "Rol",

View File

@ -2426,8 +2426,7 @@
"metadata-required": "Záznam metadat nemůže být prázdný.",
"output": "Výstup",
"test": "Test",
"help": "Nápověda",
"reset-debug-mode": "Resetovat režim ladění na všech uzlech"
"help": "Nápověda"
},
"timezone": {
"timezone": "Časová zóna",

View File

@ -2642,8 +2642,7 @@
"metadata-required": "Metadataposter må ikke være tomme.",
"output": "Output",
"test": "Test",
"help": "Hjælp",
"reset-debug-mode": "Nulstil debug-tilstand i alle knuder"
"help": "Hjælp"
},
"role": {
"role": "Rolle",

View File

@ -1886,8 +1886,7 @@
"metadata-required": "Οι καταχωρίσεις μεταδεδομένων δεν μπορούν να είναι κενές.",
"output": "Απόδοση",
"test": "Τεστ",
"help": "Βοήθεια",
"reset-debug-mode": "Επαναφορά λειτουργίας εντοπισμού σφαλμάτων σε όλους τους κόμβους"
"help": "Βοήθεια"
},
"role": {
"role": "Ρόλος",

View File

@ -990,15 +990,13 @@
"type-sms-sent": "SMS sent"
},
"debug-config": {
"min": "{{number}} min",
"label": "Debug configuration",
"on-failure": "Failures only (24/7)",
"all-messages": "All messages ({{time}})",
"failures": "Failures",
"all": "All",
"hint": {
"main": "All node debug messages rate limited with:",
"main-limited": "All node debug messages will be rate-limited, with a maximum of {{msg}} messages allowed per {{sec}} seconds.",
"main-limited": "All node debug messages will be rate-limited, with a maximum of {{msg}} messages allowed per {{time}}.",
"on-failure": "Save all failure debug events without time limit.",
"all-messages": "Save all debug events during time limit."
}
@ -4295,7 +4293,7 @@
"output": "Output",
"test": "Test",
"help": "Help",
"reset-debug-mode": "Reset debug mode in all nodes",
"reset-debug-settings": "Reset debug settings in all nodes",
"test-with-this-message": "{{test}} with this message",
"queue-hint": "Select a queue for message forwarding to another queue. 'Main' queue is used by default.",
"queue-singleton-hint": "Select a queue for message forwarding in multi-instance environments. 'Main' queue is used by default."
@ -4745,6 +4743,7 @@
"sec": "{{ sec }} sec",
"sec-short": "{{ sec }}s",
"short": {
"years": "{ years, plural, =1 {1 year } other {# years } }",
"days": "{ days, plural, =1 {1 day } other {# days } }",
"hours": "{ hours, plural, =1 {1 hour } other {# hours } }",
"minutes": "{{minutes}} min ",

View File

@ -3529,7 +3529,6 @@
"output": "Salida",
"test": "Test",
"help": "Ayuda",
"reset-debug-mode": "Restablecer el modo de depuración en todos los nodos",
"test-with-this-message": "{{test}} con este mensaje"
},
"timezone": {

View File

@ -1413,8 +1413,7 @@
"metadata-required": "მეტამონაცემები ვერ იქნება ცარიელი",
"output": "რეზულტატი",
"test": "ტესტი",
"help": "დახმარება",
"reset-debug-mode": "Debug რეჟიმის გათიშვა ყველა ნოდისთვის"
"help": "დახმარება"
},
"tenant": {
"tenant": "ტენანტი",

View File

@ -1878,8 +1878,7 @@
"metadata-required": "메타데이터 엔트리를 입력하세요.",
"output": "출력",
"test": "테스트",
"help": "도움말",
"reset-debug-mode": "모든 노드에 대해 디버그 모드 초기화"
"help": "도움말"
},
"timezone": {
"timezone": "Timezone",

View File

@ -4504,7 +4504,6 @@
"output": "Output",
"test": "Test",
"help": "Help",
"reset-debug-mode": "Reset debug mode in all nodes",
"test-with-this-message": "{{test}} with this message"
},
"role": {

View File

@ -1338,8 +1338,7 @@
"metadata-required": "Metadatu ievadi nevar būt tukši.",
"output": "Izeja",
"test": "Tests",
"help": "Palīdzība",
"reset-debug-mode": "Atiestatīt atkļūdošanu visās nodēs"
"help": "Palīdzība"
},
"tenant": {
"tenant": "Īrnieks",

View File

@ -4560,8 +4560,7 @@
"metadata-required": "Metagegevensvermeldingen mogen niet leeg zijn.",
"output": "Uitvoer",
"test": "Test",
"help": "Help",
"reset-debug-mode": "Foutopsporingsmodus resetten in alle rule nodes"
"help": "Help"
},
"role": {
"role": "Rol",

View File

@ -4520,7 +4520,6 @@
"output": "Wyjście",
"test": "Test",
"help": "Pomoc",
"reset-debug-mode": "Zresetuj tryb debugowania we wszystkich węzłach",
"test-with-this-message": "{{test}} with this message",
"description": "Opis"
},

View File

@ -1554,8 +1554,7 @@
"metadata-required": "As entradas de metadados não podem estar em branco.",
"output": "Saída",
"test": "Teste",
"help": "Ajuda",
"reset-debug-mode": "Redefinir modo de depuração em todos os nós"
"help": "Ajuda"
},
"timezone": {
"timezone": "Fuso horário",

View File

@ -1401,7 +1401,6 @@
"output": "Ieşire",
"test": "Test",
"help": "Ajutor",
"reset-debug-mode": "Dezactivează modul depanare în toate nodurile"
},
"tenant": {
"tenant": "Locatar",

View File

@ -1879,8 +1879,7 @@
"metadata-required": "Vnosi metapodatkov ne smejo biti prazni.",
"output": "Izdelek",
"test": "Test",
"help": "Pomoč",
"reset-debug-mode": "Ponastavi način za odpravljanje napak v vseh vozliščih"
"help": "Pomoč"
},
"timezone": {
"timezone": "Časovni pas",

View File

@ -2447,8 +2447,7 @@
"metadata-required": "Meta veri girişleri boş bırakılamaz.",
"output": ıktı",
"test": "Ölçek",
"help": "Yardım et",
"reset-debug-mode": "Tüm düğümlerde hata ayıklama modunu sıfırla"
"help": "Yardım et"
},
"timezone": {
"timezone": "Saat dilimi",

View File

@ -1979,7 +1979,7 @@
"output": "Вихід",
"test": "Тест",
"help": "Допомога",
"reset-debug-mode": "Вимкнути режим налагодження у всіх правилах"
"reset-debug-settings": "Вимкнути налаштування налагодження у всіх правилах"
},
"scheduler": {
"scheduler": "Планувальник",

View File

@ -4012,7 +4012,6 @@
"output": "输出",
"test": "测试",
"help": "帮助",
"reset-debug-mode": "重置所有节点中的调试模式",
"test-with-this-message": "使用此消息进行{{test}}测试",
"queue-hint": "选择一个队列将消息转发到另一个队列,默认情况下使用'Main'队列。",
"queue-singleton-hint": "选择一个队列以在多实体中转发消息,默认情况下使用'Main'队列。"

View File

@ -2768,8 +2768,7 @@
"metadata-required": "元資料項不能為空。",
"output": "輸出",
"test": "測試",
"help": "幫助",
"reset-debug-mode": "重置所有節點中的調試模式"
"help": "幫助"
},
"timezone": {
"timezone": "時區",