simple (and broken) sort on progress %
This commit is contained in:
parent
367f26e517
commit
796904f226
|
@ -47,6 +47,7 @@ module.exports = (grunt) ->
|
||||||
'vendor/d3-tip/index.js'
|
'vendor/d3-tip/index.js'
|
||||||
'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'
|
||||||
]
|
]
|
||||||
dest: 'public/js/vendor.js'
|
dest: 'public/js/vendor.js'
|
||||||
options:
|
options:
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
"ractive": "~0.6.0",
|
"ractive": "~0.6.0",
|
||||||
"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",
|
||||||
"superagent": "~0.19.0"
|
"superagent": "~0.19.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
|
@ -38827,4 +38827,55 @@ Router.prototype.mount = function(routes, path) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}(typeof exports === "object" ? exports : window));
|
}(typeof exports === "object" ? exports : window));;(function(root) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses a binary search to determine the smallest index at which a value
|
||||||
|
* should be inserted into a given sorted array in order to maintain the sort
|
||||||
|
* order of the array. The sort ranking is calculated internally by comparing
|
||||||
|
* an element of the array with the given value. The compare function should return
|
||||||
|
* a positive number larger than 0 if the second argument has a higher sort ranking than first,
|
||||||
|
* 0 if the first and the second argument have the same sort raking,
|
||||||
|
* and a negative number if the the second argument has a smaller sort ranking than the first.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Arrays
|
||||||
|
* @param {Array} array The array to inspect.
|
||||||
|
* @param {*} value The value to evaluate.
|
||||||
|
* @param {Function} [compare] The function to compare elements.
|
||||||
|
Received to arguments that it should return a number for as described above.
|
||||||
|
* @returns {number} Returns the index at which `value` should be inserted
|
||||||
|
* into `array`.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function sortedIndex(array, value, compare) {
|
||||||
|
var low = 0,
|
||||||
|
high = array ? array.length : low;
|
||||||
|
|
||||||
|
while (low < high) {
|
||||||
|
var mid = (low + high) >>> 1;
|
||||||
|
(compare(array[mid],value) > 0)
|
||||||
|
? low = mid + 1
|
||||||
|
: high = mid;
|
||||||
|
}
|
||||||
|
return low;
|
||||||
|
}
|
||||||
|
|
||||||
|
//export for amd, commonjs and traditional global scope
|
||||||
|
if (typeof define === 'function' && define.amd) {
|
||||||
|
define('sortedindex-compare', [], function() {
|
||||||
|
return sortedIndex;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (typeof exports !== 'undefined') {
|
||||||
|
if (typeof module !== 'undefined' && module.exports) {
|
||||||
|
exports = module.exports = sortedIndex;
|
||||||
|
}
|
||||||
|
exports.sortedIndex = sortedIndex;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
root.sortedIndex = sortedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
})(this);
|
|
@ -1,4 +1,4 @@
|
||||||
{ _, lscache } = require '../modules/vendor.coffee'
|
{ _, lscache, sortedIndexCmp } = require '../modules/vendor.coffee'
|
||||||
|
|
||||||
config = require '../models/config.coffee'
|
config = require '../models/config.coffee'
|
||||||
mediator = require '../modules/mediator.coffee'
|
mediator = require '../modules/mediator.coffee'
|
||||||
|
@ -15,6 +15,22 @@ module.exports = new Model
|
||||||
'data':
|
'data':
|
||||||
'sortBy': 'priority'
|
'sortBy': 'priority'
|
||||||
|
|
||||||
|
# Return a sort order comparator.
|
||||||
|
comparator: ->
|
||||||
|
switch @data.sortBy
|
||||||
|
# Priority comparator from most delayed in days.
|
||||||
|
when 'priority' then ([ i, j ], b) =>
|
||||||
|
# Convert existing index into actual proejct milestone.
|
||||||
|
a = @data.list[i].milestones[j]
|
||||||
|
# By progress points.
|
||||||
|
$ = { 'progress': { 'points': 0 } }
|
||||||
|
a.stats ?= $ ; b.progress ?= $
|
||||||
|
|
||||||
|
a.stats.progress.points - b.stats.progress.points
|
||||||
|
|
||||||
|
# Whatever sort order...
|
||||||
|
else -> 0
|
||||||
|
|
||||||
find: (project) ->
|
find: (project) ->
|
||||||
_.find @data.list, project
|
_.find @data.list, project
|
||||||
|
|
||||||
|
@ -61,11 +77,13 @@ module.exports = new Model
|
||||||
# Get or initialize the index.
|
# Get or initialize the index.
|
||||||
index = @data.index or []
|
index = @data.index or []
|
||||||
|
|
||||||
for p in @data.list
|
for p, i in @data.list
|
||||||
continue unless p.milestones?
|
continue unless p.milestones?
|
||||||
for m in p.milestones
|
for m, j in p.milestones
|
||||||
# Run a comparator here inserting into index.
|
# Run a comparator here inserting into index.
|
||||||
console.log @data.sortBy, m
|
idx = sortedIndexCmp index, m, do @comparator
|
||||||
|
# Log.
|
||||||
|
index.splice idx, 0, [ i, j ]
|
||||||
|
|
||||||
# Save the index.
|
# Save the index.
|
||||||
@set 'index', index
|
@set 'index', index
|
||||||
|
@ -86,7 +104,7 @@ module.exports = new Model
|
||||||
, 'init': no
|
, 'init': no
|
||||||
|
|
||||||
# Reset our index and re-sort.
|
# Reset our index and re-sort.
|
||||||
@observe 'sortKey', ->
|
@observe 'sortBy', ->
|
||||||
# Use pop as Ractive is glitchy.
|
# Use pop as Ractive is glitchy.
|
||||||
( @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.
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
{ moment } = require './vendor.coffee'
|
||||||
|
|
||||||
# Progress in %.
|
# Progress in %.
|
||||||
progress = (a, b) -> 100 * (a / (b + a))
|
progress = (a, b) -> 100 * (a / (b + a))
|
||||||
|
|
||||||
|
@ -17,9 +19,11 @@ module.exports = (milestone) ->
|
||||||
# Progress in time.
|
# Progress in time.
|
||||||
time = progress b - a, c - b
|
time = progress b - a, c - b
|
||||||
|
|
||||||
isOnTime = points > time
|
# How many days is 1% of the time?
|
||||||
|
days = (moment(a).diff(moment(b), 'days')) / 100
|
||||||
|
|
||||||
{
|
{
|
||||||
'isOnTime': isOnTime
|
'isOnTime': points > time
|
||||||
'progress': { points, time }
|
'progress': { points, time }
|
||||||
|
'days': days
|
||||||
}
|
}
|
|
@ -11,4 +11,5 @@ module.exports =
|
||||||
'marked': window.marked
|
'marked': window.marked
|
||||||
'director':
|
'director':
|
||||||
'Router': window.Router
|
'Router': window.Router
|
||||||
'lscache': window.lscache
|
'lscache': window.lscache
|
||||||
|
'sortedIndexCmp': window.sortedIndex
|
|
@ -5,35 +5,45 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
{{#projects.list}}
|
{{#projects.index}}
|
||||||
{{#if errors}}
|
{{# { index: this } }}
|
||||||
<tr>
|
|
||||||
<td colspan="3" class="repo">
|
{{# { project: projects.list[index[0]] } }}
|
||||||
<div class="project">{{owner}}/{{name}} <span class="error" title="{{errors.join('\n')}}"><Icons icon="attention"/></span></div>
|
{{#with project}}
|
||||||
</td>
|
{{#if errors}}
|
||||||
</tr>
|
<tr>
|
||||||
{{else}}
|
<td colspan="3" class="repo">
|
||||||
{{#milestones}}
|
<div class="project">{{owner}}/{{name}} <span class="error" title="{{errors.join('\n')}}"><Icons icon="attention"/></span></div>
|
||||||
<tr>
|
</td>
|
||||||
<td class="repo">
|
</tr>
|
||||||
<a class="project" href="#{{owner}}/{{name}}">{{owner}}/{{name}}</a>
|
{{else}}
|
||||||
</td>
|
|
||||||
<td>
|
{{# { milestone: project.milestones[index[1]] } }}
|
||||||
<a class="milestone" href="#{{owner}}/{{name}}/{{number}}">{{ title }}</a>
|
<tr>
|
||||||
</td>
|
<td class="repo">
|
||||||
<td style="width:1%">
|
<a class="project" href="#{{owner}}/{{name}}">{{owner}}/{{name}}</a>
|
||||||
<div class="progress">
|
</td>
|
||||||
<span class="percent">{{Math.floor(stats.progress.points)}}%</span>
|
<td>
|
||||||
<span class="due">{{{ format.due(due_on) }}}</span>
|
<a class="milestone" href="#{{owner}}/{{name}}/{{milestone.number}}">{{ title }}</a>
|
||||||
<div class="outer bar">
|
</td>
|
||||||
<div class="inner bar {{(stats.isOnTime) ? 'green' : 'red'}}" style="width:{{stats.progress.points}}%"></div>
|
<td style="width:1%">
|
||||||
</div>
|
<div class="progress">
|
||||||
</div>
|
<span class="percent">{{Math.floor(milestone.stats.progress.points)}}%</span>
|
||||||
</td>
|
<span class="due">{{{ format.due(due_on) }}}</span>
|
||||||
</tr>
|
<div class="outer bar">
|
||||||
{{/milestones}}
|
<div class="inner bar {{(milestone.stats.isOnTime) ? 'green' : 'red'}}" style="width:{{milestone.stats.progress.points}}%"></div>
|
||||||
{{/if}}
|
</div>
|
||||||
{{/projects.list}}
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{/}}
|
||||||
|
|
||||||
|
{{/if}}
|
||||||
|
{{/with}}
|
||||||
|
{{/}}
|
||||||
|
|
||||||
|
{{/}}
|
||||||
|
{{/projects.index}}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
mediator = require '../../modules/mediator.coffee'
|
mediator = require '../../modules/mediator.coffee'
|
||||||
format = require '../../utils/format.coffee'
|
format = require '../../utils/format.coffee'
|
||||||
Icons = require '../icons.coffee'
|
Icons = require '../icons.coffee'
|
||||||
|
projects = require '../../models/projects.coffee'
|
||||||
|
|
||||||
module.exports = Ractive.extend
|
module.exports = Ractive.extend
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue