Simplifying plugin select logic

This is the first small step in making the plugin select
logic more conformant with a regular workflow.
Here, we change the plugin and versions into switched
form fields, eliminating the javascript that used to
handle that.

Change-Id: I23145e340f37b25cfc63446ec381730521d066b0
Partial-Bug: #1410941
(cherry picked from commit 1922c5dd7c)
Closes-Bug: #1578235
This commit is contained in:
Chad Roberts 2016-03-29 11:14:54 -04:00 committed by Nikita Konovalov
parent 41daf5ade4
commit fefd609b6b
3 changed files with 11 additions and 58 deletions

View File

@ -33,7 +33,8 @@ import sahara_dashboard.content.data_processing. \
utils.workflow_helpers as whelpers
class SelectPluginAction(workflows.Action):
class SelectPluginAction(workflows.Action,
whelpers.PluginAndVersionMixin):
hidden_create_field = forms.CharField(
required=False,
widget=forms.HiddenInput(attrs={"class": "hidden_create_field"}))
@ -41,29 +42,8 @@ class SelectPluginAction(workflows.Action):
def __init__(self, request, *args, **kwargs):
super(SelectPluginAction, self).__init__(request, *args, **kwargs)
try:
plugins = saharaclient.plugin_list(request)
except Exception:
plugins = []
exceptions.handle(request,
_("Unable to fetch plugin list."))
plugin_choices = [(plugin.name, plugin.title) for plugin in plugins]
self.fields["plugin_name"] = forms.ChoiceField(
label=_("Plugin name"),
choices=plugin_choices,
widget=forms.Select(attrs={"class": "plugin_name_choice"}))
for plugin in plugins:
field_name = plugin.name + "_version"
choice_field = forms.ChoiceField(
label=_("Version"),
choices=[(version, version) for version in plugin.versions],
widget=forms.Select(
attrs={"class": "plugin_version_choice "
+ field_name + "_choice"})
)
self.fields[field_name] = choice_field
sahara = saharaclient.client(request)
self._generate_plugin_version_fields(sahara)
class Meta(object):
name = _("Select plugin and hadoop version for cluster template")

View File

@ -60,18 +60,8 @@
$(".configure-clustertemplate-btn")[0].href = oldHref;
return false;
});
$(".plugin_version_choice").closest(".form-group").hide();
}
}
//display version for selected plugin
$(document).on('change', '.plugin_name_choice', switch_versions);
function switch_versions() {
$(".plugin_version_choice").closest(".form-group").hide();
var plugin = $(this);
$("." + plugin.val() + "_version_choice").closest(".form-group").show();
}
$(".plugin_name_choice").change();
});
});
@ -106,20 +96,9 @@
$(".configure-nodegrouptemplate-btn")[0].href = oldHref;
return false;
});
$(".plugin_version_choice").closest(".form-group").hide();
}
}
//display version for selected plugin
$(document).on('change', '.plugin_name_choice', switch_versions);
function switch_versions() {
$(".plugin_version_choice").closest(".form-group").hide();
var plugin = $(this);
$("." + plugin.val() + "_version_choice").closest(".form-group").show();
}
$(".plugin_name_choice").change();
//handle node processes change
$("input").filter(function (idx, e) {
return $(e).attr("name") && $(e).attr("name").indexOf("processes") != -1
@ -175,18 +154,8 @@
$(".configure-cluster-btn")[0].href = oldHref;
return false;
});
$(".plugin_version_choice").closest(".form-group").hide();
}
}
//display version for selected plugin
$(document).on('change', '.plugin_name_choice', switch_versions);
function switch_versions() {
$(".plugin_version_choice").closest(".form-group").hide();
var plugin = $(this);
$("." + plugin.val() + "_version_choice").closest(".form-group").show();
}
$(".plugin_name_choice").change();
});
});

View File

@ -251,7 +251,9 @@ class PluginAndVersionMixin(object):
self.fields["plugin_name"] = forms.ChoiceField(
label=_("Plugin Name"),
choices=plugin_choices,
widget=forms.Select(attrs={"class": "plugin_name_choice"}))
widget=forms.Select(
attrs={"class": "plugin_name_choice switchable",
'data-slug': 'pluginname'}))
for plugin in plugins:
field_name = plugin.name + "_version"
@ -259,8 +261,10 @@ class PluginAndVersionMixin(object):
label=_("Version"),
choices=[(version, version) for version in plugin.versions],
widget=forms.Select(
attrs={"class": "plugin_version_choice "
+ field_name + "_choice"})
attrs={"class": "plugin_version_choice switched "
+ field_name + "_choice",
"data-switch-on": "pluginname",
"data-pluginname-%s" % plugin.name: _("Version")})
)
self.fields[field_name] = choice_field