Skip to content

Commit

Permalink
Change reconfigure setup to include values configured with originally
Browse files Browse the repository at this point in the history
  • Loading branch information
eclarizio committed Jun 28, 2018
1 parent b391af1 commit 88ba5f9
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
ManageIQ.angular.app.controller('dialogUserReconfigureController', ['API', 'dialogFieldRefreshService', 'miqService', 'resourceActionId', 'targetId', function(API, dialogFieldRefreshService, miqService, resourceActionId, targetId) {
var vm = this;

vm.$onInit = function() {
var apiCall = new Promise(function(resolve) {
var url = '/api/services/' + targetId +
'?attributes=reconfigure_dialog';

resolve(API.get(url).then(init));
});

Promise.resolve(apiCall).then(miqService.refreshSelectpicker);
};

function init(data) {
vm.dialogId = data.reconfigure_dialog[0].id;
vm.dialog = data.reconfigure_dialog[0];
vm.dialogLoaded = true;
}

vm.refreshField = refreshField;
vm.setDialogData = setDialogData;
vm.refreshUrl = '/api/service_dialogs/';

vm.submitButtonClicked = submitButtonClicked;
vm.cancelClicked = cancelClicked;
vm.saveable = saveable;
vm.isValid = false;

function refreshField(field) {
var idList = {
dialogId: vm.dialogId,
resourceActionId: resourceActionId,
targetId: targetId,
targetType: "service"
};

return dialogFieldRefreshService.refreshField(vm.dialogData, [field.name], vm.refreshUrl, idList);
}

function setDialogData(data) {
vm.isValid = data.validations.isValid;
vm.dialogData = data.data;
}

function submitButtonClicked() {
miqService.sparkleOn();

var apiData = {action: 'reconfigure', resource: _.omit(vm.dialogData, 'action')};
var apiSubmitEndpoint = '/api/services/' + targetId;

return API.post(apiSubmitEndpoint, apiData, {skipErrors: [400]}).then(function() {
miqService.redirectBack(__('Order Request was Submitted'), 'info', '/service/explorer');
}).catch(function(err) {
miqService.sparkleOff();
var fullErrorMessage = err.data.error.message;
var allErrorMessages = fullErrorMessage.split('-')[1].split(',');
clearFlash();
_.forEach(allErrorMessages, (function(errorMessage) {
add_flash(errorMessage, 'error');
}));
console.log(err);
return Promise.reject(err);
});
}

function cancelClicked(_event) {
miqService.redirectBack(__('Dialog Cancelled'), 'info', '/service/explorer');
}

function saveable() {
return vm.isValid && ! dialogFieldRefreshService.areFieldsBeingRefreshed;
}
}]);
3 changes: 3 additions & 0 deletions app/controllers/application_controller/dialog_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@ def dialog_reset_form
def dialog_initialize(ra, options)
@edit = {}
@edit[:new] = options[:dialog] || {}

opts = {
:target => options[:target_kls].constantize.find_by_id(options[:target_id])
}
opts[:reconfigure] = true if options[:dialog_mode] == :reconfigure

@edit[:wf] = ResourceActionWorkflow.new(@edit[:new], current_user, ra, opts)
@record = Dialog.find_by_id(ra.dialog_id.to_i)
@edit[:rec_id] = @record.id
Expand Down
28 changes: 12 additions & 16 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,13 @@ def service_edit

def service_reconfigure
@explorer = true
s = Service.find_by_id(params[:id])
st = s.service_template
ra = st.resource_actions.find_by_action('Reconfigure') if st
if ra && ra.dialog_id
@right_cell_text = _("Reconfigure Service \"%{name}\"") % {:name => st.name}
options = {
:header => @right_cell_text,
:target_id => s.id,
:target_kls => s.class.name,
:dialog => s.options[:dialog],
:dialog_mode => :reconfigure,
:dialog_locals => DialogLocalService.new.determine_dialog_locals_for_service_reconfiguration(ra, s)
}
dialog_initialize(ra, options)
end
service = Service.find_by_id(params[:id])
service_template = service.service_template
resource_action = service_template.resource_actions.find_by_action('Reconfigure') if service_template

@right_cell_text = _("Reconfigure Service \"%{name}\"") % {:name => service_template.name}
dialog_locals = {:resource_action_id => resource_action.id, :target_id => service.id}
replace_right_cell(:action => "reconfigure_dialog", :dialog_locals => dialog_locals)
end

def service_form_fields
Expand Down Expand Up @@ -377,6 +369,10 @@ def set_right_cell_vars(action)
partial = "shared/views/retire"
header = _("Set/Remove retirement date for Service")
action = "retire"
when "reconfigure_dialog"
partial = "shared/dialogs/reconfigure_dialog"
header = @right_cell_text
action = nil
when "service_edit"
partial = "service_form"
header = _("Editing Service \"%{name}\"") % {:name => @service.name}
Expand Down Expand Up @@ -425,7 +421,7 @@ def replace_right_cell(options = {})
# Replace right cell divs
presenter.update(
:main_div,
if %w(dialog_provision ownership retire service_edit tag service_tag).include?(action)
if %w(dialog_provision ownership retire service_edit tag service_tag reconfigure_dialog).include?(action)
r[:partial => partial, :locals => options[:dialog_locals]]
elsif params[:display]
r[:partial => 'layouts/x_gtl', :locals => {:controller => "vm", :action_url => @lastaction}]
Expand Down
14 changes: 0 additions & 14 deletions app/services/dialog_local_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ class DialogLocalService
Vm
).freeze

def determine_dialog_locals_for_service_reconfiguration(resource_action, target)
{
:resource_action_id => resource_action.id,
:target_id => target.id,
:target_type => "service",
:dialog_id => resource_action.dialog_id,
:force_old_dialog_use => false,
:api_submit_endpoint => "/api/services/#{target.id}",
:api_action => "reconfigure",
:finish_submit_endpoint => "/service/explorer",
:cancel_endpoint => "/service/explorer"
}
end

def determine_dialog_locals_for_svc_catalog_provision(resource_action, target, finish_submit_endpoint)
api_submit_endpoint = "/api/service_catalogs/#{target.service_template_catalog_id}/service_templates/#{target.id}"

Expand Down
25 changes: 25 additions & 0 deletions app/views/shared/dialogs/_reconfigure_dialog.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#main_div
.row.wrapper{"ng-controller" => "dialogUserReconfigureController as vm"}
.spinner{'ng-show' => "!vm.dialogLoaded"}
.col-md-12.col-lg-12{'ng-if' => 'vm.dialog'}
%dialog-user{"dialog" =>"vm.dialog", "refresh-field" => "vm.refreshField(field)", "on-update" => "vm.setDialogData(data)"}
.clearfix
.pull-right.button-group{'ng-show' => "vm.dialogLoaded"}
%miq-button{:name => t = _("Submit"),
:title => t,
:alt => t,
:enabled => 'vm.saveable()',
'on-click' => "vm.submitButtonClicked()",
:primary => 'true'}
%miq-button{:name => t = _("Cancel"),
:title => t,
:alt => t,
:enabled => 'true',
'on-click' => "vm.cancelClicked($event)"}
:javascript
ManageIQ.angular.app.value('resourceActionId', '#{resource_action_id}');
ManageIQ.angular.app.value('targetId', '#{target_id}');
miq_bootstrap('.wrapper');
29 changes: 29 additions & 0 deletions spec/controllers/service_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@
service
end

describe "#service_reconfigure" do
let(:service) { instance_double("Service", :id => 321, :service_template => service_template) }
let(:service_template) { instance_double("ServiceTemplate", :name => "the name") }
let(:ar_association_dummy) { double }
let(:resource_action) { instance_double("ResourceAction", :id => 123) }

before do
allow(Service).to receive(:find_by_id).with(321).and_return(service)
allow(service_template).to receive(:resource_actions).and_return(ar_association_dummy)
allow(ar_association_dummy).to receive(:find_by_action).with('Reconfigure').and_return(resource_action)
allow(controller).to receive(:replace_right_cell)
controller.instance_variable_set(:@_params, {:id => 321})
end

it "sets the right cell text" do
controller.send(:service_reconfigure)
expect(controller.instance_variable_get(:@right_cell_text)).to eq("Reconfigure Service \"the name\"")
end

it "replaces the right cell with the reconfigure dialog partial" do
expect(controller).to receive(:replace_right_cell).with(
:action => "reconfigure_dialog",
:dialog_locals => {:resource_action_id => 123, :target_id => 321}
)

controller.send(:service_reconfigure)
end
end

describe "#service_delete" do
it "display flash message with description of deleted Service" do
st = FactoryGirl.create(:service_template)
Expand Down
19 changes: 0 additions & 19 deletions spec/services/dialog_local_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
describe DialogLocalService do
let(:service) { described_class.new }

describe "#determine_dialog_locals_for_service_reconfiguration" do
let(:target) { instance_double("Service", :id => 123) }
let(:resource_action) { instance_double("ResourceAction", :id => 456, :dialog_id => 654) }

it "returns a hash" do
expect(service.determine_dialog_locals_for_service_reconfiguration(resource_action, target)).to eq(
:resource_action_id => 456,
:target_id => 123,
:target_type => "service",
:dialog_id => 654,
:force_old_dialog_use => false,
:api_submit_endpoint => "/api/services/123",
:api_action => "reconfigure",
:finish_submit_endpoint => "/service/explorer",
:cancel_endpoint => "/service/explorer"
)
end
end

describe "#determine_dialog_locals_for_svc_catalog_provision" do
let(:resource_action) { instance_double("ResourceAction", :id => 456, :dialog_id => 654) }
let(:target) { instance_double("ServiceTemplate", :class => ServiceTemplate, :id => 321, :service_template_catalog_id => 123) }
Expand Down

0 comments on commit 88ba5f9

Please sign in to comment.