From bef172e3ab50e5412a95c09340c49151297dbf66 Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 21 Apr 2021 08:33:19 +0300 Subject: [PATCH] code cleanup --- .../src/app/models/file/annotation.wrapper.ts | 12 +- .../src/app/models/file/file-data.model.ts | 2 +- ...ile-attributes-listing-screen.component.ts | 2 +- .../rule-sets-listing-screen.component.ts | 2 +- .../user-listing-screen.component.ts | 2 +- .../services/annotation-draw.service.ts | 2 +- .../shared/base/base-listing.component.ts | 4 + .../components/sort-pipe/sort-by.pipe.ts | 22 ++ .../src/app/modules/shared/shared.module.ts | 5 +- .../file-upload-download.module.ts | 2 +- package.json | 210 +++++++++--------- yarn.lock | 12 - 12 files changed, 148 insertions(+), 129 deletions(-) create mode 100644 apps/red-ui/src/app/modules/shared/components/sort-pipe/sort-by.pipe.ts diff --git a/apps/red-ui/src/app/models/file/annotation.wrapper.ts b/apps/red-ui/src/app/models/file/annotation.wrapper.ts index 5f70f97f8..a5cea00d6 100644 --- a/apps/red-ui/src/app/models/file/annotation.wrapper.ts +++ b/apps/red-ui/src/app/models/file/annotation.wrapper.ts @@ -95,11 +95,17 @@ export class AnnotationWrapper { } get isImage() { - return this.dictionary === 'image' || this.image; + return this.dictionary?.toLowerCase() === 'image' || this.image; + } + + get isOCR() { + return this.dictionary?.toLowerCase() === 'ocr'; } get isFalsePositive() { - return this.dictionary === 'false_positive' && (this.superType === 'skipped' || this.superType === 'hint' || this.superType === 'redaction'); + return ( + this.dictionary?.toLowerCase() === 'false_positive' && (this.superType === 'skipped' || this.superType === 'hint' || this.superType === 'redaction') + ); } get isManualRedaction() { @@ -218,7 +224,7 @@ export class AnnotationWrapper { return; } - if (annotationWrapper.dictionary === 'false_positive') { + if (annotationWrapper.dictionary?.toLowerCase() === 'false_positive') { if (redactionLogEntryWrapper.status === 'REQUESTED') { annotationWrapper.superType = 'suggestion-add-dictionary'; } diff --git a/apps/red-ui/src/app/models/file/file-data.model.ts b/apps/red-ui/src/app/models/file/file-data.model.ts index 3bcc31bed..cd1926b7f 100644 --- a/apps/red-ui/src/app/models/file/file-data.model.ts +++ b/apps/red-ui/src/app/models/file/file-data.model.ts @@ -86,7 +86,7 @@ export class FileDataModel { this.redactionLog.redactionLogEntry.forEach((redactionLogEntry) => { // false positive entries from the redaction-log need to be skipped - if (redactionLogEntry.type === 'false_positive') { + if (redactionLogEntry.type?.toLowerCase() === 'false_positive') { return; } diff --git a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts index 7fe68b944..44e4f3040 100644 --- a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts @@ -43,7 +43,7 @@ export class FileAttributesListingScreenComponent extends BaseListingComponent imple private async _loadData() { this.allEntities = (await this._userControllerService.getAllUsers({ requestId: new Date().toISOString() }).toPromise()).users; - this._executeSearch(); + this._executeSearchImmediately(); this._computeStats(); this.viewReady = true; this.loading = false; diff --git a/apps/red-ui/src/app/modules/projects/services/annotation-draw.service.ts b/apps/red-ui/src/app/modules/projects/services/annotation-draw.service.ts index 0fb108f35..8fccb33fc 100644 --- a/apps/red-ui/src/app/modules/projects/services/annotation-draw.service.ts +++ b/apps/red-ui/src/app/modules/projects/services/annotation-draw.service.ts @@ -81,7 +81,7 @@ export class AnnotationDrawService { highlight.ReadOnly = true; // change log entries are drawn lighter highlight.Opacity = annotationWrapper.isChangeLogRemoved ? 0.2 : 1; - highlight.Hidden = annotationWrapper.isChangeLogRemoved || (hideSkipped && annotationWrapper.isSkipped); + highlight.Hidden = annotationWrapper.isChangeLogRemoved || (hideSkipped && annotationWrapper.isSkipped) || annotationWrapper.isOCR; highlight.setCustomData('redaction', annotationWrapper.isRedacted); highlight.setCustomData('skipped', annotationWrapper.isSkipped); diff --git a/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts b/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts index 80268ccdf..5a91a608e 100644 --- a/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts +++ b/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts @@ -85,6 +85,10 @@ export class BaseListingComponent { @debounce(200) protected _executeSearch() { + this._executeSearchImmediately(); + } + + protected _executeSearchImmediately() { this.displayedEntities = (this.filters.length ? this.filteredEntities : this.allEntities).filter((entity) => this._searchField(entity).toLowerCase().includes(this.searchForm.get('query').value.toLowerCase()) ); diff --git a/apps/red-ui/src/app/modules/shared/components/sort-pipe/sort-by.pipe.ts b/apps/red-ui/src/app/modules/shared/components/sort-pipe/sort-by.pipe.ts new file mode 100644 index 000000000..3500ec404 --- /dev/null +++ b/apps/red-ui/src/app/modules/shared/components/sort-pipe/sort-by.pipe.ts @@ -0,0 +1,22 @@ +import { Pipe, PipeTransform } from '@angular/core'; +import { orderBy } from 'lodash'; + +@Pipe({ name: 'sortBy' }) +export class SortByPipe implements PipeTransform { + transform(value: T[], order = '', column: string = ''): T[] { + if (!value || order === '' || !order) { + return value; + } // no array + if (!column || column === '') { + if (order === 'asc') { + return value.sort(); + } else { + return value.sort().reverse(); + } + } // sort 1d array + if (value.length <= 1) { + return value; + } // array with only one item + return orderBy(value, [column], [order]); + } +} 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 1dc589b8e..e8af01765 100644 --- a/apps/red-ui/src/app/modules/shared/shared.module.ts +++ b/apps/red-ui/src/app/modules/shared/shared.module.ts @@ -13,7 +13,6 @@ import { IconButtonComponent } from './components/buttons/icon-button/icon-butto import { UserButtonComponent } from './components/buttons/user-button/user-button.component'; import { MatConfigModule } from '../mat-config/mat-config.module'; import { SearchInputComponent } from './components/search-input/search-input.component'; -import { NgpSortModule } from 'ngp-sort-pipe'; import { IconsModule } from '../icons/icons.module'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { AnnotationIconComponent } from './components/annotation-icon/annotation-icon.component'; @@ -28,6 +27,7 @@ import { ConfirmationDialogComponent } from './dialogs/confirmation-dialog/confi import { FilterComponent } from './components/filter/filter.component'; import { EmptyStateComponent } from './components/empty-state/empty-state.component'; import { BaseListingComponent } from './base/base-listing.component'; +import { SortByPipe } from './components/sort-pipe/sort-by.pipe'; const buttons = [ChevronButtonComponent, CircleButtonComponent, FileDownloadBtnComponent, IconButtonComponent, UserButtonComponent]; @@ -46,13 +46,14 @@ const components = [ ConfirmationDialogComponent, EmptyStateComponent, BaseListingComponent, + SortByPipe, ...buttons ]; const utils = [HumanizePipe, SyncWidthDirective, HasScrollbarDirective]; -const modules = [MatConfigModule, TranslateModule, ScrollingModule, NgpSortModule, IconsModule, FormsModule, ReactiveFormsModule]; +const modules = [MatConfigModule, TranslateModule, ScrollingModule, IconsModule, FormsModule, ReactiveFormsModule]; @NgModule({ declarations: [...components, ...utils], diff --git a/apps/red-ui/src/app/modules/upload-download/file-upload-download.module.ts b/apps/red-ui/src/app/modules/upload-download/file-upload-download.module.ts index 1804b96c5..2565e526e 100644 --- a/apps/red-ui/src/app/modules/upload-download/file-upload-download.module.ts +++ b/apps/red-ui/src/app/modules/upload-download/file-upload-download.module.ts @@ -13,7 +13,7 @@ import { StatusOverlayService } from './services/status-overlay.service'; import { FileDropOverlayService } from './services/file-drop-overlay.service'; @NgModule({ - imports: [CommonModule, SharedModule, NgxDropzoneModule, OverlayModule], + imports: [CommonModule, SharedModule, OverlayModule], declarations: [FileDropComponent, UploadStatusOverlay, OverwriteFilesDialogComponent], entryComponents: [FileDropComponent, UploadStatusOverlay], providers: [UploadDownloadDialogService, FileUploadService, FileDownloadService, StatusOverlayService, FileDropOverlayService], diff --git a/package.json b/package.json index bd7a0c517..105186e40 100644 --- a/package.json +++ b/package.json @@ -1,109 +1,107 @@ { - "name": "redaction", - "version": "1.0.74", - "private": true, - "license": "MIT", - "scripts": { - "affected": "nx affected", - "affected:apps": "nx affected:apps", - "affected:build": "nx affected:build", - "affected:dep-graph": "nx affected:dep-graph", - "affected:e2e": "nx affected:e2e", - "affected:libs": "nx affected:libs", - "affected:lint": "nx affected:lint", - "affected:test": "nx affected:test", - "build": "nx build", - "build-lint-all": "ng lint --project=red-ui-http --fix && ng build --project=red-ui-http && ng lint --project=red-ui --fix && ng build --project=red-ui --prod", - "dep-graph": "nx dep-graph", - "e2e": "nx e2e", - "format": "nx format:write", - "format:check": "nx format:check", - "format:write": "nx format:write", - "help": "nx help", - "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points", - "lint": "nx workspace-lint && nx lint", - "nx": "nx", - "start": "nx serve", - "test": "nx test", - "update": "nx migrate latest", - "workspace-schematic": "nx workspace-schematic" - }, - "husky": { - "hooks": { - "pre-commit": "pretty-quick --staged && ng lint --project=red-ui-http && ng lint --project=red-ui --fix" + "name": "redaction", + "version": "1.0.74", + "private": true, + "license": "MIT", + "scripts": { + "affected": "nx affected", + "affected:apps": "nx affected:apps", + "affected:build": "nx affected:build", + "affected:dep-graph": "nx affected:dep-graph", + "affected:e2e": "nx affected:e2e", + "affected:libs": "nx affected:libs", + "affected:lint": "nx affected:lint", + "affected:test": "nx affected:test", + "build": "nx build", + "build-lint-all": "ng lint --project=red-ui-http --fix && ng build --project=red-ui-http && ng lint --project=red-ui --fix && ng build --project=red-ui --prod", + "dep-graph": "nx dep-graph", + "e2e": "nx e2e", + "format": "nx format:write", + "format:check": "nx format:check", + "format:write": "nx format:write", + "help": "nx help", + "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points", + "lint": "nx workspace-lint && nx lint", + "nx": "nx", + "start": "nx serve", + "test": "nx test", + "update": "nx migrate latest", + "workspace-schematic": "nx workspace-schematic" + }, + "husky": { + "hooks": { + "pre-commit": "pretty-quick --staged && ng lint --project=red-ui-http && ng lint --project=red-ui --fix" + } + }, + "dependencies": { + "@angular/animations": "~11.0.1", + "@angular/cdk": "~11.0.1", + "@angular/common": "~11.0.1", + "@angular/compiler": "~11.0.1", + "@angular/core": "~11.0.1", + "@angular/forms": "~11.0.1", + "@angular/material": "~11.0.1", + "@angular/material-moment-adapter": "^11.0.2", + "@angular/platform-browser": "~11.0.1", + "@angular/platform-browser-dynamic": "~11.0.1", + "@angular/router": "~11.0.1", + "@angular/service-worker": "~11.0.1", + "@ngx-translate/core": "^13.0.0", + "@ngx-translate/http-loader": "^6.0.0", + "@nrwl/angular": "^10.2.0", + "@pdftron/webviewer": "7.3.0-20210223", + "@swimlane/ngx-charts": "^17.0.0", + "file-saver": "^2.0.2", + "jwt-decode": "^3.0.0", + "keycloak-angular": "^8.0.1", + "keycloak-js": "10.0.2", + "lint-staged": "^10.5.0", + "ng2-ace-editor": "^0.3.9", + "ngx-color-picker": "^10.1.0", + "ngx-toastr": "^13.0.0", + "papaparse": "^5.3.0", + "rxjs": "~6.6.0", + "scroll-into-view-if-needed": "^2.2.26", + "streamsaver": "^2.0.5", + "tslib": "^2.0.0", + "zone.js": "~0.10.2" + }, + "devDependencies": { + "@angular-devkit/build-angular": "~0.1100.2", + "@angular-devkit/build-ng-packagr": "~0.1002.0", + "@angular/cli": "~11.0.2", + "@angular/compiler": "~11.0.1", + "@angular/compiler-cli": "~11.0.1", + "@angular/language-service": "~11.0.2", + "@nrwl/cypress": "10.2.0", + "@nrwl/jest": "10.2.0", + "@nrwl/workspace": "10.2.0", + "@types/cypress": "^1.1.3", + "@types/jasmine": "~3.6.0", + "@types/jest": "26.0.8", + "@types/node": "^12.11.1", + "codelyzer": "^6.0.0", + "cypress": "^5.6.0", + "cypress-file-upload": "^4.1.1", + "cypress-keycloak": "^1.5.0", + "cypress-keycloak-commands": "^1.2.0", + "cypress-localstorage-commands": "^1.2.4", + "dotenv": "6.2.0", + "eslint": "6.8.0", + "google-translate-api-browser": "^1.1.71", + "husky": "^4.3.0", + "jest": "26.2.2", + "jest-preset-angular": "8.2.1", + "lodash": "^4.17.20", + "moment": "^2.29.1", + "ng-packagr": "^10.1.2", + "prettier": "2.0.4", + "pretty-quick": "^3.1.0", + "superagent": "^6.1.0", + "superagent-promise": "^1.1.0", + "ts-jest": "26.1.4", + "ts-node": "~8.3.0", + "tslint": "~6.1.0", + "typescript": "~4.0.2" } - }, - "dependencies": { - "@angular/animations": "~11.0.1", - "@angular/cdk": "~11.0.1", - "@angular/common": "~11.0.1", - "@angular/compiler": "~11.0.1", - "@angular/core": "~11.0.1", - "@angular/forms": "~11.0.1", - "@angular/material": "~11.0.1", - "@angular/material-moment-adapter": "^11.0.2", - "@angular/platform-browser": "~11.0.1", - "@angular/platform-browser-dynamic": "~11.0.1", - "@angular/router": "~11.0.1", - "@angular/service-worker": "~11.0.1", - "@ngx-translate/core": "^13.0.0", - "@ngx-translate/http-loader": "^6.0.0", - "@nrwl/angular": "^10.2.0", - "@pdftron/webviewer": "7.3.0-20210223", - "@swimlane/ngx-charts": "^17.0.0", - "file-saver": "^2.0.2", - "jwt-decode": "^3.0.0", - "keycloak-angular": "^8.0.1", - "keycloak-js": "10.0.2", - "lint-staged": "^10.5.0", - "ng2-ace-editor": "^0.3.9", - "ngp-sort-pipe": "^0.0.4", - "ngx-color-picker": "^10.1.0", - "ngx-dropzone": "^2.2.2", - "ngx-toastr": "^13.0.0", - "papaparse": "^5.3.0", - "rxjs": "~6.6.0", - "scroll-into-view-if-needed": "^2.2.26", - "streamsaver": "^2.0.5", - "tslib": "^2.0.0", - "zone.js": "~0.10.2" - }, - "devDependencies": { - "@angular-devkit/build-angular": "~0.1100.2", - "@angular-devkit/build-ng-packagr": "~0.1002.0", - "@angular/cli": "~11.0.2", - "@angular/compiler": "~11.0.1", - "@angular/compiler-cli": "~11.0.1", - "@angular/language-service": "~11.0.2", - "@nrwl/cypress": "10.2.0", - "@nrwl/jest": "10.2.0", - "@nrwl/workspace": "10.2.0", - "@types/cypress": "^1.1.3", - "@types/jasmine": "~3.6.0", - "@types/jest": "26.0.8", - "@types/node": "^12.11.1", - "codelyzer": "^6.0.0", - "cypress": "^5.6.0", - "cypress-file-upload": "^4.1.1", - "cypress-keycloak": "^1.5.0", - "cypress-keycloak-commands": "^1.2.0", - "cypress-localstorage-commands": "^1.2.4", - "dotenv": "6.2.0", - "eslint": "6.8.0", - "google-translate-api-browser": "^1.1.71", - "husky": "^4.3.0", - "jest": "26.2.2", - "jest-preset-angular": "8.2.1", - "lodash": "^4.17.20", - "moment": "^2.29.1", - "ng-packagr": "^10.1.2", - "prettier": "2.0.4", - "pretty-quick": "^3.1.0", - "superagent": "^6.1.0", - "superagent-promise": "^1.1.0", - "ts-jest": "26.1.4", - "ts-node": "~8.3.0", - "tslint": "~6.1.0", - "typescript": "~4.0.2" - } } diff --git a/yarn.lock b/yarn.lock index 0075279d3..2c3fe9ecf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8601,11 +8601,6 @@ ng2-ace-editor@^0.3.9: ace-builds "^1.4.2" brace "^0.11.1" -ngp-sort-pipe@^0.0.4: - version "0.0.4" - resolved "https://registry.yarnpkg.com/ngp-sort-pipe/-/ngp-sort-pipe-0.0.4.tgz#9d70caff0ee34f32f2ea1df16c7333b72df72b56" - integrity sha512-tqyxsjb1mKROKhQB7oIcKaDSamPaNNwQ7norqxnOLRNjMdvG0b+XofIAZQpa/cG+SN6lmdCjtzOvwhOjHzpHmA== - ngx-color-picker@^10.1.0: version "10.1.0" resolved "https://registry.yarnpkg.com/ngx-color-picker/-/ngx-color-picker-10.1.0.tgz#19a6993a74bb3553024623b20ca6ebffd2c50f9c" @@ -8613,13 +8608,6 @@ ngx-color-picker@^10.1.0: dependencies: tslib "^2.0.0" -ngx-dropzone@^2.2.2: - version "2.3.0" - resolved "https://registry.yarnpkg.com/ngx-dropzone/-/ngx-dropzone-2.3.0.tgz#fb34bceb0d8ad3c00c314b957d095018d15c5fe9" - integrity sha512-Mhsu6MW1yJRxLPRPbwal7y18trokU9josTD8GDb8wFRmaCd/N+dJeMDXn0XsxtDhlZ7vWqbpEr9k0ej4Na3v8Q== - dependencies: - tslib "^1.9.0" - ngx-toastr@^13.0.0: version "13.0.0" resolved "https://registry.yarnpkg.com/ngx-toastr/-/ngx-toastr-13.0.0.tgz#7d011117c4352d824399de2478d2aedeec5c9391"