2016-04-04 14:03:07 -04:00
|
|
|
RootView = require 'views/core/RootView'
|
2016-05-10 17:34:17 -04:00
|
|
|
template = require 'templates/artisans/level-tasks-view'
|
2016-05-13 18:32:59 -04:00
|
|
|
|
|
|
|
Campaigns = require 'collections/Campaigns'
|
|
|
|
|
2016-04-04 14:03:07 -04:00
|
|
|
Campaign = require 'models/Campaign'
|
|
|
|
|
|
|
|
module.exports = class LevelTasksView extends RootView
|
|
|
|
template: template
|
|
|
|
id: 'level-tasks-view'
|
|
|
|
events:
|
2016-05-13 18:32:59 -04:00
|
|
|
'input .searchInput': 'searchUpdate'
|
|
|
|
'change .searchInput': 'searchUpdate'
|
2016-04-04 14:03:07 -04:00
|
|
|
excludedCampaigns = [
|
2016-05-13 18:32:59 -04:00
|
|
|
'picoctf', 'auditions'
|
2016-04-04 14:03:07 -04:00
|
|
|
]
|
2016-05-13 18:32:59 -04:00
|
|
|
levels: {}
|
|
|
|
initialize: () ->
|
|
|
|
@searchUpdate = _.debounce(@searchUpdate, 250)
|
|
|
|
|
|
|
|
@campaigns = new Campaigns()
|
2016-04-04 14:03:07 -04:00
|
|
|
@listenTo(@campaigns, 'sync', @onCampaignsLoaded)
|
2016-05-13 18:32:59 -04:00
|
|
|
@supermodel.trackRequest(@campaigns.fetch(
|
|
|
|
data:
|
|
|
|
project: 'name,slug,levels,tasks'
|
|
|
|
))
|
2016-04-04 14:03:07 -04:00
|
|
|
|
2016-05-13 18:32:59 -04:00
|
|
|
onCampaignsLoaded: (campCollection) ->
|
2016-04-04 14:03:07 -04:00
|
|
|
@levels = {}
|
2016-05-13 18:32:59 -04:00
|
|
|
for campaign in campCollection.models
|
|
|
|
campaignSlug = campaign.get 'slug'
|
|
|
|
continue if campaignSlug in excludedCampaigns
|
|
|
|
levels = campaign.get 'levels'
|
2016-04-04 14:03:07 -04:00
|
|
|
for key, level of levels
|
|
|
|
continue unless ///#{$('#nameSearch')[0].value}///i.test level.name
|
|
|
|
levelSlug = level.slug
|
|
|
|
@levels[levelSlug] = level
|
2016-05-13 18:32:59 -04:00
|
|
|
@processedLevels = {}
|
|
|
|
for key, level of @levels
|
|
|
|
filteredTasks = level.tasks.filter (elem) ->
|
|
|
|
return ///#{$('#descSearch')[0].value}///i.test elem.name
|
|
|
|
@processedLevels[key] = {
|
|
|
|
tasks: filteredTasks
|
|
|
|
name: level.name
|
|
|
|
}
|
2016-04-04 14:03:07 -04:00
|
|
|
@renderSelectors '#levelTable'
|
|
|
|
|
|
|
|
searchUpdate: ->
|
2016-05-13 18:32:59 -04:00
|
|
|
@onCampaignsLoaded(@campaigns)
|
|
|
|
###
|
2016-04-04 14:03:07 -04:00
|
|
|
if not @lastLoad? or (new Date()).getTime() - @lastLoad > 60 * 1000 * 1 # Update only after a minute from last update.
|
2016-05-13 18:32:59 -04:00
|
|
|
#@campaigns.fetch()
|
2016-04-04 14:03:07 -04:00
|
|
|
@listenTo(@campaigns, 'sync', @onCampaignsLoaded)
|
2016-05-13 18:32:59 -04:00
|
|
|
@superModel.trackRequest()
|
|
|
|
#@supermodel.loadCollection(@campaigns, 'campaigns')
|
2016-04-04 14:03:07 -04:00
|
|
|
@lastLoad = (new Date()).getTime()
|
|
|
|
else
|
|
|
|
@onCampaignsLoaded()
|
2016-05-13 18:32:59 -04:00
|
|
|
###
|
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
@searchUpdate.cancel()
|
|
|
|
super()
|
2016-04-04 14:03:07 -04:00
|
|
|
|
|
|
|
# Jade helper
|
|
|
|
hasIncompleteTasks: (level) ->
|
2016-05-13 18:32:59 -04:00
|
|
|
return level.tasks and level.tasks.filter((_elem) -> return not _elem.complete).length > 0
|