Skip to content

Commit

Permalink
filter data on get; optimized #update in ctrl
Browse files Browse the repository at this point in the history
  • Loading branch information
gildub committed Jul 16, 2018
1 parent 8f8824b commit fd10dfb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function cloudSubnetFormController(API, miqService) {
}).catch(miqService.handleFailure);
} else {
API.get("/api/cloud_subnets/" + vm.cloudSubnetFormId + "?expand=resources&attributes=ext_management_system.name,cloud_tenant.name,cloud_network.name").then(function(data) {
Object.assign(vm.cloudSubnetModel, data);
Object.assign(vm.cloudSubnetModel, _.pick(data, 'name', 'ext_management_system', 'cloud_network', 'cloud_tenant', 'network_protocol', 'cidr', 'dhcp_enabled', 'gateway'));
vm.afterGet = true;
vm.modelCopy = angular.copy( vm.cloudSubnetModel );
miqService.sparkleOff();
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/cloud_subnet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ def edit
def update
assert_privileges("cloud_subnet_edit")
@subnet = find_record_with_rbac(CloudSubnet, params[:id])
options = changed_form_params
case params[:button]
when "cancel"
cancel_action(_("Edit of Subnet \"%{name}\" was cancelled by the user") % {:name => @subnet.name})

when "save"
if @subnet.supports_create?
options = changed_form_params
task_id = @subnet.update_cloud_subnet_queue(session[:userid], options)

if task_id.kind_of?(Integer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ describe('cloud-subnet-form', function() {
spyOn(miqService, 'miqAjaxButton');

var cloudSubnetFormResponse = {
name: 'abc',
gateway_ip: '172.10.1.1'
name: 'abc'
};

spyOn(API, 'get').and.callFake(function() {
Expand Down Expand Up @@ -76,13 +75,13 @@ describe('cloud-subnet-form', function() {
});

it('sets vm.cloudSubnetModel.gateway_ip', function () {
expect(vm.cloudSubnetModel.gateway_ip).toBe('172.10.1.1');
expect(vm.cloudSubnetModel.gateway_ip).toBe(undefined);
});

it('updates a Cloud Subnet record', function () {

vm.cloudSubnetModel.name = 'xyz';
vm.cloudSubnetModel.gateway_ip = '172.10.1.1';
vm.cloudSubnetModel.gateway_ip = '172.10.1.2';
vm.saveClicked();

expect(miqService.miqAjaxButton).toHaveBeenCalledWith('/cloud_subnet/update/1111?button=save', vm.cloudSubnetModel, { complete: false });
Expand Down

0 comments on commit fd10dfb

Please sign in to comment.