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 --- .../comment/video-comment-add.component.ts | 6 ++--- .../comment/video-comments.component.ts | 13 +++++---- .../modal/video-blacklist.component.ts | 9 +++---- .../+video-watch/modal/video-download.component.ts | 6 ++--- .../+video-watch/modal/video-report.component.ts | 8 +++--- .../+video-watch/modal/video-share.component.ts | 6 ++--- .../videos/+video-watch/video-watch.component.ts | 31 +++++++++------------- 7 files changed, 35 insertions(+), 44 deletions(-) (limited to 'client/src/app/videos/+video-watch') diff --git a/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts index 7f582c950..6b7e62042 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment-add.component.ts @@ -1,6 +1,6 @@ import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' import { Router } from '@angular/router' -import { NotificationsService } from 'angular2-notifications' +import { Notifier } from '@app/core' import { Observable } from 'rxjs' import { VideoCommentCreate } from '../../../../../../shared/models/videos/video-comment.model' import { FormReactive } from '../../../shared' @@ -36,7 +36,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit { constructor ( protected formValidatorService: FormValidatorService, private videoCommentValidatorsService: VideoCommentValidatorsService, - private notificationsService: NotificationsService, + private notifier: Notifier, private videoCommentService: VideoCommentService, private authService: AuthService, private modalService: NgbModal, @@ -115,7 +115,7 @@ export class VideoCommentAddComponent extends FormReactive implements OnInit { err => { this.addingComment = false - this.notificationsService.error(this.i18n('Error'), err.text) + this.notifier.error(err.text) } ) } diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.ts b/client/src/app/videos/+video-watch/comment/video-comments.component.ts index 8850eccd8..957c17bbf 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.ts @@ -1,7 +1,6 @@ -import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ElementRef } from '@angular/core' +import { Component, ElementRef, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild } from '@angular/core' import { ActivatedRoute } from '@angular/router' -import { ConfirmService } from '@app/core' -import { NotificationsService } from 'angular2-notifications' +import { ConfirmService, Notifier } from '@app/core' import { Subscription } from 'rxjs' import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' import { AuthService } from '../../../core/auth' @@ -42,7 +41,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { constructor ( private authService: AuthService, - private notificationsService: NotificationsService, + private notifier: Notifier, private confirmService: ConfirmService, private videoCommentService: VideoCommentService, private activatedRoute: ActivatedRoute, @@ -92,7 +91,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { } }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -104,7 +103,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { this.componentPagination.totalItems = res.totalComments }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -155,7 +154,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { if (this.highlightedThread.id === commentToDelete.id) this.highlightedThread = undefined }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } diff --git a/client/src/app/videos/+video-watch/modal/video-blacklist.component.ts b/client/src/app/videos/+video-watch/modal/video-blacklist.component.ts index 2c123ebed..357ce39ce 100644 --- a/client/src/app/videos/+video-watch/modal/video-blacklist.component.ts +++ b/client/src/app/videos/+video-watch/modal/video-blacklist.component.ts @@ -1,12 +1,11 @@ import { Component, Input, OnInit, ViewChild } from '@angular/core' -import { NotificationsService } from 'angular2-notifications' +import { Notifier, RedirectService } from '@app/core' import { FormReactive, VideoBlacklistService, VideoBlacklistValidatorsService } from '../../../shared/index' import { VideoDetails } from '../../../shared/video/video-details.model' import { I18n } from '@ngx-translate/i18n-polyfill' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' -import { RedirectService } from '@app/core' @Component({ selector: 'my-video-blacklist', @@ -27,7 +26,7 @@ export class VideoBlacklistComponent extends FormReactive implements OnInit { private modalService: NgbModal, private videoBlacklistValidatorsService: VideoBlacklistValidatorsService, private videoBlacklistService: VideoBlacklistService, - private notificationsService: NotificationsService, + private notifier: Notifier, private redirectService: RedirectService, private i18n: I18n ) { @@ -55,12 +54,12 @@ export class VideoBlacklistComponent extends FormReactive implements OnInit { this.videoBlacklistService.blacklistVideo(this.video.id, reason) .subscribe( () => { - this.notificationsService.success(this.i18n('Success'), this.i18n('Video blacklisted.')) + this.notifier.success(this.i18n('Video blacklisted.')) this.hide() this.redirectService.redirectToHomepage() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } } diff --git a/client/src/app/videos/+video-watch/modal/video-download.component.ts b/client/src/app/videos/+video-watch/modal/video-download.component.ts index b1b2c0623..834385771 100644 --- a/client/src/app/videos/+video-watch/modal/video-download.component.ts +++ b/client/src/app/videos/+video-watch/modal/video-download.component.ts @@ -2,7 +2,7 @@ import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core' import { VideoDetails } from '../../../shared/video/video-details.model' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { I18n } from '@ngx-translate/i18n-polyfill' -import { NotificationsService } from 'angular2-notifications' +import { Notifier } from '@app/core' @Component({ selector: 'my-video-download', @@ -18,7 +18,7 @@ export class VideoDownloadComponent implements OnInit { resolutionId: number | string = -1 constructor ( - private notificationsService: NotificationsService, + private notifier: Notifier, private modalService: NgbModal, private i18n: I18n ) { } @@ -63,6 +63,6 @@ export class VideoDownloadComponent implements OnInit { } activateCopiedMessage () { - this.notificationsService.success(this.i18n('Success'), this.i18n('Copied')) + this.notifier.success(this.i18n('Copied')) } } diff --git a/client/src/app/videos/+video-watch/modal/video-report.component.ts b/client/src/app/videos/+video-watch/modal/video-report.component.ts index 023387984..911f3b447 100644 --- a/client/src/app/videos/+video-watch/modal/video-report.component.ts +++ b/client/src/app/videos/+video-watch/modal/video-report.component.ts @@ -1,5 +1,5 @@ import { Component, Input, OnInit, ViewChild } from '@angular/core' -import { NotificationsService } from 'angular2-notifications' +import { Notifier } from '@app/core' import { FormReactive, VideoAbuseService } from '../../../shared/index' import { VideoDetails } from '../../../shared/video/video-details.model' import { I18n } from '@ngx-translate/i18n-polyfill' @@ -27,7 +27,7 @@ export class VideoReportComponent extends FormReactive implements OnInit { private modalService: NgbModal, private videoAbuseValidatorsService: VideoAbuseValidatorsService, private videoAbuseService: VideoAbuseService, - private notificationsService: NotificationsService, + private notifier: Notifier, private i18n: I18n ) { super() @@ -66,11 +66,11 @@ export class VideoReportComponent extends FormReactive implements OnInit { this.videoAbuseService.reportVideo(this.video.id, reason) .subscribe( () => { - this.notificationsService.success(this.i18n('Success'), this.i18n('Video reported.')) + this.notifier.success(this.i18n('Video reported.')) this.hide() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } diff --git a/client/src/app/videos/+video-watch/modal/video-share.component.ts b/client/src/app/videos/+video-watch/modal/video-share.component.ts index 17e2b31e1..c6205e355 100644 --- a/client/src/app/videos/+video-watch/modal/video-share.component.ts +++ b/client/src/app/videos/+video-watch/modal/video-share.component.ts @@ -1,5 +1,5 @@ import { Component, ElementRef, Input, ViewChild } from '@angular/core' -import { NotificationsService } from 'angular2-notifications' +import { Notifier } from '@app/core' import { VideoDetails } from '../../../shared/video/video-details.model' import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils' import { I18n } from '@ngx-translate/i18n-polyfill' @@ -23,7 +23,7 @@ export class VideoShareComponent { constructor ( private modalService: NgbModal, - private notificationsService: NotificationsService, + private notifier: Notifier, private i18n: I18n ) { } @@ -49,7 +49,7 @@ export class VideoShareComponent { } activateCopiedMessage () { - this.notificationsService.success(this.i18n('Success'), this.i18n('Copied')) + this.notifier.success(this.i18n('Copied')) } getStartCheckboxLabel () { diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts index ef0f685c6..7765c4660 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -5,7 +5,7 @@ import { RedirectService } from '@app/core/routing/redirect.service' import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component' import { MetaService } from '@ngx-meta/core' -import { NotificationsService } from 'angular2-notifications' +import { Notifier, ServerService } from '@app/core' import { forkJoin, Subscription } from 'rxjs' // FIXME: something weird with our path definition in tsconfig and typings // @ts-ignore @@ -13,7 +13,7 @@ import videojs from 'video.js' import 'videojs-hotkeys' import { Hotkey, HotkeysService } from 'angular2-hotkeys' import * as WebTorrent from 'webtorrent' -import { UserVideoRateType, VideoCaption, VideoPrivacy, VideoRateType, VideoState } from '../../../../../shared' +import { UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '../../../../../shared' import '../../../assets/player/peertube-videojs-plugin' import { AuthService, ConfirmService } from '../../core' import { RestExtractor, VideoBlacklistService } from '../../shared' @@ -26,7 +26,6 @@ import { VideoShareComponent } from './modal/video-share.component' import { VideoBlacklistComponent } from './modal/video-blacklist.component' import { SubscribeButtonComponent } from '@app/shared/user-subscription/subscribe-button.component' import { addContextMenu, getVideojsOptions, loadLocaleInVideoJS } from '../../../assets/player/peertube-player' -import { ServerService } from '@app/core' import { I18n } from '@ngx-translate/i18n-polyfill' import { environment } from '../../../environments/environment' import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' @@ -77,7 +76,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { private authService: AuthService, private serverService: ServerService, private restExtractor: RestExtractor, - private notificationsService: NotificationsService, + private notifier: Notifier, private markdownService: MarkdownService, private zone: NgZone, private redirectService: RedirectService, @@ -205,7 +204,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { error => { this.descriptionLoading = false - this.notificationsService.error(this.i18n('Error'), error.message) + this.notifier.error(error.message) } ) } @@ -247,16 +246,13 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.videoBlacklistService.removeVideoFromBlacklist(this.video.id).subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Video {{name}} removed from the blacklist.', { name: this.video.name }) - ) + this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: this.video.name })) this.video.blacklisted = false this.video.blacklistedReason = null }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -294,17 +290,14 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.videoService.removeVideo(this.video.id) .subscribe( - status => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Video {{videoName}} deleted.', { videoName: this.video.name }) - ) + () => { + this.notifier.success(this.i18n('Video {{videoName}} deleted.', { videoName: this.video.name })) // Go back to the video-list. this.redirectService.redirectToHomepage() }, - error => this.notificationsService.error(this.i18n('Error'), error.message) + error => this.notifier.error(error.message) ) } @@ -354,7 +347,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { return } - this.notificationsService.error(this.i18n('Error'), errorMessage) + this.notifier.error(errorMessage) } private checkUserRating () { @@ -369,7 +362,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { } }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -475,7 +468,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.userRating = nextRating }, - (err: { message: string }) => this.notificationsService.error(this.i18n('Error'), err.message) + (err: { message: string }) => this.notifier.error(err.message) ) } -- cgit v1.2.3