From 230aaf31fdb14843ead6b14bcf4cfc5f57422aa6 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Wed, 5 Jun 2019 01:56:28 -0700 Subject: [PATCH] Fixes after review --- src/app/app.module.ts | 4 +- .../notification-box.component.ts | 37 ++++++++++--------- .../notification-settings.ts | 8 ---- .../services/notification-settings.service.ts | 20 ---------- 4 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 src/app/models/notification-settings-models/notification-settings.ts delete mode 100644 src/app/services/notification-settings.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index fa9786aa..8cbff37e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -185,7 +185,6 @@ import { ConsoleService } from './services/settings/console.service'; import { DefaultConsoleService } from './services/settings/default-console.service'; import { NodeCreatedLabelStylesFixer } from './components/project-map/helpers/node-created-label-styles-fixer'; import { NotificationBoxComponent } from './components/notification-box/notification-box.component'; -import { NotificationSettingsService } from './services/notification-settings.service'; if (environment.production) { Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', { @@ -377,8 +376,7 @@ if (environment.production) { ServerManagementService, ConsoleService, DefaultConsoleService, - NodeCreatedLabelStylesFixer, - NotificationSettingsService + NodeCreatedLabelStylesFixer ], entryComponents: [ AddServerDialogComponent, diff --git a/src/app/components/notification-box/notification-box.component.ts b/src/app/components/notification-box/notification-box.component.ts index c3790195..5f466442 100644 --- a/src/app/components/notification-box/notification-box.component.ts +++ b/src/app/components/notification-box/notification-box.component.ts @@ -1,8 +1,5 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; -import { timer, interval, Observable, Subscription } from 'rxjs'; -import { take } from 'rxjs/operators'; -import { NotificationSettingsService } from '../../services/notification-settings.service'; -import { NotificationSettings } from '../../models/notification-settings-models/notification-settings'; +import { timer, Observable, Subscription } from 'rxjs'; @Component({ selector: 'app-notification-box', @@ -10,36 +7,38 @@ import { NotificationSettings } from '../../models/notification-settings-models/ styleUrls: ['./notification-box.component.scss'] }) export class NotificationBoxComponent implements OnInit, OnDestroy { - notificationSettings: NotificationSettings; timer: Observable; + viewTimer: Observable; timerSubscription: Subscription; - intervalSubscription: Subscription; + viewTimerSubscription: Subscription; viewsCounter = 0; ticks: number = 1000; progress: number = 0; isVisible = false; interval = 10; - constructor( - private notifactionSettingsService: NotificationSettingsService - ){} + delayTime: number = 0; + breakTime: number = 1000; + isEndless: boolean = true; + numberOfViews: number = 1; + + constructor(){} ngOnInit() { - this.notificationSettings = this.notifactionSettingsService.getConfiguration(); this.startTimer(); } startTimer() { - this.timer = timer(this.notificationSettings.delayTime, 1000); + this.timer = timer(this.delayTime, 1000); this.timerSubscription = this.timer.subscribe(() => { this.ticks++; - if (this.ticks > this.notificationSettings.breakTime && navigator.onLine) { + if (this.ticks > this.breakTime && !this.isVisible && navigator.onLine) { this.ticks = 0; this.showNotification(); this.viewsCounter++; - if (!this.notificationSettings.isEndless){ - if (this.viewsCounter === this.notificationSettings.numberOfViews) { + if (!this.isEndless){ + if (this.viewsCounter === this.numberOfViews) { this.timerSubscription.unsubscribe(); } } @@ -48,14 +47,15 @@ export class NotificationBoxComponent implements OnInit, OnDestroy { } showNotification() { + this.viewTimer = timer(0, 100); this.isVisible = true; this.progress = 0; - this.intervalSubscription = interval(this.interval).pipe(take(this.notificationSettings.viewTime)).subscribe(() => { - this.progress += (1/this.interval); - if (this.progress > ((this.notificationSettings.viewTime/this.interval)-(1/this.interval))) { + this.viewTimerSubscription = this.viewTimer.subscribe(() => { + this.progress += 1; + if (this.progress > 100) { this.isVisible = false; - this.intervalSubscription.unsubscribe(); + this.viewTimerSubscription.unsubscribe(); } }); } @@ -66,5 +66,6 @@ export class NotificationBoxComponent implements OnInit, OnDestroy { ngOnDestroy() { this.timerSubscription.unsubscribe(); + this.viewTimerSubscription.unsubscribe(); } } diff --git a/src/app/models/notification-settings-models/notification-settings.ts b/src/app/models/notification-settings-models/notification-settings.ts deleted file mode 100644 index 8c399e79..00000000 --- a/src/app/models/notification-settings-models/notification-settings.ts +++ /dev/null @@ -1,8 +0,0 @@ -export class NotificationSettings { - delayTime: number; - viewTime: number; - breakTime: number; - numberOfViews?: number; - isEndless: boolean; - contentToShow?: string; -} diff --git a/src/app/services/notification-settings.service.ts b/src/app/services/notification-settings.service.ts deleted file mode 100644 index 5e42a20d..00000000 --- a/src/app/services/notification-settings.service.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Injectable } from '@angular/core'; -import { NotificationSettings } from '../models/notification-settings-models/notification-settings'; - -@Injectable() -export class NotificationSettingsService { - - constructor() {} - - getConfiguration(): NotificationSettings { - let configuration: NotificationSettings = { - delayTime: 0, - viewTime: 1000, - breakTime: 1000, - isEndless: true, - numberOfViews: 1, - }; - - return configuration; - } -}