X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Fpybind%2Fmgr%2Fdashboard%2Ffrontend%2Fsrc%2Fapp%2Fshared%2Fcomponents%2Fnotifications-sidebar%2Fnotifications-sidebar.component.ts;h=0fdde25b6dc88f60e7db6c837157b05c11756541;hb=1911f103e16ae0d04db10fb41db8217ef4c320d3;hp=6af8bc04ac6cfbc195903c575b4779e9351604be;hpb=78f773100ed5d2ebc9d99e65a3d7e3a6f541a97e;p=ceph.git diff --git a/ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts b/ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts index 6af8bc04a..0fdde25b6 100644 --- a/ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts +++ b/ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts @@ -13,16 +13,16 @@ import * as _ from 'lodash'; import * as moment from 'moment'; import { Subscription } from 'rxjs'; -import { ExecutingTask } from '../../../shared/models/executing-task'; -import { SummaryService } from '../../../shared/services/summary.service'; -import { TaskMessageService } from '../../../shared/services/task-message.service'; import { Icons } from '../../enum/icons.enum'; import { CdNotification } from '../../models/cd-notification'; +import { ExecutingTask } from '../../models/executing-task'; import { FinishedTask } from '../../models/finished-task'; import { AuthStorageService } from '../../services/auth-storage.service'; import { NotificationService } from '../../services/notification.service'; import { PrometheusAlertService } from '../../services/prometheus-alert.service'; import { PrometheusNotificationService } from '../../services/prometheus-notification.service'; +import { SummaryService } from '../../services/summary.service'; +import { TaskMessageService } from '../../services/task-message.service'; @Component({ selector: 'cd-notifications-sidebar', @@ -39,8 +39,7 @@ export class NotificationsSidebarComponent implements OnInit, OnDestroy { executingTasks: ExecutingTask[] = []; - private sidebarSubscription: Subscription; - private notificationDataSubscription: Subscription; + private subs = new Subscription(); icons = Icons; @@ -68,12 +67,7 @@ export class NotificationsSidebarComponent implements OnInit, OnDestroy { ngOnDestroy() { window.clearInterval(this.interval); window.clearTimeout(this.timeout); - if (this.sidebarSubscription) { - this.sidebarSubscription.unsubscribe(); - } - if (this.notificationDataSubscription) { - this.notificationDataSubscription.unsubscribe(); - } + this.subs.unsubscribe(); } ngOnInit() { @@ -91,55 +85,59 @@ export class NotificationsSidebarComponent implements OnInit, OnDestroy { }); } - this.notificationDataSubscription = this.notificationService.data$.subscribe( - (notifications: CdNotification[]) => { + this.subs.add( + this.notificationService.data$.subscribe((notifications: CdNotification[]) => { this.notifications = _.orderBy(notifications, ['timestamp'], ['desc']); this.cdRef.detectChanges(); - } + }) ); - this.sidebarSubscription = this.notificationService.sidebarSubject.subscribe((forceClose) => { - if (forceClose) { - this.isSidebarOpened = false; - } else { - this.isSidebarOpened = !this.isSidebarOpened; - } + this.subs.add( + this.notificationService.sidebarSubject.subscribe((forceClose) => { + if (forceClose) { + this.isSidebarOpened = false; + } else { + this.isSidebarOpened = !this.isSidebarOpened; + } + + window.clearTimeout(this.timeout); + this.timeout = window.setTimeout(() => { + this.cdRef.detectChanges(); + }, 0); + }) + ); - window.clearTimeout(this.timeout); - this.timeout = window.setTimeout(() => { - this.cdRef.detectChanges(); - }, 0); - }); - - this.summaryService.subscribe((data: any) => { - if (!data) { - return; - } - this._handleTasks(data.executing_tasks); - - this.mutex.acquire().then((release) => { - _.filter( - data.finished_tasks, - (task: FinishedTask) => !this.last_task || moment(task.end_time).isAfter(this.last_task) - ).forEach((task) => { - const config = this.notificationService.finishedTaskToNotification(task, task.success); - const notification = new CdNotification(config); - notification.timestamp = task.end_time; - notification.duration = task.duration; - - if (!this.last_task || moment(task.end_time).isAfter(this.last_task)) { - this.last_task = task.end_time; - window.localStorage.setItem('last_task', this.last_task); - } - - this.notificationService.save(notification); - }); + this.subs.add( + this.summaryService.subscribe((data: any) => { + if (!data) { + return; + } + this._handleTasks(data.executing_tasks); + + this.mutex.acquire().then((release) => { + _.filter( + data.finished_tasks, + (task: FinishedTask) => !this.last_task || moment(task.end_time).isAfter(this.last_task) + ).forEach((task) => { + const config = this.notificationService.finishedTaskToNotification(task, task.success); + const notification = new CdNotification(config); + notification.timestamp = task.end_time; + notification.duration = task.duration; + + if (!this.last_task || moment(task.end_time).isAfter(this.last_task)) { + this.last_task = task.end_time; + window.localStorage.setItem('last_task', this.last_task); + } + + this.notificationService.save(notification); + }); - this.cdRef.detectChanges(); + this.cdRef.detectChanges(); - release(); - }); - }); + release(); + }); + }) + ); } _handleTasks(executingTasks: ExecutingTask[]) {