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

Commit

Permalink
feat(access-vm): add access VM action -> open modal window (#604)
Browse files Browse the repository at this point in the history
#573  add access VM action -> open modal window
  • Loading branch information
ksendart committed Oct 18, 2017
1 parent f019cba commit 099359e
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 20 deletions.
17 changes: 10 additions & 7 deletions src/app/vm/shared/vm-actions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ import {
} from '../vm-actions';
import { VmStartActionSilent } from '../vm-actions/silent/vm-start-silent';
import { VmStopActionSilent } from '../vm-actions/silent/vm-stop-silent';
import { VirtualMachineAction, VmActions } from '../vm-actions/vm-action';
import {
VirtualMachineAction,
VmActions
} from '../vm-actions/vm-action';
import { VmChangeServiceOfferingAction } from '../vm-actions/vm-change-service-offering';
import { VirtualMachine } from './vm.model';
import { VmAccessAction } from '../vm-actions/vm-access';


@Injectable()
Expand All @@ -27,12 +31,11 @@ export class VmActionsService implements ActionsService<VirtualMachine, VirtualM
this.vmRestoreAction,
this.vmDestroyAction,
this.vmResetPasswordAction,
this.vmConsoleAction
this.vmAccessAction
];

public pluginActions = [
this.vmPulseAction,
this.vmWebShellAction
];

constructor(
Expand All @@ -47,7 +50,8 @@ export class VmActionsService implements ActionsService<VirtualMachine, VirtualM
public vmConsoleAction: VmConsoleAction,
public vmWebShellAction: VmWebShellAction,
public vmPulseAction: VmPulseAction,
public vmChangeServiceOfferingAction: VmChangeServiceOfferingAction
public vmChangeServiceOfferingAction: VmChangeServiceOfferingAction,
public vmAccessAction: VmAccessAction
) {}

public getActionByName(name: VmActions): VirtualMachineAction {
Expand All @@ -58,9 +62,8 @@ export class VmActionsService implements ActionsService<VirtualMachine, VirtualM
[VmActions.RESTORE]: this.vmRestoreAction,
[VmActions.DESTROY]: this.vmDestroyAction,
[VmActions.RESET_PASSWORD]: this.vmResetPasswordAction,
[VmActions.CONSOLE]: this.vmConsoleAction,
[VmActions.WEB_SHELL]: this.vmWebShellAction,
[VmActions.PULSE]: this.vmWebShellAction
[VmActions.PULSE]: this.vmWebShellAction,
[VmActions.ACCESS]: this.vmAccessAction
};

return actions[name];
Expand Down
3 changes: 3 additions & 0 deletions src/app/vm/vm-actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { VmStopAction } from './vm-stop';
import { VmWebShellAction } from './vm-webshell';
import { VmURLAction } from './vm-url';
import { VmSavePasswordAction } from './vm-save-password';
import { VmAccessAction } from './vm-access';

export {
VmStartAction,
Expand All @@ -32,6 +33,7 @@ export {
VmChangeServiceOfferingAction,
VmURLAction,
VmSavePasswordAction,
VmAccessAction
};

export const VmActionProviders = [
Expand All @@ -51,4 +53,5 @@ export const VmActionProviders = [
VmChangeServiceOfferingAction,
VmURLAction,
VmSavePasswordAction,
VmAccessAction
];
44 changes: 44 additions & 0 deletions src/app/vm/vm-actions/vm-access.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
VirtualMachineAction,
VmActions
} from './vm-action';
import {
VirtualMachine,
VmState
} from '../shared/vm.model';
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import {
MdDialog,
MdDialogConfig
} from '@angular/material';
import { VmService } from '../shared/vm.service';
import { JobsNotificationService } from '../../shared/services/jobs-notification.service';
import { DialogService } from '../../dialog/dialog-service/dialog.service';
import { VmAccessComponent } from './vm-actions-component/vm-access.component';


@Injectable()
export class VmAccessAction extends VirtualMachineAction {
public action = VmActions.ACCESS;
public name = 'VM_PAGE.COMMANDS.VM_ACCESS';
public icon = 'computer';

constructor (private dialog: MdDialog,
protected dialogService: DialogService,
protected jobsNotificationService: JobsNotificationService,
protected vmService: VmService){
super(dialogService, jobsNotificationService, vmService);
}

public canActivate(vm: VirtualMachine): boolean {
return !!vm && vm.state === VmState.Running;
}

public activate(vm: VirtualMachine): Observable<void> {
return this.dialog.open(VmAccessComponent, <MdDialogConfig>{
width: '550px',
data: vm
}).afterClosed();
}
}
3 changes: 2 additions & 1 deletion src/app/vm/vm-actions/vm-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export enum VmActions {
CONSOLE = 'console',
CHANGE_SERVICE_OFFERING = 'changeServiceOffering',
WEB_SHELL = 'webShell',
PULSE = 'pulse'
PULSE = 'pulse',
ACCESS = 'access'
}

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<cs-postdeployment-dialog
[vm]="vm"
[dialogRef]="dialogRef"
[title]="title">
</cs-postdeployment-dialog>
26 changes: 26 additions & 0 deletions src/app/vm/vm-actions/vm-actions-component/vm-access.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
Component,
Inject
} from '@angular/core';
import {
MD_DIALOG_DATA,
MdDialogRef
} from '@angular/material';
import { VirtualMachine } from '../../shared/vm.model';


@Component({
selector: 'cs-vm-access-dialog',
templateUrl: 'vm-access.component.html'
})
export class VmAccessComponent {
public vm: VirtualMachine;
public title = 'VM_PAGE.COMMANDS.VM_ACCESS_TITLE';

constructor(
public dialogRef: MdDialogRef<VmAccessComponent>,
@Inject(MD_DIALOG_DATA) data
) {
this.vm = data;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Component, Input } from '@angular/core';
import {
Component,
Input
} from '@angular/core';
import { VmActionsService } from '../../shared/vm-actions.service';
import { VirtualMachine, VmState } from '../../shared/vm.model';
import {
VirtualMachine,
VmState
} from '../../shared/vm.model';
import { VirtualMachineAction } from '../vm-action';
import { VmExpungeAction } from '../vm-expunge';
import { VmRecoverAction } from '../vm-recover';
Expand All @@ -16,7 +22,7 @@ export class VmActionsComponent {
public vmActions: Array<VirtualMachineAction>;
public pluginActions: Array<VirtualMachineAction>;

public destroyedVmActions: Array<VirtualMachineAction>;;
public destroyedVmActions: Array<VirtualMachineAction>;

public vmActionsContext: {};
public pluginActionsContext: {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<h5 >{{ 'VM_POST_ACTION.TITLE' | translate}}</h5>
<div><b>{{ 'VM_POST_ACTION.VM' | translate }}:</b> {{vm.name}}</div>
<div *ngIf="vm.passwordEnabled">
<b>{{ 'VM_POST_ACTION.VM_PASSWORD' | translate }}:</b> {{vm.password}}
<b>{{ 'VM_POST_ACTION.VM_PASSWORD' | translate }}:</b>
<span *ngIf="getPassword()">{{ getPassword()}}</span>
<i *ngIf="!getPassword()">{{ 'VM_POST_ACTION.UNKNOWN' | translate }}</i>
<button md-button color="primary" *ngIf="canSavePassword" [disabled]="disableButton"
(click)="savePassword()">{{ 'COMMON.SAVE' | translate }}</button>
<div class="saved">
Expand All @@ -13,8 +15,8 @@ <h5 >{{ 'VM_POST_ACTION.TITLE' | translate}}</h5>
</div>
</div>
<div *ngIf="vm.ipIsAvailable"><b>{{ 'VM_POST_ACTION.VM_IP' | translate }}:</b> {{vm.nic[0].ipAddress}}</div>
<div *ngIf="isHttpAuthMode(vm) && getLogin(vm)"><b>{{ 'VM_POST_ACTION.LOGIN' | translate }}</b> {{getLogin(vm)}}</div>
<div *ngIf="isHttpAuthMode(vm) && getPassword(vm)"><b>{{ 'VM_POST_ACTION.VM_PASSWORD' | translate }}</b> {{getPassword(vm)}}</div>
<div *ngIf="isHttpAuthMode(vm) && getUrlLogin(vm)"><b>{{ 'VM_POST_ACTION.LOGIN' | translate }}</b> {{getUrlLogin(vm)}}</div>
<div *ngIf="isHttpAuthMode(vm) && getUrlPassword(vm)"><b>{{ 'VM_POST_ACTION.VM_PASSWORD' | translate }}</b> {{getUrlPassword(vm)}}</div>
<div class="mat-dialog-actions">
<span *ngFor="let act of actions">
<button md-button color="primary"
Expand Down
12 changes: 10 additions & 2 deletions src/app/vm/vm-creation/postdeployment/postdeployment.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class PostdeploymentComponent {

@Input() public vm: VirtualMachine;
@Input() public dialogRef: MdDialogRef<VmCreationComponent>;
@Input() public title: string;

private passwordToken = 'csui.vm.password';

public canSavePassword: boolean;
public disableButton: boolean = false;
Expand All @@ -49,15 +52,20 @@ export class PostdeploymentComponent {
});
}

public getPassword() {
const passwordTag = this.vm.tags.find(tag => tag.key === this.passwordToken);
return this.vm.password || passwordTag && passwordTag.value;
}

public isHttpAuthMode(vm): boolean {
return this.vmURL.canActivate(vm);
}

public getLogin(vm) {
public getUrlLogin(vm) {
return this.vmURL.getLogin(vm);
}

public getPassword(vm) {
public getUrlPassword(vm) {
return this.vmURL.getPassword(vm);
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/vm/vm-creation/vm-creation.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<cs-postdeployment-dialog
*ngIf="!deploymentStopped && deployedVm"
[vm]="deployedVm"
[dialogRef]="dialogRef">
[dialogRef]="dialogRef"
[title]="'VM_POST_ACTION.TITLE'">
</cs-postdeployment-dialog>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/app/vm/vm.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import { SecondaryIpComponent } from './vm-sidebar/network-detail/nics/secondary
import { SecondaryIpListComponent } from './vm-sidebar/network-detail/nics/secondary-ip-list/secondary-ip-list.component';
import { NicFieldsComponent } from './vm-sidebar/network-detail/nics/nic/nic-fields/nic-fields.component';
import { VmResetPasswordComponent } from './vm-actions/vm-reset-password-component/vm-reset-password.component';
import { VmAccessComponent } from './vm-actions/vm-actions-component/vm-access.component';


@NgModule({
Expand Down Expand Up @@ -137,6 +138,7 @@ import { VmResetPasswordComponent } from './vm-actions/vm-reset-password-compone
VmDetailZoneComponent,
VmListComponent,
VmActionsComponent,
VmAccessComponent,
VmActionsSidebarComponent,
VmColorComponent,
VmCreationComponent,
Expand Down Expand Up @@ -192,7 +194,8 @@ import { VmResetPasswordComponent } from './vm-actions/vm-reset-password-compone
SshKeypairResetComponent,
VmCreationSecurityGroupComponent,
PostdeploymentComponent,
VmResetPasswordComponent
VmResetPasswordComponent,
VmAccessComponent
]
})
export class VmModule { }
5 changes: 4 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@
"RECOVER": "Recover",
"RESET_PASSWORD": "Reset password",
"CONSOLE": "Console",
"WEB_SHELL": "WebShell"
"WEB_SHELL": "WebShell",
"VM_ACCESS": "Access VM",
"VM_ACCESS_TITLE": "Virtual Machine"
},
"RESOURCE_USAGE": {
"TITLE": "Resource usage",
Expand Down Expand Up @@ -482,6 +484,7 @@
"OPEN_SHELL_CONSOLE": "Open WebShell",
"OPEN_URL": "Open URL",
"VM_PASSWORD": "Password",
"UNKNOWN": "Unknown",
"LOGIN": "Login",
"VM": "Virtual machine name",
"VM_IP": "IP"
Expand Down
5 changes: 4 additions & 1 deletion src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@
"RECOVER": "Восстановить",
"RESET_PASSWORD": "Сбросить пароль",
"CONSOLE": "Консоль",
"WEB_SHELL": "WebShell"
"WEB_SHELL": "WebShell",
"VM_ACCESS": "Доступ к ВМ",
"VM_ACCESS_TITLE": "Виртуальная машина"
},
"RESOURCE_USAGE": {
"TITLE": "Использование ресурсов",
Expand Down Expand Up @@ -481,6 +483,7 @@
"OPEN_SHELL_CONSOLE": "Окрыть WebShell",
"OPEN_URL": "Открыть URL",
"VM_PASSWORD": "Пароль",
"UNKNOWN": "Неизвестно",
"LOGIN": "Логин",
"VM": "Имя машины",
"VM_IP": "IP адрес"
Expand Down

0 comments on commit 099359e

Please sign in to comment.