Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #214. User can select the host from available list in volume provision service #216

Merged
merged 4 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ <h2>Parameters</h2>

<div class="form-item-container" *ngSwitchCase="'select'">
<form-item label="{{prop.label}}" [required]="true">
<p-dropdown [options]="prop.options" [required]="true" [formControlName]="prop.key" [placeholder]="prop.description ? prop.description : ''"></p-dropdown>
<p-dropdown [disabled]="noHosts && (prop.key == 'host_id')" [options]="prop.options" [required]="true" [formControlName]="prop.key" [placeholder]="prop.description ? prop.description : ''"></p-dropdown>
<div *ngIf="(prop.key == 'host_id')">
<i class="fa fa-exclamation-circle fa-2x"></i>
<span >Would you like to add a host? </span>
<a [routerLink]="['/createHost']">Add Host</a>
</div>
<div *ngIf="noHosts && (prop.key == 'host_id')">
<i class="fa fa-exclamation-circle fa-2x"></i>
<span >There are no hosts. Would you like to add one? </span>
<a [routerLink]="['/createHost']">Add Host</a>
</div>
</form-item>
</div>
</div>
Expand Down
44 changes: 34 additions & 10 deletions src/app/business/services/dynamic-form/dynamic-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { I18NService, MsgBoxService, Utils, ParamStorService } from '../../../sh
import { Validators, FormControl, FormGroup, FormBuilder } from '@angular/forms';
import { WorkflowService } from '../workflow.service';
import { ProfileService } from '../../profile/profile.service';
import { HostsService } from '../../block/hosts.service';
import { trigger, state, style, transition, animate } from '@angular/animations';
import { CreateClusterComponent } from '../create-cluster/create-cluster.component'
import * as _ from "underscore";
Expand All @@ -23,6 +24,9 @@ export class DynamicFormComponent implements OnInit {

msgs: Message[];
profileOptions: any[] = [];
allHosts;
noHosts: boolean = false;
hostOptions: any[] = [];
objectProps: any;
displayFormObject: any[];
form: FormGroup;
Expand Down Expand Up @@ -56,6 +60,7 @@ export class DynamicFormComponent implements OnInit {
public i18n: I18NService,
private wfservice: WorkflowService,
private profileService: ProfileService,
private HostsService: HostsService,
private paramStor: ParamStorService,
private fb: FormBuilder) {
this.default_parameters['auth_token'] = localStorage['auth-token'];
Expand All @@ -66,6 +71,7 @@ export class DynamicFormComponent implements OnInit {
ngOnInit() {
let self = this;
self.getProfiles();
self.getAllHosts();
this.dataObject['instanceName'] = {
"description": "Name of the Instance",
"required": true,
Expand Down Expand Up @@ -107,12 +113,15 @@ export class DynamicFormComponent implements OnInit {
item['showThis'] = false;
}
/* Adding host info object for volume provisioning. */
if(item['key'] == 'host_info'){
item['label'] = "Host IP";
if(item['key'] == 'host_id'){
item['label'] = "Host";
item['showThis'] = true;
item['validation'] = {required: true};
item['required'] = true;
item['type'] = 'string';
item['inputType'] = "select";
item['options'] = self.hostOptions;

formGroup[item['key']] = new FormControl(item['value'] || '', self.mapValidators(item['validation']));
}

if(item['key'] == 'port' || item['key']=='analysis_args'){
Expand Down Expand Up @@ -170,7 +179,28 @@ export class DynamicFormComponent implements OnInit {
}
}


getAllHosts(){
let self = this;
this.HostsService.getHosts().subscribe((res) => {
this.allHosts = res.json();
if(this.allHosts.length == 0){
this.noHosts = true;
}
if(this.allHosts && this.allHosts.length){
_.each(self.allHosts, function(item){
let option = {
label: item['hostName'] + ' ' + '(' + item['ip'] + ')',
value: item['id']
}
self.hostOptions.push(option);
})
}
console.log("Host Options", self.hostOptions);
}, (error) =>{
console.log(error);
})

}
mapValidators(validators) {
const formValidators = [];

Expand Down Expand Up @@ -206,12 +236,6 @@ export class DynamicFormComponent implements OnInit {

onSubmit(value) {
let formObject = value;
if(_.has(formObject, 'host_info')){
let val = {
"ip" : formObject['host_info']
}
formObject['host_info'] = val;
}
this.requestBody.service_id = this.serviceId;
this.requestBody.action = this.selectedService.action;
this.requestBody.user_id = this.default_parameters['user_id'];
Expand Down
3 changes: 2 additions & 1 deletion src/app/business/services/services.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CreateInstanceComponent } from './create-instance/create-instance.compo
import { CreateClusterComponent } from './create-cluster/create-cluster.component';
import { WorkflowService } from './workflow.service';
import { ProfileService } from '../profile/profile.service';
import { HostsService } from '../block/hosts.service';
import { HttpClientModule } from '@angular/common/http';
import { DynamicFormComponent } from './dynamic-form/dynamic-form.component';

Expand Down Expand Up @@ -57,6 +58,6 @@ import { DynamicFormComponent } from './dynamic-form/dynamic-form.component';
HttpClientModule,
SpinnerModule],
exports: [ServicesRoutingModule],
providers: [WorkflowService, ProfileService, ConfirmationService]
providers: [WorkflowService, ProfileService, HostsService, ConfirmationService]
})
export class ServicesModule { }