From 8f5f3af0d843a42d2c290607e0aadae3b3d6a435 Mon Sep 17 00:00:00 2001 From: Frederick Borges Date: Mon, 27 Apr 2020 19:21:53 +0200 Subject: [PATCH] B #3604: Hide instantiate options (#4608) --- src/sunstone/public/app/sunstone-config.js | 8 +++++ .../form-panels/instantiate/templateRow.hbs | 22 +++++++------ .../templates/helpers/isOneFeatureEnabled.js | 32 +++++++++++++++++++ 3 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/sunstone/public/app/templates/helpers/isOneFeatureEnabled.js diff --git a/src/sunstone/public/app/sunstone-config.js b/src/sunstone/public/app/sunstone-config.js index 05c595b9ad..dd0a3dc4c9 100644 --- a/src/sunstone/public/app/sunstone-config.js +++ b/src/sunstone/public/app/sunstone-config.js @@ -78,6 +78,14 @@ define(function(require) { } }, + "isOneFeatureEnabled": function(feature1Name, feature2Name) { + if (_config["view"]["features"]) { + return _config["view"]["features"][feature1Name] || _config["view"]["features"][feature2Name]; + } else { + return false; + } + }, + "isAdvancedEnabled": function(featureName) { if (_config["view"]["features"] && featureName in _config["view"]["features"]) { return _config["view"]["features"][featureName]; diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs index 4790d30dd5..cebf2cb1cb 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/instantiate/templateRow.hbs @@ -48,16 +48,17 @@
- {{#advancedImportationSection "" (tr "Network") }} {{#isFeatureEnabled "show_vnet_instantiate"}} + {{#advancedImportationSection "" (tr "Network") }}
- {{/isFeatureEnabled}} {{/advancedImportationSection}} + {{/isFeatureEnabled}} + {{#isOneFeatureEnabled "show_as_uid_instantiate" "show_as_gid_instantiate"}} {{#advancedImportationSection "" (tr "Instantiate as different User / Group")}} {{#isFeatureEnabled "show_as_uid_instantiate"}}
@@ -78,8 +79,9 @@
{{/isFeatureEnabled}} {{/advancedImportationSection}} - {{#advancedImportationSection "" (tr "Deploy VM in a specific Host") }} + {{/isOneFeatureEnabled}} {{#isFeatureEnabled "show_host_instantiate"}} + {{#advancedImportationSection "" (tr "Deploy VM in a specific Host") }}
@@ -96,10 +98,10 @@
- {{/isFeatureEnabled}} {{/advancedImportationSection}} - {{#advancedImportationSection "" (tr "Deploy VM in a specific Datastore") }} + {{/isFeatureEnabled}} {{#isFeatureEnabled "show_ds_instantiate"}} + {{#advancedImportationSection "" (tr "Deploy VM in a specific Datastore") }}
@@ -116,8 +118,8 @@
- {{/isFeatureEnabled}} {{/advancedImportationSection}} + {{/isFeatureEnabled}} {{#advancedImportationSection "" (tr "Schedule Actions for VM") }}
@@ -127,8 +129,8 @@
{{/advancedImportationSection}} - {{#advancedImportationSection "" (tr "Associate VM to a VM Group") }} {{#isFeatureEnabled "show_vmgroup_instantiate"}} + {{#advancedImportationSection "" (tr "Associate VM to a VM Group") }}
@@ -142,9 +144,10 @@
- {{/isFeatureEnabled}} {{/advancedImportationSection}} - {{#advancedImportationSection "" (tr "vCenter Deployment") }} + {{/isFeatureEnabled}} + {{#isFeatureEnabled "vcenter_vm_folder"}} + {{#advancedImportationSection "" (tr "vCenter Deployment")}}
@@ -152,5 +155,6 @@
{{/advancedImportationSection}} + {{/isFeatureEnabled}}

\ No newline at end of file diff --git a/src/sunstone/public/app/templates/helpers/isOneFeatureEnabled.js b/src/sunstone/public/app/templates/helpers/isOneFeatureEnabled.js new file mode 100644 index 0000000000..556d96bf72 --- /dev/null +++ b/src/sunstone/public/app/templates/helpers/isOneFeatureEnabled.js @@ -0,0 +1,32 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + var Handlebars = require('hbs/handlebars'); + var Config = require('sunstone-config'); + + var isOneFeatureEnabled = function(feature1, feature2 , options) { + if (Config.isOneFeatureEnabled(feature1, feature2)) { + return options.fn(this); + } else { + return options.inverse(this); + } + }; + + Handlebars.registerHelper('isOneFeatureEnabled', isOneFeatureEnabled); + + return isOneFeatureEnabled; +})