Adds the Thang Task View.

This commit is contained in:
Josh Callebaut 2015-12-21 12:44:22 -08:00
parent a9e0447c7d
commit 79ff058117
4 changed files with 122 additions and 0 deletions

View file

@ -92,6 +92,7 @@ module.exports = class CocoRouter extends Backbone.Router
'editor/campaign/:campaignID': go('editor/campaign/CampaignEditorView')
'editor/poll': go('editor/poll/PollSearchView')
'editor/poll/:articleID': go('editor/poll/PollEditView')
'editor/thang-tasks': go('editor/ThangTasksView')
'employers': go('EmployersView')

View file

@ -0,0 +1,26 @@
#thang-tasks-view
#taskTable
width: 100%
.taskOwner
width: 12.5%
.tasksTable
width: 87.5%
.taskDescription:nth-of-type(odd)
background-color: rgba(0, 0, 0, 0.0625)
.taskDescription
width: 100%
padding-left: 4px
border-radius: 4px
&:hover
background-color: rgba(0, 0, 0, 0.125)
.taskCompletion
text-align: center
width: 5%
.task
width: 100%

View file

@ -0,0 +1,50 @@
extends /templates/base
block content
#thang-tasks-view
input#nameSearch(placeholder='Filter: Thang Name')
br
input#descSearch(placeholder='Filter: Task Description')
hr
if view.processedThangs
table.table#taskTable
tr
th Thang Name
th Task List
for thang in view.processedThangs
if (thang.tasks && thang.tasks.filter(function(_elem) {return !_elem.complete}).length > 0) || false
tr
td.taskOwner
a(href= "thang/" + thang.get('slug'))
| #{thang.get('name')}
td.tasksTable
for task in (thang.tasks || [])
if !task.complete
div.taskDescription
| #{task.name}
else
span No view.processedThangs
//
block content
#thang-tasks-view
if view.processedThangs
input#search
hr
table.table#taskTable
tr
th Thang Name
th Task List
for thang in view.processedThangs.models
if (thang.get('tasks') && thang.get('tasks').filter(function(_elem) {return !_elem.complete}).length > 0) || false
tr
td.taskOwner
a(href= "thang/" + thang.get('slug'))
| #{thang.get('name')}
td.tasksTable
for task in (thang.get('tasks') || [])
if !task.complete
div.taskDescription
| #{task.name}
else
span Loading...

View file

@ -0,0 +1,45 @@
RootView = require 'views/core/RootView'
template = require 'templates/editor/thangTasksView'
ThangType = require 'models/ThangType'
CocoCollection = require 'collections/CocoCollection'
module.exports = class ThangTasksView extends RootView
template: template
id: 'thang-tasks-view'
events:
'input input': 'searchUpdate'
'change input': 'searchUpdate'
constructor: (options) ->
super options
@thangs = new CocoCollection([],
url: '/db/thang.type?project=name,tasks,slug'
model: ThangType
comparator: @sortThangs
)
@lastLoad = (new Date()).getTime()
@listenTo(@thangs, 'sync', @onColLoaded)
@supermodel.loadCollection(@thangs, 'thangs')
searchUpdate: ->
if !@lastLoad? or (new Date()).getTime() - @lastLoad > 60 * 1000 * 1 # Update only after a minute from last update.
@thangs.fetch()
@listenTo(@thangs, 'sync', @onColLoaded)
@supermodel.loadCollection(@thangs, 'thangs')
@lastLoad = (new Date()).getTime()
else
@onColLoaded()
onColLoaded: ->
@processedThangs = @thangs.filter((_elem) ->
return _elem.get('name').toLowerCase().indexOf($('#nameSearch')[0].value.toLowerCase()) isnt -1
)
for thang in @processedThangs
thang.tasks = _.filter(thang.attributes.tasks, (_elem) ->
return _elem.name.toLowerCase().indexOf($('#descSearch')[0].value.toLowerCase()) isnt -1
)
newContent = $(template({me:me, view:@}))
@$el.find('#taskTable').replaceWith($(newContent[1]).find('#taskTable'))
sortThangs: (a, b) ->
a.get('name').localeCompare(b.get('name'))