From 2b011a34bbab08c7b2bf9c3df0dcc940d5fe2ef9 Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Tue, 22 Sep 2020 10:46:37 +0300 Subject: [PATCH] added SW --- angular.json | 12 +- apps/red-ui/ngsw-config.json | 30 + apps/red-ui/src/app/app.module.ts | 7 +- apps/red-ui/src/app/i18n/language.service.ts | 7 + .../app/notification/notification.service.ts | 28 +- .../base-screen/base-screen.component.html | 6 + .../base-screen/base-screen.component.ts | 5 + .../add-edit-project-dialog.component.ts | 6 +- .../project-listing-screen.component.ts | 6 +- .../project-overview-screen.component.ts | 30 +- apps/red-ui/src/assets/config/config.json | 2 +- apps/red-ui/src/assets/i18n/de.json | 142 ++++ apps/red-ui/src/assets/i18n/en.json | 9 + apps/red-ui/src/assets/icons/icon-128x128.png | Bin 0 -> 1253 bytes apps/red-ui/src/assets/icons/icon-144x144.png | Bin 0 -> 1394 bytes apps/red-ui/src/assets/icons/icon-152x152.png | Bin 0 -> 1427 bytes apps/red-ui/src/assets/icons/icon-192x192.png | Bin 0 -> 1790 bytes apps/red-ui/src/assets/icons/icon-384x384.png | Bin 0 -> 3557 bytes apps/red-ui/src/assets/icons/icon-512x512.png | Bin 0 -> 5008 bytes apps/red-ui/src/assets/icons/icon-72x72.png | Bin 0 -> 792 bytes apps/red-ui/src/assets/icons/icon-96x96.png | Bin 0 -> 958 bytes apps/red-ui/src/index.html | 15 +- apps/red-ui/src/manifest.webmanifest | 59 ++ assets/styles/red-theme.scss | 1 + docker/red-ui/docker-entrypoint.sh | 10 +- package.json | 10 +- yarn.lock | 773 ++++++++++++++++-- 27 files changed, 1054 insertions(+), 104 deletions(-) create mode 100644 apps/red-ui/ngsw-config.json create mode 100644 apps/red-ui/src/assets/icons/icon-128x128.png create mode 100644 apps/red-ui/src/assets/icons/icon-144x144.png create mode 100644 apps/red-ui/src/assets/icons/icon-152x152.png create mode 100644 apps/red-ui/src/assets/icons/icon-192x192.png create mode 100644 apps/red-ui/src/assets/icons/icon-384x384.png create mode 100644 apps/red-ui/src/assets/icons/icon-512x512.png create mode 100644 apps/red-ui/src/assets/icons/icon-72x72.png create mode 100644 apps/red-ui/src/assets/icons/icon-96x96.png create mode 100644 apps/red-ui/src/manifest.webmanifest diff --git a/angular.json b/angular.json index 3b9543f85..8c9e1dc10 100644 --- a/angular.json +++ b/angular.json @@ -32,7 +32,8 @@ "glob": "**/*", "input": "apps/red-ui/src/assets/", "output": "/assets/" - } + }, + "apps/red-ui/src/manifest.webmanifest" ], "styles": [ "apps/red-ui/src/styles.scss" @@ -68,7 +69,9 @@ "maximumWarning": "6kb", "maximumError": "10kb" } - ] + ], + "serviceWorker": true, + "ngswConfigPath": "apps/red-ui/ngsw-config.json" } } }, @@ -147,7 +150,8 @@ } }, "cli": { - "defaultCollection": "@nrwl/angular" + "defaultCollection": "@nrwl/angular", + "analytics": false }, "schematics": { "@nrwl/angular:application": { @@ -159,4 +163,4 @@ } }, "defaultProject": "red-ui" -} +} \ No newline at end of file diff --git a/apps/red-ui/ngsw-config.json b/apps/red-ui/ngsw-config.json new file mode 100644 index 000000000..ea7898845 --- /dev/null +++ b/apps/red-ui/ngsw-config.json @@ -0,0 +1,30 @@ +{ + "$schema": "../../node_modules/@angular/service-worker/config/schema.json", + "index": "/index.html", + "assetGroups": [ + { + "name": "app", + "installMode": "prefetch", + "resources": { + "files": [ + "/favicon.ico", + "/index.html", + "/manifest.webmanifest", + "/*.css", + "/*.js" + ] + } + }, + { + "name": "assets", + "installMode": "lazy", + "updateMode": "prefetch", + "resources": { + "files": [ + "/assets/**", + "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)" + ] + } + } + ] +} diff --git a/apps/red-ui/src/app/app.module.ts b/apps/red-ui/src/app/app.module.ts index ecfe56c77..facfd3485 100644 --- a/apps/red-ui/src/app/app.module.ts +++ b/apps/red-ui/src/app/app.module.ts @@ -38,6 +38,9 @@ import {MatSelectModule} from "@angular/material/select"; import {NgxDropzoneModule} from "ngx-dropzone"; import {MatSidenavModule} from "@angular/material/sidenav"; import { FileDetailsDialogComponent } from './screens/file/file-preview-screen/file-details-dialog/file-details-dialog.component'; +import {ToastrModule} from "ngx-toastr"; +import { ServiceWorkerModule } from '@angular/service-worker'; +import { environment } from '../environments/environment'; export function HttpLoaderFactory(httpClient: HttpClient) { return new TranslateHttpLoader(httpClient, '/assets/i18n/', '.json'); @@ -100,9 +103,11 @@ export function HttpLoaderFactory(httpClient: HttpClient) { MatTabsModule, MatButtonToggleModule, MatFormFieldModule, + ToastrModule.forRoot(), MatSelectModule, NgxDropzoneModule, - MatSidenavModule + MatSidenavModule, + ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }) ], providers: [{ provide: KeycloakService, diff --git a/apps/red-ui/src/app/i18n/language.service.ts b/apps/red-ui/src/app/i18n/language.service.ts index f806dbbc8..ca1a2205d 100644 --- a/apps/red-ui/src/app/i18n/language.service.ts +++ b/apps/red-ui/src/app/i18n/language.service.ts @@ -33,4 +33,11 @@ export class LanguageService { get currentLanguage() { return this.translateService.currentLang; } + + changeLanguage(language: string) { + localStorage.setItem('redaction.language',language); + document.documentElement.lang = language; + this.translateService.use(language).subscribe(() => { + }); + } } diff --git a/apps/red-ui/src/app/notification/notification.service.ts b/apps/red-ui/src/app/notification/notification.service.ts index d97ff9f80..aca34b4cd 100644 --- a/apps/red-ui/src/app/notification/notification.service.ts +++ b/apps/red-ui/src/app/notification/notification.service.ts @@ -1,18 +1,36 @@ import {Injectable} from "@angular/core"; import {MatSnackBar} from "@angular/material/snack-bar"; +import {ToastrService} from "ngx-toastr"; +export enum NotificationType { + SUCCESS = 'SUCCESS', WARNING = 'WARNING', ERROR = 'ERROR', INFO = 'INFO', +} + @Injectable({ providedIn: 'root' }) export class NotificationService { - constructor(private readonly _snackBar: MatSnackBar) { + + constructor(private readonly _snackBar: MatSnackBar, + private readonly _toastr: ToastrService) { } - showToastNotification(message: string) { - this._snackBar.open(message, null, { - duration: 5000 - }); + showToastNotification(message: string, title?: string, notificationType: NotificationType = NotificationType.INFO) { + switch (notificationType) { + case NotificationType.ERROR: + this._toastr.error(message, title); + break; + case NotificationType.SUCCESS: + this._toastr.success(message, title); + break; + case NotificationType.WARNING: + this._toastr.warning(message, title); + break + case NotificationType.INFO: + this._toastr.info(message, title); + break + } } } diff --git a/apps/red-ui/src/app/screens/base-screen/base-screen.component.html b/apps/red-ui/src/app/screens/base-screen/base-screen.component.html index 5bef5c50b..a3825abab 100644 --- a/apps/red-ui/src/app/screens/base-screen/base-screen.component.html +++ b/apps/red-ui/src/app/screens/base-screen/base-screen.component.html @@ -31,6 +31,12 @@