diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-19 16:04:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-19 17:26:52 +0100 |
commit | f8b2c1b4f509c037b9650cca2c5befd21f056df3 (patch) | |
tree | 89d278f9628d657e6aad1b1e15febaf8ff9fcfa9 /client/src/app/core | |
parent | e0e665f0efa98f2701dd9f5529e99989680481ae (diff) | |
download | PeerTube-f8b2c1b4f509c037b9650cca2c5befd21f056df3.tar.gz PeerTube-f8b2c1b4f509c037b9650cca2c5befd21f056df3.tar.zst PeerTube-f8b2c1b4f509c037b9650cca2c5befd21f056df3.zip |
Refractor notification service
Shorter name and use primeng component
Diffstat (limited to 'client/src/app/core')
-rw-r--r-- | client/src/app/core/auth/auth.service.ts | 9 | ||||
-rw-r--r-- | client/src/app/core/auth/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/core.module.ts | 17 | ||||
-rw-r--r-- | client/src/app/core/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/notification/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/notification/notifier.service.ts | 41 | ||||
-rw-r--r-- | client/src/app/core/routing/user-right-guard.service.ts | 2 |
7 files changed, 58 insertions, 14 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 5f5730e02..79ea32ced 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts | |||
@@ -3,7 +3,7 @@ import { catchError, map, mergeMap, share, tap } from 'rxjs/operators' | |||
3 | import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' | 3 | import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' |
4 | import { Injectable } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
5 | import { Router } from '@angular/router' | 5 | import { Router } from '@angular/router' |
6 | import { NotificationsService } from 'angular2-notifications' | 6 | import { Notifier } from '@app/core/notification' |
7 | import { OAuthClientLocal, User as UserServerModel, UserRefreshToken } from '../../../../../shared' | 7 | import { OAuthClientLocal, User as UserServerModel, UserRefreshToken } from '../../../../../shared' |
8 | import { User } from '../../../../../shared/models/users' | 8 | import { User } from '../../../../../shared/models/users' |
9 | import { UserLogin } from '../../../../../shared/models/users/user-login.model' | 9 | import { UserLogin } from '../../../../../shared/models/users/user-login.model' |
@@ -47,7 +47,7 @@ export class AuthService { | |||
47 | 47 | ||
48 | constructor ( | 48 | constructor ( |
49 | private http: HttpClient, | 49 | private http: HttpClient, |
50 | private notificationsService: NotificationsService, | 50 | private notifier: Notifier, |
51 | private hotkeysService: HotkeysService, | 51 | private hotkeysService: HotkeysService, |
52 | private restExtractor: RestExtractor, | 52 | private restExtractor: RestExtractor, |
53 | private router: Router, | 53 | private router: Router, |
@@ -105,9 +105,8 @@ export class AuthService { | |||
105 | ) | 105 | ) |
106 | } | 106 | } |
107 | 107 | ||
108 | // We put a bigger timeout | 108 | // We put a bigger timeout: this is an important message |
109 | // This is an important message | 109 | this.notifier.error(errorMessage, this.i18n('Error'), 7000) |
110 | this.notificationsService.error(this.i18n('Error'), errorMessage, { timeOut: 7000 }) | ||
111 | } | 110 | } |
112 | ) | 111 | ) |
113 | } | 112 | } |
diff --git a/client/src/app/core/auth/index.ts b/client/src/app/core/auth/index.ts index bc7bfec0e..8e5caa7ed 100644 --- a/client/src/app/core/auth/index.ts +++ b/client/src/app/core/auth/index.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | export * from './auth-status.model' | 1 | export * from './auth-status.model' |
2 | export * from './auth-user.model' | 2 | export * from './auth-user.model' |
3 | export * from './auth.service' | 3 | export * from './auth.service' |
4 | export * from '../routing/login-guard.service' | ||
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index 8a6654aa1..7c0d4ac8f 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts | |||
@@ -7,8 +7,6 @@ import { LoadingBarModule } from '@ngx-loading-bar/core' | |||
7 | import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client' | 7 | import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client' |
8 | import { LoadingBarRouterModule } from '@ngx-loading-bar/router' | 8 | import { LoadingBarRouterModule } from '@ngx-loading-bar/router' |
9 | 9 | ||
10 | import { SimpleNotificationsModule } from 'angular2-notifications' | ||
11 | |||
12 | import { AuthService } from './auth' | 10 | import { AuthService } from './auth' |
13 | import { ConfirmComponent, ConfirmService } from './confirm' | 11 | import { ConfirmComponent, ConfirmService } from './confirm' |
14 | import { throwIfAlreadyLoaded } from './module-import-guard' | 12 | import { throwIfAlreadyLoaded } from './module-import-guard' |
@@ -16,7 +14,10 @@ import { LoginGuard, RedirectService, UserRightGuard } from './routing' | |||
16 | import { ServerService } from './server' | 14 | import { ServerService } from './server' |
17 | import { ThemeService } from './theme' | 15 | import { ThemeService } from './theme' |
18 | import { HotkeyModule } from 'angular2-hotkeys' | 16 | import { HotkeyModule } from 'angular2-hotkeys' |
19 | import { CheatSheetComponent } from '@app/core/hotkeys' | 17 | import { CheatSheetComponent } from './hotkeys' |
18 | import { ToastModule } from 'primeng/toast' | ||
19 | import { Notifier } from './notification' | ||
20 | import { MessageService } from 'primeng/api' | ||
20 | 21 | ||
21 | @NgModule({ | 22 | @NgModule({ |
22 | imports: [ | 23 | imports: [ |
@@ -25,11 +26,10 @@ import { CheatSheetComponent } from '@app/core/hotkeys' | |||
25 | FormsModule, | 26 | FormsModule, |
26 | BrowserAnimationsModule, | 27 | BrowserAnimationsModule, |
27 | 28 | ||
28 | SimpleNotificationsModule.forRoot(), | ||
29 | |||
30 | LoadingBarHttpClientModule, | 29 | LoadingBarHttpClientModule, |
31 | LoadingBarRouterModule, | 30 | LoadingBarRouterModule, |
32 | LoadingBarModule, | 31 | LoadingBarModule, |
32 | ToastModule, | ||
33 | 33 | ||
34 | HotkeyModule.forRoot({ | 34 | HotkeyModule.forRoot({ |
35 | cheatSheetCloseEsc: true | 35 | cheatSheetCloseEsc: true |
@@ -42,10 +42,11 @@ import { CheatSheetComponent } from '@app/core/hotkeys' | |||
42 | ], | 42 | ], |
43 | 43 | ||
44 | exports: [ | 44 | exports: [ |
45 | SimpleNotificationsModule, | ||
46 | LoadingBarHttpClientModule, | 45 | LoadingBarHttpClientModule, |
47 | LoadingBarModule, | 46 | LoadingBarModule, |
48 | 47 | ||
48 | ToastModule, | ||
49 | |||
49 | ConfirmComponent, | 50 | ConfirmComponent, |
50 | CheatSheetComponent | 51 | CheatSheetComponent |
51 | ], | 52 | ], |
@@ -57,7 +58,9 @@ import { CheatSheetComponent } from '@app/core/hotkeys' | |||
57 | ThemeService, | 58 | ThemeService, |
58 | LoginGuard, | 59 | LoginGuard, |
59 | UserRightGuard, | 60 | UserRightGuard, |
60 | RedirectService | 61 | RedirectService, |
62 | Notifier, | ||
63 | MessageService | ||
61 | ] | 64 | ] |
62 | }) | 65 | }) |
63 | export class CoreModule { | 66 | export class CoreModule { |
diff --git a/client/src/app/core/index.ts b/client/src/app/core/index.ts index 524589d74..f664aff41 100644 --- a/client/src/app/core/index.ts +++ b/client/src/app/core/index.ts | |||
@@ -2,6 +2,7 @@ export * from './auth' | |||
2 | export * from './confirm' | 2 | export * from './confirm' |
3 | export * from './routing' | 3 | export * from './routing' |
4 | export * from './server' | 4 | export * from './server' |
5 | export * from './notification' | ||
5 | export * from './theme' | 6 | export * from './theme' |
6 | 7 | ||
7 | export * from './core.module' | 8 | export * from './core.module' |
diff --git a/client/src/app/core/notification/index.ts b/client/src/app/core/notification/index.ts new file mode 100644 index 000000000..8b0cfde5f --- /dev/null +++ b/client/src/app/core/notification/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './notifier.service' | |||
diff --git a/client/src/app/core/notification/notifier.service.ts b/client/src/app/core/notification/notifier.service.ts new file mode 100644 index 000000000..9833c65a0 --- /dev/null +++ b/client/src/app/core/notification/notifier.service.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { MessageService } from 'primeng/api' | ||
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
4 | |||
5 | @Injectable() | ||
6 | export class Notifier { | ||
7 | readonly TIMEOUT = 5000 | ||
8 | |||
9 | constructor ( | ||
10 | private i18n: I18n, | ||
11 | private messageService: MessageService) { | ||
12 | } | ||
13 | |||
14 | info (text: string, title?: string, timeout?: number) { | ||
15 | if (!title) title = this.i18n('Info') | ||
16 | |||
17 | return this.notify('info', text, title, timeout) | ||
18 | } | ||
19 | |||
20 | error (text: string, title?: string, timeout?: number) { | ||
21 | if (!title) title = this.i18n('Error') | ||
22 | |||
23 | return this.notify('error', text, title, timeout) | ||
24 | } | ||
25 | |||
26 | success (text: string, title?: string, timeout?: number) { | ||
27 | if (!title) title = this.i18n('Success') | ||
28 | |||
29 | return this.notify('success', text, title, timeout) | ||
30 | } | ||
31 | |||
32 | private notify (severity: 'success' | 'info' | 'warn' | 'error', text: string, title: string, timeout?: number) { | ||
33 | this.messageService.add({ | ||
34 | severity, | ||
35 | summary: title, | ||
36 | detail: text, | ||
37 | closable: true, | ||
38 | life: timeout || this.TIMEOUT | ||
39 | }) | ||
40 | } | ||
41 | } | ||
diff --git a/client/src/app/core/routing/user-right-guard.service.ts b/client/src/app/core/routing/user-right-guard.service.ts index 65d029977..50c3d8c19 100644 --- a/client/src/app/core/routing/user-right-guard.service.ts +++ b/client/src/app/core/routing/user-right-guard.service.ts | |||
@@ -7,7 +7,7 @@ import { | |||
7 | Router | 7 | Router |
8 | } from '@angular/router' | 8 | } from '@angular/router' |
9 | 9 | ||
10 | import { AuthService } from '../auth' | 10 | import { AuthService } from '../auth/auth.service' |
11 | 11 | ||
12 | @Injectable() | 12 | @Injectable() |
13 | export class UserRightGuard implements CanActivate, CanActivateChild { | 13 | export class UserRightGuard implements CanActivate, CanActivateChild { |