RED-10498 - added the locked rules indicator; implemented the reset.

This commit is contained in:
Nicoleta Panaghiu 2024-11-20 18:11:48 +02:00
parent 887157e588
commit 301616fb06
12 changed files with 128 additions and 16 deletions

View File

@ -12,6 +12,7 @@ import { DefaultColorsService } from '@services/entity-services/default-colors.s
import { WatermarkService } from '@services/entity-services/watermark.service';
import { FileAttributesService } from '@services/entity-services/file-attributes.service';
import { getConfig } from '@iqser/common-ui';
import { RulesService } from '../modules/admin/services/rules.service';
export function templateExistsWhenEnteringAdmin(): CanActivateFn {
return async function (route: ActivatedRouteSnapshot): Promise<boolean> {
@ -21,12 +22,14 @@ export function templateExistsWhenEnteringAdmin(): CanActivateFn {
const defaultColorsService = inject(DefaultColorsService);
const watermarksService = inject(WatermarkService);
const router = inject(Router);
const rulesService = inject(RulesService);
const isDocumine = getConfig().IS_DOCUMINE;
const dossierTemplate = inject(DossierTemplateStatsService).get(dossierTemplateId);
await firstValueFrom(fileAttributesService.loadFileAttributesConfig(dossierTemplateId));
await firstValueFrom(dictionaryService.loadDictionaryDataForDossierTemplate(dossierTemplateId));
await firstValueFrom(defaultColorsService.loadForDossierTemplate(dossierTemplateId));
await firstValueFrom(rulesService.getFor(dossierTemplateId));
if (!isDocumine) {
await firstValueFrom(watermarksService.loadForDossierTemplate(dossierTemplateId));
}

View File

@ -34,6 +34,16 @@
<span [innerHTML]="'dossier-template-info-screen.created-on' | translate: { date: createdOn }"></span>
</div>
<div *ngIf="areRulesLocked()">
<mat-icon
(click)="resetRules()"
[matTooltip]="'dossier-template-info-screen.rules-reset.tooltip' | translate"
svgIcon="iqser:alert-circle"
class="action-icon"
></mat-icon>
<span class="error">{{ 'dossier-template-info-screen.rules-reset.label' | translate }}</span>
</div>
<div>
<mat-icon svgIcon="red:entries"></mat-icon>
{{ 'dossier-template-info-screen.entries' | translate: { count: ctx.stats.numberOfEntries } }}

View File

@ -18,3 +18,11 @@
padding-right: 24px;
margin-right: 24px;
}
.error {
color: var(--iqser-primary);
}
.action-icon {
cursor: pointer;
}

View File

@ -1,4 +1,4 @@
import { Component, Input, OnInit } from '@angular/core';
import { Component, computed, Input, OnInit } from '@angular/core';
import { ContextComponent } from '@iqser/common-ui/lib/utils';
import { type DossierTemplate, type DossierTemplateStats } from '@red/domain';
import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service';
@ -9,6 +9,11 @@ import { MatIcon } from '@angular/material/icon';
import { TranslateModule } from '@ngx-translate/core';
import { InitialsAvatarComponent } from '@common-ui/users';
import { DatePipe } from '@shared/pipes/date.pipe';
import { RulesService } from '../../../services/rules.service';
import { Toaster } from '@iqser/common-ui';
import { MatTooltip } from '@angular/material/tooltip';
import { firstValueFrom } from 'rxjs';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
interface Context {
readonly dossierTemplate: DossierTemplate;
@ -20,16 +25,20 @@ interface Context {
templateUrl: './dossier-template-details.component.html',
styleUrls: ['./dossier-template-details.component.scss'],
standalone: true,
imports: [NgIf, AsyncPipe, MatIcon, TranslateModule, DatePipe, InitialsAvatarComponent],
imports: [NgIf, AsyncPipe, MatIcon, TranslateModule, DatePipe, InitialsAvatarComponent, MatTooltip],
})
export class DossierTemplateDetailsComponent extends ContextComponent<Context> implements OnInit {
readonly translations = dossierTemplateStatusTranslations;
@Input({ required: true }) dossierTemplateId: string;
readonly areRulesLocked = computed(() => {
return this._rulesService.currentTemplateRules().timeoutDetected;
});
constructor(
private readonly _dossierTemplatesService: DossierTemplatesService,
private readonly _dossierTemplateStatsService: DossierTemplateStatsService,
private readonly _rulesService: RulesService,
private readonly _toaster: Toaster,
) {
super();
}
@ -40,4 +49,14 @@ export class DossierTemplateDetailsComponent extends ContextComponent<Context> i
stats: this._dossierTemplateStatsService.watch$(this.dossierTemplateId),
});
}
async resetRules() {
try {
await firstValueFrom(this._rulesService.reset(this.dossierTemplateId));
this._toaster.success(_('dossier-template-info-screen.rules-reset.success'));
await firstValueFrom(this._rulesService.getFor(this.dossierTemplateId));
} catch (error) {
this._toaster.rawError(error.error.message);
}
}
}

View File

@ -1,9 +1,25 @@
import { Injectable } from '@angular/core';
import { GenericService } from '@iqser/common-ui';
import { IRules } from '@red/domain';
import { EntitiesService, QueryParam } from '@iqser/common-ui';
import { IRules, Rules } from '@red/domain';
import { map, Observable, tap } from 'rxjs';
import { List } from '@common-ui/utils';
import { toSignal } from '@angular/core/rxjs-interop';
import { distinctUntilChanged, filter } from 'rxjs/operators';
@Injectable()
export class RulesService extends GenericService<IRules> {
@Injectable({ providedIn: 'root' })
export class RulesService extends EntitiesService<IRules, Rules> {
readonly currentTemplateRules = toSignal(
this.all$.pipe(
filter(all => !!all.length),
map(rules => rules[0]),
distinctUntilChanged(
(prev, curr) =>
prev.rules === curr.rules &&
prev.timeoutDetected === curr.timeoutDetected &&
prev.dossierTemplateId === curr.dossierTemplateId,
),
),
);
protected readonly _defaultModelPath = 'rules';
download(dossierTemplateId: string, ruleFileType: IRules['ruleFileType'] = 'ENTITY') {
@ -13,4 +29,12 @@ export class RulesService extends GenericService<IRules> {
uploadRules(body: IRules) {
return this._post<unknown>({ ...body, ruleFileType: body.ruleFileType ?? 'ENTITY' });
}
getFor<R = IRules>(entityId: string, queryParams?: List<QueryParam>): Observable<R> {
return super.getFor<R>(entityId, queryParams).pipe(tap(rules => this.setEntities([rules as Rules])));
}
reset(dossierTemplateId: string, ruleFileType: IRules['ruleFileType'] = 'ENTITY') {
return this._put(null, `${this._defaultModelPath}/${dossierTemplateId}/${ruleFileType}/reset`);
}
}

View File

@ -1069,6 +1069,11 @@
"entities": "{count} {count, plural, one{Entität} other{Entitäten}}",
"entries": "{count} {count, plural, one{Eintrag} other{Einträge}}",
"modified-on": "Geändert am: {date}",
"rules-reset": {
"label": "Regeln gesperrt",
"success": "Die Regeln der Dossier-Vorlage wurden erfolgreich zurückgesetzt.",
"tooltip": "Klicken Sie hier, um die Regeln zurückzusetzen"
},
"title": "Dossier-Vorlage bearbeiten",
"valid-from": "Gültig ab: {date}",
"valid-to": "Gültig bis: {Datum}"

View File

@ -1069,6 +1069,11 @@
"entities": "{count} {count, plural, one{entity} other{entities}}",
"entries": "{count} {count, plural, one{entry} other{entries}}",
"modified-on": "Modified on: {date}",
"rules-reset": {
"label": "Rules locked",
"success": "Dossier template rules successfully reset.",
"tooltip": "Click to reset rules"
},
"title": "Edit dossier template",
"valid-from": "Valid from: {date}",
"valid-to": "Valid to: {date}"

View File

@ -1064,14 +1064,19 @@
}
},
"dossier-template-info-screen": {
"created-by": "Created by",
"created-on": "Created on: {date}",
"entities": "{count} {count, plural, one{entity} other{entities}}",
"entries": "{count} {count, plural, one{entry} other{entries}}",
"modified-on": "Modified on: {date}",
"title": "Edit dossier template",
"valid-from": "Valid from: {date}",
"valid-to": "Valid to: {date}"
"created-by": "Ersteller",
"created-on": "Erstellt am {date}",
"entities": "{count} {count, plural, one{Entität} other{Entitäten}}",
"entries": "{count} {count, plural, one{Eintrag} other{Einträge}}",
"modified-on": "Geändert am {date}",
"rules-reset": {
"label": "Regeln gesperrt",
"success": "Die Regeln der Dossier-Vorlage wurden erfolgreich zurückgesetzt.",
"tooltip": "Klicken Sie hier, um die Regeln zurückzusetzen"
},
"title": "Dossier-Vorlage bearbeiten",
"valid-from": "Gültig ab: {date}",
"valid-to": "Gültig bis: {date}"
},
"dossier-template-stats": {
"active-dossiers": "Active {count, plural, one{dossier} other{dossiers}}",

View File

@ -1069,6 +1069,11 @@
"entities": "{count} {count, plural, one{entity} other{entities}}",
"entries": "{count} {count, plural, one{entry} other{entries}}",
"modified-on": "Modified on: {date}",
"rules-reset": {
"label": "Rules locked",
"success": "Dossier template rules successfully reset.",
"tooltip": "Click to reset rules"
},
"title": "Edit dossier template",
"valid-from": "Valid from: {date}",
"valid-to": "Valid to: {date}"

View File

@ -13,3 +13,4 @@ export * from './app-config';
export * from './system-preferences';
export * from './component-rules';
export * from './editor.types';
export * from './rules.model';

View File

@ -0,0 +1,23 @@
import { IRules } from '@red/domain';
import { Entity } from '@iqser/common-ui';
export class Rules extends Entity<IRules> implements IRules {
readonly id: string;
readonly routerLink: string;
readonly searchKey: string;
readonly dossierTemplateId: string;
readonly ruleFileType?: 'ENTITY' | 'COMPONENT';
readonly rules?: string;
readonly dryRun?: boolean;
readonly timeoutDetected?: boolean;
constructor(rules: IRules) {
super(rules);
this.id = rules.dossierTemplateId;
this.dossierTemplateId = rules.dossierTemplateId;
this.ruleFileType = rules.ruleFileType;
this.rules = rules.rules;
this.dryRun = rules.dryRun;
this.timeoutDetected = rules.timeoutDetected;
}
}

View File

@ -5,7 +5,7 @@ export interface IRules {
/**
* The DossierTemplate ID for these rules
*/
dossierTemplateId?: string;
dossierTemplateId: string;
/**
* The file type to be retrieved/saved under, defaults to ENTITY
*/
@ -18,4 +18,8 @@ export interface IRules {
* Request param for rules validation, without updating them
*/
dryRun?: boolean;
/**
* Flag which indicates whether the dossier template rules have been locked due to a timeout
*/
timeoutDetected?: boolean;
}