From 7f804e3fab41dda846d606a206433ecb7ab07e2a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stephan=20M=C3=BCller?= Date: Wed, 8 Aug 2018 13:19:27 +0200 Subject: [PATCH] mgr/dashboard: Rename to taskMessageService MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Renames taskManagerMessageService to taskMessageService. Signed-off-by: Stephan Müller --- .../task-manager/task-manager.component.ts | 12 ++--- .../services/notification.service.spec.ts | 4 +- .../shared/services/notification.service.ts | 16 ++---- ...e.spec.ts => task-message.service.spec.ts} | 6 +-- ...age.service.ts => task-message.service.ts} | 50 +++++++------------ .../shared/services/task-wrapper.service.ts | 7 ++- 6 files changed, 38 insertions(+), 57 deletions(-) rename src/pybind/mgr/dashboard/frontend/src/app/shared/services/{task-manager-message.service.spec.ts => task-message.service.spec.ts} (96%) rename src/pybind/mgr/dashboard/frontend/src/app/shared/services/{task-manager-message.service.ts => task-message.service.ts} (78%) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.ts index 4e17c704a1f4..3eb58985ee67 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.ts @@ -3,7 +3,7 @@ import { Component, OnInit } from '@angular/core'; import { ExecutingTask } from '../../../shared/models/executing-task'; import { FinishedTask } from '../../../shared/models/finished-task'; import { SummaryService } from '../../../shared/services/summary.service'; -import { TaskManagerMessageService } from '../../../shared/services/task-manager-message.service'; +import { TaskMessageService } from '../../../shared/services/task-message.service'; @Component({ selector: 'cd-task-manager', @@ -18,7 +18,7 @@ export class TaskManagerComponent implements OnInit { constructor( private summaryService: SummaryService, - private taskMessageManager: TaskManagerMessageService + private taskMessageService: TaskMessageService ) {} ngOnInit() { @@ -33,14 +33,14 @@ export class TaskManagerComponent implements OnInit { _handleTasks(executingTasks: ExecutingTask[], finishedTasks: FinishedTask[]) { for (const excutingTask of executingTasks) { - excutingTask.description = this.taskMessageManager.getRunningTitle(excutingTask); + excutingTask.description = this.taskMessageService.getRunningTitle(excutingTask); } for (const finishedTask of finishedTasks) { if (finishedTask.success === false) { - finishedTask.description = this.taskMessageManager.getErrorTitle(finishedTask); - finishedTask.errorMessage = this.taskMessageManager.getErrorMessage(finishedTask); + finishedTask.description = this.taskMessageService.getErrorTitle(finishedTask); + finishedTask.errorMessage = this.taskMessageService.getErrorMessage(finishedTask); } else { - finishedTask.description = this.taskMessageManager.getSuccessTitle(finishedTask); + finishedTask.description = this.taskMessageService.getSuccessTitle(finishedTask); } } this.executingTasks = executingTasks; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts index 763a086b71ef..204a9e1c5379 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.spec.ts @@ -7,7 +7,7 @@ import { configureTestBed } from '../../../testing/unit-test-helper'; import { NotificationType } from '../enum/notification-type.enum'; import { FinishedTask } from '../models/finished-task'; import { NotificationService } from './notification.service'; -import { TaskManagerMessageService } from './task-manager-message.service'; +import { TaskMessageService } from './task-message.service'; describe('NotificationService', () => { let notificationService: NotificationService; @@ -20,7 +20,7 @@ describe('NotificationService', () => { configureTestBed({ providers: [ NotificationService, - TaskManagerMessageService, + TaskMessageService, { provide: ToastsManager, useValue: toastFakeService } ] }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.ts index f736a1e41905..9c03095ac119 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/notification.service.ts @@ -8,7 +8,7 @@ import { NotificationType } from '../enum/notification-type.enum'; import { CdNotification } from '../models/cd-notification'; import { FinishedTask } from '../models/finished-task'; import { ServicesModule } from './services.module'; -import { TaskManagerMessageService } from './task-manager-message.service'; +import { TaskMessageService } from './task-message.service'; @Injectable({ providedIn: ServicesModule @@ -22,10 +22,7 @@ export class NotificationService { KEY = 'cdNotifications'; - constructor( - public toastr: ToastsManager, - private taskManagerMessageService: TaskManagerMessageService - ) { + constructor(public toastr: ToastsManager, private taskMessageService: TaskMessageService) { const stringNotifications = localStorage.getItem(this.KEY); let notifications: CdNotification[] = []; @@ -97,15 +94,12 @@ export class NotificationService { notifyTask(finishedTask: FinishedTask, success: boolean = true) { if (finishedTask.success && success) { - this.show( - NotificationType.success, - this.taskManagerMessageService.getSuccessTitle(finishedTask) - ); + this.show(NotificationType.success, this.taskMessageService.getSuccessTitle(finishedTask)); } else { this.show( NotificationType.error, - this.taskManagerMessageService.getErrorTitle(finishedTask), - this.taskManagerMessageService.getErrorMessage(finishedTask) + this.taskMessageService.getErrorTitle(finishedTask), + this.taskMessageService.getErrorMessage(finishedTask) ); } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.spec.ts similarity index 96% rename from src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.spec.ts rename to src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.spec.ts index aeb36234077a..af4fb6681ff9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.spec.ts @@ -2,14 +2,14 @@ import * as _ from 'lodash'; import { FinishedTask } from '../models/finished-task'; import { TaskException } from '../models/task-exception'; -import { TaskManagerMessageService, TaskMessageOperation } from './task-manager-message.service'; +import { TaskMessageOperation, TaskMessageService } from './task-message.service'; describe('TaskManagerMessageService', () => { - let service: TaskManagerMessageService; + let service: TaskMessageService; let finishedTask: FinishedTask; beforeEach(() => { - service = new TaskManagerMessageService(); + service = new TaskMessageService(); finishedTask = new FinishedTask(); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts similarity index 78% rename from src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.ts rename to src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts index f8210fb9eb82..444f274cc78c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager-message.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-message.service.ts @@ -17,7 +17,7 @@ export class TaskMessageOperation { } } -class TaskManagerMessage { +class TaskMessage { operation: TaskMessageOperation; involves: (object) => string; errors: (metadata) => object; @@ -48,8 +48,8 @@ class TaskManagerMessage { @Injectable({ providedIn: ServicesModule }) -export class TaskManagerMessageService { - defaultMessage = new TaskManagerMessage( +export class TaskMessageService { + defaultMessage = new TaskMessage( new TaskMessageOperation('Executing', 'execute', 'Executed'), (metadata) => { return (metadata && (Components[metadata.component] || metadata.component)) || 'unknown task'; @@ -74,28 +74,16 @@ export class TaskManagerMessageService { }; messages = { - 'rbd/create': new TaskManagerMessage( - this.commonOperations.create, - this.rbd.default, - (metadata) => ({ - '17': `Name is already used by ${this.rbd.default(metadata)}.` - }) - ), - 'rbd/edit': new TaskManagerMessage( - this.commonOperations.update, - this.rbd.default, - (metadata) => ({ - '17': `Name is already used by ${this.rbd.default(metadata)}.` - }) - ), - 'rbd/delete': new TaskManagerMessage( - this.commonOperations.delete, - this.rbd.default, - (metadata) => ({ - '39': `${this.rbd.default(metadata)} contains snapshots.` - }) - ), - 'rbd/clone': new TaskManagerMessage( + 'rbd/create': new TaskMessage(this.commonOperations.create, this.rbd.default, (metadata) => ({ + '17': `Name is already used by ${this.rbd.default(metadata)}.` + })), + 'rbd/edit': new TaskMessage(this.commonOperations.update, this.rbd.default, (metadata) => ({ + '17': `Name is already used by ${this.rbd.default(metadata)}.` + })), + 'rbd/delete': new TaskMessage(this.commonOperations.delete, this.rbd.default, (metadata) => ({ + '39': `${this.rbd.default(metadata)} contains snapshots.` + })), + 'rbd/clone': new TaskMessage( new TaskMessageOperation('Cloning', 'clone', 'Cloned'), this.rbd.child, (metadata) => ({ @@ -103,39 +91,39 @@ export class TaskManagerMessageService { '22': `Snapshot of ${this.rbd.child(metadata)} must be protected.` }) ), - 'rbd/copy': new TaskManagerMessage( + 'rbd/copy': new TaskMessage( new TaskMessageOperation('Copying', 'copy', 'Copied'), this.rbd.destination, (metadata) => ({ '17': `Name is already used by ${this.rbd.destination(metadata)}.` }) ), - 'rbd/flatten': new TaskManagerMessage( + 'rbd/flatten': new TaskMessage( new TaskMessageOperation('Flattening', 'flatten', 'Flattened'), this.rbd.default ), - 'rbd/snap/create': new TaskManagerMessage( + 'rbd/snap/create': new TaskMessage( this.commonOperations.create, this.rbd.snapshot, (metadata) => ({ '17': `Name is already used by ${this.rbd.snapshot(metadata)}.` }) ), - 'rbd/snap/edit': new TaskManagerMessage( + 'rbd/snap/edit': new TaskMessage( this.commonOperations.update, this.rbd.snapshot, (metadata) => ({ '16': `Cannot unprotect ${this.rbd.snapshot(metadata)} because it contains child images.` }) ), - 'rbd/snap/delete': new TaskManagerMessage( + 'rbd/snap/delete': new TaskMessage( this.commonOperations.delete, this.rbd.snapshot, (metadata) => ({ '16': `Cannot delete ${this.rbd.snapshot(metadata)} because it's protected.` }) ), - 'rbd/snap/rollback': new TaskManagerMessage( + 'rbd/snap/rollback': new TaskMessage( new TaskMessageOperation('Rolling back', 'rollback', 'Rolled back'), this.rbd.snapshot ) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-wrapper.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-wrapper.service.ts index 9e91cab8e541..5ac34a6324c9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-wrapper.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-wrapper.service.ts @@ -9,8 +9,8 @@ import { FinishedTask } from '../models/finished-task'; import { NotificationService } from './notification.service'; import { ServicesModule } from './services.module'; import { SummaryService } from './summary.service'; -import { TaskManagerMessageService } from './task-manager-message.service'; import { TaskManagerService } from './task-manager.service'; +import { TaskMessageService } from './task-message.service'; @Injectable({ providedIn: ServicesModule @@ -19,7 +19,7 @@ export class TaskWrapperService { constructor( private notificationService: NotificationService, private summaryService: SummaryService, - private taskManagerMessageService: TaskManagerMessageService, + private taskMessageService: TaskMessageService, private taskManagerService: TaskManagerService ) {} @@ -50,8 +50,7 @@ export class TaskWrapperService { _handleExecutingTasks(task: FinishedTask) { this.notificationService.show( NotificationType.info, - this.taskManagerMessageService.getRunningTitle(task), - this.taskManagerMessageService.getErrorTitle(task) + this.taskMessageService.getRunningTitle(task) ); const executingTask = new ExecutingTask(task.name, task.metadata); -- 2.47.3