1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 06:51:10 +03:00

fixes to edit->host and host list

removing the copy and delete icons from the top level host list,
as well as fixing the edit host view which was slightly bjorked.
This commit is contained in:
jaredevantabor 2017-04-06 14:02:58 -07:00 committed by Jared Tabor
parent 54a92b5b5e
commit 14ec5183d2
3 changed files with 82 additions and 21 deletions

View File

@ -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();
}];

View File

@ -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'
}
},

View File

@ -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')
},