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': go('artisans/ArtisansView')
|
||||||
|
|
||||||
'artisans/solution-problems': go('artisans/SolutionProblemsView')
|
|
||||||
'artisans/course-gear': go('artisans/CourseGearView')
|
|
||||||
'artisans/level-tasks': go('artisans/LevelTasksView')
|
'artisans/level-tasks': go('artisans/LevelTasksView')
|
||||||
|
'artisans/solution-problems': go('artisans/SolutionProblemsView')
|
||||||
'artisans/thang-tasks': go('artisans/ThangTasksView')
|
'artisans/thang-tasks': go('artisans/ThangTasksView')
|
||||||
|
|
||||||
'beta': go('HomeView')
|
'beta': go('HomeView')
|
||||||
|
|
|
@ -10,7 +10,4 @@ block content
|
||||||
|Level Tasks
|
|Level Tasks
|
||||||
div
|
div
|
||||||
a(href="/artisans/solution-problems")
|
a(href="/artisans/solution-problems")
|
||||||
|Solution Problems
|
|Solution Problems
|
||||||
div
|
|
||||||
a(href="/artisans/course-gear")
|
|
||||||
|Course Gear Progression
|
|
|
@ -1,3 +0,0 @@
|
||||||
extends /templates/base
|
|
||||||
|
|
||||||
block content
|
|
|
@ -1,25 +1,28 @@
|
||||||
|
# DNT
|
||||||
extends /templates/base
|
extends /templates/base
|
||||||
|
|
||||||
block content
|
block content
|
||||||
#level-tasks-view
|
#level-tasks-view
|
||||||
div
|
div
|
||||||
a(href='/artisans')
|
a(href='/artisans')
|
||||||
| < Artisans Home
|
span.glyphicon.glyphicon-chevron-left
|
||||||
|
span Artisans Home
|
||||||
br
|
br
|
||||||
input#nameSearch(placeholder='Filter: Level Name')
|
input.searchInput#nameSearch(placeholder='Filter: Level Name')
|
||||||
br
|
br
|
||||||
input#descSearch(placeholder='Filter: Task Description')
|
input.searchInput#descSearch(placeholder='Filter: Task Description')
|
||||||
hr
|
hr
|
||||||
if view.processedLevels
|
div#levelTable
|
||||||
table.table.table-striped#levelTable
|
if view.processedLevels
|
||||||
tr
|
table.table.table-striped
|
||||||
th Level Name
|
tr
|
||||||
th Task List
|
th Level Name
|
||||||
for level in view.processedLevels
|
th Task List
|
||||||
if view.hasIncompleteTasks(level)
|
for level in view.processedLevels
|
||||||
+levelRow(level)
|
if view.hasIncompleteTasks(level)
|
||||||
else
|
+levelRow(level)
|
||||||
div ole?
|
else
|
||||||
|
div No view.processedLevels
|
||||||
|
|
||||||
mixin levelRow(level)
|
mixin levelRow(level)
|
||||||
tr
|
tr
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
|
# DNT
|
||||||
extends /templates/base
|
extends /templates/base
|
||||||
|
|
||||||
block content
|
block content
|
||||||
#solution-problems-view
|
#solution-problems-view
|
||||||
div
|
div
|
||||||
a(href='/artisans')
|
a(href='/artisans')
|
||||||
| < Artisans Home
|
span.glyphicon.glyphicon-chevron-left
|
||||||
|
span Artisans Home
|
||||||
br
|
br
|
||||||
div Total number of problems: #{view.problemCount}
|
div Total number of problems: #{view.problemCount}
|
||||||
hr
|
hr
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
|
# DNT
|
||||||
extends /templates/base
|
extends /templates/base
|
||||||
|
|
||||||
block content
|
block content
|
||||||
#thang-tasks-view
|
#thang-tasks-view
|
||||||
div
|
div
|
||||||
a(href='/artisans')
|
a(href='/artisans')
|
||||||
| < Artisans Home
|
span.glyphicon.glyphicon-chevron-left
|
||||||
|
span Artisans Home
|
||||||
|
input.inputSearch#nameSearch(placeholder='Filter: Thang Name')
|
||||||
br
|
br
|
||||||
input#nameSearch(placeholder='Filter: Thang Name')
|
input.inputSearch#descSearch(placeholder='Filter: Task Description')
|
||||||
br
|
|
||||||
input#descSearch(placeholder='Filter: Task Description')
|
|
||||||
hr
|
hr
|
||||||
if view.processedThangs
|
div#thangTable
|
||||||
table.table.table-striped#thangTable
|
if view.processedThangs
|
||||||
tr
|
table.table.table-striped#thangTable
|
||||||
th Thang Name
|
tr
|
||||||
th Task List
|
th Thang Name
|
||||||
for thang in view.processedThangs
|
th Task List
|
||||||
if view.hasIncompleteTasks(thang)
|
for thang in view.processedThangs
|
||||||
+thangRow(thang)
|
if view.hasIncompleteTasks(thang)
|
||||||
else
|
+thangRow(thang)
|
||||||
span No view.processedThangs
|
else
|
||||||
|
span No view.processedThangs
|
||||||
|
|
||||||
mixin thangRow(thang)
|
mixin thangRow(thang)
|
||||||
tr
|
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
|
template: template
|
||||||
id: 'level-tasks-view'
|
id: 'level-tasks-view'
|
||||||
events:
|
events:
|
||||||
'input .searchInput': 'searchUpdate'
|
'input .searchInput': 'processLevels'
|
||||||
'change .searchInput': 'searchUpdate'
|
'change .searchInput': 'processLevels'
|
||||||
|
|
||||||
excludedCampaigns = [
|
excludedCampaigns = [
|
||||||
'picoctf', 'auditions'
|
'picoctf', 'auditions'
|
||||||
]
|
]
|
||||||
|
|
||||||
levels: {}
|
levels: {}
|
||||||
|
processedLevels: {}
|
||||||
|
|
||||||
initialize: () ->
|
initialize: () ->
|
||||||
@searchUpdate = _.debounce(@searchUpdate, 250)
|
@processLevels = _.debounce(@processLevels, 250)
|
||||||
|
|
||||||
@campaigns = new Campaigns()
|
@campaigns = new Campaigns()
|
||||||
@listenTo(@campaigns, 'sync', @onCampaignsLoaded)
|
@listenTo(@campaigns, 'sync', @onCampaignsLoaded)
|
||||||
|
@ -32,12 +36,16 @@ module.exports = class LevelTasksView extends RootView
|
||||||
continue if campaignSlug in excludedCampaigns
|
continue if campaignSlug in excludedCampaigns
|
||||||
levels = campaign.get 'levels'
|
levels = campaign.get 'levels'
|
||||||
for key, level of levels
|
for key, level of levels
|
||||||
continue unless ///#{$('#nameSearch')[0].value}///i.test level.name
|
|
||||||
levelSlug = level.slug
|
levelSlug = level.slug
|
||||||
@levels[levelSlug] = level
|
@levels[levelSlug] = level
|
||||||
|
@processLevels()
|
||||||
|
|
||||||
|
processLevels: () ->
|
||||||
@processedLevels = {}
|
@processedLevels = {}
|
||||||
for key, level of @levels
|
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
|
return ///#{$('#descSearch')[0].value}///i.test elem.name
|
||||||
@processedLevels[key] = {
|
@processedLevels[key] = {
|
||||||
tasks: filteredTasks
|
tasks: filteredTasks
|
||||||
|
@ -45,23 +53,6 @@ module.exports = class LevelTasksView extends RootView
|
||||||
}
|
}
|
||||||
@renderSelectors '#levelTable'
|
@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
|
# Jade helper
|
||||||
hasIncompleteTasks: (level) ->
|
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
|
||||||
|
|
|
@ -16,7 +16,8 @@ module.exports = class SolutionProblemsView extends RootView
|
||||||
'picoctf', 'auditions'
|
'picoctf', 'auditions'
|
||||||
|
|
||||||
# Campaign-version campaigns
|
# Campaign-version campaigns
|
||||||
#'dungeon', 'forest', 'desert', 'mountain', 'glacier'
|
'dungeon', 'forest', 'desert',# 'mountain',
|
||||||
|
'glacier'
|
||||||
|
|
||||||
# Test campaigns
|
# Test campaigns
|
||||||
'dungeon-branching-test', 'forest-branching-test', 'desert-branching-test'
|
'dungeon-branching-test', 'forest-branching-test', 'desert-branching-test'
|
||||||
|
@ -48,11 +49,12 @@ module.exports = class SolutionProblemsView extends RootView
|
||||||
]
|
]
|
||||||
# TODO: Phase the following out:
|
# TODO: Phase the following out:
|
||||||
excludedLanguages = [
|
excludedLanguages = [
|
||||||
#'java', 'lua', 'coffeescript'
|
'java', 'lua', 'coffeescript'
|
||||||
]
|
]
|
||||||
|
excludedLevelSnippets = [
|
||||||
rob: []
|
'treasure', 'brawl', 'siege'
|
||||||
test2: []
|
]
|
||||||
|
|
||||||
unloadedCampaigns: 0
|
unloadedCampaigns: 0
|
||||||
campaignLevels: {}
|
campaignLevels: {}
|
||||||
loadedLevels: {}
|
loadedLevels: {}
|
||||||
|
@ -92,6 +94,11 @@ module.exports = class SolutionProblemsView extends RootView
|
||||||
console.error 'Level Slug doesn\'t have associated Level', levelSlug
|
console.error 'Level Slug doesn\'t have associated Level', levelSlug
|
||||||
continue
|
continue
|
||||||
continue if levelSlug in excludedSolutionLevels
|
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'
|
thangs = level.get 'thangs'
|
||||||
component = null
|
component = null
|
||||||
thangs = _.filter(thangs, (elem) ->
|
thangs = _.filter(thangs, (elem) ->
|
||||||
|
|
|
@ -9,25 +9,26 @@ module.exports = class ThangTasksView extends RootView
|
||||||
template: template
|
template: template
|
||||||
id: 'thang-tasks-view'
|
id: 'thang-tasks-view'
|
||||||
events:
|
events:
|
||||||
'input input': 'searchUpdate'
|
'input input': 'processThangs'
|
||||||
'change input': 'searchUpdate'
|
'change input': 'processThangs'
|
||||||
|
|
||||||
|
thangs: {}
|
||||||
|
processedThangs: {}
|
||||||
|
|
||||||
initialize: () ->
|
initialize: () ->
|
||||||
|
@processThangs = _.debounce(@processThangs, 250)
|
||||||
|
|
||||||
@thangs = new ThangTypes()
|
@thangs = new ThangTypes()
|
||||||
@listenTo(@thangs, 'sync', @onThangsLoaded)
|
@listenTo(@thangs, 'sync', @onThangsLoaded)
|
||||||
@supermodel.trackRequest(@thangs.fetch(
|
@supermodel.trackRequest(@thangs.fetch(
|
||||||
data:
|
data:
|
||||||
project: 'name,tasks,slug'
|
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) ->
|
@processedThangs = @thangs.filter (_elem) ->
|
||||||
# Case-insensitive search of input vs name.
|
# Case-insensitive search of input vs name.
|
||||||
return ///#{$('#nameSearch')[0].value}///i.test _elem.get('name')
|
return ///#{$('#nameSearch')[0].value}///i.test _elem.get('name')
|
||||||
|
@ -42,4 +43,4 @@ module.exports = class ThangTasksView extends RootView
|
||||||
|
|
||||||
# Jade helper
|
# Jade helper
|
||||||
hasIncompleteTasks: (thang) ->
|
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
|
||||||
|
|
Loading…
Reference in a new issue