Commit 03da3cc4 authored by Georgios Ouzounis's avatar Georgios Ouzounis
Browse files

Added setupController method in create-lambda-instance route

parent c17b1c49
......@@ -117,7 +117,12 @@ export default Ember.Controller.extend({
},
selectFromDropDownList: function(variable, event){
this.set(variable, event.target.value);
if(variable === "selectedProjectName"){
this.set(variable, event.target.value);
}
else{
this.set(variable, parseInt(event.target.value));
}
this.calculateDropDownListValues();
}
......
......@@ -2,7 +2,7 @@ import Ember from "ember";
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model() {
model: function() {
return Ember.RSVP.hash({
newLambdaInstance: this.store.createRecord('create-lambda-instance', {}),
userPublicKeys: this.store.findAll('user-public-key'),
......@@ -18,9 +18,6 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
var controller = this.controllerFor('create-lambda-instance');
var minQuotasPerProject = controller.get('minQuotasPerProject');
// Keep the index of the first project that satisfies the restrictions since deleted
// records are not immediately removed from the model.
var selectedProjectIndex = -1;
for (var i = 0;i < model.userOkeanosProjects.get('length');i++){
if (model.userOkeanosProjects.objectAt(i).get('vm') >= minQuotasPerProject['vms'] &&
model.userOkeanosProjects.objectAt(i).get('cpu') >= minQuotasPerProject['cpus'] &&
......@@ -31,19 +28,20 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
if(!controller.get('enoughQuotas')){
controller.set('enoughQuotas', true);
selectedProjectIndex = i;
}
}
else{
model.userOkeanosProjects.objectAt(i).deleteRecord();
}
}
},
setupController: function(controller, model){
this._super(controller, model);
if(model.userOkeanosProjects.get('length') > 0){
var minQuotasPerProject = controller.get('minQuotasPerProject');
// If at least one project has enough quotas, set the default values for the drop down lists.
// If there is no project with enough quotas, then 'enoughQuotas' will be set to false and
// the form will never be presented to the user.
if(selectedProjectIndex > - 1){
var selectedProject = model.userOkeanosProjects.objectAt(selectedProjectIndex);
var selectedProject = model.userOkeanosProjects.objectAt(0);
controller.set('selectedProjectName', selectedProject.get('name'));
controller.set('selectedProjectVMs', selectedProject.get('vm'));
controller.set('selectedProjectCPUs', selectedProject.get('cpu'));
......@@ -63,29 +61,29 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
var slaveNodeDiskValues = controller.get('slaveNodeDiskValues');
var n = model.VMParameterValues.get('length');
for(i = 0;i < n;i++){
for(var i = 0;i < n;i++){
var cpus = model.VMParameterValues.objectAt(i).get('vcpus');
for(var j = 0, m = cpus.get('length');j < m;j++){
if(cpus[j] >= minQuotasPerVM['cpus']){
masterNodeCPUValues.pushObject(Ember.Object.create({'value': cpus[j], 'enabled': true}));
slaveNodeCPUValues.pushObject(Ember.Object.create({'value': cpus[j], 'enabled': true}));
masterNodeCPUValues.pushObject(Ember.Object.create({'value': parseInt(cpus[j]), 'enabled': true}));
slaveNodeCPUValues.pushObject(Ember.Object.create({'value': parseInt(cpus[j]), 'enabled': true}));
}
}
var ram = model.VMParameterValues.objectAt(i).get('ram');
for(j = 0, m = ram.get('length');j < m;j++){
if(ram[j] >= minQuotasPerVM['ram']){
masterNodeRAMValues.pushObject(Ember.Object.create({'value': ram[j], 'enabled': true}));
slaveNodeRAMValues.pushObject(Ember.Object.create({'value': ram[j], 'enabled': true}));
masterNodeRAMValues.pushObject(Ember.Object.create({'value': parseInt(ram[j]), 'enabled': true}));
slaveNodeRAMValues.pushObject(Ember.Object.create({'value': parseInt(ram[j]), 'enabled': true}));
}
}
var disk = model.VMParameterValues.objectAt(i).get('disk');
for(j = 0, m = disk.get('length');j < m;j++){
if(disk[j] >= minQuotasPerVM['disk']){
masterNodeDiskValues.pushObject(Ember.Object.create({'value': disk[j], 'enabled': true}));
slaveNodeDiskValues.pushObject(Ember.Object.create({'value': disk[j], 'enabled': true}));
masterNodeDiskValues.pushObject(Ember.Object.create({'value': parseInt(disk[j]), 'enabled': true}));
slaveNodeDiskValues.pushObject(Ember.Object.create({'value': parseInt(disk[j]), 'enabled': true}));
}
}
}
......
......@@ -149,7 +149,7 @@
<label for="vcpus_master">Number of CPUs on Master Node:</label>
<select name="vcpus_master" class="form-control" onchange={{action "selectFromDropDownList" "selectedMasterNodeCPUs"}} disabled={{masterCPUsSelectDisabled}}>
{{#each masterNodeCPUValues as |vcpusValue|}}
{{#if (compare vcpusValue.value "==" selectedMasterNodeCPUs)}}
{{#if (compare vcpusValue.value "===" selectedMasterNodeCPUs)}}
<option value={{vcpusValue.value}} selected>{{vcpusValue.value}}</option>
{{else}}
{{#if vcpusValue.enabled}}
......@@ -166,7 +166,7 @@
<label for="ram_master" >Amount or RAM memory on Master Node: </label>
<select name="ram_master" class="form-control" onchange={{action "selectFromDropDownList" "selectedMasterNodeRAM"}} disabled={{masterRAMSelectDisabled}}>
{{#each masterNodeRAMValues as |ramValue|}}
{{#if (compare ramValue.value "==" selectedMasterNodeRAM)}}
{{#if (compare ramValue.value "===" selectedMasterNodeRAM)}}
<option value={{ramValue.value}} selected>{{ramValue.value}}</option>
{{else}}
{{#if ramValue.enabled}}
......@@ -183,7 +183,7 @@
<label for="disk_master"> Size of hard disk on Master Node: </label>
<select name="disk_master" class="form-control" onchange={{action "selectFromDropDownList" "selectedMasterNodeDisk"}} disabled={{masterDiskSelectDisabled}}>
{{#each masterNodeDiskValues as |diskValue|}}
{{#if (compare diskValue.value "==" selectedMasterNodeDisk)}}
{{#if (compare diskValue.value "===" selectedMasterNodeDisk)}}
<option value={{diskValue.value}} selected>{{diskValue.value}}</option>
{{else}}
{{#if diskValue.enabled}}
......@@ -214,7 +214,7 @@
<label for="vcpus_slave">Number of CPUs on each Slave Node:</label>
<select name="vcpus_slave" class="form-control" onchange={{action "selectFromDropDownList" "selectedSlaveNodeCPUs"}} disabled={{slaveCPUsSelectDisabled}}>
{{#each slaveNodeCPUValues as |vcpusValue|}}
{{#if (compare vcpusValue.value "==" selectedSlaveNodeCPUs)}}
{{#if (compare vcpusValue.value "===" selectedSlaveNodeCPUs)}}
<option value={{vcpusValue.value}} selected>{{vcpusValue.value}}</option>
{{else}}
{{#if vcpusValue.enabled}}
......@@ -231,7 +231,7 @@
<label for="ram_slave" >Amount or RAM memory on each Slave Node:</label>
<select name="ram_slave" class="form-control" onchange={{action "selectFromDropDownList" "selectedSlaveNodeRAM"}} disabled={{slaveRAMSelectDisabled}}>
{{#each slaveNodeRAMValues as |ramValue|}}
{{#if (compare ramValue.value "==" selectedSlaveNodeRAM)}}
{{#if (compare ramValue.value "===" selectedSlaveNodeRAM)}}
<option value={{ramValue.value}} selected>{{ramValue.value}}</option>
{{else}}
{{#if ramValue.enabled}}
......@@ -249,7 +249,7 @@
<label for="disk_slave"> Size of hard disk on each Slave Node:</label>
<select name="disk_slave" class="form-control" onchange={{action "selectFromDropDownList" "selectedSlaveNodeDisk"}} disabled={{slaveDiskSelectDisabled}}>
{{#each slaveNodeDiskValues as |diskValue|}}
{{#if (compare diskValue.value "==" selectedSlaveNodeDisk)}}
{{#if (compare diskValue.value "===" selectedSlaveNodeDisk)}}
<option value={{diskValue.value}} selected>{{diskValue.value}}</option>
{{else}}
{{#if diskValue.enabled}}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment