diff --git a/awx/ui/client/src/forms/Hosts.js b/awx/ui/client/src/forms/Hosts.js index 23df0f009d..0efc38c4b6 100644 --- a/awx/ui/client/src/forms/Hosts.js +++ b/awx/ui/client/src/forms/Hosts.js @@ -15,14 +15,23 @@ export default .value('HostForm', { addTitle: 'Create Host', - editTitle: '{{ name }}', + editTitle: '{{ host.name }}', name: 'host', well: false, formLabelSize: 'col-lg-3', formFieldSize: 'col-lg-9', - cancelButton: false, - showHeader: false, - + iterator: 'host', + headerFields:{ + enabled: { + class: 'Form-header-field', + ngClick: 'toggleHostEnabled(host)', + type: 'toggle', + editRequired: false, + awToolTip: "

Indicates if a host is available and should be included in running jobs.

For hosts that " + + "are part of an external inventory, this flag cannot be changed. It will be set by the inventory sync process.

", + dataTitle: 'Host Enabled', + } + }, fields: { name: { label: 'Host Name', @@ -45,19 +54,6 @@ export default addRequired: false, editRequired: false }, - enabled: { - label: 'Enabled?', - type: 'checkbox', - addRequired: false, - editRequired: false, - "default": true, - awPopOver: "

Indicates if a host is available and should be included in running jobs.

For hosts that " + - "are part of an external inventory, this flag cannot be changed. It will be set by the inventory sync process.

", - dataTitle: 'Host Enabled', - dataPlacement: 'right', - dataContainer: 'body', - ngDisabled: 'has_inventory_sources == true' - }, variables: { label: 'Variables', type: 'textarea', @@ -84,17 +80,15 @@ export default } }, - buttons: { //for now always generates - - -
-
-
- - -
-
- 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