change sort order

This commit is contained in:
Radek Stepan 2014-10-22 21:33:03 -07:00
parent 95a6d45f02
commit 426f064dc5
8 changed files with 79 additions and 72 deletions

View File

@ -3,8 +3,6 @@
##Release: Assembly
- [ ] 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
- [ ] sort on name using https://github.com/npm/node-semver/blob/master/semver.js if detected
###Git
@ -33,6 +31,7 @@
###Misc
- [ ] extend from Eventful object that disposes of mediator subscriptions on teardown
- [ ] the deploy script needs to disable autoreload; `make watch` should start a static web server and also launch a build script with a flag saying which files to include in the head (uncompressed, with live reload); standard build script should minify scripts
- [ ] vendor module so we can proxy require all `window` libs
- [ ] show a countdown clock towards the end of the milestone or show overdue

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,10 @@ module.exports = new Model
'name': 'models/projects'
'data':
'sortBy': 'name'
# Current sort order.
'sortBy': 'priority'
# Sort functions.
'sortFns': [ 'progress', 'priority', 'name' ]
# Return a sort order comparator.
comparator: ->
@ -128,7 +131,7 @@ module.exports = new Model
continue unless p.milestones?
for m, j in p.milestones
# Run a comparator here inserting into index.
idx = sortedIndexCmp index, data, do @comparator
idx = sortedIndexCmp index, [ p, m ], do @comparator
# Log.
index.splice idx, 0, [ i, j ]
@ -151,7 +154,7 @@ module.exports = new Model
# Reset our index and re-sort.
@observe 'sortBy', ->
# Use pop as Ractive is glitchy when resetting arrays.
( @pop 'index' while @data.index.length ) if @data.index?
@set 'index', null
# Run the sort again.
do @sort
, 'init': no

View File

@ -1,6 +1,6 @@
<div id="projects">
<div class="header">
<a href="#" class="sort"><Icons icon="sort-alphabet"/> Sorted by priority</a>
<a class="sort" on-click="sortBy"><Icons icon="sort-alphabet"/> Sorted by {{projects.sortBy}}</a>
<h2>Milestones</h2>
</div>

View File

@ -1,6 +1,6 @@
<div id="projects">
<div class="header">
<a href="#" class="sort"><Icons icon="sort-alphabet"/> Sorted by priority</a>
<a class="sort" on-click="sortBy"><Icons icon="sort-alphabet"/> Sorted by {{projects.sortBy}}</a>
<h2>Projects</h2>
</div>

View File

@ -1,18 +1,7 @@
{ Ractive } = require '../../modules/vendor.coffee'
Table = require './table.coffee'
mediator = require '../../modules/mediator.coffee'
projects = require '../../models/projects.coffee'
format = require '../../utils/format.coffee'
Icons = require '../icons.coffee'
module.exports = Ractive.extend
module.exports = Table.extend
'name': 'views/milestones'
'template': require '../../templates/tables/milestones.html'
'data': { format }
'components': { Icons }
'adapt': [ Ractive.adaptors.Ractive ]
'template': require '../../templates/tables/milestones.html'

View File

@ -1,18 +1,7 @@
{ Ractive } = require '../../modules/vendor.coffee'
Table = require './table.coffee'
mediator = require '../../modules/mediator.coffee'
format = require '../../utils/format.coffee'
Icons = require '../icons.coffee'
projects = require '../../models/projects.coffee'
module.exports = Ractive.extend
module.exports = Table.extend
'name': 'views/projects'
'template': require '../../templates/tables/projects.html'
'data': { format }
'components': { Icons }
'adapt': [ Ractive.adaptors.Ractive ]
'template': require '../../templates/tables/projects.html'

View File

@ -0,0 +1,25 @@
{ Ractive } = require '../../modules/vendor.coffee'
format = require '../../utils/format.coffee'
Icons = require '../icons.coffee'
projects = require '../../models/projects.coffee'
module.exports = Ractive.extend
'name': 'views/table'
'data': { format }
'components': { Icons }
'adapt': [ Ractive.adaptors.Ractive ]
onconstruct: ->
# Change sort order.
@on 'sortBy', ->
fns = projects.data.sortFns
idx = 1 + fns.indexOf projects.data.sortBy
idx = 0 if idx is fns.length
projects.set 'sortBy', fns[idx]