Skip to content

Commit

Permalink
Fixing contest sorting via object cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
etousley committed Oct 2, 2017
1 parent 2034612 commit 5fc9d43
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions controllers/contest.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ getActiveContestName = (logEntry) => {

/**
* Get teams object
* Helpful to return an independent object if mutating
*/
getTeams = () => {
let teams = {};
Expand All @@ -73,6 +74,9 @@ getTeams = () => {
}


/**
* Convert object to list
*/
objToList = (obj, keyName = "key") => {
let list = [];
for (let key of Object.keys(obj)) {
Expand All @@ -83,6 +87,7 @@ objToList = (obj, keyName = "key") => {
return list;
}


/**
* Aggregate user-level point totals to team-level point totals
* Note: Want to show points = 0 rather than omitting team entirely
Expand All @@ -108,10 +113,12 @@ getContestResults = (callback) => {
let contestInfo = contestDefinitions[contestName];
let contest = {
'name': contestName,
'startDate': contestInfo.startDate.format(dateMask),
'endDate': contestInfo.endDate.format(dateMask),
'teams': teams,
'users': userTeams
'startDate': contestInfo.startDate,
'endDate': contestInfo.endDate,
'startDateFormatted': contestInfo.startDate.format(dateMask),
'endDateFormatted': contestInfo.endDate.format(dateMask),
'teams': getTeams(), // Needs to be independent clone
'users': JSON.parse(JSON.stringify(userTeams)) // Needs to be independent clone
};

// Ignore contests that haven't started yet
Expand Down Expand Up @@ -150,6 +157,7 @@ getContestResults = (callback) => {
}

// Sort contests by date, descending
// console.log(contests);
contests.sort( (a, b) => {
return b.startDate - a.startDate;
});
Expand Down
2 changes: 1 addition & 1 deletion public/js/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ selectActivity = (activityElem) => {
/**
* Validate entry; return list of errors
*/
getEntryErrors = (entryData) => {
getEntryErrors = (entryData) => {
const requiredFields = ['date', 'activity', 'durationValue', 'durationUnit'];
const numFields = ['durationValue'];
let errors = [];
Expand Down
2 changes: 1 addition & 1 deletion views/contest/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ block content
hr

each contest in contests
h3 #{contest.name} (#{contest.startDate} to #{contest.endDate})
h3 #{contest.name} (#{contest.startDateFormatted} to #{contest.endDateFormatted})

.row
.col-md-12
Expand Down

0 comments on commit 5fc9d43

Please sign in to comment.