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`
|
||||
if typeof(global) is 'undefined'
|
||||
if typeof(global) is "undefined"
|
||||
window.global = window
|
||||
|
||||
global._ = require '../common/underscore'
|
||||
global.$ = require 'jquery'
|
||||
global.c = require '../common/constants'
|
||||
global._ = require "../common/underscore"
|
||||
global.$ = require "jquery"
|
||||
global.c = require "../common/constants"
|
||||
global.π = Math.PI
|
||||
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
|
||||
|
||||
Tracker = require './tracker'
|
||||
Tracker = require "./tracker"
|
||||
global.tracker = new Tracker
|
||||
|
||||
marked = require 'marked'
|
||||
marked = require "marked"
|
||||
marked.setOptions sanitize:true
|
||||
|
||||
global.Backbone = Backbone = require 'backbone'
|
||||
global.Backbone = Backbone = require "backbone"
|
||||
Backbone.$ = $
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
global.hostName = window.location.hostname
|
||||
switch global.hostName
|
||||
when 'prerender.crafting-guide.com'
|
||||
global.env = 'prerender'
|
||||
when "prerender.crafting-guide.com"
|
||||
global.env = "prerender"
|
||||
logger.level = Logger.FATAL
|
||||
apiBaseUrl = 'http://prerender.crafting-guide.com:4347'
|
||||
when 'local.crafting-guide.com', 'localhost'
|
||||
global.env = 'local'
|
||||
apiBaseUrl = "http://prerender.crafting-guide.com:4347"
|
||||
when "local.crafting-guide.com", "localhost"
|
||||
global.env = "local"
|
||||
logger.level = Logger.DEBUG
|
||||
apiBaseUrl = "http://#{global.hostName}:4347"
|
||||
when 'staging.crafting-guide.com'
|
||||
global.env = 'staging'
|
||||
when "staging.crafting-guide.com"
|
||||
global.env = "staging"
|
||||
logger.level = Logger.VERBOSE
|
||||
apiBaseUrl = 'http://api-staging.crafting-guide.com'
|
||||
when 'crafting-guide.com'
|
||||
global.env = 'production'
|
||||
apiBaseUrl = "http://api-staging.crafting-guide.com"
|
||||
when "crafting-guide.com"
|
||||
global.env = "production"
|
||||
logger.level = Logger.INFO
|
||||
tracker.enabled = true
|
||||
apiBaseUrl = 'http://api.crafting-guide.com'
|
||||
apiBaseUrl = "http://api.crafting-guide.com"
|
||||
else
|
||||
throw new Error "cannot determine the environment of: #{window.location.hostname}"
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
Storage = require './storage'
|
||||
Storage = require "./storage"
|
||||
storage = new Storage storage:global.localStorage
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
tracker.trackPageView()
|
||||
|
||||
{CraftingGuideClient} = require('crafting-guide-common').api
|
||||
{CraftingGuideClient} = require("crafting-guide-common").api
|
||||
client = _(new CraftingGuideClient(baseUrl:apiBaseUrl)).extend Backbone.Events
|
||||
client.onStatusChanged = (client, oldStatus, newStatus)->
|
||||
logger.info "Crafting Guide server status changed from #{oldStatus} to #{newStatus}"
|
||||
client.trigger 'change:status', client, oldStatus, newStatus
|
||||
client.trigger 'change', client
|
||||
client.trigger "change:status", client, oldStatus, newStatus
|
||||
client.trigger "change", client
|
||||
|
||||
client.startMonitoringStatus()
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
{http, ModPackStore} = require("crafting-guide-common").api
|
||||
modPackBaseUrl = "#{location.protocol}//#{location.hostname}:#{location.port}"
|
||||
modPackStore = new ModPackStore http, modPackBaseUrl
|
||||
{http, ModPackStore, ItemDetailStore} = require("crafting-guide-common").api
|
||||
storeOptions = http:http, baseUrl:"#{location.protocol}//#{location.hostname}:#{location.port}"
|
||||
global.stores =
|
||||
modPack: new ModPackStore storeOptions
|
||||
itemDetail: new ItemDetailStore storeOptions
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
modPackStore.load c.modPacks.default
|
||||
global.stores.modPack.load c.modPacks.default
|
||||
.then (modPack)->
|
||||
SiteController = require './site/site_controller'
|
||||
SiteController = require "./site/site_controller"
|
||||
global.site = site = new SiteController client:client, storage:storage, modPack:modPack
|
||||
site.render()
|
||||
site.loadCurrentUser()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Crafting Guide - item_page.coffee
|
||||
# Crafting Guide - item_display.coffee
|
||||
#
|
||||
# Copyright © 2014-2017 by Redwood Labs
|
||||
# All rights reserved.
|
||||
|
||||
@@ -27,7 +27,9 @@ module.exports = class ItemPage extends Observable
|
||||
set: (item)->
|
||||
if @_item? then throw new Error "item cannot be reassigned"
|
||||
if not item? then throw new Error "item is required"
|
||||
if @_item? then @_item.off Observable::ANY, this
|
||||
@_item = item
|
||||
@_item.on Observable::ANY, this, "_onItemChanged"
|
||||
|
||||
itemDisplay:
|
||||
get: -> return @_itemDisplay ?= new ItemDisplay @item
|
||||
@@ -60,6 +62,14 @@ module.exports = class ItemPage extends Observable
|
||||
return @_findItemsWithMatchingRecipes (recipe)=>
|
||||
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 ##############################################################################
|
||||
|
||||
_findItemsWithMatchingRecipes: (isMatching)->
|
||||
@@ -79,3 +89,7 @@ module.exports = class ItemPage extends Observable
|
||||
return a.displayName.localeCompare b.displayName
|
||||
|
||||
return result
|
||||
|
||||
_onItemChanged: ->
|
||||
@trigger Observable::CHANGE
|
||||
|
||||
|
||||
@@ -5,30 +5,31 @@
|
||||
# All rights reserved.
|
||||
#
|
||||
|
||||
BaseController = require '../../base_controller'
|
||||
BaseController = require "../../base_controller"
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
module.exports = class VideoController extends BaseController
|
||||
|
||||
constructor: (options={})->
|
||||
if not options.model? then throw new Error 'options.model is required'
|
||||
options.templateName = 'common/video'
|
||||
if not options.model? then throw new Error "options.model is required"
|
||||
options.templateName = "common/video"
|
||||
super options
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
onDidRender: ->
|
||||
@$iframe = @$('iframe')
|
||||
@$caption = @$('.caption p')
|
||||
@$iframe = @$("iframe")
|
||||
@$caption = @$(".caption p")
|
||||
super
|
||||
|
||||
refresh: ->
|
||||
@$caption.html @model.name
|
||||
@$iframe.attr 'src', @_createYouTubeUrl()
|
||||
@$iframe.attr "src", @_createYouTubeUrl()
|
||||
super
|
||||
|
||||
# Private ######################################################################################
|
||||
|
||||
_createYouTubeUrl: ->
|
||||
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
|
||||
|
||||
if @model.item.officialUrl?
|
||||
@$officialLink.attr 'href', @model.item.officialUrl
|
||||
if @model.item.detail?.links.length > 0
|
||||
@$officialLink.attr 'href', @model.item.detail.links[0]
|
||||
@show @$aboutLinks
|
||||
else
|
||||
@hide @$aboutLinks
|
||||
@@ -217,8 +217,8 @@ module.exports = class ItemPageController extends PageController
|
||||
throw e
|
||||
|
||||
_refreshDescription: ->
|
||||
if @model.item?.description?.length > 0
|
||||
@_descriptionController.model = @model.item.description
|
||||
if @model.item.detail?.description.length > 0
|
||||
@_descriptionController.model = @model.item.detail.description
|
||||
@_descriptionController.resetToDefaultState()
|
||||
|
||||
_refreshMultiblock: ->
|
||||
@@ -284,7 +284,7 @@ module.exports = class ItemPageController extends PageController
|
||||
@_videoControllers ?= []
|
||||
index = 0
|
||||
|
||||
videos = @model?.item?.videos or []
|
||||
videos = @model.item.detail?.videos
|
||||
if videos? and videos.length > 0
|
||||
@$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
|
||||
@_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}"
|
||||
|
||||
itemPage = new ItemPage item
|
||||
itemPage.loadDetails()
|
||||
|
||||
params = new UrlParams login:{type:'boolean', default:false}
|
||||
controller = new ItemPageController @_makeOptions {model:itemPage, login:params.login}
|
||||
@_siteController.setPage 'browseModItem', controller
|
||||
|
||||
@@ -41,3 +41,4 @@ module.exports = class CraftingGuideServer
|
||||
console.log "CraftingGuide is shutting down"
|
||||
@httpServer.close() =>
|
||||
resolve this
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ exports.installBefore = (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
|
||||
|
||||
# Middleware Functions #####################################################################################
|
||||
|
||||
Reference in New Issue
Block a user