1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-04 12:51:18 +03:00

Edit inventory properties on group tab starting to work

This commit is contained in:
chouseknecht 2013-08-08 18:13:50 -04:00
parent b73077b2f3
commit 8794da7cd1
3 changed files with 95 additions and 24 deletions

View File

@ -185,7 +185,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInit, Prompt,
OrganizationList, TreeInit, GetBasePath, GroupsList, GroupsAdd, GroupsEdit, LoadInventory,
GroupsDelete, HostsList, HostsAdd, HostsEdit, HostsDelete, RefreshGroupName, ParseTypeChange,
HostsReload)
HostsReload, EditInventory)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
@ -242,8 +242,8 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
scope.inventory_variables = "---";
}
});
LoadInventory({ scope: scope });
LoadInventory({ scope: scope, doPostSteps: true });
scope.filterInventory = function() {
RefreshTree({ scope: scope });
@ -347,6 +347,10 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
$location.path('/' + base + '/' + $routeParams.id + '/' + set + '/' + id);
};
scope.editInventory = function() {
EditInventory({ scope: scope, 'inventory_id': scope['inventory_id'] });
};
// Related set: Delete button
scope['delete'] = function(set, itm_id, name, title) {
$rootScope.flashMessage = null;
@ -384,7 +388,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
if (!scope.$$phase) {
scope.$digest();
}
InventoryEdit({ "inventory_id": id, group_id: null });
EditInventory({ scope: scope, "inventory_id": id });
}
},
addGroup: {
@ -542,6 +546,6 @@ InventoriesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$l
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInit', 'Prompt',
'OrganizationList', 'TreeInit', 'GetBasePath', 'GroupsList', 'GroupsAdd', 'GroupsEdit', 'LoadInventory',
'GroupsDelete', 'HostsList', 'HostsAdd', 'HostsEdit', 'HostsDelete', 'RefreshGroupName',
'ParseTypeChange', 'HostsReload'
'ParseTypeChange', 'HostsReload', 'EditInventory'
];

View File

@ -13,12 +13,10 @@ angular.module('InventoryFormDefinition', [])
addTitle: 'Create Inventory',
editTitle: '{{ inventory_name }}',
name: 'inventory',
well: true,
collapse: true,
collapseTitle: 'Edit Inventory',
collapseMode: 'edit',
twoColumns: true,
parseTypeName: 'inventoryParseType',
well: false,
formLabelSize: 'col-lg-3',
formFieldSize: 'col-lg-9',
fields: {
has_active_failures: {
@ -27,8 +25,7 @@ angular.module('InventoryFormDefinition', [])
'<i class="icon-exclamation-sign"></i> Failed jobs</div>',
type: 'custom',
ngShow: 'has_active_failures',
readonly: true,
column: 1
readonly: true
},
inventory_name: {
realName: 'name',
@ -36,8 +33,7 @@ angular.module('InventoryFormDefinition', [])
type: 'text',
addRequired: true,
editRequired: true,
capitalize: false,
column: 1
capitalize: false
},
inventory_description: {
realName: 'description',
@ -45,7 +41,6 @@ angular.module('InventoryFormDefinition', [])
type: 'text',
addRequired: false,
editRequired: false,
column: 1
},
organization: {
label: 'Organization',
@ -55,8 +50,7 @@ angular.module('InventoryFormDefinition', [])
addRequired: true,
editRequired: true,
ngClick: 'lookUpOrganization()',
awRequiredWhen: {variable: "organizationrequired", init: "true" },
column: 1
awRequiredWhen: {variable: "organizationrequired", init: "true" }
},
inventory_variables: {
realName: 'variables',
@ -76,8 +70,7 @@ angular.module('InventoryFormDefinition', [])
'<p>View YAML examples at <a href="http://www.ansibleworks.com/docs/YAMLSyntax.html" target="_blank">ansibleworks.com</a></p>',
dataTitle: 'Inventory Variables',
dataPlacement: 'bottom',
dataContainer: "body",
column: 2
dataContainer: '#form-modal .modal-content'
}
},

View File

@ -11,7 +11,7 @@
angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition',
'SearchHelper', 'PaginateHelper', 'ListGenerator', 'AuthService',
'InventoryHelper', 'RelatedSearchHelper', 'RelatedPaginateHelper',
'InventoryFormDefinition'
'InventoryFormDefinition', 'ParseHelper'
])
.factory('LoadTreeData', ['Alert', 'Rest', 'Authorization', '$http',
@ -227,12 +227,15 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
}
}
// Load the tree view
scope.TreeParams = { scope: scope, inventory: data };
scope.variable_url = data.related.variable_data;
scope.relatedSets['hosts'] = { url: data.related.hosts, iterator: 'host' };
RelatedSearchInit({ scope: scope, form: form, relatedSets: scope.relatedSets });
RelatedPaginateInit({ scope: scope, relatedSets: scope.relatedSets });
// Load the tree view
if (params.doPostSteps) {
RelatedSearchInit({ scope: scope, form: form, relatedSets: scope.relatedSets });
RelatedPaginateInit({ scope: scope, relatedSets: scope.relatedSets });
}
scope.$emit('inventoryLoaded');
})
.error( function(data, status, headers, config) {
@ -305,5 +308,76 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
LoadInventory({ scope: scope });
}
}]);
}])
.factory('EditInventory', ['InventoryForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LookUpInit', 'OrganizationList',
'GetBasePath', 'ParseTypeChange', 'LoadInventory',
function(InventoryForm, GenerateForm, Rest, Alert, ProcessErrors, LookUpInit, OrganizationList, GetBasePath, ParseTypeChange,
LoadInventory) {
return function(params) {
var generator = GenerateForm;
var form = InventoryForm;
var defaultUrl=GetBasePath('inventory');
var scope = params.scope
generator.inject(form, {mode: 'edit', modal: true, related: false});
ParseTypeChange(scope,'inventory_variables', 'inventoryParseType');
scope.inventoryParseType = 'yaml';
scope['inventory_id'] = params['inventory_id'];
scope.formModalActionLabel = 'Save';
scope.formModalCancelShow = true;
scope.formModalInfo = false;
$('#form-modal .btn-success').removeClass('btn-none').addClass('btn-success');
scope.formModalHeader = 'Inventory Properties';
// Retrieve each related set and any lookups
if (scope.inventoryLoadedRemove) {
scope.inventoryLoadedRemove();
}
scope.inventoryLoadedRemove = scope.$on('inventoryLoaded', function() {
LookUpInit({
scope: scope,
form: form,
current_item: (scope.organization !== undefined) ? scope.organization : null,
list: OrganizationList,
field: 'organization'
});
if (scope.variable_url) {
Rest.setUrl(scope.variable_url);
Rest.get()
.success( function(data, status, headers, config) {
if ($.isEmptyObject(data)) {
scope.inventory_variables = "---";
}
else {
scope.inventory_variables = jsyaml.safeDump(data);
}
})
.error( function(data, status, headers, config) {
scope.inventory_variables = null;
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to retrieve inventory variables. GET returned status: ' + status });
});
}
else {
scope.inventory_variables = "---";
}
if (!scope.$$phase) {
scope.$digest();
}
});
LoadInventory({ scope: scope, doPostSteps: false });
if (!scope.$$phase) {
scope.$digest();
}
}
}]);