Eslint curly
This commit is contained in:
parent
6d9806160a
commit
1afafe0e28
@ -11,10 +11,7 @@
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
||||
"plugin:@angular-eslint/recommended--extra",
|
||||
"airbnb-typescript/base",
|
||||
"prettier",
|
||||
"plugin:prettier/recommended"
|
||||
"plugin:@angular-eslint/recommended--extra"
|
||||
],
|
||||
"parserOptions": {
|
||||
"project": ["libs/common-ui/tsconfig.*?.json"]
|
||||
|
||||
@ -35,7 +35,9 @@ export class CircleButtonComponent implements OnInit {
|
||||
}
|
||||
|
||||
performAction($event: MouseEvent): void {
|
||||
if (this.disabled) return;
|
||||
if (this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.removeTooltip) {
|
||||
this._matTooltip.hide();
|
||||
|
||||
@ -4,14 +4,18 @@ import { FilterGroup } from './models/filter-group.model';
|
||||
import { Filter } from './models/filter.model';
|
||||
|
||||
function copySettings(oldFilters: NestedFilter[], newFilters: NestedFilter[]) {
|
||||
if (!oldFilters || !newFilters) return;
|
||||
if (!oldFilters || !newFilters) {
|
||||
return;
|
||||
}
|
||||
|
||||
oldFilters.forEach(filter => {
|
||||
const newFilter = newFilters.find(f => f.key === filter.key);
|
||||
if (newFilter) {
|
||||
newFilter.checked = filter.checked;
|
||||
newFilter.indeterminate = filter.indeterminate;
|
||||
if (filter.children && newFilter.children) copySettings(filter.children, newFilter.children);
|
||||
if (filter.children && newFilter.children) {
|
||||
copySettings(filter.children, newFilter.children);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -49,7 +53,9 @@ export function checkFilter(
|
||||
): boolean {
|
||||
const hasChecked = filters.find(f => f.checked);
|
||||
|
||||
if (!hasChecked) return true;
|
||||
if (!hasChecked) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let filterMatched = matchAll;
|
||||
filters.forEach(filter => {
|
||||
@ -75,7 +81,9 @@ export function getFilteredEntities<T>(entities: T[], filters: FilterGroup[]): T
|
||||
filters.forEach(filter => {
|
||||
add = add && checkFilter(entity, filter.filters, filter.checker, filter.checkerArgs, filter.matchAll);
|
||||
});
|
||||
if (add) filteredEntities.push(entity);
|
||||
if (add) {
|
||||
filteredEntities.push(entity);
|
||||
}
|
||||
});
|
||||
return filteredEntities;
|
||||
}
|
||||
|
||||
@ -40,20 +40,30 @@ export class FilterService {
|
||||
|
||||
toggleFilter(filterGroupSlug: string, key: string): void {
|
||||
const filters = this.filterGroups.find(group => group.slug === filterGroupSlug)?.filters;
|
||||
if (!filters) return console.error(`Cannot find filter group "${filterGroupSlug}"`);
|
||||
if (!filters) {
|
||||
return console.error(`Cannot find filter group "${filterGroupSlug}"`);
|
||||
}
|
||||
|
||||
let found = filters.find(f => f.key === key);
|
||||
if (!found) [found] = filters.map(f => f.children?.find(ff => ff.key === key));
|
||||
if (!found) return console.error(`Cannot find filter with key "${key}" in group "${filterGroupSlug}"`);
|
||||
if (!found) {
|
||||
[found] = filters.map(f => f.children?.find(ff => ff.key === key));
|
||||
}
|
||||
if (!found) {
|
||||
return console.error(`Cannot find filter with key "${key}" in group "${filterGroupSlug}"`);
|
||||
}
|
||||
|
||||
found.checked = !found.checked;
|
||||
if (found) {
|
||||
found.checked = !found.checked;
|
||||
}
|
||||
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
addFilterGroup(value: FilterGroup): void {
|
||||
const oldFilters = this.getGroup(value.slug)?.filters;
|
||||
if (!oldFilters) return this._filterGroups$.next([...this.filterGroups, value]);
|
||||
if (!oldFilters) {
|
||||
return this._filterGroups$.next([...this.filterGroups, value]);
|
||||
}
|
||||
|
||||
const newGroup = { ...value, filters: processFilters(oldFilters, value.filters) };
|
||||
this._filterGroups$.next([...this.filterGroups.filter(f => f.slug !== newGroup.slug), newGroup]);
|
||||
|
||||
@ -73,7 +73,9 @@ export class PopupFilterComponent implements OnInit {
|
||||
handleCheckedValue(parent);
|
||||
} else {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
if (nestedFilter.indeterminate) nestedFilter.checked = false;
|
||||
if (nestedFilter.indeterminate) {
|
||||
nestedFilter.checked = false;
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
nestedFilter.indeterminate = false;
|
||||
// eslint-disable-next-line no-return-assign,no-param-reassign
|
||||
@ -89,7 +91,9 @@ export class PopupFilterComponent implements OnInit {
|
||||
|
||||
deactivateFilters(): void {
|
||||
this._setFilters(this.primaryFiltersSlug);
|
||||
if (this.secondaryFiltersSlug) this._setFilters(this.secondaryFiltersSlug);
|
||||
if (this.secondaryFiltersSlug) {
|
||||
this._setFilters(this.secondaryFiltersSlug);
|
||||
}
|
||||
}
|
||||
|
||||
toggleFilterExpanded($event: MouseEvent, nestedFilter: NestedFilter): void {
|
||||
|
||||
@ -70,7 +70,9 @@ export class HelpModeService {
|
||||
}
|
||||
|
||||
highlightHelperElements(): void {
|
||||
if (!this.isHelpModeActive) return;
|
||||
if (!this.isHelpModeActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.values(this._elements).forEach(({ helperElement }) => {
|
||||
this._renderer.addClass(helperElement, 'help-highlight');
|
||||
|
||||
@ -110,13 +110,17 @@ export class EntitiesService<T extends Listable> {
|
||||
}
|
||||
|
||||
selectAll(): void {
|
||||
if (this._allSelected) return this.setSelected([]);
|
||||
if (this._allSelected) {
|
||||
return this.setSelected([]);
|
||||
}
|
||||
this.setSelected(this._displayed);
|
||||
}
|
||||
|
||||
select(entity: T): void {
|
||||
const currentEntityIdx = this.selected.indexOf(entity);
|
||||
if (currentEntityIdx === -1) return this.setSelected([...this.selected, entity]);
|
||||
if (currentEntityIdx === -1) {
|
||||
return this.setSelected([...this.selected, entity]);
|
||||
}
|
||||
this.setSelected(this.selected.filter((el, idx) => idx !== currentEntityIdx));
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,11 @@ export class SyncWidthDirective implements OnDestroy {
|
||||
clearInterval(this._interval);
|
||||
}
|
||||
|
||||
@HostListener('window:resize')
|
||||
onResize(): void {
|
||||
this._matchWidth();
|
||||
}
|
||||
|
||||
private _matchWidth() {
|
||||
const headerItems = (this._elementRef.nativeElement as HTMLElement).children;
|
||||
const tableRows = (this._elementRef.nativeElement as HTMLElement).parentElement?.parentElement?.getElementsByClassName(
|
||||
@ -30,7 +35,9 @@ export class SyncWidthDirective implements OnDestroy {
|
||||
(this._elementRef.nativeElement as HTMLElement).setAttribute('synced', 'true');
|
||||
|
||||
const { tableRow, length } = this._sampleRow(tableRows);
|
||||
if (!tableRow) return;
|
||||
if (!tableRow) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasExtraColumns = headerItems.length !== length ? 1 : 0;
|
||||
|
||||
@ -50,11 +57,6 @@ export class SyncWidthDirective implements OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('window:resize')
|
||||
onResize(): void {
|
||||
this._matchWidth();
|
||||
}
|
||||
|
||||
private _sampleRow(tableRows: HTMLCollectionOf<Element>): {
|
||||
tableRow?: Element;
|
||||
length: number;
|
||||
|
||||
@ -17,7 +17,9 @@ export class SearchService<T> {
|
||||
}
|
||||
|
||||
searchIn(entities: T[]): T[] {
|
||||
if (!this._searchKey) return entities;
|
||||
if (!this._searchKey) {
|
||||
return entities;
|
||||
}
|
||||
|
||||
const searchValue = this.searchValue.toLowerCase();
|
||||
return entities.filter(entity => this._searchField(entity).includes(searchValue));
|
||||
|
||||
@ -8,12 +8,13 @@ import { HttpErrorResponse } from '@angular/common/http';
|
||||
export class ErrorMessageService {
|
||||
constructor(private readonly _translateService: TranslateService) {}
|
||||
|
||||
private _parseErrorResponse(err: HttpErrorResponse): string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions
|
||||
return err?.error?.message?.includes('message') ? ` ${err.error.message.match('"message":"(.*?)\\"')[1]}` : '';
|
||||
}
|
||||
|
||||
getMessage(error: HttpErrorResponse, defaultMessage: string): string {
|
||||
return (this._translateService.instant(defaultMessage) as string) + this._parseErrorResponse(error);
|
||||
}
|
||||
|
||||
private _parseErrorResponse(err: HttpErrorResponse): string {
|
||||
// eslint-disable-next-line max-len
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions
|
||||
return err?.error?.message?.includes('message') ? ` ${err.error.message.match('"message":"(.*?)\\"')[1]}` : '';
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,8 +47,11 @@ export class Toaster {
|
||||
|
||||
error(message: string, options?: Partial<ErrorToasterOptions>): ActiveToast<unknown> {
|
||||
let resultedMsg;
|
||||
if (options?.error) resultedMsg = this._errorMessageService.getMessage(options.error, message);
|
||||
else resultedMsg = this._translateService.instant(message, options?.params) as string;
|
||||
if (options?.error) {
|
||||
resultedMsg = this._errorMessageService.getMessage(options.error, message);
|
||||
} else {
|
||||
resultedMsg = this._translateService.instant(message, options?.params) as string;
|
||||
}
|
||||
|
||||
return this._toastr.error(resultedMsg, options?.title, options);
|
||||
}
|
||||
|
||||
@ -4,7 +4,9 @@ export const SortingOrders = {
|
||||
asc: 'asc',
|
||||
desc: 'desc',
|
||||
inverseOf: (order?: 'asc' | 'desc') => {
|
||||
if (order === undefined) return 'asc';
|
||||
if (order === undefined) {
|
||||
return 'asc';
|
||||
}
|
||||
return order === 'asc' ? 'desc' : 'asc';
|
||||
}
|
||||
} as const;
|
||||
|
||||
@ -15,7 +15,9 @@ export class SortingService<T> {
|
||||
}
|
||||
|
||||
static sort<T>(values: T[], order?: SortingOrder, column?: KeysOf<T>): T[] {
|
||||
if (!values || values.length <= 1 || !order) return values;
|
||||
if (!values || values.length <= 1 || !order) {
|
||||
return values;
|
||||
}
|
||||
|
||||
if (!column) {
|
||||
/** sort 1D array */
|
||||
|
||||
@ -4,7 +4,9 @@ export function Required<T>(condition: Condition<T> = () => true): PropertyDecor
|
||||
return function _required(target: unknown, propertyKey: PropertyKey) {
|
||||
Object.defineProperty(target, propertyKey, {
|
||||
get() {
|
||||
if (condition(this)) throw new Error(`Attribute ${String(propertyKey)} is required`);
|
||||
if (condition(this)) {
|
||||
throw new Error(`Attribute ${String(propertyKey)} is required`);
|
||||
}
|
||||
},
|
||||
set(value: unknown) {
|
||||
Object.defineProperty(this, propertyKey, {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user