From f8b2c1b4f509c037b9650cca2c5befd21f056df3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Dec 2018 16:04:34 +0100 Subject: Refractor notification service Shorter name and use primeng component --- .../app/shared/forms/reactive-file.component.ts | 6 +- .../shared/moderation/user-ban-modal.component.ts | 8 +- .../user-moderation-dropdown.component.ts | 86 +++++++--------------- .../subscribe-button.component.ts | 23 +++--- client/src/app/shared/video/abstract-video-list.ts | 6 +- 5 files changed, 47 insertions(+), 82 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/forms/reactive-file.component.ts b/client/src/app/shared/forms/reactive-file.component.ts index 8d22aa56c..c3986838f 100644 --- a/client/src/app/shared/forms/reactive-file.component.ts +++ b/client/src/app/shared/forms/reactive-file.component.ts @@ -1,6 +1,6 @@ import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core' import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' -import { NotificationsService } from 'angular2-notifications' +import { Notifier } from '@app/core' import { I18n } from '@ngx-translate/i18n-polyfill' @Component({ @@ -30,7 +30,7 @@ export class ReactiveFileComponent implements OnInit, ControlValueAccessor { private file: File constructor ( - private notificationsService: NotificationsService, + private notifier: Notifier, private i18n: I18n ) {} @@ -49,7 +49,7 @@ export class ReactiveFileComponent implements OnInit, ControlValueAccessor { const [ file ] = event.target.files if (file.size > this.maxFileSize) { - this.notificationsService.error(this.i18n('Error'), this.i18n('This file is too large.')) + this.notifier.error(this.i18n('This file is too large.')) return } diff --git a/client/src/app/shared/moderation/user-ban-modal.component.ts b/client/src/app/shared/moderation/user-ban-modal.component.ts index 60bd442dd..f755ba0e8 100644 --- a/client/src/app/shared/moderation/user-ban-modal.component.ts +++ b/client/src/app/shared/moderation/user-ban-modal.component.ts @@ -1,5 +1,5 @@ import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' -import { NotificationsService } from 'angular2-notifications' +import { Notifier } from '@app/core' import { I18n } from '@ngx-translate/i18n-polyfill' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' @@ -23,7 +23,7 @@ export class UserBanModalComponent extends FormReactive implements OnInit { constructor ( protected formValidatorService: FormValidatorService, private modalService: NgbModal, - private notificationsService: NotificationsService, + private notifier: Notifier, private userService: UserService, private userValidatorsService: UserValidatorsService, private i18n: I18n @@ -57,13 +57,13 @@ export class UserBanModalComponent extends FormReactive implements OnInit { ? this.i18n('{{num}} users banned.', { num: this.usersToBan.length }) : this.i18n('User {{username}} banned.', { username: this.usersToBan.username }) - this.notificationsService.success(this.i18n('Success'), message) + this.notifier.success(message) this.userBanned.emit(this.usersToBan) this.hideBanUserModal() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } diff --git a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts index e3c9db923..9a2461ebf 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts @@ -1,10 +1,9 @@ import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core' -import { NotificationsService } from 'angular2-notifications' import { I18n } from '@ngx-translate/i18n-polyfill' import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component' import { UserService } from '@app/shared/users' -import { AuthService, ConfirmService, ServerService } from '@app/core' +import { AuthService, ConfirmService, Notifier, ServerService } from '@app/core' import { User, UserRight } from '../../../../../shared/models/users' import { Account } from '@app/shared/account/account.model' import { BlocklistService } from '@app/shared/blocklist' @@ -30,7 +29,7 @@ export class UserModerationDropdownComponent implements OnChanges { constructor ( private authService: AuthService, - private notificationsService: NotificationsService, + private notifier: Notifier, private confirmService: ConfirmService, private serverService: ServerService, private userService: UserService, @@ -48,7 +47,7 @@ export class UserModerationDropdownComponent implements OnChanges { openBanUserModal (user: User) { if (user.username === 'root') { - this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot ban root.')) + this.notifier.error(this.i18n('You cannot ban root.')) return } @@ -67,21 +66,18 @@ export class UserModerationDropdownComponent implements OnChanges { this.userService.unbanUsers(user) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('User {{username}} unbanned.', { username: user.username }) - ) + this.notifier.success(this.i18n('User {{username}} unbanned.', { username: user.username })) this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } async removeUser (user: User) { if (user.username === 'root') { - this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot delete root.')) + this.notifier.error(this.i18n('You cannot delete root.')) return } @@ -91,29 +87,23 @@ export class UserModerationDropdownComponent implements OnChanges { this.userService.removeUser(user).subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('User {{username}} deleted.', { username: user.username }) - ) + this.notifier.success(this.i18n('User {{username}} deleted.', { username: user.username })) this.userDeleted.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } setEmailAsVerified (user: User) { this.userService.updateUser(user.id, { emailVerified: true }).subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('User {{username}} email set as verified', { username: user.username }) - ) + this.notifier.success(this.i18n('User {{username}} email set as verified', { username: user.username })) this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -121,16 +111,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.blockAccountByUser(account) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost }) - ) + this.notifier.success(this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost })) this.account.mutedByUser = true this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -138,16 +125,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.unblockAccountByUser(account) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost }) - ) + this.notifier.success(this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost })) this.account.mutedByUser = false this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -155,16 +139,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.blockServerByUser(host) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Instance {{host}} muted.', { host }) - ) + this.notifier.success(this.i18n('Instance {{host}} muted.', { host })) this.account.mutedServerByUser = true this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -172,16 +153,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.unblockServerByUser(host) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Instance {{host}} unmuted.', { host }) - ) + this.notifier.success(this.i18n('Instance {{host}} unmuted.', { host })) this.account.mutedServerByUser = false this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -189,16 +167,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.blockAccountByInstance(account) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost }) - ) + this.notifier.success(this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost })) this.account.mutedByInstance = true this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -206,16 +181,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.unblockAccountByInstance(account) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Account {{nameWithHost}} unmuted by the instance.', { nameWithHost: account.nameWithHost }) - ) + this.notifier.success(this.i18n('Account {{nameWithHost}} unmuted by the instance.', { nameWithHost: account.nameWithHost })) this.account.mutedByInstance = false this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -223,16 +195,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.blockServerByInstance(host) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Instance {{host}} muted by the instance.', { host }) - ) + this.notifier.success(this.i18n('Instance {{host}} muted by the instance.', { host })) this.account.mutedServerByInstance = true this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -240,16 +209,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.unblockServerByInstance(host) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Instance {{host}} unmuted by the instance.', { host }) - ) + this.notifier.success(this.i18n('Instance {{host}} unmuted by the instance.', { host })) this.account.mutedServerByInstance = false this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } diff --git a/client/src/app/shared/user-subscription/subscribe-button.component.ts b/client/src/app/shared/user-subscription/subscribe-button.component.ts index 9c8a15023..8f1754c7f 100644 --- a/client/src/app/shared/user-subscription/subscribe-button.component.ts +++ b/client/src/app/shared/user-subscription/subscribe-button.component.ts @@ -1,9 +1,8 @@ import { Component, Input, OnInit } from '@angular/core' import { Router } from '@angular/router' -import { AuthService } from '@app/core' +import { AuthService, Notifier } from '@app/core' import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service' import { VideoChannel } from '@app/shared/video-channel/video-channel.model' -import { NotificationsService } from 'angular2-notifications' import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoService } from '@app/shared/video/video.service' import { FeedFormat } from '../../../../../shared/models/feeds' @@ -23,7 +22,7 @@ export class SubscribeButtonComponent implements OnInit { constructor ( private authService: AuthService, private router: Router, - private notificationsService: NotificationsService, + private notifier: Notifier, private userSubscriptionService: UserSubscriptionService, private i18n: I18n, private videoService: VideoService @@ -43,7 +42,7 @@ export class SubscribeButtonComponent implements OnInit { .subscribe( res => this.subscribed = res[this.uri], - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } } @@ -62,13 +61,13 @@ export class SubscribeButtonComponent implements OnInit { () => { this.subscribed = true - this.notificationsService.success( - this.i18n('Subscribed'), - this.i18n('Subscribed to {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }) + this.notifier.success( + this.i18n('Subscribed to {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }), + this.i18n('Subscribed') ) }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -84,13 +83,13 @@ export class SubscribeButtonComponent implements OnInit { () => { this.subscribed = false - this.notificationsService.success( - this.i18n('Unsubscribed'), - this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }) + this.notifier.success( + this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }), + this.i18n('Unsubscribed') ) }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index 2d32dd6ad..d234c8bfa 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts @@ -3,7 +3,6 @@ import { ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { Location } from '@angular/common' import { InfiniteScrollerDirective } from '@app/shared/video/infinite-scroller.directive' -import { NotificationsService } from 'angular2-notifications' import { fromEvent, Observable, Subscription } from 'rxjs' import { AuthService } from '../../core/auth' import { ComponentPagination } from '../rest/component-pagination.model' @@ -13,6 +12,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill' import { ScreenService } from '@app/shared/misc/screen.service' import { OwnerDisplayType } from '@app/shared/video/video-miniature.component' import { Syndication } from '@app/shared/video/syndication.model' +import { Notifier } from '@app/core' export abstract class AbstractVideoList implements OnInit, OnDestroy { private static LINES_PER_PAGE = 4 @@ -43,7 +43,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { protected baseVideoWidth = 215 protected baseVideoHeight = 205 - protected abstract notificationsService: NotificationsService + protected abstract notifier: Notifier protected abstract authService: AuthService protected abstract router: Router protected abstract route: ActivatedRoute @@ -157,7 +157,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { }, error => { this.loadingPage[page] = false - this.notificationsService.error(this.i18n('Error'), error.message) + this.notifier.error(error.message) } ) } -- cgit v1.2.3