forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ManageIQ#2828 from gildub/subnet-component
CloudSubnet: Convert Controller to Component
- Loading branch information
Showing
9 changed files
with
358 additions
and
274 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
app/assets/javascripts/components/cloud_subnet/cloud-subnet-form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
ManageIQ.angular.app.component('cloudSubnetForm', { | ||
bindings: { | ||
cloudSubnetFormId: '@', | ||
}, | ||
controllerAs: 'vm', | ||
controller: cloudSubnetFormController, | ||
templateUrl: '/static/cloud_subnet/cloud-subnet-form.html.haml', | ||
}); | ||
|
||
cloudSubnetFormController.$inject = ['API', 'miqService']; | ||
|
||
function cloudSubnetFormController(API, miqService) { | ||
var vm = this; | ||
|
||
this.$onInit = function() { | ||
vm.afterGet = false; | ||
|
||
vm.cloudSubnetModel = { name: '' }; | ||
vm.networkProtocols = ['ipv4', 'ipv6']; | ||
|
||
vm.formId = vm.cloudSubnetFormId; | ||
vm.model = 'cloudSubnetModel'; | ||
ManageIQ.angular.scope = vm; | ||
vm.saveable = miqService.saveable; | ||
|
||
vm.newRecord = vm.cloudSubnetFormId === 'new'; | ||
|
||
miqService.sparkleOn(); | ||
if (vm.newRecord) { | ||
vm.cloudSubnetModel.ems_id = ''; | ||
vm.cloudSubnetModel.network_id = ''; | ||
vm.cloudSubnetModel.dhcp_enabled = true; | ||
vm.cloudSubnetModel.network_protocol = 'ipv4'; | ||
API.get("/api/providers?expand=resources&attributes=name&filter[]=type='*NetworkManager'").then(function(data) { | ||
vm.available_ems = data.resources; | ||
vm.afterGet = true; | ||
vm.modelCopy = angular.copy( vm.cloudSubnetModel ); | ||
miqService.sparkleOff(); | ||
}).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, _.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(); | ||
}).catch(miqService.handleFailure); | ||
} | ||
}; | ||
|
||
vm.addClicked = function() { | ||
var url = 'create/new?button=add'; | ||
miqService.miqAjaxButton(url, vm.cloudSubnetModel, { complete: false }); | ||
}; | ||
|
||
vm.cancelClicked = function() { | ||
var url = ''; | ||
if (vm.newRecord) { | ||
url = '/cloud_subnet/create/new?button=cancel'; | ||
} else { | ||
url = '/cloud_subnet/update/' + vm.cloudSubnetFormId + '?button=cancel'; | ||
} | ||
miqService.miqAjaxButton(url); | ||
}; | ||
|
||
vm.saveClicked = function() { | ||
var url = '/cloud_subnet/update/' + vm.cloudSubnetFormId + '?button=save'; | ||
miqService.miqAjaxButton(url, vm.cloudSubnetModel, { complete: false }); | ||
}; | ||
|
||
vm.resetClicked = function(angularForm) { | ||
vm.cloudSubnetModel = angular.copy( vm.modelCopy ); | ||
angularForm.$setPristine(true); | ||
miqService.miqFlash("warn", _('All changes have been reset')); | ||
}; | ||
|
||
vm.filterNetworkManagerChanged = function(id) { | ||
if (id) { | ||
API.get("/api/cloud_networks?expand=resources&attributes=name,ems_ref&filter[]=ems_id=" + id).then(function(data) { | ||
vm.available_networks = data.resources; | ||
}).catch(miqService.handleFailure); | ||
miqService.getProviderTenants(function(data) { | ||
vm.available_tenants = data.resources; | ||
})(id); | ||
} | ||
}; | ||
} |
89 changes: 0 additions & 89 deletions
89
app/assets/javascripts/controllers/cloud_subnet/cloud_subnet_form_controller.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,6 @@ | ||
%form#form_div{"name" => "angularForm", | ||
"form-changed" => true, | ||
"miq-form" => true, | ||
"model" => "vm.cloudSubnetModel", | ||
"model-copy" => "vm.modelCopy", | ||
"ng-cloak" => "", | ||
"ng-controller" => "cloudSubnetFormController as vm", | ||
"ng-show" => "vm.afterGet"} | ||
= render :partial => "layouts/flash_msg" | ||
%h3 | ||
= _('Network Provider') | ||
.form-horizontal | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('Network Manager') | ||
.col-md-8 | ||
%input.form-control{"type" => "text", | ||
"name" => "ems_name", | ||
"ng-model" => "vm.cloudSubnetModel.ems_name", | ||
"ng-maxlength" => 128, | ||
"readonly" => true} | ||
%h3 | ||
= _('Placement') | ||
.form-horizontal | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('Cloud Tenant') | ||
.col-md-8 | ||
%input.form-control{"type" => "text", | ||
"name" => "tenant_name", | ||
"ng-model" => "vm.cloudSubnetModel.tenant_name", | ||
"ng-maxlength" => 128, | ||
"readonly" => true} | ||
%h3 | ||
= _('Cloud Subnet details') | ||
.form-horizontal | ||
.form-group | ||
%label.col-md-2.control-label | ||
= _('Network') | ||
.col-md-8 | ||
%input.form-control{"type" => "text", | ||
"name" => "network_name", | ||
"ng-model" => "vm.cloudSubnetModel.network_name", | ||
"ng-maxlength" => 128, | ||
"readonly" => true} | ||
= render :partial => "common_new_edit" | ||
= render :partial => "layouts/angular/generic_form_buttons" | ||
= render :partial => "layouts/flash_msg" | ||
|
||
%cloud-subnet-form{'cloud-subnet-form-id' => @subnet.id} | ||
|
||
:javascript | ||
ManageIQ.angular.app.value('cloudSubnetFormId', '#{@subnet.id}'); | ||
miq_bootstrap('#form_div'); | ||
miq_bootstrap('cloud-subnet-form'); |
Oops, something went wrong.