diff --git a/awx/ui/client/src/inventories/manage/manage-hosts/directive/manage-hosts.directive.controller.js b/awx/ui/client/src/inventories/manage/manage-hosts/directive/manage-hosts.directive.controller.js
deleted file mode 100644
index 2940bf810c..0000000000
--- a/awx/ui/client/src/inventories/manage/manage-hosts/directive/manage-hosts.directive.controller.js
+++ /dev/null
@@ -1,198 +0,0 @@
-/*************************************************
- * Copyright (c) 2016 Ansible, Inc.
- *
- * All Rights Reserved
- *************************************************/
-
-function manageHostsDirectiveController($rootScope, $location, $log, $stateParams, $state, $scope, Rest, Alert, HostForm,
- GenerateForm, Prompt, ProcessErrors, GetBasePath, HostsReload, ParseTypeChange, Wait,
- Find, SetStatus, ApplyEllipsis, ToJSON, ParseVariableString, CreateDialog, TextareaResize, ParamPass) {
-
- var vm = this;
-
- var params = ParamPass.get();
- if (params === undefined) {
- params = {};
- params.host_scope = $scope.$new();
- params.group_scope = $scope.$new();
- }
- var parent_scope = params.host_scope,
- group_scope = params.group_scope,
- inventory_id = $stateParams.inventory_id,
- mode = $state.current.data.mode, // 'add' or 'edit'
- selected_group_id = params.selected_group_id,
- generator = GenerateForm,
- form = HostForm,
- defaultUrl,
- scope = parent_scope.$new(),
- master = {},
- relatedSets = {},
- url, form_scope;
-
- var host_id = $stateParams.host_id || undefined;
- var hostName = '';
- form_scope =
- generator.inject(HostForm, {
- mode: mode,
- id: 'host-panel-form',
- related: false,
- scope: scope,
- });
- generator.reset();
- // Retrieve detail record and prepopulate the form
- if (mode === 'edit') {
- defaultUrl = GetBasePath('hosts') + host_id + '/';
- Rest.setUrl(defaultUrl);
- Rest.get()
- .success(function(data) {
- vm.hostName = data.name;
- var set, fld, related;
- for (fld in form.fields) {
- if (data[fld]) {
- scope[fld] = data[fld];
- master[fld] = scope[fld];
- }
- }
- related = data.related;
- for (set in form.related) {
- if (related[set]) {
- relatedSets[set] = {
- url: related[set],
- iterator: form.related[set].iterator
- };
- }
- }
- scope.variable_url = data.related.variable_data;
- scope.has_inventory_sources = data.has_inventory_sources;
- scope.parseType = 'yaml';
- ParseTypeChange({
- scope: scope,
- field_id: 'host_variables',
- });
-
- })
- .error(function(data, status) {
- ProcessErrors(parent_scope, data, status, form, {
- hdr: 'Error!',
- msg: 'Failed to retrieve host: ' + host_id + '. GET returned status: ' + status
- });
- });
- } else {
- if (selected_group_id) {
- // adding hosts to a group
- url = GetBasePath('groups') + selected_group_id + '/';
- } else {
- // adding hosts to the top-level (inventory)
- url = GetBasePath('inventory') + inventory_id + '/';
- }
- // Add mode
- Rest.setUrl(url);
- Rest.get()
- .success(function(data) {
- scope.has_inventory_sources = data.has_inventory_sources;
- scope.enabled = true;
- scope.variables = '---';
- defaultUrl = data.related.hosts;
- scope.parseType = 'yaml';
- ParseTypeChange({
- scope: scope,
- field_id: 'host_variables',
- });
- scope.parseType = 'yaml';
- ParseTypeChange({
- scope: scope,
- field_id: 'host_variables',
- });
-
- })
- .error(function(data, status) {
- ProcessErrors(parent_scope, data, status, form, {
- hdr: 'Error!',
- msg: 'Failed to retrieve group: ' + selected_group_id + '. GET returned status: ' + status
- });
- });
- }
-
- if (scope.removeSaveCompleted) {
- scope.removeSaveCompleted();
- }
- scope.removeSaveCompleted = scope.$on('saveCompleted', function() {
- Wait('stop');
- try {
- $('#host-modal-dialog').dialog('close');
- } catch (err) {
- // ignore
- }
- if (group_scope && group_scope.refreshHosts) {
- group_scope.refreshHosts();
- }
- if (parent_scope.refreshHosts) {
- parent_scope.refreshHosts();
- }
- scope.$destroy();
- $state.go('inventoryManage', {}, {
- reload: true
- });
- });
-
- // Save changes to the parent
- var saveHost = function() {
- Wait('start');
- var fld, data = {};
-
- try {
- data.variables = ToJSON(scope.parseType, scope.variables, true);
- for (fld in form.fields) {
- data[fld] = scope[fld];
- }
- data.inventory = inventory_id;
- Rest.setUrl(defaultUrl);
- if (mode === 'edit') {
- Rest.put(data)
- .success(function() {
- scope.$emit('saveCompleted');
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, form, {
- hdr: 'Error!',
- msg: 'Failed to update host: ' + host_id + '. PUT returned status: ' + status
- });
- });
- } else {
- Rest.post(data)
- .success(function() {
- scope.$emit('saveCompleted');
- })
- .error(function(data, status) {
- ProcessErrors(scope, data, status, form, {
- hdr: 'Error!',
- msg: 'Failed to create host. POST returned status: ' + status
- });
- });
- }
- } catch (e) {
- // ignore. ToJSON will have already alerted the user
- }
- };
-
- var cancelPanel = function() {
- scope.$destroy();
- if (scope.codeMirror) {
- scope.codeMirror.destroy();
- }
- $state.go('inventoryManage');
- };
-
- angular.extend(vm, {
- cancelPanel: cancelPanel,
- saveHost: saveHost,
- mode: mode,
- hostName: hostName
- });
-}
-
-export default ['$rootScope', '$location', '$log', '$stateParams', '$state', '$scope', 'Rest', 'Alert', 'HostForm',
- 'GenerateForm', 'Prompt', 'ProcessErrors', 'GetBasePath', 'HostsReload', 'ParseTypeChange',
- 'Wait', 'Find', 'SetStatus', 'ApplyEllipsis', 'ToJSON', 'ParseVariableString',
- 'CreateDialog', 'TextareaResize', 'ParamPass', manageHostsDirectiveController
-];
diff --git a/awx/ui/client/src/inventories/manage/manage-hosts/directive/manage-hosts.directive.js b/awx/ui/client/src/inventories/manage/manage-hosts/directive/manage-hosts.directive.js
deleted file mode 100644
index ac10ea1dfd..0000000000
--- a/awx/ui/client/src/inventories/manage/manage-hosts/directive/manage-hosts.directive.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/*************************************************
- * Copyright (c) 2015 Ansible, Inc.
- *
- * All Rights Reserved
- *************************************************/
-
-/* jshint unused: vars */
-import manageHostsDirectiveController from './manage-hosts.directive.controller';
-
-export default ['templateUrl', 'ParamPass',
- function(templateUrl, ParamPass) {
- return {
- restrict: 'EA',
- scope: true,
- replace: true,
- templateUrl: templateUrl('inventories/manage/manage-hosts/directive/manage-hosts.directive'),
- link: function(scope, element, attrs) {
-
- },
- controller: manageHostsDirectiveController,
- controllerAs: 'vm',
- bindToController: true
- };
- }
-];
diff --git a/awx/ui/client/src/inventories/manage/manage-hosts/directive/manage-hosts.directive.partial.html b/awx/ui/client/src/inventories/manage/manage-hosts/directive/manage-hosts.directive.partial.html
deleted file mode 100644
index 16bb9e16ac..0000000000
--- a/awx/ui/client/src/inventories/manage/manage-hosts/directive/manage-hosts.directive.partial.html
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/awx/ui/client/src/inventories/manage/manage-hosts/main.js b/awx/ui/client/src/inventories/manage/manage-hosts/main.js
index e90954f2de..90d5cf3e70 100644
--- a/awx/ui/client/src/inventories/manage/manage-hosts/main.js
+++ b/awx/ui/client/src/inventories/manage/manage-hosts/main.js
@@ -1,16 +1,16 @@
/*************************************************
- * Copyright (c) 2015 Ansible, Inc.
+ * Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
-import route from './manage-hosts.route';
-import manageHostsDirective from './directive/manage-hosts.directive';
+import {ManageHostsAdd, ManageHostsEdit} from './manage-hosts.route';
+import service from './manage-hosts.service';
export default
- angular.module('manage-hosts', [])
- .directive('manageHosts', manageHostsDirective)
- .run(['$stateExtender', function($stateExtender) {
- $stateExtender.addState(route.edit);
- $stateExtender.addState(route.add);
- }]);
+ angular.module('manageHosts', [])
+ .service('ManageHostsService', service)
+ .run(['$stateExtender', function($stateExtender){
+ $stateExtender.addState(ManageHostsAdd);
+ $stateExtender.addState(ManageHostsEdit);
+ }]);
diff --git a/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts-add.controller.js b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts-add.controller.js
new file mode 100644
index 0000000000..0cad2dc9fa
--- /dev/null
+++ b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts-add.controller.js
@@ -0,0 +1,42 @@
+/*************************************************
+ * Copyright (c) 2016 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+ export default
+ ['$state', '$stateParams', '$scope', 'HostForm', 'ParseTypeChange', 'GenerateForm', 'ManageHostsService',
+ function($state, $stateParams, $scope, HostForm, ParseTypeChange, GenerateForm, ManageHostsService){
+ var generator = GenerateForm,
+ form = HostForm;
+ $scope.parseType = 'yaml';
+ $scope.extraVars = '---';
+ $scope.formCancel = function(){
+ $state.go('^', null, {reload: true});
+ };
+ $scope.toggleEnabled = function(){
+ $scope.host.enabled = !$scope.host.enabled;
+ };
+ $scope.formSave = function(){;
+ var params = {
+ variables: $scope.extraVars === '---' || $scope.extraVars === '{}' ? null : $scope.extraVars,
+ name: $scope.name,
+ description: $scope.description,
+ enabled: $scope.host.enabled,
+ inventory: $stateParams.inventory_id
+ };
+ ManageHostsService.post(params).then(function(res){
+ $state.go('^', null, {reload: true});
+ });
+ };
+ var init = function(){
+ $scope.host = {enabled: true};
+ generator.inject(form, {mode: 'add', related: false, id: 'Inventory-hostManage--panel', scope: $scope});
+ ParseTypeChange({
+ scope: $scope,
+ field_id: 'host_variables',
+ variable: 'extraVars',
+ });
+ };
+ init();
+ }];
\ No newline at end of file
diff --git a/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts-edit.controller.js b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts-edit.controller.js
new file mode 100644
index 0000000000..b8322fbdf2
--- /dev/null
+++ b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts-edit.controller.js
@@ -0,0 +1,45 @@
+/*************************************************
+ * Copyright (c) 2016 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+ export default
+ ['$state', '$stateParams', '$scope', 'HostForm', 'ParseTypeChange', 'GenerateForm', 'ManageHostsService', 'host',
+ function($state, $stateParams, $scope, HostForm, ParseTypeChange, GenerateForm, ManageHostsService, host){
+ var generator = GenerateForm,
+ form = HostForm;
+ $scope.parseType = 'yaml';
+ $scope.formCancel = function(){
+ $state.go('^', null, {reload: true});
+ };
+ $scope.toggleHostEnabled = function(){
+ $scope.host.enabled = !$scope.host.enabled;
+ };
+ $scope.formSave = function(){
+ var host = {
+ id: $scope.host.id,
+ variables: $scope.extraVars === '---' || $scope.extraVars === '{}' ? null : $scope.extraVars,
+ name: $scope.name,
+ description: $scope.description,
+ enabled: $scope.host.enabled
+ };
+ ManageHostsService.put(host).then(function(res){
+ $state.go('^', null, {reload: true});
+ });
+ };
+ var init = function(){
+ $scope.host = host;
+ $scope.extraVars = host.variables === '' ? '---' : host.variables;
+ generator.inject(form, {mode: 'edit', related: false, id: 'Inventory-hostManage--panel', scope: $scope});
+ $scope.extraVars = $scope.host.variables === '' ? '---' : $scope.host.variables;
+ $scope.name = host.name;
+ $scope.description = host.description;
+ ParseTypeChange({
+ scope: $scope,
+ field_id: 'host_variables',
+ variable: 'extraVars',
+ });
+ };
+ init();
+ }];
\ No newline at end of file
diff --git a/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.partial.html b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.partial.html
index f145702511..78a73ed50a 100644
--- a/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.partial.html
+++ b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.partial.html
@@ -1,5 +1,4 @@
diff --git a/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.route.js b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.route.js
index 8e97578aa5..670652c1c7 100644
--- a/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.route.js
+++ b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.route.js
@@ -3,44 +3,47 @@
*
* All Rights Reserved
*************************************************/
-import {
- templateUrl
-} from '../../../shared/template-url/template-url.factory';
+import {templateUrl} from '../../../shared/template-url/template-url.factory';
+import addController from './manage-hosts-add.controller';
+import editController from './manage-hosts-edit.controller';
-export default {
- edit: {
- name: 'inventoryManage.editHost',
- route: '/:host_id/editHost',
- templateUrl: templateUrl('inventories/manage/manage-hosts/manage-hosts'),
- data: {
- host_id: 'host_id',
- mode: 'edit'
- },
- ncyBreadcrumb: {
- label: "INVENTORY EDIT HOSTS"
- },
- resolve: {
- features: ['FeaturesService', function(FeaturesService) {
- return FeaturesService.get();
- }]
- }
+var ManageHostsEdit = {
+ name: 'inventoryManage.editHost',
+ route: '/host/:host_id',
+ controller: editController,
+ templateUrl: templateUrl('inventories/manage/manage-hosts/manage-hosts'),
+ ncyBreadcrumb: {
+ label: "INVENTORY EDIT HOSTS"
},
-
- add: {
- name: 'inventoryManage.addHost',
- route: '/addHost',
- templateUrl: templateUrl('inventories/manage/manage-hosts/manage-hosts'),
- data: {
- mode: 'add'
- },
- ncyBreadcrumb: {
- label: "INVENTORY ADD HOST"
- },
- resolve: {
- features: ['FeaturesService', function(FeaturesService) {
- return FeaturesService.get();
- }]
- }
+ data: {
+ mode: 'edit'
},
-
+ resolve: {
+ features: ['FeaturesService', function(FeaturesService) {
+ return FeaturesService.get();
+ }],
+ host: ['$stateParams', 'ManageHostsService', function($stateParams, ManageHostsService){
+ return ManageHostsService.get({id: $stateParams.host_id}).then(function(res){
+ return res.data.results[0];
+ });
+ }]
+ }
};
+var ManageHostsAdd = {
+ name: 'inventoryManage.addHost',
+ route: '/host/add',
+ controller: addController,
+ templateUrl: templateUrl('inventories/manage/manage-hosts/manage-hosts'),
+ ncyBreadcrumb: {
+ label: "INVENTORY ADD HOST"
+ },
+ data: {
+ mode: 'add'
+ },
+ resolve: {
+ features: ['FeaturesService', function(FeaturesService) {
+ return FeaturesService.get();
+ }]
+ }
+};
+export {ManageHostsAdd, ManageHostsEdit};
diff --git a/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.service.js b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.service.js
new file mode 100644
index 0000000000..c7a64cb60d
--- /dev/null
+++ b/awx/ui/client/src/inventories/manage/manage-hosts/manage-hosts.service.js
@@ -0,0 +1,53 @@
+/*************************************************
+ * Copyright (c) 2016 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+ export default
+ ['$rootScope', 'Rest', 'GetBasePath', 'ProcessErrors',
+ function($rootScope, Rest, GetBasePath, ProcessErrors){
+ return {
+ stringifyParams: function(params){
+ return _.reduce(params, (result, value, key) => {
+ return result + key + '=' + value + '&';
+ }, '');
+ },
+ get: function(params){
+ var url = GetBasePath('hosts') + '?' + this.stringifyParams(params);
+ Rest.setUrl(url);
+ return Rest.get()
+ .success(function(res){
+ return res;
+ })
+ .error(function(data, status) {
+ ProcessErrors($rootScope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + '. GET returned: ' + status });
+ });
+ },
+ post: function(params){
+ var url = GetBasePath('hosts');
+ Rest.setUrl(url);
+ return Rest.post(params)
+ .success(function(res){
+ return res;
+ })
+ .error(function(data, status) {
+ ProcessErrors($rootScope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + '. GET returned: ' + status });
+ });
+ },
+ put: function(host){
+ var url = GetBasePath('hosts') + host.id;
+ Rest.setUrl(url);
+ return Rest.put(host)
+ .success(function(res){
+ return res;
+ })
+ .error(function(data, status) {
+ ProcessErrors($rootScope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + '. GET returned: ' + status });
+ });
+ }
+ };
+ }];
\ No newline at end of file