+
+
+
+
+
+
+
-
-
+
+
{{ translations[preference] | translate }}
diff --git a/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.ts b/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.ts
index c2003cddb..73657ced5 100644
--- a/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.ts
+++ b/apps/red-ui/src/app/modules/account/screens/notifications/notifications-screen/notifications-screen.component.ts
@@ -4,8 +4,12 @@ import { notificationsTranslations } from '../../../translations/notifications-t
import { NotificationPreferencesService } from '../../../services/notification-preferences.service';
import { LoadingService, Toaster } from '@iqser/common-ui';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
-import { NotificationCategoriesValues, NotificationGroupsKeys, NotificationGroupsValues } from '../constants';
-import { EmailNotificationScheduleTypesValues } from '@red/domain';
+import {
+ EmailNotificationScheduleTypesValues,
+ NotificationCategoriesValues,
+ NotificationGroupsKeys,
+ NotificationGroupsValues,
+} from '@red/domain';
@Component({
selector: 'redaction-notifications-screen',
@@ -33,16 +37,6 @@ export class NotificationsScreenComponent implements OnInit {
await this._initializeForm();
}
- private _getForm(): FormGroup {
- return this._formBuilder.group({
- inAppNotificationsEnabled: [undefined],
- emailNotificationsEnabled: [undefined],
- emailNotificationType: [undefined],
- emailNotifications: [undefined],
- inAppNotifications: [undefined],
- });
- }
-
isCategoryActive(category: string) {
return this.formGroup.get(`${category}Enabled`).value;
}
@@ -80,6 +74,16 @@ export class NotificationsScreenComponent implements OnInit {
this._loadingService.stop();
}
+ private _getForm(): FormGroup {
+ return this._formBuilder.group({
+ inAppNotificationsEnabled: [undefined],
+ emailNotificationsEnabled: [undefined],
+ emailNotificationType: [undefined],
+ emailNotifications: [undefined],
+ inAppNotifications: [undefined],
+ });
+ }
+
private async _initializeForm() {
this._loadingService.start();
diff --git a/apps/red-ui/src/app/modules/account/screens/user-profile/user-profile-screen/user-profile-screen.component.ts b/apps/red-ui/src/app/modules/account/screens/user-profile/user-profile-screen/user-profile-screen.component.ts
index 6531660b4..566ae678e 100644
--- a/apps/red-ui/src/app/modules/account/screens/user-profile/user-profile-screen/user-profile-screen.component.ts
+++ b/apps/red-ui/src/app/modules/account/screens/user-profile/user-profile-screen/user-profile-screen.component.ts
@@ -73,7 +73,7 @@ export class UserProfileScreenComponent implements OnInit {
}
if (this.profileChanged) {
- const value = this.form.value as IProfile;
+ const value = this.form.getRawValue() as IProfile;
delete value.language;
await this._userService
diff --git a/apps/red-ui/src/app/modules/admin/components/combo-chart/combo-chart.component.ts b/apps/red-ui/src/app/modules/admin/components/combo-chart/combo-chart.component.ts
index fff29fbc4..0f949194c 100644
--- a/apps/red-ui/src/app/modules/admin/components/combo-chart/combo-chart.component.ts
+++ b/apps/red-ui/src/app/modules/admin/components/combo-chart/combo-chart.component.ts
@@ -12,7 +12,18 @@ import {
import { curveLinear } from 'd3-shape';
import { scaleBand, scaleLinear, scalePoint, scaleTime } from 'd3-scale';
-import { BaseChartComponent, calculateViewDimensions, ColorHelper, LineSeriesComponent, ViewDimensions } from '@swimlane/ngx-charts';
+import {
+ BaseChartComponent,
+ calculateViewDimensions,
+ Color,
+ ColorHelper,
+ LegendPosition,
+ LineSeriesComponent,
+ Orientation,
+ ScaleType,
+ ViewDimensions,
+} from '@swimlane/ngx-charts';
+import { ILineChartSeries } from './models';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
@@ -25,7 +36,7 @@ export class ComboChartComponent extends BaseChartComponent {
@Input() curve: any = curveLinear;
@Input() legend = false;
@Input() legendTitle = 'Legend';
- @Input() legendPosition = 'right';
+ @Input() legendPosition: LegendPosition = LegendPosition.Right;
@Input() xAxis;
@Input() yAxis;
@Input() showXAxisLabel;
@@ -38,33 +49,33 @@ export class ComboChartComponent extends BaseChartComponent {
@Input() gradient: boolean;
@Input() showGridLines = true;
@Input() activeEntries: any[] = [];
- @Input() schemeType: string;
+ @Input() schemeType: ScaleType;
@Input() xAxisTickFormatting: any;
@Input() yAxisTickFormatting: any;
@Input() yRightAxisTickFormatting: any;
@Input() roundDomains = false;
- @Input() colorSchemeLine: any;
+ @Input() colorSchemeLine: Color;
@Input() autoScale;
- @Input() lineChart: any;
+ @Input() lineChart: ILineChartSeries[];
@Input() yLeftAxisScaleFactor: any;
@Input() yRightAxisScaleFactor: any;
@Input() rangeFillOpacity: number;
@Input() animations = true;
@Input() noBarWhenZero = true;
- @Output() activate: EventEmitter
= new EventEmitter();
- @Output() deactivate: EventEmitter = new EventEmitter();
+ @Output() activate = new EventEmitter<{ value; entries: unknown[] }>();
+ @Output() deactivate = new EventEmitter<{ value; entries: unknown[] }>();
- @ContentChild('tooltipTemplate') tooltipTemplate: TemplateRef;
- @ContentChild('seriesTooltipTemplate') seriesTooltipTemplate: TemplateRef;
+ @ContentChild('tooltipTemplate') tooltipTemplate: TemplateRef;
+ @ContentChild('seriesTooltipTemplate') seriesTooltipTemplate: TemplateRef;
@ViewChild(LineSeriesComponent) lineSeriesComponent: LineSeriesComponent;
dims: ViewDimensions;
xScale: any;
yScale: any;
- xDomain: any;
- yDomain: any;
+ xDomain: string[] | number[];
+ yDomain: string[] | number[];
transform: string;
colors: ColorHelper;
colorsLine: ColorHelper;
@@ -72,19 +83,19 @@ export class ComboChartComponent extends BaseChartComponent {
xAxisHeight = 0;
yAxisWidth = 0;
legendOptions: any;
- scaleType = 'linear';
+ scaleType: ScaleType = ScaleType.Linear;
xScaleLine;
yScaleLine;
xDomainLine;
yDomainLine;
seriesDomain;
scaledAxis;
- combinedSeries;
+ combinedSeries: ILineChartSeries[];
xSet;
filteredDomain;
hoveredVertical;
- yOrientLeft = 'left';
- yOrientRight = 'right';
+ yOrientLeft: Orientation = Orientation.Left;
+ yOrientRight: Orientation = Orientation.Right;
legendSpacing = 0;
bandwidth: number;
barPadding = 8;
@@ -176,15 +187,11 @@ export class ComboChartComponent extends BaseChartComponent {
return this.combinedSeries.map(d => d.name);
}
- isDate(value): boolean {
- if (value instanceof Date) {
- return true;
- }
-
- return false;
+ isDate(value): value is Date {
+ return value instanceof Date;
}
- getScaleType(values): string {
+ getScaleType(values): ScaleType {
let date = true;
let num = true;
@@ -199,16 +206,16 @@ export class ComboChartComponent extends BaseChartComponent {
}
if (date) {
- return 'time';
+ return ScaleType.Time;
}
if (num) {
- return 'linear';
+ return ScaleType.Linear;
}
- return 'ordinal';
+ return ScaleType.Ordinal;
}
getXDomainLine(): any[] {
- let values = [];
+ let values: number[] = [];
for (const results of this.lineChart) {
for (const d of results.series) {
@@ -239,7 +246,7 @@ export class ComboChartComponent extends BaseChartComponent {
}
getYDomainLine(): any[] {
- const domain = [];
+ const domain: number[] = [];
for (const results of this.lineChart) {
for (const d of results.series) {
@@ -263,7 +270,7 @@ export class ComboChartComponent extends BaseChartComponent {
const max = Math.max(...domain);
if (this.yRightAxisScaleFactor) {
const minMax = this.yRightAxisScaleFactor(min, max);
- return [Math.min(0, minMax.min), minMax.max];
+ return [Math.min(0, minMax.min as number), minMax.max];
} else {
min = Math.min(0, min);
return [min, max];
@@ -317,12 +324,12 @@ export class ComboChartComponent extends BaseChartComponent {
}
getYDomain() {
- const values = this.results.map(d => d.value);
+ const values: number[] = this.results.map(d => d.value);
const min = Math.min(0, ...values);
const max = Math.max(...values);
if (this.yLeftAxisScaleFactor) {
const minMax = this.yLeftAxisScaleFactor(min, max);
- return [Math.min(0, minMax.min), minMax.max];
+ return [Math.min(0, minMax.min as number), minMax.max];
} else {
return [min, max];
}
@@ -333,7 +340,7 @@ export class ComboChartComponent extends BaseChartComponent {
}
setColors(): void {
- let domain;
+ let domain: number[] | string[];
if (this.schemeType === 'ordinal') {
domain = this.xDomain;
} else {
diff --git a/apps/red-ui/src/app/modules/admin/components/combo-chart/combo-series-vertical.component.ts b/apps/red-ui/src/app/modules/admin/components/combo-chart/combo-series-vertical.component.ts
index 6289f88d6..483125c2a 100644
--- a/apps/red-ui/src/app/modules/admin/components/combo-chart/combo-series-vertical.component.ts
+++ b/apps/red-ui/src/app/modules/admin/components/combo-chart/combo-series-vertical.component.ts
@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { animate, style, transition, trigger } from '@angular/animations';
-import { formatLabel } from '@swimlane/ngx-charts';
+import { Bar, BarOrientation, formatLabel, PlacementTypes, StyleTypes } from '@swimlane/ngx-charts';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
@@ -17,7 +17,7 @@ import { formatLabel } from '@swimlane/ngx-charts';
[fill]="bar.color"
[stops]="bar.gradientStops"
[data]="bar.data"
- [orientation]="'vertical'"
+ [orientation]="orientations.Vertical"
[roundEdges]="bar.roundEdges"
[gradient]="gradient"
[isActive]="isActive(bar.data)"
@@ -27,8 +27,8 @@ import { formatLabel } from '@swimlane/ngx-charts';
(deactivate)="deactivate.emit($event)"
ngx-tooltip
[tooltipDisabled]="tooltipDisabled"
- [tooltipPlacement]="0"
- [tooltipType]="1"
+ [tooltipPlacement]="tooltipPlacements.Top"
+ [tooltipType]="tooltipTypes.tooltip"
[tooltipTitle]="bar.tooltipText"
>
`,
@@ -67,6 +67,9 @@ export class ComboSeriesVerticalComponent implements OnChanges {
bars: any;
x: any;
y: any;
+ readonly tooltipTypes = StyleTypes;
+ readonly tooltipPlacements = PlacementTypes;
+ readonly orientations = BarOrientation;
ngOnChanges(): void {
this.update();
@@ -91,7 +94,7 @@ export class ComboSeriesVerticalComponent implements OnChanges {
const formattedLabel = formatLabel(label);
const roundEdges = this.type === 'standard';
- const bar: any = {
+ const bar: Bar = {
value,
label,
roundEdges,
@@ -101,8 +104,15 @@ export class ComboSeriesVerticalComponent implements OnChanges {
height: 0,
x: 0,
y: 0,
+ ariaLabel: label,
+ tooltipText: label,
+ color: undefined,
+ gradientStops: undefined,
};
+ let offset0 = d0;
+ let offset1 = offset0 + value;
+
if (this.type === 'standard') {
bar.height = Math.abs(this.yScale(value) - this.yScale(0));
bar.x = this.xScale(label);
@@ -113,18 +123,14 @@ export class ComboSeriesVerticalComponent implements OnChanges {
bar.y = this.yScale(value);
}
} else if (this.type === 'stacked') {
- const offset0 = d0;
- const offset1 = offset0 + value;
d0 += value;
bar.height = this.yScale(offset0) - this.yScale(offset1);
bar.x = 0;
bar.y = this.yScale(offset1);
- bar.offset0 = offset0;
- bar.offset1 = offset1;
+ // bar.offset0 = offset0;
+ // bar.offset1 = offset1;
} else if (this.type === 'normalized') {
- let offset0 = d0;
- let offset1 = offset0 + value;
d0 += value;
if (total > 0) {
@@ -138,8 +144,8 @@ export class ComboSeriesVerticalComponent implements OnChanges {
bar.height = this.yScale(offset0) - this.yScale(offset1);
bar.x = 0;
bar.y = this.yScale(offset1);
- bar.offset0 = offset0;
- bar.offset1 = offset1;
+ // bar.offset0 = offset0;
+ // bar.offset1 = offset1;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
value = (offset1 - offset0).toFixed(2) + '%';
@@ -152,8 +158,8 @@ export class ComboSeriesVerticalComponent implements OnChanges {
bar.color = this.colors.getColor(value);
bar.gradientStops = this.colors.getLinearGradientStops(value);
} else {
- bar.color = this.colors.getColor(bar.offset1);
- bar.gradientStops = this.colors.getLinearGradientStops(bar.offset1, bar.offset0);
+ bar.color = this.colors.getColor(offset1);
+ bar.gradientStops = this.colors.getLinearGradientStops(offset1, offset0);
}
}
diff --git a/apps/red-ui/src/app/modules/admin/components/combo-chart/models.ts b/apps/red-ui/src/app/modules/admin/components/combo-chart/models.ts
new file mode 100644
index 000000000..7358f8e55
--- /dev/null
+++ b/apps/red-ui/src/app/modules/admin/components/combo-chart/models.ts
@@ -0,0 +1,11 @@
+export interface ISeries {
+ name: number;
+ value: number;
+ min: number;
+ max: number;
+}
+
+export interface ILineChartSeries {
+ name: string;
+ series: ISeries[];
+}
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.html b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.html
index 903caceaf..7acf0cf23 100644
--- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.html
+++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.html
@@ -95,11 +95,11 @@
-
-
+
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts
index 737d96915..0c80cb245 100644
--- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts
+++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component.ts
@@ -1,4 +1,4 @@
-import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
+import { ChangeDetectionStrategy, Component, Inject, Injector } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Observable } from 'rxjs';
@@ -6,7 +6,7 @@ import { BaseDialogComponent, shareDistinctLast, Toaster } from '@iqser/common-u
import { TranslateService } from '@ngx-translate/core';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { AppStateService } from '@state/app-state.service';
-import { toKebabCase } from '@utils/functions';
+import { toSnakeCase } from '@utils/functions';
import { DictionaryService } from '@shared/services/dictionary.service';
import { Dictionary, IDictionary } from '@red/domain';
import { UserService } from '@services/user.service';
@@ -21,7 +21,6 @@ import { HttpStatusCode } from '@angular/common/http';
})
export class AddEditDictionaryDialogComponent extends BaseDialogComponent {
readonly dictionary = this._data.dictionary;
- readonly form: FormGroup = this._getForm(this.dictionary);
readonly canEditLabel$ = this._canEditLabel$;
readonly technicalName$: Observable
;
readonly dialogHeader = this._translateService.instant('add-edit-dictionary.title', {
@@ -29,7 +28,6 @@ export class AddEditDictionaryDialogComponent extends BaseDialogComponent {
name: this._data.dictionary?.label,
});
readonly hasColor$: Observable;
- readonly disabled = false;
private readonly _dossierTemplateId = this._data.dossierTemplateId;
constructor(
@@ -39,37 +37,18 @@ export class AddEditDictionaryDialogComponent extends BaseDialogComponent {
private readonly _appStateService: AppStateService,
private readonly _translateService: TranslateService,
private readonly _dictionaryService: DictionaryService,
- private readonly _dialogRef: MatDialogRef,
+ protected readonly _injector: Injector,
+ protected readonly _dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA)
private readonly _data: { readonly dictionary: Dictionary; readonly dossierTemplateId: string },
) {
- super();
+ super(_injector, _dialogRef);
+ this.form = this._getForm(this.dictionary);
+ this.initialFormValue = this.form.getRawValue();
this.hasColor$ = this._colorEmpty$;
this.technicalName$ = this.form.get('label').valueChanges.pipe(map(value => this._toTechnicalName(value)));
}
- get valid(): boolean {
- return this.form.valid;
- }
-
- get changed(): boolean {
- if (!this.dictionary) {
- return true;
- }
-
- for (const key of Object.keys(this.form.getRawValue())) {
- if (key === 'caseSensitive') {
- if (this.getDictCaseSensitive(this.dictionary) !== this.form.get(key).value) {
- return true;
- }
- } else if (this.dictionary[key] !== this.form.get(key).value) {
- return true;
- }
- }
-
- return false;
- }
-
private get _canEditLabel$() {
return this.userService.currentUser$.pipe(
map(user => user.isAdmin || !this._data.dictionary),
@@ -126,11 +105,11 @@ export class AddEditDictionaryDialogComponent extends BaseDialogComponent {
private _toTechnicalName(value: string) {
const existingTechnicalNames = Object.keys(this._appStateService.dictionaryData[this._dossierTemplateId]);
- const baseTechnicalName = toKebabCase(value.trim());
+ const baseTechnicalName = toSnakeCase(value.trim());
let technicalName = baseTechnicalName;
let suffix = 1;
while (existingTechnicalNames.includes(technicalName)) {
- technicalName = [baseTechnicalName, suffix++].join('-');
+ technicalName = [baseTechnicalName, suffix++].join('_');
}
return technicalName;
}
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-attribute-dialog/add-edit-dossier-attribute-dialog.component.html b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-attribute-dialog/add-edit-dossier-attribute-dialog.component.html
index 0eaf795a8..4abe7268e 100644
--- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-attribute-dialog/add-edit-dossier-attribute-dialog.component.html
+++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-attribute-dialog/add-edit-dossier-attribute-dialog.component.html
@@ -35,11 +35,11 @@
-
+
{{ 'add-edit-dossier-attribute.save' | translate }}
-
+
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-attribute-dialog/add-edit-dossier-attribute-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-attribute-dialog/add-edit-dossier-attribute-dialog.component.ts
index 96642be2e..f20fa7042 100644
--- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-attribute-dialog/add-edit-dossier-attribute-dialog.component.ts
+++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-attribute-dialog/add-edit-dossier-attribute-dialog.component.ts
@@ -1,8 +1,8 @@
-import { Component, HostListener, Inject, OnDestroy } from '@angular/core';
+import { Component, HostListener, Inject, Injector, OnDestroy } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { DossierAttributeConfigTypes, FileAttributeConfigTypes, IDossierAttributeConfig } from '@red/domain';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
-import { AutoUnsubscribe, IqserEventTarget, LoadingService, Toaster } from '@iqser/common-ui';
+import { BaseDialogComponent, IqserEventTarget, LoadingService, Toaster } from '@iqser/common-ui';
import { HttpErrorResponse } from '@angular/common/http';
import { DossierAttributesService } from '@shared/services/controller-wrappers/dossier-attributes.service';
import { dossierAttributeTypesTranslations } from '../../translations/dossier-attribute-types-translations';
@@ -12,9 +12,8 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
templateUrl: './add-edit-dossier-attribute-dialog.component.html',
styleUrls: ['./add-edit-dossier-attribute-dialog.component.scss'],
})
-export class AddEditDossierAttributeDialogComponent extends AutoUnsubscribe implements OnDestroy {
+export class AddEditDossierAttributeDialogComponent extends BaseDialogComponent implements OnDestroy {
dossierAttribute: IDossierAttributeConfig = this.data.dossierAttribute;
- readonly form: FormGroup = this._getForm(this.dossierAttribute);
readonly translations = dossierAttributeTypesTranslations;
readonly typeOptions = Object.keys(DossierAttributeConfigTypes);
@@ -23,11 +22,14 @@ export class AddEditDossierAttributeDialogComponent extends AutoUnsubscribe impl
private readonly _loadingService: LoadingService,
private readonly _dossierAttributesService: DossierAttributesService,
private readonly _toaster: Toaster,
- readonly dialogRef: MatDialogRef
,
+ protected readonly _injector: Injector,
+ protected readonly _dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA)
readonly data: { readonly dossierAttribute: IDossierAttributeConfig },
) {
- super();
+ super(_injector, _dialogRef);
+ this.form = this._getForm(this.dossierAttribute);
+ this.initialFormValue = this.form.getRawValue();
}
get changed(): boolean {
@@ -55,7 +57,7 @@ export class AddEditDossierAttributeDialogComponent extends AutoUnsubscribe impl
this._dossierAttributesService.createOrUpdate(attribute).subscribe(
() => {
- this.dialogRef.close(true);
+ this._dialogRef.close(true);
},
(error: HttpErrorResponse) => {
this._loadingService.stop();
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.html b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.html
index abf0d181d..a5d11d920 100644
--- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.html
+++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.html
@@ -33,16 +33,11 @@
-
+
{{ 'add-edit-dossier-template.save' | translate }}
-
+
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.ts
index f42bebd94..4d6b575bd 100644
--- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.ts
+++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component.ts
@@ -1,6 +1,6 @@
-import { Component, Inject } from '@angular/core';
+import { Component, Inject, Injector } from '@angular/core';
import { AppStateService } from '@state/app-state.service';
-import { FormBuilder, FormGroup, Validators } from '@angular/forms';
+import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import * as moment from 'moment';
import { Moment } from 'moment';
@@ -17,7 +17,6 @@ import { HttpStatusCode } from '@angular/common/http';
styleUrls: ['./add-edit-dossier-template-dialog.component.scss'],
})
export class AddEditDossierTemplateDialogComponent extends BaseDialogComponent {
- readonly form: FormGroup = this._getForm();
hasValidFrom: boolean;
hasValidTo: boolean;
downloadTypesEnum: DownloadFileType[] = ['ORIGINAL', 'PREVIEW', 'REDACTED'];
@@ -25,66 +24,50 @@ export class AddEditDossierTemplateDialogComponent extends BaseDialogComponent {
key: type,
label: downloadTypesTranslations[type],
}));
- readonly disabled = false;
private _previousValidFrom: Moment;
private _previousValidTo: Moment;
+ private _lastValidFrom: Moment;
+ private _lastValidTo: Moment;
constructor(
private readonly _appStateService: AppStateService,
private readonly _toaster: Toaster,
private readonly _dossierTemplatesService: DossierTemplatesService,
private readonly _formBuilder: FormBuilder,
+ protected readonly _injector: Injector,
+ protected readonly _dialogRef: MatDialogRef,
private readonly _loadingService: LoadingService,
- public dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA) readonly dossierTemplate: IDossierTemplate,
) {
- super();
+ super(_injector, _dialogRef);
+ this.form = this._getForm();
+ this.initialFormValue = this.form.getRawValue();
this.hasValidFrom = !!this.dossierTemplate?.validFrom;
this.hasValidTo = !!this.dossierTemplate?.validTo;
- this._previousValidFrom = this.form.get('validFrom').value;
- this._previousValidTo = this.form.get('validTo').value;
+ this._previousValidFrom = this._lastValidFrom = this.form.get('validFrom').value;
+ this._previousValidTo = this._lastValidTo = this.form.get('validTo').value;
- this.form.valueChanges.subscribe(value => {
+ this.addSubscription = this.form.valueChanges.subscribe(value => {
this._applyValidityIntervalConstraints(value);
});
+
+ this.addSubscription = this.form.controls['validFrom'].valueChanges.subscribe(value => {
+ this._lastValidFrom = value ? value : this._lastValidFrom;
+ });
+ this.addSubscription = this.form.controls['validTo'].valueChanges.subscribe(value => {
+ this._lastValidFrom = value ? value : this._lastValidFrom;
+ });
}
- get valid(): boolean {
- return this.form.valid;
- }
-
- get changed(): boolean {
- if (!this.dossierTemplate) {
- return true;
+ toggleHasValid(extremity: string) {
+ if (extremity === 'from') {
+ this.hasValidFrom = !this.hasValidFrom;
+ this.form.controls['validFrom'].setValue(this.hasValidFrom ? this._lastValidFrom : null);
+ } else {
+ this.hasValidTo = !this.hasValidTo;
+ this.form.controls['validTo'].setValue(this.hasValidTo ? this._lastValidTo : null);
}
-
- for (const key of Object.keys(this.form.getRawValue())) {
- const formValue = this.form.get(key).value;
- const objectValue = this.dossierTemplate[key];
- if (key === 'validFrom') {
- if (this.hasValidFrom !== !!objectValue || (this.hasValidFrom && !moment(objectValue).isSame(moment(formValue)))) {
- return true;
- }
- } else if (key === 'validTo') {
- if (this.hasValidTo !== !!objectValue || (this.hasValidTo && !moment(objectValue).isSame(moment(formValue)))) {
- return true;
- }
- } else if (formValue instanceof Array) {
- if (objectValue.length !== formValue.length) {
- return true;
- }
- for (const item of objectValue) {
- if (!formValue.includes(item)) {
- return true;
- }
- }
- } else if (objectValue !== formValue) {
- return true;
- }
- }
-
- return false;
}
async save() {
@@ -95,10 +78,10 @@ export class AddEditDossierTemplateDialogComponent extends BaseDialogComponent {
...this.form.getRawValue(),
validFrom: this.hasValidFrom ? this.form.get('validFrom').value : null,
validTo: this.hasValidTo ? this.form.get('validTo').value : null,
- };
+ } as IDossierTemplate;
await this._dossierTemplatesService.createOrUpdate(dossierTemplate).toPromise();
await this._appStateService.loadDictionaryData();
- this.dialogRef.close(true);
+ this._dialogRef.close(true);
} catch (error: any) {
const message =
error.status === HttpStatusCode.Conflict
@@ -136,7 +119,7 @@ export class AddEditDossierTemplateDialogComponent extends BaseDialogComponent {
}
private _requiredIfValidator(predicate) {
- return formControl => {
+ return (formControl: AbstractControl) => {
if (!formControl.parent) {
return null;
}
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-file-attribute-dialog/add-edit-file-attribute-dialog.component.html b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-file-attribute-dialog/add-edit-file-attribute-dialog.component.html
index 82f32ef3e..7867b41a6 100644
--- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-file-attribute-dialog/add-edit-file-attribute-dialog.component.html
+++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-file-attribute-dialog/add-edit-file-attribute-dialog.component.html
@@ -84,11 +84,11 @@