mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Created superclass & common templates for article & level (fix for #30)
This commit is contained in:
parent
f4a2209d6f
commit
4633ced78d
10 changed files with 94 additions and 143 deletions
|
@ -1,21 +0,0 @@
|
|||
table.table
|
||||
tr
|
||||
th(colspan=3)
|
||||
span(data-i18n="article.index_table_results")
|
||||
| Results
|
||||
span
|
||||
|: #{documents.length}
|
||||
|
||||
tr
|
||||
th(data-i18n="article.index_table_name") Name
|
||||
th(data-i18n="article.index_table_body") Body
|
||||
th(data-i18n="article.index_table_version") Version
|
||||
|
||||
for article in documents
|
||||
- article = article.attributes;
|
||||
tr
|
||||
td
|
||||
a(href="/editor/article/#{article.slug || article._id}")
|
||||
| #{article.name}
|
||||
td.body-row #{article.body}
|
||||
td #{article.version.major}.#{article.version.minor}
|
|
@ -1,19 +0,0 @@
|
|||
extends /templates/base
|
||||
|
||||
block content
|
||||
if articles.length
|
||||
h3 Version History for: "#{articles[0].name}"
|
||||
|
||||
table.table
|
||||
tr
|
||||
th Name
|
||||
th Version
|
||||
th Commit Message
|
||||
|
||||
for article in articles
|
||||
tr
|
||||
td
|
||||
a(href="/editor/article/#{article.slug || article._id}")
|
||||
| #{article.name}
|
||||
td #{article.version.major}.#{article.version.minor}
|
||||
td #{article.commitMessage}
|
|
@ -1,21 +0,0 @@
|
|||
table.table
|
||||
tr
|
||||
th(colspan=3)
|
||||
span(data-i18n="level.index_table_results")
|
||||
| Results
|
||||
span
|
||||
|: #{documents.length}
|
||||
|
||||
tr
|
||||
th(data-i18n="level.index_table_name") Name
|
||||
th(data-i18n="level.index_table_description") Description
|
||||
th(data-i18n="level.index_table_version") Version
|
||||
|
||||
for level in documents
|
||||
- level = level.attributes;
|
||||
tr
|
||||
td
|
||||
a(href="/editor/level/#{level.slug || level._id}")
|
||||
| #{level.name}
|
||||
td.body-row #{level.description}
|
||||
td #{level.version.major}.#{level.version.minor}
|
|
@ -1,19 +0,0 @@
|
|||
extends /templates/base
|
||||
|
||||
block content
|
||||
if levels
|
||||
h3 Version History for: "#{levels[0].name}"
|
||||
|
||||
table.table
|
||||
tr
|
||||
th Name
|
||||
th Version
|
||||
th Commit Message
|
||||
|
||||
for level in levels
|
||||
tr
|
||||
td
|
||||
a(href="/editor/level/#{level.slug || level._id}")
|
||||
| #{level.name}
|
||||
td #{level.version.major}.#{level.version.minor}
|
||||
td #{level.commitMessage}
|
21
app/templates/kinds/table.jade
Executable file
21
app/templates/kinds/table.jade
Executable file
|
@ -0,0 +1,21 @@
|
|||
table.table
|
||||
tr
|
||||
th(colspan=3)
|
||||
span(data-i18n="general.results")
|
||||
| Results
|
||||
span
|
||||
|: #{documents.length}
|
||||
|
||||
tr
|
||||
th(data-i18n="general.name") Name
|
||||
th(data-i18n="general.description") Description
|
||||
th(data-i18n="general.version") Version
|
||||
|
||||
for data in documents
|
||||
- data = data.attributes;
|
||||
tr
|
||||
td
|
||||
a(href="/editor/#{page}/#{data.slug || data._id}")
|
||||
| #{data.name}
|
||||
td.body-row #{data.description}
|
||||
td #{data.version.major}.#{data.version.minor}
|
19
app/templates/kinds/versions.jade
Executable file
19
app/templates/kinds/versions.jade
Executable file
|
@ -0,0 +1,19 @@
|
|||
extends /templates/base
|
||||
|
||||
block content
|
||||
if dataList
|
||||
h3(data-i18n="general.version_history_for") Version History for: "#{dataList[0].name}"
|
||||
|
||||
table.table
|
||||
tr
|
||||
th(data-i18n="general.name") Name
|
||||
th(data-i18n="general.version") Version
|
||||
th(data-i18n="general.commit_msg") Commit Message
|
||||
|
||||
for data in dataList
|
||||
tr
|
||||
td
|
||||
a(href="/editor/#{page}/#{data.slug || data._id}")
|
||||
| #{data.name}
|
||||
td #{data.version.major}.#{data.version.minor}
|
||||
td #{data.commitMessage}
|
|
@ -5,4 +5,4 @@ module.exports = class ThangTypeHomeView extends SearchView
|
|||
modelLabel: 'Article'
|
||||
model: require 'models/Article'
|
||||
modelURL: '/db/article'
|
||||
tableTemplate: require 'templates/editor/article/table'
|
||||
tableTemplate: require 'templates/kinds/table'
|
||||
|
|
|
@ -1,34 +1,9 @@
|
|||
View = require 'views/kinds/RootView'
|
||||
template = require 'templates/editor/article/versions'
|
||||
tableTemplate = require 'templates/editor/article/table'
|
||||
Article = require 'models/Article'
|
||||
VersionsView = require 'views/kinds/VersionsView'
|
||||
|
||||
class ArticleVersionsCollection extends Backbone.Collection
|
||||
url: '/db/article/'
|
||||
model: Article
|
||||
initialize: (@articleID) -> @url += articleID + '/versions'
|
||||
|
||||
module.exports = class ArticleVersionsView extends View
|
||||
module.exports = class SuperVersionsView extends VersionsView
|
||||
id: "editor-article-versions-view"
|
||||
template: template
|
||||
startsLoading: true
|
||||
url: "/db/article/"
|
||||
page: "article"
|
||||
|
||||
constructor: (options, @articleID) ->
|
||||
super options
|
||||
@article = new Article(_id: @articleID)
|
||||
@article.fetch()
|
||||
@article.once('sync', @onArticleSync)
|
||||
|
||||
onArticleSync: =>
|
||||
@collection = new ArticleVersionsCollection(@article.attributes.original)
|
||||
@collection.fetch()
|
||||
@collection.on('sync', @onVersionFetched)
|
||||
|
||||
onVersionFetched: =>
|
||||
@startsLoading = false
|
||||
@render()
|
||||
|
||||
getRenderData: (context={}) =>
|
||||
context = super(context)
|
||||
context.articles = if @collection then (m.attributes for m in @collection.models) else []
|
||||
context
|
||||
constructor: (options, @ID) ->
|
||||
super options, ID, require 'models/Article'
|
|
@ -1,34 +1,9 @@
|
|||
View = require 'views/kinds/RootView'
|
||||
template = require 'templates/editor/level/versions'
|
||||
tableTemplate = require 'templates/editor/level/table'
|
||||
Level = require 'models/Level'
|
||||
VersionsView = require 'views/kinds/VersionsView'
|
||||
|
||||
class LevelVersionsCollection extends Backbone.Collection
|
||||
url: '/db/level/'
|
||||
model: Level
|
||||
initialize: (@levelID) -> @url += levelID + '/versions'
|
||||
|
||||
module.exports = class LevelVersionsView extends View
|
||||
module.exports = class SuperVersionsView extends VersionsView
|
||||
id: "editor-level-versions-view"
|
||||
template: template
|
||||
startsLoading: true
|
||||
url: "/db/level/"
|
||||
page: "level"
|
||||
|
||||
constructor: (options, @levelID) ->
|
||||
super options
|
||||
@level = new Level(_id: @levelID)
|
||||
@level.fetch()
|
||||
@level.once('sync', @onLevelSync)
|
||||
|
||||
onLevelSync: =>
|
||||
@collection = new LevelVersionsCollection(@level.attributes.original)
|
||||
@collection.fetch()
|
||||
@collection.on('sync', @onVersionFetched)
|
||||
|
||||
onVersionFetched: =>
|
||||
@startsLoading = false
|
||||
@render()
|
||||
|
||||
getRenderData: (context={}) =>
|
||||
context = super(context)
|
||||
context.levels = (m.attributes for m in @collection.models) if @collection
|
||||
context
|
||||
constructor: (options, @ID) ->
|
||||
super options, ID, require 'models/Level'
|
41
app/views/kinds/VersionsView.coffee
Executable file
41
app/views/kinds/VersionsView.coffee
Executable file
|
@ -0,0 +1,41 @@
|
|||
View = require 'views/kinds/RootView'
|
||||
template = require 'templates/kinds/versions'
|
||||
tableTemplate = require 'templates/kinds/table'
|
||||
|
||||
class VersionsViewCollection extends Backbone.Collection
|
||||
url: ""
|
||||
model: null
|
||||
|
||||
initialize: (@url, @levelID, @model) ->
|
||||
@url = url + levelID + '/versions'
|
||||
@model = model
|
||||
|
||||
module.exports = class SuperVersionsView extends View
|
||||
template: template
|
||||
startsLoading: true
|
||||
|
||||
# needs to be overwritten by child
|
||||
id: ""
|
||||
url = ""
|
||||
page = ""
|
||||
|
||||
constructor: (options, @ID, @model) ->
|
||||
super options
|
||||
@view = new model(_id: @ID)
|
||||
@view.fetch()
|
||||
@view.once('sync', @onViewSync)
|
||||
|
||||
onViewSync: =>
|
||||
@collection = new VersionsViewCollection(@url, @view.attributes.original, @model)
|
||||
@collection.fetch()
|
||||
@collection.on('sync', @onVersionFetched)
|
||||
|
||||
onVersionFetched: =>
|
||||
@startsLoading = false
|
||||
@render()
|
||||
|
||||
getRenderData: (context={}) =>
|
||||
context = super(context)
|
||||
context.page = @page
|
||||
context.dataList = (m.attributes for m in @collection.models) if @collection
|
||||
context
|
Loading…
Reference in a new issue