From a5cad6f98660bb973d37e5ef31d3988786c81181 Mon Sep 17 00:00:00 2001 From: Josh Callebaut Date: Mon, 16 May 2016 11:45:06 -0700 Subject: [PATCH] Utilize debounce, clean up event logic, remove unused CourseGearView --- app/core/Router.coffee | 3 +- app/styles/artisans/course-gear-view.sass | 0 app/templates/artisans/artisans-view.jade | 5 +-- app/templates/artisans/course-gear-view.jade | 3 -- app/templates/artisans/level-tasks-view.jade | 29 ++++++++------- .../artisans/solution-problems-view.jade | 4 +- app/templates/artisans/thang-tasks-view.jade | 30 ++++++++------- app/views/artisans/CourseGearView.coffee | 16 -------- app/views/artisans/LevelTasksView.coffee | 37 +++++++------------ .../artisans/SolutionProblemsView.coffee | 17 ++++++--- app/views/artisans/ThangTasksView.coffee | 25 +++++++------ 11 files changed, 76 insertions(+), 93 deletions(-) delete mode 100644 app/styles/artisans/course-gear-view.sass delete mode 100644 app/templates/artisans/course-gear-view.jade delete mode 100644 app/views/artisans/CourseGearView.coffee diff --git a/app/core/Router.coffee b/app/core/Router.coffee index 64ba4535e..44bc54c6a 100644 --- a/app/core/Router.coffee +++ b/app/core/Router.coffee @@ -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') diff --git a/app/styles/artisans/course-gear-view.sass b/app/styles/artisans/course-gear-view.sass deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/templates/artisans/artisans-view.jade b/app/templates/artisans/artisans-view.jade index 9eebf08d4..c2b5b3215 100644 --- a/app/templates/artisans/artisans-view.jade +++ b/app/templates/artisans/artisans-view.jade @@ -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 \ No newline at end of file + |Solution Problems \ No newline at end of file diff --git a/app/templates/artisans/course-gear-view.jade b/app/templates/artisans/course-gear-view.jade deleted file mode 100644 index 5b40f96a0..000000000 --- a/app/templates/artisans/course-gear-view.jade +++ /dev/null @@ -1,3 +0,0 @@ -extends /templates/base - -block content \ No newline at end of file diff --git a/app/templates/artisans/level-tasks-view.jade b/app/templates/artisans/level-tasks-view.jade index cead6003a..f905d61ac 100644 --- a/app/templates/artisans/level-tasks-view.jade +++ b/app/templates/artisans/level-tasks-view.jade @@ -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 diff --git a/app/templates/artisans/solution-problems-view.jade b/app/templates/artisans/solution-problems-view.jade index ab9cfefba..6b44bf71b 100644 --- a/app/templates/artisans/solution-problems-view.jade +++ b/app/templates/artisans/solution-problems-view.jade @@ -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 diff --git a/app/templates/artisans/thang-tasks-view.jade b/app/templates/artisans/thang-tasks-view.jade index 1e08cea18..01275b99c 100644 --- a/app/templates/artisans/thang-tasks-view.jade +++ b/app/templates/artisans/thang-tasks-view.jade @@ -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 diff --git a/app/views/artisans/CourseGearView.coffee b/app/views/artisans/CourseGearView.coffee deleted file mode 100644 index 9a9181f4a..000000000 --- a/app/views/artisans/CourseGearView.coffee +++ /dev/null @@ -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 ) \ No newline at end of file diff --git a/app/views/artisans/LevelTasksView.coffee b/app/views/artisans/LevelTasksView.coffee index 174b5b4de..51269886f 100644 --- a/app/views/artisans/LevelTasksView.coffee +++ b/app/views/artisans/LevelTasksView.coffee @@ -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 \ No newline at end of file + return level.tasks and level.tasks.filter((_elem) -> return not _elem.complete).length > 0 diff --git a/app/views/artisans/SolutionProblemsView.coffee b/app/views/artisans/SolutionProblemsView.coffee index c672f3fea..bec950ba2 100644 --- a/app/views/artisans/SolutionProblemsView.coffee +++ b/app/views/artisans/SolutionProblemsView.coffee @@ -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) -> diff --git a/app/views/artisans/ThangTasksView.coffee b/app/views/artisans/ThangTasksView.coffee index 65d170493..5e226f806 100644 --- a/app/views/artisans/ThangTasksView.coffee +++ b/app/views/artisans/ThangTasksView.coffee @@ -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 \ No newline at end of file + return thang.tasks and thang.tasks.filter((_elem) -> return not _elem.complete).length > 0