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

View File

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

View File

@@ -11,7 +11,7 @@
angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition', angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition',
'SearchHelper', 'PaginateHelper', 'ListGenerator', 'AuthService', 'SearchHelper', 'PaginateHelper', 'ListGenerator', 'AuthService',
'InventoryHelper', 'RelatedSearchHelper', 'RelatedPaginateHelper', 'InventoryHelper', 'RelatedSearchHelper', 'RelatedPaginateHelper',
'InventoryFormDefinition' 'InventoryFormDefinition', 'ParseHelper'
]) ])
.factory('LoadTreeData', ['Alert', 'Rest', 'Authorization', '$http', .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.TreeParams = { scope: scope, inventory: data };
scope.variable_url = data.related.variable_data; scope.variable_url = data.related.variable_data;
scope.relatedSets['hosts'] = { url: data.related.hosts, iterator: 'host' }; 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'); scope.$emit('inventoryLoaded');
}) })
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
@@ -305,5 +308,76 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
LoadInventory({ scope: scope }); 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();
}
}
}]);