From 2cb86ab702a5dbe1e17550dda013bf17bb7d2f3e Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Fri, 6 Aug 2021 03:43:49 +0300 Subject: [PATCH] move sort and humanize pipe --- .../add-edit-dictionary-dialog.component.ts | 2 +- .../remove-annotations-dialog.component.ts | 4 +-- .../app/modules/shared/pipes/humanize.pipe.ts | 11 ------- .../app/modules/shared/pipes/sort-by.pipe.ts | 11 ------- .../src/app/modules/shared/shared.module.ts | 7 ++-- .../red-ui/src/app/state/app-state.service.ts | 3 +- apps/red-ui/src/app/utils/functions.ts | 33 +------------------ package.json | 2 +- 8 files changed, 9 insertions(+), 64 deletions(-) delete mode 100644 apps/red-ui/src/app/modules/shared/pipes/humanize.pipe.ts delete mode 100644 apps/red-ui/src/app/modules/shared/pipes/sort-by.pipe.ts 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 75577153c..88ce6e0e5 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 @@ -6,8 +6,8 @@ import { Observable } from 'rxjs'; import { Toaster } from '@services/toaster.service'; import { TranslateService } from '@ngx-translate/core'; import { TypeValueWrapper } from '@models/file/type-value.wrapper'; -import { humanize } from '../../../../utils/functions'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; +import { humanize } from '@iqser/common-ui'; @Component({ selector: 'redaction-add-edit-dictionary-dialog', diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/remove-annotations-dialog/remove-annotations-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/remove-annotations-dialog/remove-annotations-dialog.component.ts index 2c7039e83..2a9966164 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/remove-annotations-dialog/remove-annotations-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/remove-annotations-dialog/remove-annotations-dialog.component.ts @@ -2,9 +2,9 @@ import { Component, Inject } from '@angular/core'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; import { TranslateService } from '@ngx-translate/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { humanize } from '../../../../utils/functions'; -import { PermissionsService } from '../../../../services/permissions.service'; +import { PermissionsService } from '@services/permissions.service'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { humanize } from '@iqser/common-ui'; export interface RemoveAnnotationsDialogInput { annotationsToRemove: AnnotationWrapper[]; diff --git a/apps/red-ui/src/app/modules/shared/pipes/humanize.pipe.ts b/apps/red-ui/src/app/modules/shared/pipes/humanize.pipe.ts deleted file mode 100644 index 1d9b329bf..000000000 --- a/apps/red-ui/src/app/modules/shared/pipes/humanize.pipe.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; -import { humanize } from '@utils/functions'; - -@Pipe({ - name: 'humanize' -}) -export class HumanizePipe implements PipeTransform { - transform(item: string, lowercase: boolean = false): any { - return humanize(item, lowercase); - } -} diff --git a/apps/red-ui/src/app/modules/shared/pipes/sort-by.pipe.ts b/apps/red-ui/src/app/modules/shared/pipes/sort-by.pipe.ts deleted file mode 100644 index 974299f02..000000000 --- a/apps/red-ui/src/app/modules/shared/pipes/sort-by.pipe.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; -import { SortingOrder, SortingService } from '@iqser/common-ui'; - -@Pipe({ name: 'sortBy' }) -export class SortByPipe implements PipeTransform { - constructor(private readonly _sortingService: SortingService) {} - - transform(value: T[], order: SortingOrder, column: string): T[] { - return this._sortingService.sort(value, order, column); - } -} diff --git a/apps/red-ui/src/app/modules/shared/shared.module.ts b/apps/red-ui/src/app/modules/shared/shared.module.ts index 4062c0c0f..ff6820f6c 100644 --- a/apps/red-ui/src/app/modules/shared/shared.module.ts +++ b/apps/red-ui/src/app/modules/shared/shared.module.ts @@ -14,14 +14,13 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { AnnotationIconComponent } from './components/annotation-icon/annotation-icon.component'; import { SimpleDoughnutChartComponent } from './components/simple-doughnut-chart/simple-doughnut-chart.component'; import { StatusBarComponent } from './components/status-bar/status-bar.component'; -import { HumanizePipe } from './pipes/humanize.pipe'; import { SyncWidthDirective } from './directives/sync-width.directive'; import { HasScrollbarDirective } from './directives/has-scrollbar.directive'; import { DictionaryAnnotationIconComponent } from './components/dictionary-annotation-icon/dictionary-annotation-icon.component'; import { HiddenActionComponent } from './components/hidden-action/hidden-action.component'; import { ConfirmationDialogComponent } from './dialogs/confirmation-dialog/confirmation-dialog.component'; import { EmptyStateComponent } from './components/empty-state/empty-state.component'; -import { SortByPipe } from './pipes/sort-by.pipe'; +import { CommonUiModule } from '@iqser/common-ui'; import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core'; import { MomentDateAdapter } from '@angular/material-moment-adapter'; import { SelectComponent } from './components/select/select.component'; @@ -36,7 +35,6 @@ import { InputWithActionComponent } from '@shared/components/input-with-action/i import { PageHeaderComponent } from './components/page-header/page-header.component'; import { DatePipe } from '@shared/pipes/date.pipe'; import { TableHeaderComponent } from './components/table-header/table-header.component'; -import { CommonUiModule } from '@iqser/common-ui'; const buttons = [FileDownloadBtnComponent, UserButtonComponent]; @@ -54,7 +52,6 @@ const components = [ PopupFilterComponent, ConfirmationDialogComponent, EmptyStateComponent, - SortByPipe, SelectComponent, SideNavComponent, DictionaryManagerComponent, @@ -65,7 +62,7 @@ const components = [ ...buttons ]; -const utils = [HumanizePipe, DatePipe, SyncWidthDirective, HasScrollbarDirective, NavigateLastDossiersScreenDirective]; +const utils = [DatePipe, SyncWidthDirective, HasScrollbarDirective, NavigateLastDossiersScreenDirective]; const modules = [MatConfigModule, TranslateModule, ScrollingModule, IconsModule, FormsModule, ReactiveFormsModule, CommonUiModule]; diff --git a/apps/red-ui/src/app/state/app-state.service.ts b/apps/red-ui/src/app/state/app-state.service.ts index 537dd0a0a..f2b6befb1 100644 --- a/apps/red-ui/src/app/state/app-state.service.ts +++ b/apps/red-ui/src/app/state/app-state.service.ts @@ -15,13 +15,14 @@ import { Event, NavigationEnd, ResolveStart, Router } from '@angular/router'; import { UserService } from '@services/user.service'; import { forkJoin, Observable, of } from 'rxjs'; import { catchError, tap } from 'rxjs/operators'; -import { FALLBACK_COLOR, hexToRgb, humanize } from '@utils/functions'; +import { FALLBACK_COLOR, hexToRgb } from '@utils/functions'; import { FileStatusWrapper } from '@models/file/file-status.wrapper'; import { DossierWrapper } from './model/dossier.wrapper'; import { TypeValueWrapper } from '@models/file/type-value.wrapper'; import { DossierTemplateModelWrapper } from '@models/file/dossier-template-model.wrapper'; import { DossiersService } from '../modules/dossier/services/dossiers.service'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; +import { humanize } from '@iqser/common-ui'; export interface AppState { dossiers: DossierWrapper[]; diff --git a/apps/red-ui/src/app/utils/functions.ts b/apps/red-ui/src/app/utils/functions.ts index 83f1a5ed5..183aae547 100644 --- a/apps/red-ui/src/app/utils/functions.ts +++ b/apps/red-ui/src/app/utils/functions.ts @@ -7,25 +7,6 @@ export function groupBy(xs: any[], key: string) { }, {}); } -export function computerize(str: string) { - if (!str) { - return undefined; - } - const frags = str.toLowerCase().split(/[ \-_]+/); - return frags.join('_'); -} - -export function humanize(str: string, lowercase: boolean = true) { - if (!str) { - return undefined; - } - const frags = (lowercase ? str.toLowerCase() : str).split(/[ \-_]+/); - for (let i = 0; i < frags.length; i++) { - frags[i] = frags[i].charAt(0).toUpperCase() + frags[i].slice(1); - } - return frags.join(' '); -} - export function hexToRgb(hex) { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result @@ -37,14 +18,6 @@ export function hexToRgb(hex) { : null; } -export function keypress(key: string) { - document.dispatchEvent(new KeyboardEvent('keypress', { key: key })); -} - -export function reference(x: any) { - return x; -} - export function getFirstRelevantTextPart(text, direction: 'FORWARD' | 'BACKWARD') { let spaceCount = 0; let accumulator = ''; @@ -58,11 +31,7 @@ export function getFirstRelevantTextPart(text, direction: 'FORWARD' | 'BACKWARD' accumulator += char; - if (spaceCount >= 2) { - return true; - } else { - return false; - } + return spaceCount >= 2; }; if (direction === 'FORWARD') { diff --git a/package.json b/package.json index b6809138a..a2630e3fd 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "husky": { "hooks": { - "pre-commit": "pretty-quick --staged && ng lint --project=red-ui-http && ng lint --project=red-ui --fix" + "pre-commit": "pretty-quick --staged && ng lint --project=red-ui-http && ng lint --project=red-ui --fix && ng lint --project=common-ui --fix" } }, "dependencies": {