Group and Host variables working.

This commit is contained in:
chouseknecht
2013-05-21 16:13:20 -04:00
parent c238a85581
commit 53212da149
5 changed files with 178 additions and 111 deletions

View File

@@ -166,25 +166,45 @@ function GroupsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
// Save // Save
scope.formSave = function() { scope.formSave = function() {
Rest.setUrl(defaultUrl); try {
var data = {} // Make sure we have valid JSON
for (var fld in form.fields) { var myjson = JSON.parse(scope.variables);
data[fld] = scope[fld];
}
if ($routeParams.inventory_id) { var data = {}
data['inventory'] = $routeParams.inventory_id; for (var fld in form.fields) {
} if (fld != 'variables') {
data[fld] = scope[fld];
}
}
Rest.post(data) if ($routeParams.inventory_id) {
.success( function(data, status, headers, config) { data['inventory'] = $routeParams.inventory_id;
ReturnToCaller(1); }
})
.error( function(data, status, headers, config) { Rest.setUrl(defaultUrl);
ProcessErrors(scope, data, status, form, Rest.post(data)
{ hdr: 'Error!', msg: 'Failed to add new group. Post returned status: ' + status }); .success( function(data, status, headers, config) {
}); if (scope.variables) {
}; Rest.setUrl(data.related.variable_data);
Rest.put({data: scope.variables})
.success( function(data, status, headers, config) {
ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add group varaibles. PUT returned status: ' + status });
});
}
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add new group. Post returned status: ' + status });
});
}
catch(err) {
Alert("Error", "Error parsing group variables. Expecting valid JSON. Parser returned " + err);
}
}
// Cancel // Cancel
scope.formReset = function() { scope.formReset = function() {
@@ -222,6 +242,26 @@ function GroupsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams
for (var set in relatedSets) { for (var set in relatedSets) {
scope.search(relatedSets[set].iterator); scope.search(relatedSets[set].iterator);
} }
if (scope.variable_url) {
Rest.setUrl(scope.variable_url);
Rest.get()
.success( function(data, status, headers, config) {
if ($.isEmptyObject(data.data)) {
scope.variables = "\{\}";
}
else {
scope.variables = data.data;
}
})
.error( function(data, status, headers, config) {
scope.variables = null;
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to retrieve host variables. GET returned status: ' + status });
});
}
else {
scope.variables = "\{\}";
}
}); });
// Retrieve detail record and prepopulate the form // Retrieve detail record and prepopulate the form
@@ -241,6 +281,9 @@ function GroupsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams
relatedSets[set] = { url: related[set], iterator: form.related[set].iterator }; relatedSets[set] = { url: related[set], iterator: form.related[set].iterator };
} }
} }
scope.variable_url = data.related.variable_data;
// Initialize related search functions. Doing it here to make sure relatedSets object is populated. // Initialize related search functions. Doing it here to make sure relatedSets object is populated.
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets }); RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
RelatedPaginateInit({ scope: scope, relatedSets: relatedSets }); RelatedPaginateInit({ scope: scope, relatedSets: relatedSets });
@@ -253,21 +296,42 @@ function GroupsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams
// Save changes to the parent // Save changes to the parent
scope.formSave = function() { scope.formSave = function() {
Rest.setUrl(defaultUrl); try {
var data = {} // Make sure we have valid JSON
for (var fld in form.fields) { var myjson = JSON.parse(scope.variables);
data[fld] = scope[fld];
} var data = {}
Rest.put(data) for (var fld in form.fields) {
.success( function(data, status, headers, config) { data[fld] = scope[fld];
var base = $location.path().replace(/^\//,'').split('/')[0]; }
(base == 'groups') ? ReturnToCaller() : ReturnToCaller(1);
}) Rest.setUrl(defaultUrl);
.error( function(data, status, headers, config) { Rest.put(data)
ProcessErrors(scope, data, status, form, .success( function(data, status, headers, config) {
{ hdr: 'Error!', msg: 'Failed to update group: ' + id + '. PUT status: ' + status }); if (scope.variables) {
}); Rest.setUrl(GetBasePath('groups') + data.id + '/variable_data/');
}; Rest.put({data: scope.variables})
.success( function(data, status, headers, config) {
var base = $location.path().replace(/^\//,'').split('/')[0];
(base == 'groups') ? ReturnToCaller() : ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update group varaibles. PUT returned status: ' + status });
});
}
var base = $location.path().replace(/^\//,'').split('/')[0];
(base == 'groups') ? ReturnToCaller() : ReturnToCaller(1);
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update group: ' + id + '. PUT status: ' + status });
});
}
catch(err) {
Alert("Error", "Error parsing group variables. Expecting valid JSON. Parser returned " + err);
}
};
// Cancel // Cancel
scope.formReset = function() { scope.formReset = function() {

View File

@@ -175,27 +175,35 @@ function HostsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
if ($routeParams.inventory_id) { if ($routeParams.inventory_id) {
data['inventory'] = $routeParams.inventory_id; data['inventory'] = $routeParams.inventory_id;
} }
Rest.post(data) try {
.success( function(data, status, headers, config) { // Make sure we have valid JSON
if (scope.variables) { var myjson = JSON.parse(scope.variables);
Rest.setUrl(GetBasePath('hosts') + data.id + '/variable_data/'); Rest.post(data)
Rest.post({data: scope.variables}) .success( function(data, status, headers, config) {
.success( function(data, status, headers, config) { if (scope.variables) {
ReturnToCaller(1); Rest.setUrl(data.related.variable_data);
}) Rest.put({data: scope.variables})
.error( function(data, status, headers, config) { .success( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form, ReturnToCaller(1);
{ hdr: 'Error!', msg: 'Failed to add host varaibles. POST returned status: ' + status }); })
}); .error( function(data, status, headers, config) {
} ProcessErrors(scope, data, status, form,
else { { hdr: 'Error!', msg: 'Failed to add host varaibles. POST returned status: ' + status });
ReturnToCaller(1); });
} }
}) else {
.error( function(data, status, headers, config) { ReturnToCaller(1);
ProcessErrors(scope, data, status, form, }
{ hdr: 'Error!', msg: 'Failed to add new host. POST returned status: ' + status }); })
}); .error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to add new host. POST returned status: ' + status });
});
}
catch(err) {
Alert("Error", "Error parsing host variables. Expecting valid JSON. Parser returned " + err);
}
}; };
// Cancel // Cancel
@@ -236,7 +244,12 @@ function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
Rest.setUrl(scope.variable_url); Rest.setUrl(scope.variable_url);
Rest.get() Rest.get()
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
scope.variables = data.data; if ($.isEmptyObject(data.data)) {
scope.variables = "\{\}";
}
else {
scope.variables = data.data;
}
}) })
.error( function(data, status, headers, config) { .error( function(data, status, headers, config) {
scope.variables = null; scope.variables = null;
@@ -245,7 +258,7 @@ function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
}); });
} }
else { else {
scope.variables = null; scope.variables = "\{\}";
} }
}); });
@@ -284,27 +297,36 @@ function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
for (var fld in form.fields) { for (var fld in form.fields) {
data[fld] = scope[fld]; data[fld] = scope[fld];
} }
Rest.put(data)
.success( function(data, status, headers, config) { try {
if (scope.variables) { // Make sure we have valid JSON
Rest.setUrl(GetBasePath('hosts') + data.id + '/variable_data/'); var myjson = JSON.parse(scope.variables);
Rest.put({data: scope.variables}) Rest.put(data)
.success( function(data, status, headers, config) { .success( function(data, status, headers, config) {
(base == 'hosts') ? ReturnToCaller() : ReturnToCaller(1); if (scope.variables) {
}) Rest.setUrl(GetBasePath('hosts') + data.id + '/variable_data/');
.error( function(data, status, headers, config) { Rest.put({data: scope.variables})
ProcessErrors(scope, data, status, form, .success( function(data, status, headers, config) {
{ hdr: 'Error!', msg: 'Failed to update host varaibles. PUT returned status: ' + status }); (base == 'hosts') ? ReturnToCaller() : ReturnToCaller(1);
}); })
} .error( function(data, status, headers, config) {
else { ProcessErrors(scope, data, status, form,
(base == 'hosts') ? ReturnToCaller() : ReturnToCaller(1); { hdr: 'Error!', msg: 'Failed to update host varaibles. PUT returned status: ' + status });
} });
}) }
.error( function(data, status, headers, config) { else {
ProcessErrors(scope, data, status, form, (base == 'hosts') ? ReturnToCaller() : ReturnToCaller(1);
{ hdr: 'Error!', msg: 'Failed to update host: ' + id + '. PUT status: ' + status }); }
}); })
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to update host: ' + id + '. PUT status: ' + status });
});
}
catch(err) {
Alert("Error", "Error parsing host variables. Expecting valid JSON. Parser returned " + err);
}
}; };
// Cancel // Cancel

View File

@@ -378,12 +378,6 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
show: true show: true
}); });
} }
},
vairables: {
label: 'Host Variables',
separator_before: true,
"_disabled": true,
action: function(obj) { }
} }
} }
} }
@@ -392,17 +386,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
addGroup: { addGroup: {
label: 'Add Group', label: 'Add Group',
action: function() { changePath($location.path() + '/groups'); } action: function() { changePath($location.path() + '/groups'); }
}, }
addHost: {
label: 'Add Host',
action: function() { changePath($location.path() + '/hosts'); }
},
variables: {
label: 'Inventory variables',
action: function(obj) { },
"_disabled": true,
separator_before: true
}
} }
} }
else { else {
@@ -459,13 +443,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
show: true show: true
}); });
}, },
"_disabled": (nodeType == 'all-hosts-group') ? true : false "_disabled": (nodeType == 'all-hosts-group') ? true : false
},
variables: {
label: 'Group variables',
action: function(obj) { },
"_disabled": true,
separator_before: true
} }
} }
} }

View File

@@ -27,14 +27,16 @@ angular.module('GroupFormDefinition', [])
type: 'text', type: 'text',
addRequired: false, addRequired: false,
editRequired: false editRequired: false
},
variables: {
label: 'Variables',
type: 'textarea',
addRequired: false,
editRequird: false,
rows: 10,
class: 'span12',
default: "\{\}"
} }
// ,
// inventory: {
// label: 'Inventory',
// type: 'hidden',
// includeOnEdit: true,
// includeOnAdd: true
// }
}, },
buttons: { //for now always generates <button> tags buttons: { //for now always generates <button> tags

View File

@@ -39,7 +39,8 @@ angular.module('HostFormDefinition', [])
addRequired: false, addRequired: false,
editRequird: false, editRequird: false,
rows: 10, rows: 10,
class: 'span12' class: 'span12',
default: "\{\}"
} }
}, },