Fix bug with recipe books table
This commit is contained in:
@@ -2,3 +2,4 @@
|
|||||||
.sass-cache
|
.sass-cache
|
||||||
dist
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
|
src/scripts/views.js
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ All rights reserved.
|
|||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
td:nth-child(1) { width: 30%; }
|
td:nth-child(1) { width: 5%; }
|
||||||
td:nth-child(2) { width: 70%; border-left: 0.1em solid $color-brick-light; }
|
td:nth-child(2) { width: 30%; }
|
||||||
|
td:nth-child(3) { width: 65%; border-left: 0.1em solid $color-brick-light; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ module.exports = class CraftingTableController extends BaseController
|
|||||||
# Private Methods ##############################################################################
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
_craft: ->
|
_craft: ->
|
||||||
if @model.catalog.findRecipes(@model.name).length > 0
|
if @model.catalog.hasRecipe @model.name
|
||||||
router.navigate "/item/#{encodeURIComponent(@model.name)}"
|
router.navigate "/item/#{encodeURIComponent(@model.name)}"
|
||||||
@model.craft()
|
@model.craft()
|
||||||
else
|
else
|
||||||
@@ -118,7 +118,7 @@ module.exports = class CraftingTableController extends BaseController
|
|||||||
onChanged = => @onNameFieldChanged()
|
onChanged = => @onNameFieldChanged()
|
||||||
|
|
||||||
@$nameField.autocomplete
|
@$nameField.autocomplete
|
||||||
source: @model.catalog.getRecipeNames()
|
source: @model.catalog.gatherNames()
|
||||||
delay: 0
|
delay: 0
|
||||||
minLength: 0
|
minLength: 0
|
||||||
change: onChanged
|
change: onChanged
|
||||||
|
|||||||
@@ -16,13 +16,27 @@ module.exports = class RecipeBookController extends BaseController
|
|||||||
options.templateName = 'recipe_book'
|
options.templateName = 'recipe_book'
|
||||||
super options
|
super options
|
||||||
|
|
||||||
|
# Event Methods ################################################################################
|
||||||
|
|
||||||
|
onEnabledChanged: ->
|
||||||
|
return unless @rendered
|
||||||
|
|
||||||
|
@model.enabled = @$(':checked').length > 0
|
||||||
|
|
||||||
# BaseController Overrides #####################################################################
|
# BaseController Overrides #####################################################################
|
||||||
|
|
||||||
onDidRender: ->
|
onDidRender: ->
|
||||||
@$name = @$('td:nth-child(1) p')
|
@$enabled = @$('td:nth-child(1) input')
|
||||||
@$description = @$('td:nth-child(2) p')
|
@$name = @$('td:nth-child(2) p')
|
||||||
|
@$description = @$('td:nth-child(3) p')
|
||||||
super
|
super
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
|
if @model.enabled then @$enabled.attr('checked', 'checked') else @$enabled.removeAttr('checked')
|
||||||
@$name.html "#{@model.modName} (#{@model.modVersion})"
|
@$name.html "#{@model.modName} (#{@model.modVersion})"
|
||||||
@$description.html "#{@model.description}"
|
@$description.html "#{@model.description}"
|
||||||
|
|
||||||
|
# Backbone.View Overrides ######################################################################
|
||||||
|
|
||||||
|
events:
|
||||||
|
'change input[type="checkbox"]': 'onEnabledChanged'
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ module.exports = class CraftingPlan
|
|||||||
targetItem = @_pending.pop()
|
targetItem = @_pending.pop()
|
||||||
return unless targetItem?
|
return unless targetItem?
|
||||||
|
|
||||||
recipes = @catalog.findRecipes targetItem.name
|
recipes = @catalog.gatherRecipes targetItem.name
|
||||||
return if not recipes.length > 0
|
return if not recipes.length > 0
|
||||||
recipe = recipes[0]
|
recipe = recipes[0]
|
||||||
|
|
||||||
|
|||||||
@@ -17,22 +17,39 @@ module.exports = class RecipeBook extends BaseModel
|
|||||||
|
|
||||||
attributes.description ?= ''
|
attributes.description ?= ''
|
||||||
attributes.recipes ?= []
|
attributes.recipes ?= []
|
||||||
|
attributes.enabled ?= true
|
||||||
super attributes, options
|
super attributes, options
|
||||||
|
|
||||||
# Public Methods ###############################################################################
|
# Public Methods ###############################################################################
|
||||||
|
|
||||||
findRecipes: (name)->
|
gatherNames: (result)->
|
||||||
result = []
|
return unless @enabled
|
||||||
|
|
||||||
|
for recipe in @recipes
|
||||||
|
continue if result[recipe.name]
|
||||||
|
result[recipe.name] = value:recipe.name, label:"#{recipe.name} (from #{@modName} #{@modVersion})"
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
gatherRecipes: (name, result)->
|
||||||
|
return unless @enabled
|
||||||
|
|
||||||
for recipe in @recipes
|
for recipe in @recipes
|
||||||
if recipe.name is name
|
if recipe.name is name
|
||||||
result.push recipe
|
result.push recipe
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
hasRecipe: (name)->
|
||||||
|
for recipe in @recipes
|
||||||
|
return true if recipe.name is name
|
||||||
|
return false
|
||||||
|
|
||||||
# Object Overrides #############################################################################
|
# Object Overrides #############################################################################
|
||||||
|
|
||||||
toString: ->
|
toString: ->
|
||||||
return "RecipeBook (#{@cid}) {
|
return "RecipeBook (#{@cid}) {
|
||||||
|
enabled:#{@enabled},
|
||||||
modName:#{@modName},
|
modName:#{@modName},
|
||||||
modVersion:#{@modVersion},
|
modVersion:#{@modVersion},
|
||||||
recipes:#{@recipes.length} items}"
|
recipes:#{@recipes.length} items}"
|
||||||
|
|||||||
@@ -21,27 +21,29 @@ module.exports = class RecipeCatalog extends BaseModel
|
|||||||
|
|
||||||
# Public Methods ###############################################################################
|
# Public Methods ###############################################################################
|
||||||
|
|
||||||
findRecipes: (name)->
|
gatherNames: ->
|
||||||
result = []
|
nameData = {}
|
||||||
for book in @books
|
for book in @books
|
||||||
for recipe in book.findRecipes name
|
book.gatherNames nameData
|
||||||
result.push recipe
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
getRecipeNames: ->
|
|
||||||
nameHash = {}
|
|
||||||
for book in @books
|
|
||||||
for recipe in book.recipes
|
|
||||||
nameHash[recipe.name] = "#{recipe.name} (from #{book.modName} #{book.modVersion})"
|
|
||||||
|
|
||||||
names = (k for k, v of nameHash).sort()
|
|
||||||
result = []
|
result = []
|
||||||
|
names = _.keys(nameData).sort()
|
||||||
for name in names
|
for name in names
|
||||||
result.push value:name, label:nameHash[name]
|
result.push nameData[name]
|
||||||
|
return result
|
||||||
|
|
||||||
|
gatherRecipes: (name)->
|
||||||
|
result = []
|
||||||
|
for book in @books
|
||||||
|
book.gatherRecipes name, result
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
hasRecipe: (name)->
|
||||||
|
for book in @books
|
||||||
|
return true if book.hasRecipe(name)
|
||||||
|
return false
|
||||||
|
|
||||||
loadBook: (url)->
|
loadBook: (url)->
|
||||||
w.promise (resolve, reject)=>
|
w.promise (resolve, reject)=>
|
||||||
@trigger Event.load.started, this, url
|
@trigger Event.load.started, this, url
|
||||||
@@ -59,6 +61,7 @@ module.exports = class RecipeCatalog extends BaseModel
|
|||||||
@books.sort (a, b)->
|
@books.sort (a, b)->
|
||||||
return 0 if a.modName is b.modName
|
return 0 if a.modName is b.modName
|
||||||
return if a.modName < b.modName then -1 else +1
|
return if a.modName < b.modName then -1 else +1
|
||||||
|
book.on Event.change, => @trigger Event.change, this
|
||||||
|
|
||||||
return book
|
return book
|
||||||
|
|
||||||
|
|||||||
@@ -6,5 +6,6 @@
|
|||||||
//-
|
//-
|
||||||
|
|
||||||
tr
|
tr
|
||||||
|
td: input(type="checkbox")
|
||||||
td: p
|
td: p
|
||||||
td: p
|
td: p
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
table
|
table
|
||||||
tr
|
tr
|
||||||
|
td
|
||||||
td
|
td
|
||||||
td
|
td
|
||||||
input.recipe_book_url(placeholder="enter a URL to load another recipe book...")
|
input.recipe_book_url(placeholder="enter a URL to load another recipe book...")
|
||||||
|
|||||||
Reference in New Issue
Block a user