Add nascent version of the mod detail page

* Create a nascent version of the mod detail page
* Make the slug mandatory for Mod instead of name, and load the name
  from the data file
* Make the Feedback view universal on all pages
* Refactor the use of mod pack to have a single global object at the
  router level which is shared between pages. Further, make this one
  object load itself immediately and have it automatically load any
  activated mod version
* Refactor the use of Storage related to mod pack versions into the
  router as well.
* Add trace logging back in for events, but allow individual classes
  to suppress it (as opposed to actually supressing the events)
* Fix a bug in ModVersion.eachItem where it would suggest so-called
  items which are merely registered slugs without associated items
This commit is contained in:
Andrew Miner
2015-01-20 10:55:38 -08:00
parent d33723b3c2
commit 164c0d4892
25 changed files with 151 additions and 26 deletions
+7
View File
@@ -13,6 +13,7 @@ All rights reserved.
module.exports = class BaseModel extends Backbone.Model
constructor: (attributes={}, options={})->
options.logEvents ?= true
super attributes, options
makeGetter = (name)-> return -> @get name
@@ -21,6 +22,7 @@ module.exports = class BaseModel extends Backbone.Model
continue if name is 'id'
Object.defineProperty this, name, get:makeGetter(name), set:makeSetter(name)
@logEvents = options.logEvents or false
@state = ModelState.unloaded
@on 'request', => @state = ModelState.loading
@@ -77,6 +79,11 @@ module.exports = class BaseModel extends Backbone.Model
sync: (method, model)->
throw new Error "#{@constructor.name}.#{@cid} is not permitted to #{method}"
trigger: (name, model, args...)->
if @logEvents
logger.trace "#{@constructor.name}.#{@cid} triggered event #{name} with args: #{args}"
super
# Object Overrides #############################################################################
toString: ->
+2 -1
View File
@@ -19,6 +19,7 @@ module.exports = class Item extends BaseModel
attributes.isGatherable ?= false
attributes.slug ?= _.slugify attributes.name
options.logEvents ?= false
super attributes, options
@_recipes = []
@@ -57,7 +58,7 @@ module.exports = class Item extends BaseModel
if _.slugify(@name) isnt @slug
result.push ', slug:'; result.push @slug
if @recipes.length > 0
if @_recipes.length > 0
result.push ', recipes:«'
result.push @_recipes.length
result.push ' items»'
+2 -2
View File
@@ -15,11 +15,11 @@ BaseModel = require './base_model'
module.exports = class Mod extends BaseModel
constructor: (attributes={}, options={})->
if not attributes.name? then throw new Error 'attributes.name is required'
if not attributes.slug? then throw new Error 'attributes.slug is required'
attributes.author ?= ''
attributes.description ?= ''
attributes.name ?= ''
attributes.primaryUrl ?= null
attributes.slug ?= _.slugify attributes.name
super attributes, options
@_activeModVersion = null
+6
View File
@@ -78,6 +78,7 @@ module.exports = class ModPack extends BaseModel
# Property Methods #############################################################################
addMod: (mod)->
if not mod? then throw new Error 'mod is required'
return if @_mods.indexOf(mod) isnt -1
@_mods.push mod
@@ -94,6 +95,11 @@ module.exports = class ModPack extends BaseModel
for mod in @_mods
callback mod
getMod: (slug)->
for mod in @_mods
return mod if mod.slug is slug
return null
getMods: ->
return @_mods[..]
+2
View File
@@ -46,6 +46,8 @@ module.exports = class ModVersion extends BaseModel
eachItem: (callback)->
for slug in @_slugs
item = @_items[slug]
continue unless item?
callback @_items[slug], slug
return this
@@ -37,6 +37,11 @@ module.exports = class ModParserV2 extends CommandParserVersionBase
@_rawData.description = description
_command_name: (name)->
if @_rawData.name? then throw new Error 'duplicate declaration of "name"'
if name.length is 0 then throw new Error '"name" cannot be empty'
@_rawData.name = name
_command_url: (url='')->
if @_rawData.url? then throw new Error 'duplicate declaration of "url"'
if url.length is 0 then throw new Error 'url cannot be empty'
@@ -52,11 +57,13 @@ module.exports = class ModParserV2 extends CommandParserVersionBase
# Object Building Methods ######################################################################
_buildMod: (rawData, model)->
if not rawData.name? then throw new Error 'the "name" declaration is required'
if not rawData.url? then throw new Error 'the "url" declaration is required'
if not rawData.versions? then throw new Error 'at least one "version" declaration is required'
model.author = rawData.author if rawData.author?
model.description = rawData.description if rawData.description?
model.name = rawData.name
model.primaryUrl = rawData.url
for version in rawData.versions
+1
View File
@@ -27,6 +27,7 @@ module.exports = class Recipe extends BaseModel
attributes.pattern = @_parsePattern attributes.pattern
attributes.slug ?= attributes.output[0].slug
attributes.tools ?= []
options.logEvents ?= false
super attributes, options
# Public Methods ###############################################################################
+3 -2
View File
@@ -11,10 +11,11 @@ BaseModel = require './base_model'
module.exports = class Stack extends BaseModel
constructor: (attributes={})->
constructor: (attributes={}, options={})->
if not attributes.slug? then throw new Error 'attributes.slug is required'
attributes.quantity ?= 1
super attributes
options.logEvents ?= false
super attributes, options
# Object Overrides #############################################################################