name compare using semver too

This commit is contained in:
Radek Stepan 2014-10-22 19:59:44 -07:00
parent c0692275ff
commit 95a6d45f02
8 changed files with 1308 additions and 46 deletions

View File

@ -48,6 +48,7 @@ module.exports = (grunt) ->
'vendor/marked/lib/marked.js' 'vendor/marked/lib/marked.js'
'vendor/director/build/director.js' 'vendor/director/build/director.js'
'vendor/sorted-index-compare/index.js' 'vendor/sorted-index-compare/index.js'
'node-semver/semver.js'
] ]
dest: 'public/js/vendor.js' dest: 'public/js/vendor.js'
options: options:

View File

@ -123,3 +123,4 @@
- [ ] derive insights; one part is to see if we are on track, the other is to get better at estimating. If we know when an issue is worked on and when closed, with its accompanying size, we can say which issues went well, and which fared poorly. Then we can visualize a weekly/monthly/per-milestone list of loosers and winners. Perhaps the user can glean a pattern from that. - [ ] derive insights; one part is to see if we are on track, the other is to get better at estimating. If we know when an issue is worked on and when closed, with its accompanying size, we can say which issues went well, and which fared poorly. Then we can visualize a weekly/monthly/per-milestone list of loosers and winners. Perhaps the user can glean a pattern from that.
- [ ] create fake Firebase endpoint for GitHub auth, or change the endpoint in settings (easier) - [ ] create fake Firebase endpoint for GitHub auth, or change the endpoint in settings (easier)
- [ ] have an icon that shows a progress for a milestone that can be shown on GitHub README page - [ ] have an icon that shows a progress for a milestone that can be shown on GitHub README page
- [ ] try appending '.0' to milestone titles to pass `semver` validation and compare 4.0, 5.x etc.

View File

@ -17,6 +17,7 @@
"ractive-ractive": "rstacruz/ractive-ractive", "ractive-ractive": "rstacruz/ractive-ractive",
"ractive-transitions-fade": "~0.1.2", "ractive-transitions-fade": "~0.1.2",
"sorted-index-compare": "6wunderkinder/sortedindex-compare", "sorted-index-compare": "6wunderkinder/sortedindex-compare",
"superagent": "~0.19.0" "superagent": "~0.19.0",
"node-semver": "npm/node-semver#~4.1.0"
} }
} }

View File

@ -27,5 +27,8 @@
"coffeeify", "coffeeify",
"ractivate" "ractivate"
] ]
},
"browser": {
"semver": "./vendor/node-semver/semver.js"
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@ module.exports = new Model
# Login. # Login.
@auth.login config.data.provider, @auth.login config.data.provider,
'rememberMe': yes 'rememberMe': yes
'scope': 'public_repo' 'scope': 'private_repo'
# Logout a user. # Logout a user.
logout: -> logout: ->

View File

@ -1,4 +1,4 @@
{ _, lscache, sortedIndexCmp } = require '../modules/vendor.coffee' { _, lscache, sortedIndexCmp, semver } = require '../modules/vendor.coffee'
config = require '../models/config.coffee' config = require '../models/config.coffee'
mediator = require '../modules/mediator.coffee' mediator = require '../modules/mediator.coffee'
@ -12,7 +12,7 @@ module.exports = new Model
'name': 'models/projects' 'name': 'models/projects'
'data': 'data':
'sortBy': 'priority' 'sortBy': 'name'
# Return a sort order comparator. # Return a sort order comparator.
comparator: -> comparator: ->
@ -20,8 +20,8 @@ module.exports = new Model
# Convert existing index into actual project milestone. # Convert existing index into actual project milestone.
deIdx = (fn) => deIdx = (fn) =>
([ i, j ], b) => ([ i, j ], rest...) =>
fn list[i].milestones[j], b fn.apply @, [ [ list[i], list[i].milestones[j] ] ].concat rest
# Set default fields, in place. # Set default fields, in place.
defaults = (arr, hash) -> defaults = (arr, hash) ->
@ -37,21 +37,32 @@ module.exports = new Model
# The actual fn selection. # The actual fn selection.
switch sortBy switch sortBy
# From highest progress points. # From highest progress points.
when 'progress' then deIdx (a, b) -> when 'progress' then deIdx ([ aP, aM ], [ bP, bM ]) ->
defaults [ a, b ], { 'stats.progress.points': 0 } defaults [ aM, bM ], { 'stats.progress.points': 0 }
# Simple points difference. # Simple points difference.
a.stats.progress.points - b.stats.progress.points aM.stats.progress.points - bM.stats.progress.points
# From most delayed in days. # From most delayed in days.
when 'priority' then deIdx (a, b) -> when 'priority' then deIdx ([ aP, aM ], [ bP, bM ]) ->
# Milestones with no deadline are always at the "beginning". # Milestones with no deadline are always at the "beginning".
defaults [ a, b ], { 'stats.progress.time': 0, 'stats.days': 1e3 } defaults [ aM, bM ], { 'stats.progress.time': 0, 'stats.days': 1e3 }
# % difference in progress times the number of days ahead or behind. # % difference in progress times the number of days ahead or behind.
[ $a, $b ] = _.map [ a, b ], ({ stats }) -> [ $a, $b ] = _.map [ aM, bM ], ({ stats }) ->
(stats.progress.points - stats.progress.time) * stats.days (stats.progress.points - stats.progress.time) * stats.days
$b - $a $b - $a
# Based on project then milestone name including semver.
when 'name' then deIdx ([ aP, aM ], [ bP, bM ]) ->
return owner if owner = bP.owner.localeCompare aP.owner
return name if name = bP.name.localeCompare aP.name
# Try semver.
if semver.valid(bM.title) and semver.valid(aM.title)
semver.gt bM.title, aM.title
# Back to string compare.
else
bM.title.localeCompare aM.title
# The "whatever" sort order... # The "whatever" sort order...
else -> 0 else -> 0
@ -85,7 +96,7 @@ module.exports = new Model
j = 0 # index in milestones j = 0 # index in milestones
# Now index this milestone. # Now index this milestone.
@sort [ i, j ], milestone @sort [ i, j ], [ project, milestone ]
# Save an error from loading milestones or issues # Save an error from loading milestones or issues
saveError: (project, err) -> saveError: (project, err) ->
@ -102,13 +113,13 @@ module.exports = new Model
@set 'list', [] @set 'list', []
# Sort/or insert into an already sorted index. # Sort/or insert into an already sorted index.
sort: (ref, m) -> sort: (ref, data) ->
# Get or initialize the index. # Get or initialize the index.
index = @data.index or [] index = @data.index or []
# Do one. # Do one.
if m if ref
idx = sortedIndexCmp index, m, do @comparator idx = sortedIndexCmp index, data, do @comparator
index.splice idx, 0, ref index.splice idx, 0, ref
# Do all. # Do all.
else else
@ -117,7 +128,7 @@ module.exports = new Model
continue unless p.milestones? continue unless p.milestones?
for m, j in p.milestones for m, j in p.milestones
# Run a comparator here inserting into index. # Run a comparator here inserting into index.
idx = sortedIndexCmp index, m, do @comparator idx = sortedIndexCmp index, data, do @comparator
# Log. # Log.
index.splice idx, 0, [ i, j ] index.splice idx, 0, [ i, j ]
@ -142,4 +153,5 @@ module.exports = new Model
# Use pop as Ractive is glitchy when resetting arrays. # Use pop as Ractive is glitchy when resetting arrays.
( @pop 'index' while @data.index.length ) if @data.index? ( @pop 'index' while @data.index.length ) if @data.index?
# Run the sort again. # Run the sort again.
do @sort do @sort
, 'init': no

View File

@ -12,4 +12,5 @@ module.exports =
'director': 'director':
'Router': window.Router 'Router': window.Router
'lscache': window.lscache 'lscache': window.lscache
'sortedIndexCmp': window.sortedIndex 'sortedIndexCmp': window.sortedIndex
'semver': require 'semver'