Skip to content

Commit

Permalink
GOD's button group can have buttons assign/unassign during create/edit
Browse files Browse the repository at this point in the history
  • Loading branch information
ZitaNemeckova committed Nov 20, 2018
1 parent e1e7030 commit d141114
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ ManageIQ.angular.app.component('mainCustomButtonGroupFormComponent', {
templateUrl: '/static/generic_object/main_custom_button_group_form.html.haml',
});

mainCustomButtonGroupFormController.$inject = ['API', 'miqService'];
mainCustomButtonGroupFormController.$inject = ['API', 'miqService', '$http'];

function mainCustomButtonGroupFormController(API, miqService) {
function mainCustomButtonGroupFormController(API, miqService, $http) {
var vm = this;

vm.$onInit = function() {
Expand All @@ -26,8 +26,15 @@ function mainCustomButtonGroupFormController(API, miqService) {
button_icon: '',
button_color: '#4d5258',
set_data: {},
assigned_buttons: [],
unassigned_buttons: [],
};

$http.get('/generic_object_definition/custom_buttons_in_set/?custom_button_set_id=' + vm.customButtonGroupRecordId + '&generic_object_definition_id=' + vm.genericObjectDefnRecordId)
.then(function(response) {
Object.assign(vm.customButtonGroupModel, response.data);
})
.catch(miqService.handleFailure);
if (vm.customButtonGroupRecordId) {
vm.newRecord = false;
miqService.sparkleOn();
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/generic_object_definition_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def custom_button_group_new
def custom_button_group_edit
assert_privileges('ab_group_edit')
@custom_button_group = CustomButtonSet.find(params[:id])
@generic_object_definition = GenericObjectDefinition.find(@custom_button_group.set_data[:applies_to_id])
title = _("Edit Custom Button Group '%{name}'") % {:name => @custom_button_group.name}
render_form(title, 'custom_button_group_form')
end
Expand Down Expand Up @@ -144,6 +145,20 @@ def add_button_in_group
custom_button_set.save!
end

def custom_buttons_in_set
assigned_buttons = if params[:custom_button_set_id].present?
button_set = CustomButtonSet.find(params[:custom_button_set_id])
button_set.custom_buttons
else
[]
end
generic_object_definition = GenericObjectDefinition.find(params[:generic_object_definition_id])
unassigned_buttons = generic_object_definition.custom_buttons
assigned_buttons.map!{ |button| [button.name, button.id]}
unassigned_buttons.map!{ |button| [button.name, button.id]}
render :json => {:assigned_buttons => assigned_buttons, :unassigned_buttons => unassigned_buttons}
end

private

def node_type(node)
Expand Down
69 changes: 69 additions & 0 deletions app/views/static/generic_object/custom_button_group_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,72 @@
'#4d5258',
"ng-model" => "vm.model.button_color",
:class => "form-control")
.form-horizontal
%hr
%h3
= _('Assign Buttons')
#column_lists
.col-md-5
= _('Unassigned:')
= select_tag('available_fields[]',
options_for_select("{{vm.model.unassigned_buttons}}"),
:multiple => true,
:class => "form-control",
:style => "overflow-x: scroll;",
:size => 8,
:id => "available_fields")
.col-md-1{:style => "padding: 10px"}
.spacer
.spacer
- t = _("Move selected fields right")
%button.btn.btn-default.btn-block{:title => t,
:remote => true,
"data-submit" => 'column_lists',
"data-method" => :post}
%i.fa.fa-angle-right.fa-lg.hidden-xs.hidden-sm
%i.fa.fa-lg.fa-angle-right.fa-rotate-90.hidden-md.hidden-lg
- t = _("Move selected fields left")
%button.btn.btn-default.btn-block{:title => t,
:remote => true,
"data-submit" => 'column_lists',
"data-method" => :post}
%i.fa.fa-angle-left.fa-lg.hidden-xs.hidden-sm
%i.fa.fa-lg.fa-angle-left.fa-rotate-90.hidden-md.hidden-lg
.spacer
.col-md-5
= _('Selected:')
= select_tag('selected_fields[]',
options_for_select("vm.model.assigned_buttons"),
:multiple => true,
:class => "form-control",
:style => "overflow-x: scroll;",
:size => 8,
:id => "selected_fields")
.col-md-1{:style => "padding: 10px"}
.spacer
.spacer
- t = _("Move selected fields to top")
%button.btn.btn-default.btn-block{:title => t,
:remote => true,
"data-submit" => 'column_lists',
"data-method" => :post}
%i.fa.fa-angle-double-up.fa-lg
- t = _("Move selected fields up")
%button.btn.btn-default.btn-block{:title => t,
:remote => true,
"data-submit" => 'column_lists',
"data-method" => :post}
%i.fa.fa-angle-up.fa-lg
- t = _("Move selected fields down")
%button.btn.btn-default.btn-block{:title => t,
:remote => true,
"data-submit" => 'column_lists',
"data-method" => :post}
%i.fa.fa-angle-down.fa-lg
- t = _("Move selected fields to bottom")
%button.btn.btn-default.btn-block{:title => t,
:remote => true,
"data-submit" => 'column_lists',
"data-method" => :post}
%i.fa.fa-angle-double-down
.spacer
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,7 @@
:get => %w(
download_data
download_summary_pdf
custom_buttons_in_set
edit
new
retrieve_distinct_instances_across_domains
Expand Down

0 comments on commit d141114

Please sign in to comment.