sort on priority; need tests later on to verify

This commit is contained in:
Radek Stepan 2014-10-21 20:46:15 -07:00
parent 082251f352
commit c0692275ff
4 changed files with 73 additions and 32 deletions

10
TODO.md
View File

@ -4,15 +4,7 @@
- [ ] use Browserify as an app build pipeline
- [ ] sort milestones on index and project page based on priority (most delayed first); Trend - actual = difference in days and those overdue come first
1. in a projects collection observe the list prop and resort index; already sorted flag passed in as yes)
1. The index is not already sorted when sort order changes
1. index is a list ofls and its milestones in two loops to extract and sort using function
1. tables loop index getting the obj from projects collection and render
1. sort order link toggles available sort by keys and changes the current key
1. use while loop and pop when resetting the index
1. third number in tuples be the priority number so we can insert into already sorted
1. leave the code open so we can remove a project or milestone later on
- [ ] sort on name using https://github.com/npm/node-semver/blob/master/semver.js if detected
###Git

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,7 @@ module.exports = new Model
'name': 'models/projects'
'data':
'sortBy': 'progress'
'sortBy': 'priority'
# Return a sort order comparator.
comparator: ->
@ -23,17 +23,34 @@ module.exports = new Model
([ i, j ], b) =>
fn list[i].milestones[j], b
# Set default fields, in place.
defaults = (arr, hash) ->
for item in arr
for k, v of hash
ref = item
for p, i in keys = k.split '.'
if i is keys.length - 1
ref[p] ?= v
else
ref = ref[p] ?= {}
# The actual fn selection.
switch sortBy
# From highest progress points.
when 'progress' then deIdx (a, b) ->
$ = { 'progress': { 'points': 0 } }
a.stats ?= $ ; b.progress ?= $
defaults [ a, b ], { 'stats.progress.points': 0 }
# Simple points difference.
a.stats.progress.points - b.stats.progress.points
# From most delayed in days.
when 'priority' then deIdx (a, b) ->
throw 'Not implemented'
# Milestones with no deadline are always at the "beginning".
defaults [ a, b ], { 'stats.progress.time': 0, 'stats.days': 1e3 }
# % difference in progress times the number of days ahead or behind.
[ $a, $b ] = _.map [ a, b ], ({ stats }) ->
(stats.progress.points - stats.progress.time) * stats.days
$b - $a
# The "whatever" sort order...
else -> 0

View File

@ -20,7 +20,7 @@ module.exports = (milestone) ->
time = progress b - a, c - b
# How many days is 1% of the time?
days = (moment(a).diff(moment(b), 'days')) / 100
days = (moment(b).diff(moment(a), 'days')) / 100
{
'isOnTime': points > time