RED-8692 - WIP on "Automatic code validation in the rule editor"
This commit is contained in:
parent
e80eb4cd25
commit
d322c0a148
@ -1,4 +1,4 @@
|
|||||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, computed, OnInit, signal } from '@angular/core';
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, computed, OnChanges, OnInit, signal, SimpleChanges } from '@angular/core';
|
||||||
import { PermissionsService } from '@services/permissions.service';
|
import { PermissionsService } from '@services/permissions.service';
|
||||||
import { IconButtonTypes, LoadingService, Toaster } from '@iqser/common-ui';
|
import { IconButtonTypes, LoadingService, Toaster } from '@iqser/common-ui';
|
||||||
import { RulesService } from '../../../services/rules.service';
|
import { RulesService } from '../../../services/rules.service';
|
||||||
@ -19,6 +19,8 @@ interface SyntaxError {
|
|||||||
message: string;
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RULE_VALIDATION_TIMEOUT = 2000;
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: './rules-screen.component.html',
|
templateUrl: './rules-screen.component.html',
|
||||||
styleUrls: ['./rules-screen.component.scss'],
|
styleUrls: ['./rules-screen.component.scss'],
|
||||||
@ -44,6 +46,7 @@ export class RulesScreenComponent implements OnInit, ComponentCanDeactivate {
|
|||||||
readonly #errorGlyphs = signal<string[]>([]);
|
readonly #errorGlyphs = signal<string[]>([]);
|
||||||
readonly numberOfErrors = computed(() => this.#errorGlyphs().length);
|
readonly numberOfErrors = computed(() => this.#errorGlyphs().length);
|
||||||
readonly #dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID);
|
readonly #dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID);
|
||||||
|
#ruleValidationTimeout: number = null;
|
||||||
|
|
||||||
set isLeavingPage(isLeaving: boolean) {
|
set isLeavingPage(isLeaving: boolean) {
|
||||||
this.isLeaving = isLeaving;
|
this.isLeaving = isLeaving;
|
||||||
@ -61,6 +64,7 @@ export class RulesScreenComponent implements OnInit, ComponentCanDeactivate {
|
|||||||
set codeEditorText($event: any) {
|
set codeEditorText($event: any) {
|
||||||
this.currentLines = $event.split('\n');
|
this.currentLines = $event.split('\n');
|
||||||
this.codeEditorTextChanged();
|
this.codeEditorTextChanged();
|
||||||
|
this.validateRules();
|
||||||
this._closeProblemsView();
|
this._closeProblemsView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +84,15 @@ export class RulesScreenComponent implements OnInit, ComponentCanDeactivate {
|
|||||||
await this._initialize();
|
await this._initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validateRules() {
|
||||||
|
if (this.#ruleValidationTimeout) {
|
||||||
|
clearTimeout(this.#ruleValidationTimeout);
|
||||||
|
}
|
||||||
|
this.#ruleValidationTimeout = window.setTimeout(async () => {
|
||||||
|
await this.#uploadRules(true);
|
||||||
|
}, RULE_VALIDATION_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
async onCodeEditorInit(editor: ICodeEditor): Promise<void> {
|
async onCodeEditorInit(editor: ICodeEditor): Promise<void> {
|
||||||
this._codeEditor = editor;
|
this._codeEditor = editor;
|
||||||
for (const theme of this._editorThemeService.themes) {
|
for (const theme of this._editorThemeService.themes) {
|
||||||
@ -103,14 +116,23 @@ export class RulesScreenComponent implements OnInit, ComponentCanDeactivate {
|
|||||||
async save(): Promise<void> {
|
async save(): Promise<void> {
|
||||||
this._loadingService.start();
|
this._loadingService.start();
|
||||||
this._removeErrorMarkers();
|
this._removeErrorMarkers();
|
||||||
await firstValueFrom(
|
await this.#uploadRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
async #uploadRules(dryRun = false) {
|
||||||
|
return firstValueFrom(
|
||||||
this._rulesService.uploadRules({
|
this._rulesService.uploadRules({
|
||||||
rules: this._getValue(),
|
rules: this._getValue(),
|
||||||
dossierTemplateId: this.#dossierTemplateId,
|
dossierTemplateId: this.#dossierTemplateId,
|
||||||
ruleFileType: this.type,
|
ruleFileType: this.type,
|
||||||
|
dryRun,
|
||||||
}),
|
}),
|
||||||
).then(
|
).then(
|
||||||
async () => {
|
async response => {
|
||||||
|
if (dryRun) {
|
||||||
|
console.log('RESPONSE: ', response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
await this._initialize();
|
await this._initialize();
|
||||||
this._toaster.success(rulesScreenTranslations[this.type]['success-generic']);
|
this._toaster.success(rulesScreenTranslations[this.type]['success-generic']);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -14,4 +14,8 @@ export interface IRules {
|
|||||||
* The actual string of rules.
|
* The actual string of rules.
|
||||||
*/
|
*/
|
||||||
rules?: string;
|
rules?: string;
|
||||||
|
/**
|
||||||
|
* Request param for rules validation, without updating them
|
||||||
|
*/
|
||||||
|
dryRun?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user