mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-03-23 12:05:15 +00:00
Fixes after review
This commit is contained in:
parent
8eafbf66c9
commit
230aaf31fd
@ -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,
|
||||
|
@ -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<number>;
|
||||
viewTimer: Observable<number>;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
export class NotificationSettings {
|
||||
delayTime: number;
|
||||
viewTime: number;
|
||||
breakTime: number;
|
||||
numberOfViews?: number;
|
||||
isEndless: boolean;
|
||||
contentToShow?: string;
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user