2016-08-25 18:31:24 -04:00
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
template = require 'templates/artisans/level-guides-view'
|
|
|
|
|
|
|
|
Campaigns = require 'collections/Campaigns'
|
|
|
|
Campaign = require 'models/Campaign'
|
|
|
|
|
|
|
|
Levels = require 'collections/Levels'
|
|
|
|
Level = require 'models/Level'
|
|
|
|
|
|
|
|
module.exports = class LevelGuidesView extends RootView
|
|
|
|
template: template
|
|
|
|
id: 'level-guides-view'
|
|
|
|
events:
|
|
|
|
'click #overview-button': 'onOverviewButtonClicked'
|
|
|
|
'click #intro-button': 'onIntroButtonClicked'
|
|
|
|
|
|
|
|
excludedCampaigns = [
|
|
|
|
'pico-ctf', 'auditions'
|
|
|
|
]
|
|
|
|
includedCampaigns = [
|
|
|
|
'intro', 'course-2', 'course-3', 'course-4', 'course-5', 'course-6',
|
|
|
|
'web-dev-1', 'web-dev-2',
|
|
|
|
'game-dev-1', 'game-dev-2'
|
|
|
|
]
|
|
|
|
levels: []
|
|
|
|
|
|
|
|
onOverviewButtonClicked: (e) ->
|
2016-08-25 18:37:49 -04:00
|
|
|
@$('.overview').toggleClass('in')
|
2016-08-25 18:31:24 -04:00
|
|
|
onIntroButtonClicked: (e) ->
|
2016-08-25 18:37:49 -04:00
|
|
|
@$('.intro').toggleClass('in')
|
2016-08-25 18:31:24 -04:00
|
|
|
|
|
|
|
initialize: () ->
|
|
|
|
|
|
|
|
@campaigns = new Campaigns()
|
|
|
|
|
|
|
|
@listenTo(@campaigns, 'sync', @onCampaignsLoaded)
|
|
|
|
@supermodel.trackRequest(@campaigns.fetch(
|
|
|
|
data:
|
|
|
|
project: 'name,slug,levels'
|
|
|
|
))
|
|
|
|
onCampaignsLoaded: (campCollection) ->
|
|
|
|
for camp in campCollection.models
|
|
|
|
campaignSlug = camp.get 'slug'
|
|
|
|
continue if campaignSlug in excludedCampaigns
|
|
|
|
continue unless campaignSlug in includedCampaigns
|
|
|
|
levels = camp.get 'levels'
|
|
|
|
|
|
|
|
levels = new Levels()
|
2016-08-25 18:37:49 -04:00
|
|
|
@listenTo(levels, 'sync', @onLevelsLoaded)
|
2016-08-25 18:31:24 -04:00
|
|
|
levels.fetchForCampaign(campaignSlug)
|
|
|
|
#for key, level of levels
|
|
|
|
|
|
|
|
onLevelsLoaded: (lvlCollection) ->
|
|
|
|
lvlCollection.models.reverse()
|
|
|
|
#console.log lvlCollection
|
|
|
|
for level in lvlCollection.models
|
|
|
|
#console.log level
|
|
|
|
levelSlug = level.get 'slug'
|
2016-08-25 18:37:49 -04:00
|
|
|
overview = _.find(level.get('documentation').specificArticles, name:'Overview')
|
|
|
|
intro = _.find(level.get('documentation').specificArticles, name:'Intro')
|
2016-08-25 18:31:24 -04:00
|
|
|
#if intro and overview
|
|
|
|
problems = []
|
|
|
|
if not overview
|
2016-08-25 18:37:49 -04:00
|
|
|
problems.push 'No Overview'
|
2016-08-25 18:31:24 -04:00
|
|
|
else
|
|
|
|
if not overview.i18n
|
2016-08-25 18:37:49 -04:00
|
|
|
problems.push 'Overview doesn't have i18n field'
|
2016-08-25 18:31:24 -04:00
|
|
|
if not overview.body
|
2016-08-25 18:37:49 -04:00
|
|
|
problems.push 'Overview doesn't have a body'
|
2016-08-25 18:31:24 -04:00
|
|
|
else
|
|
|
|
if level.get('campaign')?.indexOf('web') is -1
|
|
|
|
jsIndex = overview.body.indexOf('```javascript')
|
|
|
|
pyIndex = overview.body.indexOf('```python')
|
|
|
|
if jsIndex is -1 and pyIndex isnt -1 or jsIndex isnt -1 and pyIndex is -1
|
2016-08-25 18:37:49 -04:00
|
|
|
problems.push 'Overview is missing a language example.'
|
2016-08-25 18:31:24 -04:00
|
|
|
if not intro
|
2016-08-25 18:37:49 -04:00
|
|
|
problems.push 'No Intro'
|
2016-08-25 18:31:24 -04:00
|
|
|
else
|
|
|
|
if not intro.i18n
|
2016-08-25 18:37:49 -04:00
|
|
|
problems.push 'Intro doesn't have i18n field'
|
2016-08-25 18:31:24 -04:00
|
|
|
if not intro.body
|
2016-08-25 18:37:49 -04:00
|
|
|
problems.push 'Intro doesn't have a body'
|
2016-08-25 18:31:24 -04:00
|
|
|
else
|
|
|
|
if intro.body.indexOf('file/db') is -1
|
2016-08-25 18:37:49 -04:00
|
|
|
problems.push 'Intro is missing image'
|
2016-08-25 18:31:24 -04:00
|
|
|
if level.get('campaign')?.indexOf('web') is -1
|
|
|
|
jsIndex = intro.body.indexOf('```javascript')
|
|
|
|
pyIndex = intro.body.indexOf('```python')
|
|
|
|
if jsIndex is -1 and pyIndex isnt -1 or jsIndex isnt -1 and pyIndex is -1
|
2016-08-25 18:37:49 -04:00
|
|
|
problems.push 'Intro is missing a language example.'
|
2016-08-25 18:31:24 -04:00
|
|
|
@levels.push
|
|
|
|
level: level
|
|
|
|
overview: overview
|
|
|
|
intro: intro
|
|
|
|
problems: problems
|
|
|
|
@levels.sort (a, b) ->
|
|
|
|
return b.problems.length - a.problems.length
|
2016-08-25 18:37:49 -04:00
|
|
|
@renderSelectors '#level-table'
|