mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-17 19:12:33 -05:00
Utilize debounce, clean up event logic, remove unused CourseGearView
This commit is contained in:
parent
38e97ab404
commit
a5cad6f986
11 changed files with 76 additions and 93 deletions
|
@ -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')
|
||||
|
|
|
@ -11,6 +11,3 @@ block content
|
|||
div
|
||||
a(href="/artisans/solution-problems")
|
||||
|Solution Problems
|
||||
div
|
||||
a(href="/artisans/course-gear")
|
||||
|Course Gear Progression
|
|
@ -1,3 +0,0 @@
|
|||
extends /templates/base
|
||||
|
||||
block content
|
|
@ -1,17 +1,20 @@
|
|||
# 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
|
||||
div#levelTable
|
||||
if view.processedLevels
|
||||
table.table.table-striped#levelTable
|
||||
table.table.table-striped
|
||||
tr
|
||||
th Level Name
|
||||
th Task List
|
||||
|
@ -19,7 +22,7 @@ block content
|
|||
if view.hasIncompleteTasks(level)
|
||||
+levelRow(level)
|
||||
else
|
||||
div ole?
|
||||
div No view.processedLevels
|
||||
|
||||
mixin levelRow(level)
|
||||
tr
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
# 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
|
||||
div#thangTable
|
||||
if view.processedThangs
|
||||
table.table.table-striped#thangTable
|
||||
tr
|
||||
|
|
|
@ -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 )
|
|
@ -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
|
||||
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
|
|
@ -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'
|
||||
]
|
||||
excludedLevelSnippets = [
|
||||
'treasure', 'brawl', 'siege'
|
||||
]
|
||||
|
||||
rob: []
|
||||
test2: []
|
||||
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) ->
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue