Merge remote-tracking branch 'origin/master'

This commit is contained in:
Valentin Mihai 2022-06-16 15:47:01 +03:00
commit 0a6b0c49bb
6 changed files with 33 additions and 25 deletions

View File

@ -1,6 +1,6 @@
import { Directive, HostListener, Injector, OnInit } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { FormGroup } from '@angular/forms';
import { UntypedFormGroup } from '@angular/forms';
import { AutoUnsubscribe, hasFormChanged, IqserEventTarget } from '../utils';
import { ConfirmOptions } from '../misc';
import { ConfirmationDialogService } from './confirmation-dialog.service';
@ -25,7 +25,7 @@ export interface SaveOptions {
* (otherwise the save request will be triggered twice).
* */
export abstract class BaseDialogComponent extends AutoUnsubscribe implements OnInit {
form!: FormGroup;
form!: UntypedFormGroup;
initialFormValue!: Record<string, string>;
private readonly _confirmationDialogService: ConfirmationDialogService = this._injector.get(ConfirmationDialogService);
private readonly _dialog: MatDialog = this._injector.get(MatDialog);

View File

@ -12,5 +12,6 @@ export interface IFilterGroup {
readonly hide?: boolean;
readonly checker?: (...args: unknown[]) => boolean;
readonly matchAll?: boolean;
readonly singleSelect?: boolean;
readonly checkerArgs?: unknown[];
}

View File

@ -44,7 +44,7 @@
*ngFor="let filter of filters"
[ngTemplateOutletContext]="{
filter: filter,
filterTemplate: primaryGroup.filterTemplate,
filterGroup: primaryGroup,
atLeastOneIsExpandable: atLeastOneFilterIsExpandable$ | async
}"
[ngTemplateOutlet]="defaultFilterTemplate"
@ -60,7 +60,7 @@
*ngFor="let filter of secondaryGroup.filters"
[ngTemplateOutletContext]="{
filter: filter,
filterTemplate: secondaryGroup.filterTemplate,
filterGroup: secondaryGroup,
atLeastOneIsExpandable: atLeastOneSecondaryFilterIsExpandable$ | async
}"
[ngTemplateOutlet]="defaultFilterTemplate"
@ -77,8 +77,9 @@
<ng-template #filterHeader>
<div class="filter-menu-header">
<div class="all-caps-label" translate="filter-menu.filter-types"></div>
<div class="actions">
<div class="actions" *ngIf="primaryFilterGroup$ | async as primaryGroup">
<div
*ngIf="!primaryGroup.singleSelect"
(click)="activatePrimaryFilters(); $event.stopPropagation()"
class="all-caps-label primary pointer"
translate="actions.all"
@ -96,7 +97,7 @@
#defaultFilterTemplate
let-atLeastOneIsExpandable="atLeastOneIsExpandable"
let-filter="filter"
let-filterTemplate="filterTemplate"
let-filterGroup="filterGroup"
>
<div (click)="toggleFilterExpanded($event, filter)" class="mat-menu-item flex">
<div *ngIf="filter.children?.length > 0" class="arrow-wrapper">
@ -107,14 +108,14 @@
<div *ngIf="atLeastOneIsExpandable && filter.children?.length === 0" class="arrow-wrapper spacer">&nbsp;</div>
<mat-checkbox
(click)="filterCheckboxClicked($event, filter)"
(click)="filterCheckboxClicked($event, filter, filterGroup)"
[checked]="filter.checked"
[indeterminate]="filter.indeterminate"
class="filter-menu-checkbox"
>
<ng-container
[ngTemplateOutletContext]="{ filter: filter }"
[ngTemplateOutlet]="filterTemplate ?? defaultFilterLabelTemplate"
[ngTemplateOutlet]="filterGroup.filterTemplate ?? defaultFilterLabelTemplate"
></ng-container>
</mat-checkbox>
@ -123,10 +124,10 @@
<div *ngIf="filter.children?.length && filter.expanded">
<div (click)="$event.stopPropagation()" *ngFor="let child of filter.children" class="padding-left mat-menu-item">
<mat-checkbox (click)="filterCheckboxClicked($event, child, filter)" [checked]="child.checked">
<mat-checkbox (click)="filterCheckboxClicked($event, child, filterGroup, filter)" [checked]="child.checked">
<ng-container
[ngTemplateOutletContext]="{ filter: child }"
[ngTemplateOutlet]="filterTemplate ?? defaultFilterLabelTemplate"
[ngTemplateOutlet]="filterGroup.filterTemplate ?? defaultFilterLabelTemplate"
></ng-container>
</mat-checkbox>

View File

@ -84,9 +84,13 @@ export class PopupFilterComponent implements OnInit {
this.atLeastOneSecondaryFilterIsExpandable$ = atLeastOneIsExpandable(this.secondaryFilterGroup$);
}
filterCheckboxClicked($event: MouseEvent, nestedFilter: INestedFilter, parent?: INestedFilter): void {
filterCheckboxClicked($event: MouseEvent, nestedFilter: INestedFilter, filterGroup: IFilterGroup, parent?: INestedFilter): void {
$event.stopPropagation();
if (filterGroup.singleSelect) {
this.deactivateFilters(nestedFilter.id);
}
// eslint-disable-next-line no-param-reassign
nestedFilter.checked = !nestedFilter.checked;
@ -110,10 +114,10 @@ export class PopupFilterComponent implements OnInit {
this._setFilters(this.primaryFiltersSlug, true);
}
deactivateFilters(): void {
this._setFilters(this.primaryFiltersSlug);
deactivateFilters(exceptedFilterId?: string): void {
this._setFilters(this.primaryFiltersSlug, false, exceptedFilterId);
if (this.secondaryFiltersSlug) {
this._setFilters(this.secondaryFiltersSlug);
this._setFilters(this.secondaryFiltersSlug, false, exceptedFilterId);
}
}
@ -124,15 +128,17 @@ export class PopupFilterComponent implements OnInit {
this.filterService.refresh();
}
private _setFilters(filterGroup: string, checked = false) {
private _setFilters(filterGroup: string, checked = false, exceptedFilterId?: string) {
const filters = this.filterService.getGroup(filterGroup)?.filters;
filters?.forEach(f => {
// eslint-disable-next-line no-param-reassign
f.checked = checked;
// eslint-disable-next-line no-param-reassign
f.indeterminate = false;
// eslint-disable-next-line no-return-assign,no-param-reassign
f.children?.forEach(ff => (ff.checked = checked));
if (f.id !== exceptedFilterId) {
// eslint-disable-next-line no-param-reassign
f.checked = checked;
// eslint-disable-next-line no-param-reassign
f.indeterminate = false;
// eslint-disable-next-line no-return-assign,no-param-reassign
f.children?.forEach(ff => (ff.checked = checked));
}
});
this.filterService.refresh();
}

View File

@ -1,10 +1,10 @@
import { Directive } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { UntypedFormGroup } from '@angular/forms';
import { AutoUnsubscribe, hasFormChanged } from '../utils';
@Directive()
export abstract class BaseFormComponent extends AutoUnsubscribe {
form!: FormGroup;
form!: UntypedFormGroup;
initialFormValue!: Record<string, string>;
get changed(): boolean {

View File

@ -1,5 +1,5 @@
import { ITrackable } from '../listing/models/trackable';
import { FormGroup } from '@angular/forms';
import { UntypedFormGroup } from '@angular/forms';
import { forOwn, has, isEqual, isPlainObject, transform } from 'lodash-es';
import dayjs, { Dayjs } from 'dayjs';
@ -35,7 +35,7 @@ export function trackByFactory<T extends ITrackable>() {
return (index: number, item: T): string => item.id;
}
export function hasFormChanged(form: FormGroup, initialFormValue: Record<string, string>): boolean {
export function hasFormChanged(form: UntypedFormGroup, initialFormValue: Record<string, string>): boolean {
if (form && initialFormValue) {
for (const key of Object.keys(form.getRawValue())) {
const initialValue = initialFormValue[key];