Job detail page

Added custom sort routine in drawing routines to explicitly sort primary key values as integers rather than strings.
This commit is contained in:
Chris Houseknecht
2014-07-02 18:26:32 -04:00
parent befffdb8d9
commit 1c57d49981

View File

@@ -939,7 +939,7 @@ function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, Ge
}; };
}]) }])
.factory('DrawPlays', ['$log', function($log) { .factory('DrawPlays', [function() {
return function(params) { return function(params) {
var scope = params.scope, var scope = params.scope,
idx = 0, idx = 0,
@@ -947,18 +947,25 @@ function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, Ge
newKeys = [], newKeys = [],
plays = JSON.parse(JSON.stringify(scope.jobData.plays)), plays = JSON.parse(JSON.stringify(scope.jobData.plays)),
keys = Object.keys(plays); keys = Object.keys(plays);
keys.sort().reverse();
function listSort(a,b) {
if (parseInt(a,10) < parseInt(b,10))
return -1;
if (parseInt(a,10) > parseInt(b,10))
return 1;
return 0;
}
keys.sort(function(a,b) { return listSort(a,b); }).reverse();
for (idx=0; idx < scope.playsMaxRows && idx < keys.length; idx++) { for (idx=0; idx < scope.playsMaxRows && idx < keys.length; idx++) {
newKeys.push(keys[idx]); newKeys.push(keys[idx]);
} }
newKeys.sort(); newKeys.sort(function(a,b) { return listSort(a,b); });
idx = 0; idx = 0;
while (idx < newKeys.length) { while (idx < newKeys.length) {
result.push(plays[newKeys[idx]]); result.push(plays[newKeys[idx]]);
idx++; idx++;
} }
$log.debug('setting plays to:');
$log.debug(result);
scope.plays = result; scope.plays = result;
if (scope.liveEventProcessing) { if (scope.liveEventProcessing) {
scope.$emit('FixPlaysScroll'); scope.$emit('FixPlaysScroll');
@@ -972,15 +979,23 @@ function($rootScope, $log, UpdatePlayStatus, UpdateHostStatus, AddHostResult, Ge
result = [], result = [],
idx, keys, newKeys, tasks; idx, keys, newKeys, tasks;
function listSort(a,b) {
if (parseInt(a,10) < parseInt(b,10))
return -1;
if (parseInt(a,10) > parseInt(b,10))
return 1;
return 0;
}
if (scope.activePlay) { if (scope.activePlay) {
tasks = JSON.parse(JSON.stringify(scope.jobData.plays[scope.activePlay].tasks)); tasks = JSON.parse(JSON.stringify(scope.jobData.plays[scope.activePlay].tasks));
keys = Object.keys(tasks); keys = Object.keys(tasks);
keys.sort().reverse(); keys.sort(function(a,b) { return listSort(a,b); }).reverse();
newKeys = []; newKeys = [];
for (idx=0; result.length < scope.tasksMaxRows && idx < keys.length; idx++) { for (idx=0; result.length < scope.tasksMaxRows && idx < keys.length; idx++) {
newKeys.push(keys[idx]); newKeys.push(keys[idx]);
} }
newKeys.sort(); newKeys.sort(function(a,b) { return listSort(a,b); });
idx = 0; idx = 0;
while (idx < newKeys.length) { while (idx < newKeys.length) {
result.push(tasks[newKeys[idx]]); result.push(tasks[newKeys[idx]]);