diff --git a/awx/ui/client/src/inventories/hosts/edit/host-edit.controller.js b/awx/ui/client/src/inventories/hosts/edit/host-edit.controller.js index d1d1092085..250c65e4d7 100644 --- a/awx/ui/client/src/inventories/hosts/edit/host-edit.controller.js +++ b/awx/ui/client/src/inventories/hosts/edit/host-edit.controller.js @@ -1,14 +1,79 @@ /************************************************* - * Copyright (c) 2017 Ansible, Inc. + * Copyright (c) 2016 Ansible, Inc. * * All Rights Reserved *************************************************/ -function HostsEdit($scope) { + export default + ['$scope', '$state', '$stateParams', 'DashboardHostsForm', 'GenerateForm', 'ParseTypeChange', 'DashboardHostService', 'host', + function($scope, $state, $stateParams, DashboardHostsForm, GenerateForm, ParseTypeChange, DashboardHostService, host){ + $scope.parseType = 'yaml'; + $scope.formCancel = function(){ + $state.go('^', null, {reload: true}); + }; + $scope.toggleHostEnabled = function(){ + if ($scope.host.has_inventory_sources){ + return; + } + $scope.host.enabled = !$scope.host.enabled; + }; + $scope.toggleEnabled = function(){ + $scope.host.enabled = !$scope.host.enabled; + }; + $scope.formSave = function(){ + var host = { + id: $scope.host.id, + variables: $scope.variables === '---' || $scope.variables === '{}' ? null : $scope.variables, + name: $scope.name, + description: $scope.description, + enabled: $scope.host.enabled + }; + DashboardHostService.putHost(host).then(function(){ + $state.go('^', null, {reload: true}); + }); - console.log('inside host edit'); + }; + var init = function(){ + $scope.host = host.data; + $scope.name = host.data.name; + $scope.description = host.data.description; + $scope.variables = getVars(host.data.variables); + ParseTypeChange({ + scope: $scope, + field_id: 'host_variables', + variable: 'variables', + }); + }; -} + // Adding this function b/c sometimes extra vars are returned to the + // UI as a string (ex: "foo: bar"), and other times as a + // json-object-string (ex: "{"foo": "bar"}"). CodeMirror wouldn't know + // how to prettify the latter. The latter occurs when host vars were + // system generated and not user-input (such as adding a cloud host); + function getVars(str){ -export default ['$scope', HostsEdit -]; + // Quick function to test if the host vars are a json-object-string, + // by testing if they can be converted to a JSON object w/o error. + function IsJsonString(str) { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; + } + + if(str === ''){ + return '---'; + } + else if(IsJsonString(str)){ + str = JSON.parse(str); + return jsyaml.safeDump(str); + } + else if(!IsJsonString(str)){ + return str; + } + } + + init(); + }]; diff --git a/awx/ui/client/src/inventories/hosts/host.list.js b/awx/ui/client/src/inventories/hosts/host.list.js index ec70bb2716..cc1a1aa613 100644 --- a/awx/ui/client/src/inventories/hosts/host.list.js +++ b/awx/ui/client/src/inventories/hosts/host.list.js @@ -74,13 +74,6 @@ export default ['i18n', function(i18n) { fieldActions: { columnClass: 'col-lg-6 col-md-4 col-sm-4 col-xs-5 text-right', - copy: { - mode: 'all', - ngClick: "copyMoveHost(host.id)", - awToolTip: 'Copy or move host to another group', - dataPlacement: "top", - ngShow: 'host.summary_fields.user_capabilities.edit' - }, edit: { //label: 'Edit', ngClick: "editHost(host.id)", @@ -95,14 +88,6 @@ export default ['i18n', function(i18n) { awToolTip: 'View host', dataPlacement: 'top', ngShow: '!host.summary_fields.user_capabilities.edit' - }, - "delete": { - //label: 'Delete', - ngClick: "deleteHost(host.id, host.name)", - icon: 'icon-trash', - awToolTip: 'Delete host', - dataPlacement: 'top', - ngShow: 'host.summary_fields.user_capabilities.delete' } }, diff --git a/awx/ui/client/src/inventories/main.js b/awx/ui/client/src/inventories/main.js index 794cf76a5e..5ff397b7fd 100644 --- a/awx/ui/client/src/inventories/main.js +++ b/awx/ui/client/src/inventories/main.js @@ -80,6 +80,17 @@ angular.module('inventory', [ urls: { list: '/hosts' }, + resolve: { + edit: { + host: ['Rest', '$stateParams', 'GetBasePath', + function(Rest, $stateParams, GetBasePath) { + let path = GetBasePath('hosts') + $stateParams.host_id; + Rest.setUrl(path); + return Rest.get(); + } + ] + } + }, ncyBreadcrumb: { label: N_('HOSTS') },