RED-5228: add auto expand filters on action setting

This commit is contained in:
Dan Percic 2022-09-23 14:58:25 +03:00
parent 7b31f20944
commit bcc478e72b
13 changed files with 119 additions and 11 deletions

View File

@ -3,6 +3,7 @@ import { RouterModule, Routes } from '@angular/router';
import { CompositeRouteGuard, IqserAuthGuard } from '@iqser/common-ui';
import { RedRoleGuard } from '@users/red-role.guard';
import { BaseAccountScreenComponent } from './base-account-screen/base-account-screen-component';
import { PreferencesComponent } from './screens/preferences/preferences.component';
const routes: Routes = [
{ path: '', redirectTo: 'user-profile', pathMatch: 'full' },
@ -25,6 +26,20 @@ const routes: Routes = [
},
loadChildren: () => import('./screens/notifications/notifications.module').then(m => m.NotificationsModule),
},
{
path: 'preferences',
component: BaseAccountScreenComponent,
canActivate: [CompositeRouteGuard],
data: {
routeGuards: [IqserAuthGuard, RedRoleGuard],
},
children: [
{
path: '',
component: PreferencesComponent,
},
],
},
];
@NgModule({

View File

@ -25,6 +25,10 @@ export class AccountSideNavComponent {
label: _('notifications.label'),
hideIf: !this._userService.currentUser.isUser,
},
{
screen: 'preferences',
label: _('preferences-screen.label'),
},
];
constructor(private readonly _userService: UserService) {}

View File

@ -8,9 +8,10 @@ import { NotificationPreferencesService } from './services/notification-preferen
import { TranslateModule } from '@ngx-translate/core';
import { IqserSharedModule } from '@iqser/common-ui';
import { IqserHelpModeModule } from '@iqser/common-ui';
import { PreferencesComponent } from './screens/preferences/preferences.component';
@NgModule({
declarations: [AccountSideNavComponent, BaseAccountScreenComponent],
declarations: [AccountSideNavComponent, BaseAccountScreenComponent, PreferencesComponent],
imports: [CommonModule, SharedModule, AccountRoutingModule, TranslateModule, IqserSharedModule, IqserHelpModeModule],
providers: [NotificationPreferencesService],
})

View File

@ -0,0 +1,17 @@
<form (submit)="save()" [formGroup]="form">
<div class="dialog-content">
<div class="dialog-content-left">
<div class="iqser-input-group">
<mat-slide-toggle color="primary" formControlName="autoExpandFiltersOnActions">
{{ 'preferences-screen.form.auto-expand-filters-on-action' | translate }}
</mat-slide-toggle>
</div>
</div>
</div>
<div class="dialog-actions">
<button [disabled]="!valid || !changed" color="primary" mat-flat-button type="submit">
{{ 'preferences-screen.actions.save' | translate }}
</button>
</div>
</form>

View File

@ -0,0 +1,40 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { UserPreferenceService } from '@users/user-preference.service';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { BaseFormComponent } from '@iqser/common-ui';
interface PreferencesForm {
autoExpandFiltersOnActions: boolean;
[k: string]: any;
}
type AsControl<T> = { [K in keyof T]: FormControl<T[K]> };
@Component({
selector: 'redaction-preferences',
templateUrl: './preferences.component.html',
styleUrls: ['./preferences.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PreferencesComponent extends BaseFormComponent {
readonly form: FormGroup<AsControl<PreferencesForm>>;
initialFormValue: PreferencesForm;
constructor(readonly userPreferenceService: UserPreferenceService, private readonly _formBuilder: FormBuilder) {
super();
this.form = this._formBuilder.group({
autoExpandFiltersOnActions: [this.userPreferenceService.getAutoExpandFiltersOnActions()],
});
this.initialFormValue = this.form.getRawValue();
}
async save(): Promise<any> {
if (this.form.controls.autoExpandFiltersOnActions.value !== this.userPreferenceService.getAutoExpandFiltersOnActions()) {
await this.userPreferenceService.toggleAutoExpandFiltersOnActions();
}
await this.userPreferenceService.reload();
this.form.patchValue({ autoExpandFiltersOnActions: this.userPreferenceService.getAutoExpandFiltersOnActions() });
this.initialFormValue = this.form.getRawValue();
}
}

View File

@ -101,10 +101,10 @@ export class UserProfileScreenComponent extends BaseFormComponent implements OnI
private _getForm(): UntypedFormGroup {
return this._formBuilder.group({
email: [undefined, [Validators.required, Validators.email]],
firstName: [undefined],
lastName: [undefined],
language: [undefined],
email: ['', [Validators.required, Validators.email]],
firstName: [''],
lastName: [''],
language: [''],
darkTheme: [false],
});
}
@ -113,10 +113,10 @@ export class UserProfileScreenComponent extends BaseFormComponent implements OnI
try {
this.form = this._getForm();
this.#profileModel = {
email: this._userService.currentUser.email,
firstName: this._userService.currentUser.firstName,
lastName: this._userService.currentUser.lastName,
language: this._languageService.currentLanguage,
email: this._userService.currentUser.email ?? '',
firstName: this._userService.currentUser.firstName ?? '',
lastName: this._userService.currentUser.lastName ?? '',
language: this._languageService.currentLanguage ?? '',
darkTheme: this._userPreferenceService.getTheme() === 'dark',
};
if (this._userService.currentUser.email) {

View File

@ -676,7 +676,7 @@ export class FilePreviewScreenComponent
const secondaryFilters = this._filterService.getGroup('secondaryFilters').filters;
const hasAnyFilterSet = [...primaryFilters, ...secondaryFilters].some(f => f.checked || f.indeterminate);
if (!hasAnyFilterSet) {
if (!hasAnyFilterSet || !this.userPreferenceService.getAutoExpandFiltersOnActions()) {
return;
}

View File

@ -3,4 +3,5 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
export const accountTranslations: Record<string, string> = {
notifications: _('notifications-screen.title'),
'user-profile': _('user-profile-screen.title'),
preferences: _('preferences-screen.title'),
};

View File

@ -6,6 +6,7 @@ const KEYS = {
filePreviewTooltips: 'File-Preview-Tooltips',
lastDossierTemplate: 'Last-Dossier-Template',
filesListingMode: 'Files-Listing-Mode',
autoExpandFiltersOnActions: 'Auto-Expand-Filters-On-Actions',
} as const;
@Injectable({
@ -40,6 +41,15 @@ export class UserPreferenceService extends IqserUserPreferenceService {
await this._save(KEYS.filePreviewTooltips, nextValue);
}
getAutoExpandFiltersOnActions(): boolean {
return this._getAttribute(KEYS.autoExpandFiltersOnActions, 'false') === 'true';
}
async toggleAutoExpandFiltersOnActions(): Promise<void> {
const nextValue = (!this.getAutoExpandFiltersOnActions()).toString();
await this._save(KEYS.autoExpandFiltersOnActions, nextValue);
}
getFilesListingMode(): ListingMode {
return this._getAttribute(KEYS.filesListingMode) as ListingMode;
}

View File

@ -1785,6 +1785,16 @@
"title": ""
}
},
"preferences-screen": {
"actions": {
"save": ""
},
"form": {
"auto-expand-filters-on-action": ""
},
"label": "",
"title": ""
},
"processing-status": {
"ocr": "",
"pending": "",

View File

@ -1785,6 +1785,16 @@
"title": "{length} {length, plural, one{Permission} other{Permissions}}"
}
},
"preferences-screen": {
"actions": {
"save": "Save changes"
},
"form": {
"auto-expand-filters-on-action": "Auto expand filters on action"
},
"label": "Preferences",
"title": "Edit preferences"
},
"processing-status": {
"ocr": "OCR",
"pending": "Pending",

@ -1 +1 @@
Subproject commit 440b8e6b829c099a499f4a80a4d6c27941178812
Subproject commit f65831525473687990749eb5e6bf6bd17e744e87