Fixed home page to work with new Utilities.GetChoices, which is used to get select options from the API.

This commit is contained in:
Chris Houseknecht 2013-11-04 09:14:45 +00:00 committed by Chris Church
parent 8a3a0d219c
commit 7f7140ccda
3 changed files with 43 additions and 26 deletions

View File

@ -30,7 +30,9 @@ angular.module('InventorySyncStatusWidget', ['RestServices', 'Utilities'])
function makeRow(label, count, fail) {
var html = "<tr>\n";
html += "<td><a href=\"/#/" + label.toLowerCase() + "\">" + label + "</a></td>\n";
html += "<td><a href=\"/#/" + label.toLowerCase() + "\"";
html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : "";
html += ">" + label + "</a></td>\n";
html += "<td class=\"failed-column text-right\">";
html += (fail > 0) ? "<a href=\"/blah/blah\">" + fail + "</a>" : "";
html += "</td>\n";
@ -141,25 +143,31 @@ angular.module('InventorySyncStatusWidget', ['RestServices', 'Utilities'])
ProcessErrors(scope, data, status, null,
{ hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status });
});
if (scope.removeTypesReady) {
scope.removeTypesReady();
}
scope.removeTypesReady = scope.$on('TypesReady', function (e, label, count, fail) {
results.push({ label: label, count: count, fail: fail });
if (results.length == expected) {
scope.$emit('CountReceived');
}
});
scope.removeCountProjects = scope.$on('CountTypes', function(e, choices) {
if (scope.CountProjects) {
scope.CountProjects();
}
scope.removeCountProjects = scope.$on('CountTypes', function() {
scm_choices = choices;
var choices = scope['inventorySources'];
function getLabel(config) {
var url = config.url;
var type = url.match(/source=.*\&/)[0].replace(/source=/,'').replace(/\&/,'');
var label;
for (var i=0; i < choices.length; i++) {
if (choices[i][0] == type) {
label = choices[i][1];
if (choices[i].value == type) {
label = choices[i].label;
break;
}
}
@ -168,24 +176,24 @@ angular.module('InventorySyncStatusWidget', ['RestServices', 'Utilities'])
// Remove ---- option from list of choices
for (var i=0; i < choices.length; i++) {
if (choices[i][1].match(/^---/)) {
if (choices[i].label.match(/^---/)) {
choices.splice(i,1);
break;
}
}
for (var i=0; i < choices.length; i++) {
if (choices[i][1].match(/^Local/)) {
if (choices[i].label.match(/^Local/)) {
choices.splice(i,1);
break;
}
}
expected = choices.length;
for (var i=0; i < choices.length; i++) {
if (!choices[i][1].match(/^---/)) {
var url = GetBasePath('inventory_sources') + '?source=' + choices[i][0] + '&page=1';
if (!choices[i].label.match(/^---/)) {
var url = GetBasePath('inventory_sources') + '?source=' + choices[i].value + '&page=1';
Rest.setUrl(url);
Rest.get()
.success( function(data, status, headers, config) {
@ -210,8 +218,9 @@ angular.module('InventorySyncStatusWidget', ['RestServices', 'Utilities'])
GetChoices({ scope: scope,
url: GetBasePath('inventory_sources'),
variable: 'inventorySources',
field: 'source',
emit: 'CountTypes' });
callback: 'CountTypes' });
}
}]);

View File

@ -28,7 +28,9 @@ angular.module('JobStatusWidget', ['RestServices', 'Utilities'])
function makeRow(label, count, fail) {
var html = '';
html += "<tr>\n";
html += "<td><a href=\"/#/" + label.toLowerCase() + "\">" + label + "</a></td>\n";
html += "<td><a href=\"/#/" + label.toLowerCase() + "\"";
html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : "";
html += ">" + label + "</a></td>\n";
html += "<td class=\"failed-column text-right\">";
html += (fail > 0) ? "<a href=\"/blah/blah\">" + fail + "</a>" : "";
html += "</td>\n";

View File

@ -27,9 +27,9 @@ angular.module('SCMSyncStatusWidget', ['RestServices', 'Utilities'])
function makeRow(label, count, fail) {
var value;
for (var i=0; i < scm_choices.length; i++) {
if (scm_choices[i][1] == label) {
value = scm_choices[i][0];
for (var i=0; i < scope['projectChoices'].length; i++) {
if (scope['projectChoices'][i].label == label) {
value = scope['projectChoices'][i].value;
break;
}
}
@ -87,17 +87,17 @@ angular.module('SCMSyncStatusWidget', ['RestServices', 'Utilities'])
});
scope.removeCountProjects = scope.$on('CountProjects', function(e, choices) {
scope.removeCountProjects = scope.$on('CountProjects', function() {
scm_choices = choices;
var choices = scope['projectChoices'];
function getScmLabel(config) {
var url = config.url;
var scm_type = url.match(/scm_type=.*\&/)[0].replace(/scm_type=/,'').replace(/\&/,'');
var label;
for (var i=0; i < choices.length; i++) {
if (choices[i][0] == scm_type) {
label = choices[i][1];
if (choices[i].value == scm_type) {
label = choices[i].label;
break;
}
}
@ -106,14 +106,14 @@ angular.module('SCMSyncStatusWidget', ['RestServices', 'Utilities'])
// Remove ---- option from list of choices
for (var i=0; i < choices.length; i++) {
if (choices[i][1].match(/^---/)) {
if (choices[i].value.match(/^---/)) {
choices.splice(i,1);
break;
}
}
// Remove Manual option from list of choices
for (var i=0; i < choices.length; i++) {
if (choices[i][1].match(/Manual/)) {
if (choices[i].label.match(/Manual/)) {
choices.splice(i,1);
break;
}
@ -122,8 +122,8 @@ angular.module('SCMSyncStatusWidget', ['RestServices', 'Utilities'])
expected = choices.length;
for (var i=0; i < choices.length; i++) {
if (!choices[i][1].match(/^---/)) {
var url = GetBasePath('projects') + '?scm_type=' + choices[i][0] + '&page=1';
if (!choices[i].label.match(/^---/)) {
var url = GetBasePath('projects') + '?scm_type=' + choices[i].value + '&page=1';
Rest.setUrl(url);
Rest.get()
.success( function(data, status, headers, config) {
@ -146,7 +146,13 @@ angular.module('SCMSyncStatusWidget', ['RestServices', 'Utilities'])
}
});
GetChoices({ scope: scope, url: GetBasePath('projects'), field: 'scm_type', emit: 'CountProjects'});
GetChoices({
scope: scope,
url: GetBasePath('projects'),
variable: 'projectChoices',
field: 'scm_type',
callback: 'CountProjects'
});
}
}]);