fix rewriting of index; milestones displayed from index

This commit is contained in:
Radek Stepan 2014-10-21 20:16:42 -07:00
parent 079c18668a
commit 082251f352
7 changed files with 160 additions and 126 deletions

View File

@ -2,8 +2,14 @@ install:
npm install npm install
bower install bower install
build: build-app:
./node_modules/.bin/browserify -e ./src/app.coffee -o public/js/app.js -d ./node_modules/.bin/browserify -e ./src/app.coffee -o public/js/app.js -d
watch-app:
./node_modules/.bin/watchify -e ./src/app.coffee -o public/js/app.js -d
build:
build-app
grunt grunt
serve: serve:

View File

@ -14,7 +14,8 @@
"grunt-watchify": "~0.1.0", "grunt-watchify": "~0.1.0",
"coffeeify": "~0.7.0L", "coffeeify": "~0.7.0L",
"ractivate": "~0.2.0", "ractivate": "~0.2.0",
"browserify": "~6.1.0" "browserify": "~6.1.0",
"watchify": "~2.1.0"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

File diff suppressed because one or more lines are too long

View File

@ -16,27 +16,26 @@ module.exports = new Model
# Return a sort order comparator. # Return a sort order comparator.
comparator: -> comparator: ->
{ list } = @data { list, sortBy } = @data
# Convert existing index into actual project milestone. # Convert existing index into actual project milestone.
deIdx = (fn) => deIdx = (fn) =>
([ i, j ], b) => ([ i, j ], b) =>
fn list[i].milestones[j], b fn list[i].milestones[j], b
switch @data.sortBy switch sortBy
# From highest progress. # From highest progress points.
when 'progress' then deIdx (a, b) -> when 'progress' then deIdx (a, b) ->
# By progress points.
$ = { 'progress': { 'points': 0 } } $ = { 'progress': { 'points': 0 } }
a.stats ?= $ ; b.progress ?= $ a.stats ?= $ ; b.progress ?= $
a.stats.progress.points - b.stats.progress.points a.stats.progress.points - b.stats.progress.points
# From most delayed in days. # From most delayed in days.
when 'priority' then deIdx (a, b) => when 'priority' then deIdx (a, b) ->
0 throw 'Not implemented'
# Whatever sort order... # The "whatever" sort order...
else -> 0 else -> 0
find: (project) -> find: (project) ->
@ -53,18 +52,23 @@ module.exports = new Model
findIndex: ({ owner, name }) -> findIndex: ({ owner, name }) ->
_.findIndex @data.list, { owner, name } _.findIndex @data.list, { owner, name }
# Add a milestone for a project.
addMilestone: (project, milestone) -> addMilestone: (project, milestone) ->
# Add in the stats. # Add in the stats.
_.extend milestone, { 'stats': stats(milestone) } _.extend milestone, { 'stats': stats(milestone) }
# We are supposed to exist already.
throw 500 if (i = @findIndex(project)) < 0
if (idx = @findIndex(project)) > -1 # Have milestones already?
if project.milestones? if project.milestones?
@push "list.#{idx}.milestones", milestone @push "list.#{i}.milestones", milestone
else j = @data.list[i].milestones.length - 1 # index in milestones
@set "list.#{idx}.milestones", [ milestone ]
else else
# We are supposed to exist already. @set "list.#{i}.milestones", [ milestone ]
throw 500 j = 0 # index in milestones
# Now index this milestone.
@sort [ i, j ], milestone
# Save an error from loading milestones or issues # Save an error from loading milestones or issues
saveError: (project, err) -> saveError: (project, err) ->
@ -80,18 +84,25 @@ module.exports = new Model
clear: -> clear: ->
@set 'list', [] @set 'list', []
# Sort an already sorted index. # Sort/or insert into an already sorted index.
sort: -> sort: (ref, m) ->
# Get or initialize the index. # Get or initialize the index.
index = @data.index or [] index = @data.index or []
for p, i in @data.list # Do one.
continue unless p.milestones? if m
for m, j in p.milestones idx = sortedIndexCmp index, m, do @comparator
# Run a comparator here inserting into index. index.splice idx, 0, ref
idx = sortedIndexCmp index, m, do @comparator # Do all.
# Log. else
index.splice idx, 0, [ i, j ] for p, i in @data.list
# TODO: need to show projects that failed too...
continue unless p.milestones?
for m, j in p.milestones
# Run a comparator here inserting into index.
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
@ -104,16 +115,14 @@ module.exports = new Model
# Init the projects. # Init the projects.
@set 'list', lscache.get('projects') or [] @set 'list', lscache.get('projects') or []
# Persist projects in local storage (sans milestones).
@observe 'list', (projects) -> @observe 'list', (projects) ->
# Persist projects in local storage (sans milestones).
lscache.set 'projects', _.pluckMany projects, [ 'owner', 'name' ] lscache.set 'projects', _.pluckMany projects, [ 'owner', 'name' ]
# Update the index.
do @sort
, 'init': no , 'init': no
# Reset our index and re-sort. # Reset our index and re-sort.
@observe 'sortBy', -> @observe 'sortBy', ->
# Use pop as Ractive is glitchy. # 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

View File

@ -5,22 +5,34 @@
</div> </div>
<table> <table>
{{#project.milestones}} {{#projects.index}}
<tr> {{# { index: this } }}
<td>
<a class="milestone" href="#{{project.owner}}/{{project.name}}/{{number}}">{{ title }}</a> {{# { p: projects.list[index[0]] } }}
</td> {{#if p.owner == project.owner && p.name == project.name }}
<td style="width:1%">
<div class="progress"> {{# { milestone: project.milestones[index[1]] } }}
<span class="percent">{{Math.floor(stats.progress.points)}}%</span> <tr>
<span class="due">{{{ format.due(due_on) }}}</span> <td>
<div class="outer bar"> <a class="milestone" href="#{{project.owner}}/{{project.name}}/{{milestone.number}}">{{ milestone.title }}</a>
<div class="inner bar {{(stats.isOnTime) ? 'green' : 'red'}}" style="width:{{stats.progress.points}}%"></div> </td>
</div> <td style="width:1%">
</div> <div class="progress">
</td> <span class="percent">{{Math.floor(milestone.stats.progress.points)}}%</span>
</tr> <span class="due">{{{ format.due(milestone.due_on) }}}</span>
{{/project.milestones}} <div class="outer bar">
<div class="inner bar {{(milestone.stats.isOnTime) ? 'green' : 'red'}}" style="width:{{milestone.stats.progress.points}}%"></div>
</div>
</div>
</td>
</tr>
{{/}}
{{/if}}
{{/}}
{{/}}
{{/projects.index}}
</table> </table>
<div class="footer"> <div class="footer">

View File

@ -24,12 +24,12 @@
<a class="project" href="#{{owner}}/{{name}}">{{owner}}/{{name}}</a> <a class="project" href="#{{owner}}/{{name}}">{{owner}}/{{name}}</a>
</td> </td>
<td> <td>
<a class="milestone" href="#{{owner}}/{{name}}/{{milestone.number}}">{{ title }}</a> <a class="milestone" href="#{{owner}}/{{name}}/{{milestone.number}}">{{ milestone.title }}</a>
</td> </td>
<td style="width:1%"> <td style="width:1%">
<div class="progress"> <div class="progress">
<span class="percent">{{Math.floor(milestone.stats.progress.points)}}%</span> <span class="percent">{{Math.floor(milestone.stats.progress.points)}}%</span>
<span class="due">{{{ format.due(due_on) }}}</span> <span class="due">{{{ format.due(milestone.due_on) }}}</span>
<div class="outer bar"> <div class="outer bar">
<div class="inner bar {{(milestone.stats.isOnTime) ? 'green' : 'red'}}" style="width:{{milestone.stats.progress.points}}%"></div> <div class="inner bar {{(milestone.stats.isOnTime) ? 'green' : 'red'}}" style="width:{{milestone.stats.progress.points}}%"></div>
</div> </div>

View File

@ -17,6 +17,7 @@ module.exports = Ractive.extend
'components': { Milestones } 'components': { Milestones }
'data': 'data':
'projects': projects
'ready': no 'ready': no
onrender: -> onrender: ->
@ -68,4 +69,4 @@ module.exports = Ractive.extend
} if err } if err
# Say we are ready. # Say we are ready.
@set 'ready', yes @set 'ready', yes