Skip to content

Commit

Permalink
F #5389: Select vCenter Template when importing images (#1198)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9fdd507)
  • Loading branch information
Frederick Borges authored and tinova committed Jun 3, 2021
1 parent cacffef commit 2a095f7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/sunstone/models/OpenNebulaJSON/MarketPlaceAppJSON.rb
Expand Up @@ -172,14 +172,16 @@ def export(params=Hash.new)
name = params['name']
vmtemplate_name = params['vmtemplate_name']
notemplate = [true, 'true'].include?(params['notemplate'])
template = params['vcenter_template'] != "" ? params['vcenter_template'].to_i : nil

tag ="tag=#{params['tag']}" if params['tag'] && !params['tag'].empty?
rc = export({
:dsid => dsid,
:name => name,
:vmtemplate_name => vmtemplate_name,
:notemplate => notemplate,
:url_args => tag
:url_args => tag,
:template => template
})

if OpenNebula.is_error?(rc)
Expand Down
Expand Up @@ -24,8 +24,10 @@ define(function(require) {
var Locale = require("utils/locale");
var Tips = require("utils/tips");
var DataStoresTable = require("tabs/datastores-tab/datatable");
var TemplatesTable = require("tabs/templates-tab/datatable");
var DockerTagsTable = require("./docker-tags");
var DataStore = require("opennebula/datastore");
var Template = require("opennebula/template");

/*
TEMPLATES
Expand Down Expand Up @@ -59,6 +61,18 @@ define(function(require) {
return r;
}

function getTemplates(formPanelId){
var r = null;
if(formPanelId){
r = new TemplatesTable(
formPanelId + "templatesTable", {
"select": true
}
);
}
return r;
}

function _getDockerTagsTable(formPanelId, resourceId){
return (formPanelId)
? new DockerTagsTable(
Expand All @@ -79,6 +93,7 @@ define(function(require) {
};

this.datastoresTable = getDataStore(FORM_PANEL_ID);
this.vCenterTemplatesTable = getTemplates(FORM_PANEL_ID);

BaseFormPanel.call(this);
}
Expand All @@ -102,7 +117,8 @@ define(function(require) {
function _htmlWizard() {
return TemplateWizardHTML({
"formPanelId": this.formPanelId,
"datastoresTableHTML": this.datastoresTable.dataTableHTML
"datastoresTableHTML": this.datastoresTable.dataTableHTML,
"vCenterTemplatesTableHTML": this.vCenterTemplatesTable.dataTableHTML
});
}

Expand All @@ -121,8 +137,10 @@ define(function(require) {
}

this.datastoresTable.resetResourceTableSelect();
this.vCenterTemplatesTable.resetResourceTableSelect();
}
$("#NAME", context).focus();
$("#placeDatatablevCenterTemplate", context).hide();
return false;
}

Expand All @@ -131,13 +149,31 @@ define(function(require) {
Tips.setup(context);
this.datastoresTable.initialize();
this.datastoresTable.idInput().attr("required", "");
this.vCenterTemplatesTable.initialize();
$("input#NAME", context).on("input", function(){
var vmname = $("#VMNAME", context).val();
if (vmname == "" || vmname == $(this).data("prev")){
$("#VMNAME", context).val($(this).val());
}
$(this).data("prev", $(this).val());
});

var that = this;
var section = $("#" + that.datastoresTable.dataTableId + "Container");
$("#" + that.datastoresTable.dataTableId + " tbody", section).delegate("tr", "click", function(e) {
var wasChecked = $("td.markrow", this).hasClass("markrow");
console.log({"dsTable": that.datastoresTable})
var aData = that.datastoresTable.dataTable.fnGetData(this);
var check = aData != undefined && !wasChecked;

if (aData[9] == "vcenter"){
$("#placeDatatablevCenterTemplate", context).show();
}
else{
$("#placeDatatablevCenterTemplate", context).hide();
}
return true;
});
}

function _setResourceId(context, appJson, type) {
Expand All @@ -150,7 +186,12 @@ define(function(require) {
? ds.TYPE == DataStore.TYPES.FILE_DS
: ds.TYPE == DataStore.TYPES.IMAGE_DS;
}
this.datastoresTable.updateFn()
this.datastoresTable.updateFn();

this.vCenterTemplatesTable.selectOptions.filter_fn = function(template) {
return template.TEMPLATE.HYPERVISOR === "vcenter";
}
this.vCenterTemplatesTable.updateFn()

$("input#NAME", context).val(appJson.MARKETPLACEAPP.NAME).trigger("input");

Expand Down Expand Up @@ -182,7 +223,8 @@ define(function(require) {
"name" : $("#NAME", context).val(),
"vmtemplate_name" : $("#VMNAME", context).val(),
"dsid" : this.datastoresTable.idInput().val(),
"notemplate" : $("#NOTEMPLATE", context).is(':checked')
"notemplate" : $("#NOTEMPLATE", context).is(':checked'),
"vcenter_template" : this.vCenterTemplatesTable.idInput().val()
};

if (this.dockertagsTable) {
Expand All @@ -193,4 +235,3 @@ define(function(require) {
return false;
}
});

Expand Up @@ -48,6 +48,10 @@
<legend>{{tr "Select the Datastore to store the resource"}}</legend>
{{{ datastoresTableHTML }}}
</fieldset>
<fieldset id="placeDatatablevCenterTemplate">
<legend>{{tr "Select the vCenter Template to use"}}</legend>
{{{ vCenterTemplatesTableHTML }}}
</fieldset>
<fieldset id="placeDatatableDockerTags" style="display: none;">
<legend>{{tr "Select the Dockerhub tag"}}</legend>
{{{ dockertagsTableHTML }}}
Expand Down

0 comments on commit 2a095f7

Please sign in to comment.