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-16 14:45:06 -04:00
|
|
|
'input .searchInput': 'processLevels'
|
|
|
|
'change .searchInput': 'processLevels'
|
|
|
|
|
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-16 14:45:06 -04:00
|
|
|
|
2016-05-13 18:32:59 -04:00
|
|
|
levels: {}
|
2016-05-16 14:45:06 -04:00
|
|
|
processedLevels: {}
|
|
|
|
|
2016-05-13 18:32:59 -04:00
|
|
|
initialize: () ->
|
2016-05-16 14:45:06 -04:00
|
|
|
@processLevels = _.debounce(@processLevels, 250)
|
2016-05-13 18:32:59 -04:00
|
|
|
|
|
|
|
@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
|
|
|
|
levelSlug = level.slug
|
|
|
|
@levels[levelSlug] = level
|
2016-05-16 14:45:06 -04:00
|
|
|
@processLevels()
|
|
|
|
|
|
|
|
processLevels: () ->
|
2016-05-13 18:32:59 -04:00
|
|
|
@processedLevels = {}
|
|
|
|
for key, level of @levels
|
2016-05-18 16:33:02 -04:00
|
|
|
continue unless ///#{$('#name-search')[0].value}///i.test level.name
|
2016-05-16 14:45:06 -04:00
|
|
|
filteredTasks = level.tasks.filter (elem) ->
|
|
|
|
# Similar case-insensitive search of input vs description (name).
|
2016-05-18 16:33:02 -04:00
|
|
|
return ///#{$('#desc-search')[0].value}///i.test elem.name
|
2016-05-13 18:32:59 -04:00
|
|
|
@processedLevels[key] = {
|
|
|
|
tasks: filteredTasks
|
|
|
|
name: level.name
|
|
|
|
}
|
2016-05-18 16:33:02 -04:00
|
|
|
@renderSelectors '#level-table'
|
2016-04-04 14:03:07 -04:00
|
|
|
|
|
|
|
# Jade helper
|
|
|
|
hasIncompleteTasks: (level) ->
|
2016-05-16 14:45:06 -04:00
|
|
|
return level.tasks and level.tasks.filter((_elem) -> return not _elem.complete).length > 0
|