Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
#289 fix job resubscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
wowshakhov committed Aug 1, 2017
1 parent 759ac36 commit 0494748
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
25 changes: 24 additions & 1 deletion src/app/vm/shared/vm-actions.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { VirtualMachineAction } from '../vm-actions/vm-action';
import { VirtualMachineAction, VirtualMachineActionType, VmActions } from '../vm-actions/vm-action';
import { VirtualMachine } from './vm.model';
import { ActionsService } from '../../shared/interfaces/action-service.interface';
import { DialogService } from '../../dialog/dialog-module/dialog.service';
Expand Down Expand Up @@ -40,6 +40,29 @@ export class VmActionsService implements ActionsService<VirtualMachine, VirtualM
private webShellService: WebShellService
) {}

public getActionByName(name: VirtualMachineActionType): VirtualMachineAction {
switch (name) {
case VmActions.START:
return this.getStartAction();
case VmActions.STOP:
return this.getStopAction();
case VmActions.REBOOT:
return this.getRebootAction();
case VmActions.RESTORE:
return this.getRestoreAction();
case VmActions.DESTROY:
return this.getDestroyAction();
case VmActions.RESET_PASSWORD:
return this.getResetPasswordAction();
case VmActions.CONSOLE:
return this.getConsoleAction();
case VmActions.WEB_SHELL:
return this.getWebShellAction();
default:
throw new Error('Unknown VM action');
}
}

public getStartAction(): VmStartAction {
return new VmStartAction(this.dialogService, this.vmService);
}
Expand Down
25 changes: 14 additions & 11 deletions src/app/vm/vm-list/vm-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { VmListItemComponent } from './vm-list-item.component';
import { VmActionsService } from '../shared/vm-actions.service';

import { config } from '../../../main';
import { VirtualMachineActionType } from '../vm-actions/vm-action';

const askToCreateVm = 'askToCreateVm';

Expand Down Expand Up @@ -79,9 +80,11 @@ export class VmListComponent implements OnInit {
public listService: ListService,
private vmService: VmService,
private dialogService: DialogService,
private jobsNotificationService: JobsNotificationService,
private asyncJobService: AsyncJobService,
private statsUpdateService: StatsUpdateService,
private userService: UserService,
private vmActionsService: VmActionsService,
private zoneService: ZoneService
) {
this.showDetail = this.showDetail.bind(this);
Expand Down Expand Up @@ -221,17 +224,17 @@ export class VmListComponent implements OnInit {
}

private resubscribeToJobs(): void {
// this.vmService.resubscribe()
// .subscribe(observables => {
// observables.forEach(observable => {
// observable.subscribe(job => {
// const action = this.vmActionsService.getAction(job.cmd);
// this.jobsNotificationService.finish({
// message: action.tokens.successMessage
// });
// });
// });
// });
this.vmService.resubscribe()
.subscribe(observables => {
observables.forEach(observable => {
observable.subscribe(job => {
const action = this.vmActionsService.getActionByName(job.cmd as VirtualMachineActionType);
this.jobsNotificationService.finish({
message: action.tokens.successMessage
});
});
});
});
}

private subscribeToVmDestroyed(): void {
Expand Down

0 comments on commit 0494748

Please sign in to comment.