Add missing detail data to item pages
This commit is contained in:
+31
-29
@@ -8,81 +8,83 @@
|
|||||||
############################################################################################################
|
############################################################################################################
|
||||||
|
|
||||||
# Allow Node.js-style `global` in addition to `window`
|
# Allow Node.js-style `global` in addition to `window`
|
||||||
if typeof(global) is 'undefined'
|
if typeof(global) is "undefined"
|
||||||
window.global = window
|
window.global = window
|
||||||
|
|
||||||
global._ = require '../common/underscore'
|
global._ = require "../common/underscore"
|
||||||
global.$ = require 'jquery'
|
global.$ = require "jquery"
|
||||||
global.c = require '../common/constants'
|
global.c = require "../common/constants"
|
||||||
global.π = Math.PI
|
global.π = Math.PI
|
||||||
global.ε = 0.0001
|
global.ε = 0.0001
|
||||||
global.w = require 'when'
|
global.w = require "when"
|
||||||
|
|
||||||
{Logger} = require('crafting-guide-common').util
|
{Logger} = require("crafting-guide-common").util
|
||||||
global.logger = new Logger
|
global.logger = new Logger
|
||||||
|
|
||||||
Tracker = require './tracker'
|
Tracker = require "./tracker"
|
||||||
global.tracker = new Tracker
|
global.tracker = new Tracker
|
||||||
|
|
||||||
marked = require 'marked'
|
marked = require "marked"
|
||||||
marked.setOptions sanitize:true
|
marked.setOptions sanitize:true
|
||||||
|
|
||||||
global.Backbone = Backbone = require 'backbone'
|
global.Backbone = Backbone = require "backbone"
|
||||||
Backbone.$ = $
|
Backbone.$ = $
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
global.hostName = window.location.hostname
|
global.hostName = window.location.hostname
|
||||||
switch global.hostName
|
switch global.hostName
|
||||||
when 'prerender.crafting-guide.com'
|
when "prerender.crafting-guide.com"
|
||||||
global.env = 'prerender'
|
global.env = "prerender"
|
||||||
logger.level = Logger.FATAL
|
logger.level = Logger.FATAL
|
||||||
apiBaseUrl = 'http://prerender.crafting-guide.com:4347'
|
apiBaseUrl = "http://prerender.crafting-guide.com:4347"
|
||||||
when 'local.crafting-guide.com', 'localhost'
|
when "local.crafting-guide.com", "localhost"
|
||||||
global.env = 'local'
|
global.env = "local"
|
||||||
logger.level = Logger.DEBUG
|
logger.level = Logger.DEBUG
|
||||||
apiBaseUrl = "http://#{global.hostName}:4347"
|
apiBaseUrl = "http://#{global.hostName}:4347"
|
||||||
when 'staging.crafting-guide.com'
|
when "staging.crafting-guide.com"
|
||||||
global.env = 'staging'
|
global.env = "staging"
|
||||||
logger.level = Logger.VERBOSE
|
logger.level = Logger.VERBOSE
|
||||||
apiBaseUrl = 'http://api-staging.crafting-guide.com'
|
apiBaseUrl = "http://api-staging.crafting-guide.com"
|
||||||
when 'crafting-guide.com'
|
when "crafting-guide.com"
|
||||||
global.env = 'production'
|
global.env = "production"
|
||||||
logger.level = Logger.INFO
|
logger.level = Logger.INFO
|
||||||
tracker.enabled = true
|
tracker.enabled = true
|
||||||
apiBaseUrl = 'http://api.crafting-guide.com'
|
apiBaseUrl = "http://api.crafting-guide.com"
|
||||||
else
|
else
|
||||||
throw new Error "cannot determine the environment of: #{window.location.hostname}"
|
throw new Error "cannot determine the environment of: #{window.location.hostname}"
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
Storage = require './storage'
|
Storage = require "./storage"
|
||||||
storage = new Storage storage:global.localStorage
|
storage = new Storage storage:global.localStorage
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
tracker.trackPageView()
|
tracker.trackPageView()
|
||||||
|
|
||||||
{CraftingGuideClient} = require('crafting-guide-common').api
|
{CraftingGuideClient} = require("crafting-guide-common").api
|
||||||
client = _(new CraftingGuideClient(baseUrl:apiBaseUrl)).extend Backbone.Events
|
client = _(new CraftingGuideClient(baseUrl:apiBaseUrl)).extend Backbone.Events
|
||||||
client.onStatusChanged = (client, oldStatus, newStatus)->
|
client.onStatusChanged = (client, oldStatus, newStatus)->
|
||||||
logger.info "Crafting Guide server status changed from #{oldStatus} to #{newStatus}"
|
logger.info "Crafting Guide server status changed from #{oldStatus} to #{newStatus}"
|
||||||
client.trigger 'change:status', client, oldStatus, newStatus
|
client.trigger "change:status", client, oldStatus, newStatus
|
||||||
client.trigger 'change', client
|
client.trigger "change", client
|
||||||
|
|
||||||
client.startMonitoringStatus()
|
client.startMonitoringStatus()
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
{http, ModPackStore} = require("crafting-guide-common").api
|
{http, ModPackStore, ItemDetailStore} = require("crafting-guide-common").api
|
||||||
modPackBaseUrl = "#{location.protocol}//#{location.hostname}:#{location.port}"
|
storeOptions = http:http, baseUrl:"#{location.protocol}//#{location.hostname}:#{location.port}"
|
||||||
modPackStore = new ModPackStore http, modPackBaseUrl
|
global.stores =
|
||||||
|
modPack: new ModPackStore storeOptions
|
||||||
|
itemDetail: new ItemDetailStore storeOptions
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
modPackStore.load c.modPacks.default
|
global.stores.modPack.load c.modPacks.default
|
||||||
.then (modPack)->
|
.then (modPack)->
|
||||||
SiteController = require './site/site_controller'
|
SiteController = require "./site/site_controller"
|
||||||
global.site = site = new SiteController client:client, storage:storage, modPack:modPack
|
global.site = site = new SiteController client:client, storage:storage, modPack:modPack
|
||||||
site.render()
|
site.render()
|
||||||
site.loadCurrentUser()
|
site.loadCurrentUser()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Crafting Guide - item_page.coffee
|
# Crafting Guide - item_display.coffee
|
||||||
#
|
#
|
||||||
# Copyright © 2014-2017 by Redwood Labs
|
# Copyright © 2014-2017 by Redwood Labs
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ module.exports = class ItemPage extends Observable
|
|||||||
set: (item)->
|
set: (item)->
|
||||||
if @_item? then throw new Error "item cannot be reassigned"
|
if @_item? then throw new Error "item cannot be reassigned"
|
||||||
if not item? then throw new Error "item is required"
|
if not item? then throw new Error "item is required"
|
||||||
|
if @_item? then @_item.off Observable::ANY, this
|
||||||
@_item = item
|
@_item = item
|
||||||
|
@_item.on Observable::ANY, this, "_onItemChanged"
|
||||||
|
|
||||||
itemDisplay:
|
itemDisplay:
|
||||||
get: -> return @_itemDisplay ?= new ItemDisplay @item
|
get: -> return @_itemDisplay ?= new ItemDisplay @item
|
||||||
@@ -60,6 +62,14 @@ module.exports = class ItemPage extends Observable
|
|||||||
return @_findItemsWithMatchingRecipes (recipe)=>
|
return @_findItemsWithMatchingRecipes (recipe)=>
|
||||||
return recipe.tools[@item.id]?
|
return recipe.tools[@item.id]?
|
||||||
|
|
||||||
|
loadDetails: ->
|
||||||
|
stores.itemDetail.loadDetailFor @item
|
||||||
|
.catch (error)=>
|
||||||
|
if error.message.indexOf("404") is -1
|
||||||
|
logger.error "Could not load details for item #{@item.id}: #{error.message}"
|
||||||
|
else
|
||||||
|
logger.info "Item #{@item.id} has no details file."
|
||||||
|
|
||||||
# Private Methods ##############################################################################
|
# Private Methods ##############################################################################
|
||||||
|
|
||||||
_findItemsWithMatchingRecipes: (isMatching)->
|
_findItemsWithMatchingRecipes: (isMatching)->
|
||||||
@@ -79,3 +89,7 @@ module.exports = class ItemPage extends Observable
|
|||||||
return a.displayName.localeCompare b.displayName
|
return a.displayName.localeCompare b.displayName
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
_onItemChanged: ->
|
||||||
|
@trigger Observable::CHANGE
|
||||||
|
|
||||||
|
|||||||
@@ -5,30 +5,31 @@
|
|||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
|
|
||||||
BaseController = require '../../base_controller'
|
BaseController = require "../../base_controller"
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
module.exports = class VideoController extends BaseController
|
module.exports = class VideoController extends BaseController
|
||||||
|
|
||||||
constructor: (options={})->
|
constructor: (options={})->
|
||||||
if not options.model? then throw new Error 'options.model is required'
|
if not options.model? then throw new Error "options.model is required"
|
||||||
options.templateName = 'common/video'
|
options.templateName = "common/video"
|
||||||
super options
|
super options
|
||||||
|
|
||||||
# BaseController Overrides #####################################################################
|
# BaseController Overrides #####################################################################
|
||||||
|
|
||||||
onDidRender: ->
|
onDidRender: ->
|
||||||
@$iframe = @$('iframe')
|
@$iframe = @$("iframe")
|
||||||
@$caption = @$('.caption p')
|
@$caption = @$(".caption p")
|
||||||
super
|
super
|
||||||
|
|
||||||
refresh: ->
|
refresh: ->
|
||||||
@$caption.html @model.name
|
@$caption.html @model.name
|
||||||
@$iframe.attr 'src', @_createYouTubeUrl()
|
@$iframe.attr "src", @_createYouTubeUrl()
|
||||||
super
|
super
|
||||||
|
|
||||||
# Private ######################################################################################
|
# Private ######################################################################################
|
||||||
|
|
||||||
_createYouTubeUrl: ->
|
_createYouTubeUrl: ->
|
||||||
return "http://www.youtube.com/embed/#{@model.youTubeId}?modestbranding=1&autohide=1&showinfo=0"
|
return "http://www.youtube.com/embed/#{@model.youTubeId}?modestbranding=1&autohide=1&showinfo=0"
|
||||||
|
|
||||||
|
|||||||
@@ -119,8 +119,8 @@ module.exports = class ItemPageController extends PageController
|
|||||||
|
|
||||||
@_descriptionController.imageBase = c.url.itemImageDir @model.itemDisplay
|
@_descriptionController.imageBase = c.url.itemImageDir @model.itemDisplay
|
||||||
|
|
||||||
if @model.item.officialUrl?
|
if @model.item.detail?.links.length > 0
|
||||||
@$officialLink.attr 'href', @model.item.officialUrl
|
@$officialLink.attr 'href', @model.item.detail.links[0]
|
||||||
@show @$aboutLinks
|
@show @$aboutLinks
|
||||||
else
|
else
|
||||||
@hide @$aboutLinks
|
@hide @$aboutLinks
|
||||||
@@ -217,8 +217,8 @@ module.exports = class ItemPageController extends PageController
|
|||||||
throw e
|
throw e
|
||||||
|
|
||||||
_refreshDescription: ->
|
_refreshDescription: ->
|
||||||
if @model.item?.description?.length > 0
|
if @model.item.detail?.description.length > 0
|
||||||
@_descriptionController.model = @model.item.description
|
@_descriptionController.model = @model.item.detail.description
|
||||||
@_descriptionController.resetToDefaultState()
|
@_descriptionController.resetToDefaultState()
|
||||||
|
|
||||||
_refreshMultiblock: ->
|
_refreshMultiblock: ->
|
||||||
@@ -284,7 +284,7 @@ module.exports = class ItemPageController extends PageController
|
|||||||
@_videoControllers ?= []
|
@_videoControllers ?= []
|
||||||
index = 0
|
index = 0
|
||||||
|
|
||||||
videos = @model?.item?.videos or []
|
videos = @model.item.detail?.videos
|
||||||
if videos? and videos.length > 0
|
if videos? and videos.length > 0
|
||||||
@$videosSectionTitle.html if videos.length is 1 then 'Video' else 'Videos'
|
@$videosSectionTitle.html if videos.length is 1 then 'Video' else 'Videos'
|
||||||
|
|
||||||
@@ -305,3 +305,4 @@ module.exports = class ItemPageController extends PageController
|
|||||||
|
|
||||||
while @_videoControllers.length > index
|
while @_videoControllers.length > index
|
||||||
@_videoControllers.pop().remove()
|
@_videoControllers.pop().remove()
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ module.exports = class Router extends Backbone.Router
|
|||||||
if not item? then throw new Error "could not find item #{modId}__#{itemSlug}"
|
if not item? then throw new Error "could not find item #{modId}__#{itemSlug}"
|
||||||
|
|
||||||
itemPage = new ItemPage item
|
itemPage = new ItemPage item
|
||||||
|
itemPage.loadDetails()
|
||||||
|
|
||||||
params = new UrlParams login:{type:'boolean', default:false}
|
params = new UrlParams login:{type:'boolean', default:false}
|
||||||
controller = new ItemPageController @_makeOptions {model:itemPage, login:params.login}
|
controller = new ItemPageController @_makeOptions {model:itemPage, login:params.login}
|
||||||
@_siteController.setPage 'browseModItem', controller
|
@_siteController.setPage 'browseModItem', controller
|
||||||
|
|||||||
@@ -41,3 +41,4 @@ module.exports = class CraftingGuideServer
|
|||||||
console.log "CraftingGuide is shutting down"
|
console.log "CraftingGuide is shutting down"
|
||||||
@httpServer.close() =>
|
@httpServer.close() =>
|
||||||
resolve this
|
resolve this
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ exports.installBefore = (app)->
|
|||||||
]
|
]
|
||||||
|
|
||||||
exports.installAfter = (app)->
|
exports.installAfter = (app)->
|
||||||
app.use '/data', express.static '../../crafting-guide-data/data/', etag:false, maxAge: 0
|
app.use '/data', express.static '/src/crafting-guide/data/data/', etag:false, maxAge: 0
|
||||||
app.use express.static './static', etag: false, maxAge: 0
|
app.use express.static './static', etag: false, maxAge: 0
|
||||||
|
|
||||||
# Middleware Functions #####################################################################################
|
# Middleware Functions #####################################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user