Utilize debounce, clean up event logic, remove unused CourseGearView

This commit is contained in:
Josh Callebaut 2016-05-16 11:45:06 -07:00
parent 38e97ab404
commit a5cad6f986
11 changed files with 76 additions and 93 deletions

View file

@ -45,9 +45,8 @@ module.exports = class CocoRouter extends Backbone.Router
'artisans': go('artisans/ArtisansView')
'artisans/solution-problems': go('artisans/SolutionProblemsView')
'artisans/course-gear': go('artisans/CourseGearView')
'artisans/level-tasks': go('artisans/LevelTasksView')
'artisans/solution-problems': go('artisans/SolutionProblemsView')
'artisans/thang-tasks': go('artisans/ThangTasksView')
'beta': go('HomeView')

View file

@ -10,7 +10,4 @@ block content
|Level Tasks
div
a(href="/artisans/solution-problems")
|Solution Problems
div
a(href="/artisans/course-gear")
|Course Gear Progression
|Solution Problems

View file

@ -1,3 +0,0 @@
extends /templates/base
block content

View file

@ -1,25 +1,28 @@
# DNT
extends /templates/base
block content
#level-tasks-view
div
a(href='/artisans')
| < Artisans Home
span.glyphicon.glyphicon-chevron-left
span Artisans Home
br
input#nameSearch(placeholder='Filter: Level Name')
input.searchInput#nameSearch(placeholder='Filter: Level Name')
br
input#descSearch(placeholder='Filter: Task Description')
input.searchInput#descSearch(placeholder='Filter: Task Description')
hr
if view.processedLevels
table.table.table-striped#levelTable
tr
th Level Name
th Task List
for level in view.processedLevels
if view.hasIncompleteTasks(level)
+levelRow(level)
else
div ole?
div#levelTable
if view.processedLevels
table.table.table-striped
tr
th Level Name
th Task List
for level in view.processedLevels
if view.hasIncompleteTasks(level)
+levelRow(level)
else
div No view.processedLevels
mixin levelRow(level)
tr

View file

@ -1,10 +1,12 @@
# DNT
extends /templates/base
block content
#solution-problems-view
div
a(href='/artisans')
| < Artisans Home
span.glyphicon.glyphicon-chevron-left
span Artisans Home
br
div Total number of problems: #{view.problemCount}
hr

View file

@ -1,25 +1,27 @@
# DNT
extends /templates/base
block content
#thang-tasks-view
div
a(href='/artisans')
| < Artisans Home
span.glyphicon.glyphicon-chevron-left
span Artisans Home
input.inputSearch#nameSearch(placeholder='Filter: Thang Name')
br
input#nameSearch(placeholder='Filter: Thang Name')
br
input#descSearch(placeholder='Filter: Task Description')
input.inputSearch#descSearch(placeholder='Filter: Task Description')
hr
if view.processedThangs
table.table.table-striped#thangTable
tr
th Thang Name
th Task List
for thang in view.processedThangs
if view.hasIncompleteTasks(thang)
+thangRow(thang)
else
span No view.processedThangs
div#thangTable
if view.processedThangs
table.table.table-striped#thangTable
tr
th Thang Name
th Task List
for thang in view.processedThangs
if view.hasIncompleteTasks(thang)
+thangRow(thang)
else
span No view.processedThangs
mixin thangRow(thang)
tr

View file

@ -1,16 +0,0 @@
RootView = require 'views/core/RootView'
template = require 'templates/artisans/course-gear-view'
Level = require 'models/Level'
Campaign = require 'models/Campaign'
Level = require 'models/Level'
CocoCollection = require 'collections/CocoCollection'
module.exports = class CourseGearView extends RootView
template: template
id: 'course-gear-view'
initialize: ->
@campaigns = new CocoCollection([],
url: '/db/campaign?project=slug'
model: Campaign
)
@supermodel.trackRequest(@campaigns.fetch(), @do )

View file

@ -9,14 +9,18 @@ module.exports = class LevelTasksView extends RootView
template: template
id: 'level-tasks-view'
events:
'input .searchInput': 'searchUpdate'
'change .searchInput': 'searchUpdate'
'input .searchInput': 'processLevels'
'change .searchInput': 'processLevels'
excludedCampaigns = [
'picoctf', 'auditions'
]
levels: {}
processedLevels: {}
initialize: () ->
@searchUpdate = _.debounce(@searchUpdate, 250)
@processLevels = _.debounce(@processLevels, 250)
@campaigns = new Campaigns()
@listenTo(@campaigns, 'sync', @onCampaignsLoaded)
@ -32,12 +36,16 @@ module.exports = class LevelTasksView extends RootView
continue if campaignSlug in excludedCampaigns
levels = campaign.get 'levels'
for key, level of levels
continue unless ///#{$('#nameSearch')[0].value}///i.test level.name
levelSlug = level.slug
@levels[levelSlug] = level
@processLevels()
processLevels: () ->
@processedLevels = {}
for key, level of @levels
filteredTasks = level.tasks.filter (elem) ->
continue unless ///#{$('#nameSearch')[0].value}///i.test level.name
filteredTasks = level.tasks.filter (elem) ->
# Similar case-insensitive search of input vs description (name).
return ///#{$('#descSearch')[0].value}///i.test elem.name
@processedLevels[key] = {
tasks: filteredTasks
@ -45,23 +53,6 @@ module.exports = class LevelTasksView extends RootView
}
@renderSelectors '#levelTable'
searchUpdate: ->
@onCampaignsLoaded(@campaigns)
###
if not @lastLoad? or (new Date()).getTime() - @lastLoad > 60 * 1000 * 1 # Update only after a minute from last update.
#@campaigns.fetch()
@listenTo(@campaigns, 'sync', @onCampaignsLoaded)
@superModel.trackRequest()
#@supermodel.loadCollection(@campaigns, 'campaigns')
@lastLoad = (new Date()).getTime()
else
@onCampaignsLoaded()
###
destroy: ->
@searchUpdate.cancel()
super()
# Jade helper
hasIncompleteTasks: (level) ->
return level.tasks and level.tasks.filter((_elem) -> return not _elem.complete).length > 0
return level.tasks and level.tasks.filter((_elem) -> return not _elem.complete).length > 0

View file

@ -16,7 +16,8 @@ module.exports = class SolutionProblemsView extends RootView
'picoctf', 'auditions'
# Campaign-version campaigns
#'dungeon', 'forest', 'desert', 'mountain', 'glacier'
'dungeon', 'forest', 'desert',# 'mountain',
'glacier'
# Test campaigns
'dungeon-branching-test', 'forest-branching-test', 'desert-branching-test'
@ -48,11 +49,12 @@ module.exports = class SolutionProblemsView extends RootView
]
# TODO: Phase the following out:
excludedLanguages = [
#'java', 'lua', 'coffeescript'
'java', 'lua', 'coffeescript'
]
rob: []
test2: []
excludedLevelSnippets = [
'treasure', 'brawl', 'siege'
]
unloadedCampaigns: 0
campaignLevels: {}
loadedLevels: {}
@ -92,6 +94,11 @@ module.exports = class SolutionProblemsView extends RootView
console.error 'Level Slug doesn\'t have associated Level', levelSlug
continue
continue if levelSlug in excludedSolutionLevels
isBad = false
for word in excludedLevelSnippets
if levelSlug.indexOf(word) isnt -1
isBad = true
continue if isBad
thangs = level.get 'thangs'
component = null
thangs = _.filter(thangs, (elem) ->

View file

@ -9,25 +9,26 @@ module.exports = class ThangTasksView extends RootView
template: template
id: 'thang-tasks-view'
events:
'input input': 'searchUpdate'
'change input': 'searchUpdate'
'input input': 'processThangs'
'change input': 'processThangs'
thangs: {}
processedThangs: {}
initialize: () ->
@processThangs = _.debounce(@processThangs, 250)
@thangs = new ThangTypes()
@listenTo(@thangs, 'sync', @onThangsLoaded)
@supermodel.trackRequest(@thangs.fetch(
data:
project: 'name,tasks,slug'
))
searchUpdate: ->
if not @lastLoad? or (new Date()).getTime() - @lastLoad > 60 * 1000 * 1 # Update only after a minute from last update.
@thangs.fetch()
@listenTo(@thangs, 'sync', @onThangsLoaded)
@supermodel.loadCollection(@thangs, 'thangs')
@lastLoad = (new Date()).getTime()
else
@onThangsLoaded()
onThangsLoaded: ->
onThangsLoaded: (thangCollection) ->
@processThangs()
processThangs: ->
@processedThangs = @thangs.filter (_elem) ->
# Case-insensitive search of input vs name.
return ///#{$('#nameSearch')[0].value}///i.test _elem.get('name')
@ -42,4 +43,4 @@ module.exports = class ThangTasksView extends RootView
# Jade helper
hasIncompleteTasks: (thang) ->
return thang.tasks and thang.tasks.filter((_elem) -> return not _elem.complete).length > 0
return thang.tasks and thang.tasks.filter((_elem) -> return not _elem.complete).length > 0