mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-16 00:19:50 -05:00
Merge branch 'refactorSchemas' of https://github.com/adi2412/codecombat into adi2412-refactorSchemas
This commit is contained in:
commit
5a794306fe
46 changed files with 98 additions and 72 deletions
|
@ -2,13 +2,6 @@ storage = require 'lib/storage'
|
||||||
deltasLib = require 'lib/deltas'
|
deltasLib = require 'lib/deltas'
|
||||||
auth = require 'lib/auth'
|
auth = require 'lib/auth'
|
||||||
|
|
||||||
class CocoSchema extends Backbone.Model
|
|
||||||
constructor: (path, args...) ->
|
|
||||||
super(args...)
|
|
||||||
@urlRoot = path + '/schema'
|
|
||||||
|
|
||||||
window.CocoSchema = CocoSchema
|
|
||||||
|
|
||||||
class CocoModel extends Backbone.Model
|
class CocoModel extends Backbone.Model
|
||||||
idAttribute: "_id"
|
idAttribute: "_id"
|
||||||
loaded: false
|
loaded: false
|
||||||
|
@ -18,7 +11,7 @@ class CocoModel extends Backbone.Model
|
||||||
|
|
||||||
initialize: ->
|
initialize: ->
|
||||||
super()
|
super()
|
||||||
@constructor.schema ?= new CocoSchema(@urlRoot)
|
@constructor.schema ?= @urlRoot[4..].replace '.', '_'
|
||||||
if not @constructor.className
|
if not @constructor.className
|
||||||
console.error("#{@} needs a className set.")
|
console.error("#{@} needs a className set.")
|
||||||
@markToRevert()
|
@markToRevert()
|
||||||
|
@ -65,8 +58,8 @@ class CocoModel extends Backbone.Model
|
||||||
|
|
||||||
loadSchema: ->
|
loadSchema: ->
|
||||||
return if @constructor.schema.loading
|
return if @constructor.schema.loading
|
||||||
@constructor.schema.fetch()
|
@constructor.schema = require 'schemas/' + @constructor.schema + '_schema' unless @constructor.schema.loaded
|
||||||
@listenToOnce(@constructor.schema, 'sync', @onConstructorSync)
|
@onConstructorSync()
|
||||||
|
|
||||||
onConstructorSync: ->
|
onConstructorSync: ->
|
||||||
@constructor.schema.loaded = true
|
@constructor.schema.loaded = true
|
||||||
|
@ -77,7 +70,7 @@ class CocoModel extends Backbone.Model
|
||||||
schema: -> return @constructor.schema
|
schema: -> return @constructor.schema
|
||||||
|
|
||||||
validate: ->
|
validate: ->
|
||||||
result = tv4.validateMultiple(@attributes, @constructor.schema?.attributes or {})
|
result = tv4.validateMultiple(@attributes, @constructor.schema? or {})
|
||||||
if result.errors?.length
|
if result.errors?.length
|
||||||
console.log @, "got validate result with errors:", result
|
console.log @, "got validate result with errors:", result
|
||||||
return result.errors unless result.valid
|
return result.errors unless result.valid
|
||||||
|
@ -138,11 +131,11 @@ class CocoModel extends Backbone.Model
|
||||||
addSchemaDefaults: ->
|
addSchemaDefaults: ->
|
||||||
return if @addedSchemaDefaults or not @constructor.hasSchema()
|
return if @addedSchemaDefaults or not @constructor.hasSchema()
|
||||||
@addedSchemaDefaults = true
|
@addedSchemaDefaults = true
|
||||||
for prop, defaultValue of @constructor.schema.attributes.default or {}
|
for prop, defaultValue of @constructor.schema.default or {}
|
||||||
continue if @get(prop)?
|
continue if @get(prop)?
|
||||||
#console.log "setting", prop, "to", defaultValue, "from attributes.default"
|
#console.log "setting", prop, "to", defaultValue, "from attributes.default"
|
||||||
@set prop, defaultValue
|
@set prop, defaultValue
|
||||||
for prop, sch of @constructor.schema.attributes.properties or {}
|
for prop, sch of @constructor.schema.properties or {}
|
||||||
continue if @get(prop)?
|
continue if @get(prop)?
|
||||||
#console.log "setting", prop, "to", sch.default, "from sch.default" if sch.default?
|
#console.log "setting", prop, "to", sch.default, "from sch.default" if sch.default?
|
||||||
@set prop, sch.default if sch.default?
|
@set prop, sch.default if sch.default?
|
||||||
|
@ -154,7 +147,7 @@ class CocoModel extends Backbone.Model
|
||||||
# returns unfetched model shells for every referenced doc in this model
|
# returns unfetched model shells for every referenced doc in this model
|
||||||
# OPTIMIZE so that when loading models, it doesn't cause the site to stutter
|
# OPTIMIZE so that when loading models, it doesn't cause the site to stutter
|
||||||
data ?= @attributes
|
data ?= @attributes
|
||||||
schema ?= @schema().attributes
|
schema ?= @schema()
|
||||||
models = []
|
models = []
|
||||||
|
|
||||||
if $.isArray(data) and schema.items?
|
if $.isArray(data) and schema.items?
|
||||||
|
@ -242,7 +235,7 @@ class CocoModel extends Backbone.Model
|
||||||
|
|
||||||
getExpandedDelta: ->
|
getExpandedDelta: ->
|
||||||
delta = @getDelta()
|
delta = @getDelta()
|
||||||
deltasLib.expandDelta(delta, @_revertAttributes, @schema().attributes)
|
deltasLib.expandDelta(delta, @_revertAttributes, @schema())
|
||||||
|
|
||||||
addPatchToAcceptOnSave: (patch) ->
|
addPatchToAcceptOnSave: (patch) ->
|
||||||
@acceptedPatches ?= []
|
@acceptedPatches ?= []
|
||||||
|
|
|
@ -29,9 +29,9 @@ class SuperModel
|
||||||
model.loadSchema()
|
model.loadSchema()
|
||||||
schema = model.schema()
|
schema = model.schema()
|
||||||
unless schema.loaded
|
unless schema.loaded
|
||||||
@schemas[schema.urlRoot] = schema
|
@schemas[model.urlRoot] = schema
|
||||||
return schema.once('sync', => @modelLoaded(model))
|
return schema.once('sync', => @modelLoaded(model))
|
||||||
refs = model.getReferencedModels(model.attributes, schema.attributes, '/', @shouldLoadProjection)
|
refs = model.getReferencedModels(model.attributes, schema, '/', @shouldLoadProjection)
|
||||||
refs = [] unless @mustPopulate is model or @shouldPopulate(model)
|
refs = [] unless @mustPopulate is model or @shouldPopulate(model)
|
||||||
# console.log 'Loaded', model.get('name')
|
# console.log 'Loaded', model.get('name')
|
||||||
for ref, i in refs when @shouldLoadReference ref
|
for ref, i in refs when @shouldLoadReference ref
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
c = require '../commons/schemas'
|
c = require './schemas'
|
||||||
|
|
||||||
ArticleSchema = c.object()
|
ArticleSchema = c.object()
|
||||||
c.extendNamedProperties ArticleSchema # name first
|
c.extendNamedProperties ArticleSchema # name first
|
34
app/schemas/languages.coffee
Normal file
34
app/schemas/languages.coffee
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
locale = require '../locale/locale' # requiring from app; will break if we stop serving from where app lives
|
||||||
|
|
||||||
|
languages = []
|
||||||
|
for code, localeInfo of locale
|
||||||
|
languages.push code: code, nativeDescription: localeInfo.nativeDescription, englishDescription: localeInfo.englishDescription
|
||||||
|
|
||||||
|
module.exports.languages = languages
|
||||||
|
module.exports.languageCodes = languageCodes = (language.code for language in languages)
|
||||||
|
module.exports.languageCodesLower = languageCodesLower = (code.toLowerCase() for code in languageCodes)
|
||||||
|
|
||||||
|
# Keep keys lower-case for matching and values with second subtag uppercase like i18next expects
|
||||||
|
languageAliases =
|
||||||
|
'en': 'en-US'
|
||||||
|
|
||||||
|
'zh-cn': 'zh-HANS'
|
||||||
|
'zh-hans-cn': 'zh-HANS'
|
||||||
|
'zh-sg': 'zh-HANS'
|
||||||
|
'zh-hans-sg': 'zh-HANS'
|
||||||
|
|
||||||
|
'zh-tw': 'zh-HANT'
|
||||||
|
'zh-hant-tw': 'zh-HANT'
|
||||||
|
'zh-hk': 'zh-HANT'
|
||||||
|
'zh-hant-hk': 'zh-HANT'
|
||||||
|
'zh-mo': 'zh-HANT'
|
||||||
|
'zh-hant-mo': 'zh-HANT'
|
||||||
|
|
||||||
|
module.exports.languageCodeFromAcceptedLanguages = languageCodeFromAcceptedLanguages = (acceptedLanguages) ->
|
||||||
|
for lang in acceptedLanguages ? []
|
||||||
|
code = languageAliases[lang.toLowerCase()]
|
||||||
|
return code if code
|
||||||
|
codeIndex = _.indexOf languageCodesLower, lang
|
||||||
|
if codeIndex isnt -1
|
||||||
|
return languageCodes[codeIndex]
|
||||||
|
return 'en-US'
|
|
@ -1,5 +1,5 @@
|
||||||
c = require '../../commons/schemas'
|
c = require './schemas'
|
||||||
metaschema = require '../../commons/metaschema'
|
metaschema = require './metaschema'
|
||||||
|
|
||||||
attackSelfCode = """
|
attackSelfCode = """
|
||||||
class AttacksSelf extends Component
|
class AttacksSelf extends Component
|
|
@ -1,4 +1,4 @@
|
||||||
c = require '../../commons/schemas'
|
c = require './schemas'
|
||||||
|
|
||||||
LevelFeedbackLevelSchema = c.object {required: ['original', 'majorVersion']}, {
|
LevelFeedbackLevelSchema = c.object {required: ['original', 'majorVersion']}, {
|
||||||
original: c.objectId({})
|
original: c.objectId({})
|
|
@ -1,5 +1,5 @@
|
||||||
c = require '../commons/schemas'
|
c = require './schemas'
|
||||||
ThangComponentSchema = require './thangs/thang_component_schema'
|
ThangComponentSchema = require './thang_component_schema'
|
||||||
|
|
||||||
SpecificArticleSchema = c.object()
|
SpecificArticleSchema = c.object()
|
||||||
c.extendNamedProperties SpecificArticleSchema # name first
|
c.extendNamedProperties SpecificArticleSchema # name first
|
|
@ -1,4 +1,4 @@
|
||||||
c = require '../../commons/schemas'
|
c = require './schemas'
|
||||||
|
|
||||||
LevelSessionPlayerSchema = c.object
|
LevelSessionPlayerSchema = c.object
|
||||||
id: c.objectId
|
id: c.objectId
|
|
@ -1,5 +1,5 @@
|
||||||
c = require '../../commons/schemas'
|
c = require './schemas'
|
||||||
metaschema = require '../../commons/metaschema'
|
metaschema = require './metaschema'
|
||||||
|
|
||||||
jitterSystemCode = """
|
jitterSystemCode = """
|
||||||
class Jitter extends System
|
class Jitter extends System
|
|
@ -1,4 +1,4 @@
|
||||||
c = require '../commons/schemas'
|
c = require './schemas'
|
||||||
|
|
||||||
patchables = ['level', 'thang_type', 'level_system', 'level_component', 'article']
|
patchables = ['level', 'thang_type', 'level_system', 'level_component', 'article']
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#language imports
|
#language imports
|
||||||
Language = require '../routes/languages'
|
Language = require './languages'
|
||||||
# schema helper methods
|
# schema helper methods
|
||||||
|
|
||||||
me = module.exports
|
me = module.exports
|
|
@ -1,4 +1,4 @@
|
||||||
c = require '../../commons/schemas'
|
c = require './schemas'
|
||||||
|
|
||||||
module.exports = ThangComponentSchema = c.object {
|
module.exports = ThangComponentSchema = c.object {
|
||||||
title: "Component"
|
title: "Component"
|
|
@ -1,4 +1,4 @@
|
||||||
c = require '../../commons/schemas'
|
c = require './schemas'
|
||||||
ThangComponentSchema = require './thang_component_schema'
|
ThangComponentSchema = require './thang_component_schema'
|
||||||
|
|
||||||
ThangTypeSchema = c.object()
|
ThangTypeSchema = c.object()
|
|
@ -1,4 +1,4 @@
|
||||||
c = require '../commons/schemas'
|
c = require './schemas'
|
||||||
emailSubscriptions = ['announcement', 'tester', 'level_creator', 'developer', 'article_editor', 'translator', 'support', 'notification']
|
emailSubscriptions = ['announcement', 'tester', 'level_creator', 'developer', 'article_editor', 'translator', 'support', 'notification']
|
||||||
|
|
||||||
UserSchema = c.object {},
|
UserSchema = c.object {},
|
|
@ -29,7 +29,7 @@ module.exports = class JobProfileView extends CocoView
|
||||||
visibleSettings = @editableSettings.concat @readOnlySettings
|
visibleSettings = @editableSettings.concat @readOnlySettings
|
||||||
data = _.pick (me.get('jobProfile') ? {}), (value, key) => key in visibleSettings
|
data = _.pick (me.get('jobProfile') ? {}), (value, key) => key in visibleSettings
|
||||||
data.name ?= (me.get('firstName') + ' ' + me.get('lastName')).trim() if me.get('firstName')
|
data.name ?= (me.get('firstName') + ' ' + me.get('lastName')).trim() if me.get('firstName')
|
||||||
schema = _.cloneDeep me.schema().get('properties').jobProfile
|
schema = _.cloneDeep me.schema().properties.jobProfile
|
||||||
schema.properties = _.pick schema.properties, (value, key) => key in visibleSettings
|
schema.properties = _.pick schema.properties, (value, key) => key in visibleSettings
|
||||||
schema.required = _.intersection schema.required, visibleSettings
|
schema.required = _.intersection schema.required, visibleSettings
|
||||||
for prop in @readOnlySettings
|
for prop in @readOnlySettings
|
||||||
|
|
|
@ -82,8 +82,8 @@ module.exports = class SettingsView extends View
|
||||||
buildPictureTreema: ->
|
buildPictureTreema: ->
|
||||||
data = photoURL: me.get('photoURL')
|
data = photoURL: me.get('photoURL')
|
||||||
data.photoURL = null if data.photoURL?.search('gravatar') isnt -1 # Old style
|
data.photoURL = null if data.photoURL?.search('gravatar') isnt -1 # Old style
|
||||||
schema = _.cloneDeep me.schema().attributes
|
schema = _.cloneDeep me.schema()
|
||||||
schema.properties = _.pick me.schema().get('properties'), 'photoURL'
|
schema.properties = _.pick me.schema().properties, 'photoURL'
|
||||||
schema.required = ['photoURL']
|
schema.required = ['photoURL']
|
||||||
treemaOptions =
|
treemaOptions =
|
||||||
filePath: "db/user/#{me.id}"
|
filePath: "db/user/#{me.id}"
|
||||||
|
|
|
@ -54,7 +54,7 @@ module.exports = class ArticleEditView extends View
|
||||||
options =
|
options =
|
||||||
data: data
|
data: data
|
||||||
filePath: "db/thang.type/#{@article.get('original')}"
|
filePath: "db/thang.type/#{@article.get('original')}"
|
||||||
schema: Article.schema.attributes
|
schema: Article.schema
|
||||||
readOnly: true unless me.isAdmin() or @article.hasWriteAccess(me)
|
readOnly: true unless me.isAdmin() or @article.hasWriteAccess(me)
|
||||||
callbacks:
|
callbacks:
|
||||||
change: @pushChangesToPreview
|
change: @pushChangesToPreview
|
||||||
|
|
|
@ -45,7 +45,7 @@ module.exports = class ThangComponentEditView extends CocoView
|
||||||
buildExtantComponentTreema: ->
|
buildExtantComponentTreema: ->
|
||||||
treemaOptions =
|
treemaOptions =
|
||||||
supermodel: @supermodel
|
supermodel: @supermodel
|
||||||
schema: Level.schema.get('properties').thangs.items.properties.components
|
schema: Level.schema.properties.thangs.items.properties.components
|
||||||
data: _.cloneDeep @components
|
data: _.cloneDeep @components
|
||||||
callbacks: {select: @onSelectExtantComponent, change:@onChangeExtantComponents}
|
callbacks: {select: @onSelectExtantComponent, change:@onChangeExtantComponents}
|
||||||
noSortable: true
|
noSortable: true
|
||||||
|
@ -69,7 +69,7 @@ module.exports = class ThangComponentEditView extends CocoView
|
||||||
|
|
||||||
treemaOptions =
|
treemaOptions =
|
||||||
supermodel: @supermodel
|
supermodel: @supermodel
|
||||||
schema: { type: 'array', items: LevelComponent.schema.attributes }
|
schema: { type: 'array', items: LevelComponent.schema }
|
||||||
data: ($.extend(true, {}, c) for c in components)
|
data: ($.extend(true, {}, c) for c in components)
|
||||||
callbacks: {select: @onSelectAddableComponent, enter: @onAddComponentEnterPressed }
|
callbacks: {select: @onSelectAddableComponent, enter: @onAddComponentEnterPressed }
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
|
|
@ -31,7 +31,7 @@ module.exports = class LevelComponentEditView extends View
|
||||||
|
|
||||||
buildSettingsTreema: ->
|
buildSettingsTreema: ->
|
||||||
data = _.pick @levelComponent.attributes, (value, key) => key in @editableSettings
|
data = _.pick @levelComponent.attributes, (value, key) => key in @editableSettings
|
||||||
schema = _.cloneDeep LevelComponent.schema.attributes
|
schema = _.cloneDeep LevelComponent.schema
|
||||||
schema.properties = _.pick schema.properties, (value, key) => key in @editableSettings
|
schema.properties = _.pick schema.properties, (value, key) => key in @editableSettings
|
||||||
schema.required = _.intersection schema.required, @editableSettings
|
schema.required = _.intersection schema.required, @editableSettings
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ module.exports = class LevelComponentEditView extends View
|
||||||
buildConfigSchemaTreema: ->
|
buildConfigSchemaTreema: ->
|
||||||
treemaOptions =
|
treemaOptions =
|
||||||
supermodel: @supermodel
|
supermodel: @supermodel
|
||||||
schema: LevelComponent.schema.get('properties').configSchema
|
schema: LevelComponent.schema.properties.configSchema
|
||||||
data: @levelComponent.get 'configSchema'
|
data: @levelComponent.get 'configSchema'
|
||||||
callbacks: {change: @onConfigSchemaEdited}
|
callbacks: {change: @onConfigSchemaEdited}
|
||||||
treemaOptions.readOnly = true unless me.isAdmin()
|
treemaOptions.readOnly = true unless me.isAdmin()
|
||||||
|
@ -63,7 +63,7 @@ module.exports = class LevelComponentEditView extends View
|
||||||
@configSchemaTreema.build()
|
@configSchemaTreema.build()
|
||||||
@configSchemaTreema.open()
|
@configSchemaTreema.open()
|
||||||
# TODO: schema is not loaded for the first one here?
|
# TODO: schema is not loaded for the first one here?
|
||||||
@configSchemaTreema.tv4.addSchema('metaschema', LevelComponent.schema.get('properties').configSchema)
|
@configSchemaTreema.tv4.addSchema('metaschema', LevelComponent.schema.properties.configSchema)
|
||||||
|
|
||||||
onConfigSchemaEdited: =>
|
onConfigSchemaEdited: =>
|
||||||
@levelComponent.set 'configSchema', @configSchemaTreema.data
|
@levelComponent.set 'configSchema', @configSchemaTreema.data
|
||||||
|
|
|
@ -22,7 +22,7 @@ module.exports = class ScriptsTabView extends View
|
||||||
@dimensions = @level.dimensions()
|
@dimensions = @level.dimensions()
|
||||||
scripts = $.extend(true, [], @level.get('scripts') ? [])
|
scripts = $.extend(true, [], @level.get('scripts') ? [])
|
||||||
treemaOptions =
|
treemaOptions =
|
||||||
schema: Level.schema.get('properties').scripts
|
schema: Level.schema.properties.scripts
|
||||||
data: scripts
|
data: scripts
|
||||||
callbacks:
|
callbacks:
|
||||||
change: @onScriptsChanged
|
change: @onScriptsChanged
|
||||||
|
@ -52,7 +52,7 @@ module.exports = class ScriptsTabView extends View
|
||||||
filePath: "db/level/#{@level.get('original')}"
|
filePath: "db/level/#{@level.get('original')}"
|
||||||
files: @files
|
files: @files
|
||||||
view: @
|
view: @
|
||||||
schema: Level.schema.get('properties').scripts.items
|
schema: Level.schema.properties.scripts.items
|
||||||
data: selected.data
|
data: selected.data
|
||||||
thangIDs: thangIDs
|
thangIDs: thangIDs
|
||||||
dimensions: @dimensions
|
dimensions: @dimensions
|
||||||
|
|
|
@ -25,7 +25,7 @@ module.exports = class SettingsTabView extends View
|
||||||
onLevelLoaded: (e) ->
|
onLevelLoaded: (e) ->
|
||||||
@level = e.level
|
@level = e.level
|
||||||
data = _.pick @level.attributes, (value, key) => key in @editableSettings
|
data = _.pick @level.attributes, (value, key) => key in @editableSettings
|
||||||
schema = _.cloneDeep Level.schema.attributes
|
schema = _.cloneDeep Level.schema
|
||||||
schema.properties = _.pick schema.properties, (value, key) => key in @editableSettings
|
schema.properties = _.pick schema.properties, (value, key) => key in @editableSettings
|
||||||
schema.required = _.intersection schema.required, @editableSettings
|
schema.required = _.intersection schema.required, @editableSettings
|
||||||
thangIDs = @getThangIDs()
|
thangIDs = @getThangIDs()
|
||||||
|
|
|
@ -29,7 +29,7 @@ module.exports = class LevelSystemEditView extends View
|
||||||
|
|
||||||
buildSettingsTreema: ->
|
buildSettingsTreema: ->
|
||||||
data = _.pick @levelSystem.attributes, (value, key) => key in @editableSettings
|
data = _.pick @levelSystem.attributes, (value, key) => key in @editableSettings
|
||||||
schema = _.cloneDeep LevelSystem.schema.attributes
|
schema = _.cloneDeep LevelSystem.schema
|
||||||
schema.properties = _.pick schema.properties, (value, key) => key in @editableSettings
|
schema.properties = _.pick schema.properties, (value, key) => key in @editableSettings
|
||||||
schema.required = _.intersection schema.required, @editableSettings
|
schema.required = _.intersection schema.required, @editableSettings
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ module.exports = class LevelSystemEditView extends View
|
||||||
buildConfigSchemaTreema: ->
|
buildConfigSchemaTreema: ->
|
||||||
treemaOptions =
|
treemaOptions =
|
||||||
supermodel: @supermodel
|
supermodel: @supermodel
|
||||||
schema: LevelSystem.schema.get('properties').configSchema
|
schema: LevelSystem.schema.properties.configSchema
|
||||||
data: @levelSystem.get 'configSchema'
|
data: @levelSystem.get 'configSchema'
|
||||||
callbacks: {change: @onConfigSchemaEdited}
|
callbacks: {change: @onConfigSchemaEdited}
|
||||||
treemaOptions.readOnly = true unless me.isAdmin()
|
treemaOptions.readOnly = true unless me.isAdmin()
|
||||||
|
@ -61,7 +61,7 @@ module.exports = class LevelSystemEditView extends View
|
||||||
@configSchemaTreema.build()
|
@configSchemaTreema.build()
|
||||||
@configSchemaTreema.open()
|
@configSchemaTreema.open()
|
||||||
# TODO: schema is not loaded for the first one here?
|
# TODO: schema is not loaded for the first one here?
|
||||||
@configSchemaTreema.tv4.addSchema('metaschema', LevelSystem.schema.get('properties').configSchema)
|
@configSchemaTreema.tv4.addSchema('metaschema', LevelSystem.schema.properties.configSchema)
|
||||||
|
|
||||||
onConfigSchemaEdited: =>
|
onConfigSchemaEdited: =>
|
||||||
@levelSystem.set 'configSchema', @configSchemaTreema.data
|
@levelSystem.set 'configSchema', @configSchemaTreema.data
|
||||||
|
|
|
@ -67,7 +67,7 @@ module.exports = class SystemsTabView extends View
|
||||||
treemaOptions =
|
treemaOptions =
|
||||||
# TODO: somehow get rid of the + button, or repurpose it to open the LevelSystemAddView instead
|
# TODO: somehow get rid of the + button, or repurpose it to open the LevelSystemAddView instead
|
||||||
supermodel: @supermodel
|
supermodel: @supermodel
|
||||||
schema: Level.schema.get('properties').systems
|
schema: Level.schema.properties.systems
|
||||||
data: systems
|
data: systems
|
||||||
readOnly: true unless me.isAdmin() or @level.hasWriteAccess(me)
|
readOnly: true unless me.isAdmin() or @level.hasWriteAccess(me)
|
||||||
callbacks:
|
callbacks:
|
||||||
|
|
|
@ -140,7 +140,7 @@ module.exports = class ThangsTabView extends View
|
||||||
return if @startsLoading
|
return if @startsLoading
|
||||||
data = $.extend(true, {}, @level.attributes)
|
data = $.extend(true, {}, @level.attributes)
|
||||||
treemaOptions =
|
treemaOptions =
|
||||||
schema: Level.schema.get('properties').thangs
|
schema: Level.schema.properties.thangs
|
||||||
data: data.thangs
|
data: data.thangs
|
||||||
supermodel: @supermodel
|
supermodel: @supermodel
|
||||||
callbacks:
|
callbacks:
|
||||||
|
|
|
@ -12,7 +12,7 @@ module.exports = class ColorsTabView extends CocoView
|
||||||
|
|
||||||
constructor: (@thangType, options) ->
|
constructor: (@thangType, options) ->
|
||||||
@listenToOnce(@thangType, 'sync', @tryToBuild)
|
@listenToOnce(@thangType, 'sync', @tryToBuild)
|
||||||
@listenToOnce(@thangType.schema(), 'sync', @tryToBuild)
|
# @listenToOnce(@thangType.schema(), 'sync', @tryToBuild)
|
||||||
@colorConfig = { hue: 0, saturation: 0.5, lightness: 0.5 }
|
@colorConfig = { hue: 0, saturation: 0.5, lightness: 0.5 }
|
||||||
@spriteBuilder = new SpriteBuilder(@thangType)
|
@spriteBuilder = new SpriteBuilder(@thangType)
|
||||||
f = =>
|
f = =>
|
||||||
|
@ -115,7 +115,7 @@ module.exports = class ColorsTabView extends CocoView
|
||||||
return unless @thangType.loaded and @thangType.schema().loaded
|
return unless @thangType.loaded and @thangType.schema().loaded
|
||||||
data = @thangType.get('colorGroups')
|
data = @thangType.get('colorGroups')
|
||||||
data ?= {}
|
data ?= {}
|
||||||
schema = @thangType.schema().attributes.properties?.colorGroups
|
schema = @thangType.schema().properties?.colorGroups
|
||||||
treemaOptions =
|
treemaOptions =
|
||||||
data: data
|
data: data
|
||||||
schema: schema
|
schema: schema
|
||||||
|
|
|
@ -62,7 +62,6 @@ module.exports = class ThangTypeEditView extends View
|
||||||
|
|
||||||
@thangType.fetch()
|
@thangType.fetch()
|
||||||
@thangType.loadSchema()
|
@thangType.loadSchema()
|
||||||
@listenToOnce(@thangType.schema(), 'sync', @onThangTypeSync)
|
|
||||||
@listenToOnce(@thangType, 'sync', @onThangTypeSync)
|
@listenToOnce(@thangType, 'sync', @onThangTypeSync)
|
||||||
@refreshAnimation = _.debounce @refreshAnimation, 500
|
@refreshAnimation = _.debounce @refreshAnimation, 500
|
||||||
|
|
||||||
|
@ -344,7 +343,7 @@ module.exports = class ThangTypeEditView extends View
|
||||||
|
|
||||||
buildTreema: ->
|
buildTreema: ->
|
||||||
data = @getThangData()
|
data = @getThangData()
|
||||||
schema = _.cloneDeep ThangType.schema.attributes
|
schema = _.cloneDeep ThangType.schema
|
||||||
schema.properties = _.pick schema.properties, (value, key) => not (key in ['components'])
|
schema.properties = _.pick schema.properties, (value, key) => not (key in ['components'])
|
||||||
options =
|
options =
|
||||||
data: data
|
data: data
|
||||||
|
|
|
@ -96,7 +96,7 @@ module.exports = class SearchView extends View
|
||||||
name = @$el.find('#name').val()
|
name = @$el.find('#name').val()
|
||||||
model = new @model()
|
model = new @model()
|
||||||
model.set('name', name)
|
model.set('name', name)
|
||||||
if @model.schema.get('properties').permissions
|
if @model.schema.properties.permissions
|
||||||
model.set 'permissions', [{access: 'owner', target: me.id}]
|
model.set 'permissions', [{access: 'owner', target: me.id}]
|
||||||
res = model.save()
|
res = model.save()
|
||||||
return unless res
|
return unless res
|
||||||
|
|
|
@ -36,7 +36,7 @@ module.exports = class LoginModalView extends View
|
||||||
loginAccount: (e) =>
|
loginAccount: (e) =>
|
||||||
forms.clearFormAlerts(@$el)
|
forms.clearFormAlerts(@$el)
|
||||||
userObject = forms.formToObject @$el
|
userObject = forms.formToObject @$el
|
||||||
res = tv4.validateMultiple userObject, User.schema.attributes
|
res = tv4.validateMultiple userObject, User.schema
|
||||||
return forms.applyErrorsToForm(@$el, res.errors) unless res.valid
|
return forms.applyErrorsToForm(@$el, res.errors) unless res.valid
|
||||||
@enableModalInProgress(@$el) # TODO: part of forms
|
@enableModalInProgress(@$el) # TODO: part of forms
|
||||||
loginUser(userObject)
|
loginUser(userObject)
|
||||||
|
|
|
@ -57,7 +57,7 @@ module.exports = class SignupModalView extends View
|
||||||
userObject.emailSubscriptions.push 'notification' unless 'notification' in userObject.emailSubscriptions
|
userObject.emailSubscriptions.push 'notification' unless 'notification' in userObject.emailSubscriptions
|
||||||
else
|
else
|
||||||
userObject.emailSubscriptions = _.without (userObject.emailSubscriptions ? []), 'announcement', 'notification'
|
userObject.emailSubscriptions = _.without (userObject.emailSubscriptions ? []), 'announcement', 'notification'
|
||||||
res = tv4.validateMultiple userObject, User.schema.attributes
|
res = tv4.validateMultiple userObject, User.schema
|
||||||
return forms.applyErrorsToForm(@$el, res.errors) unless res.valid
|
return forms.applyErrorsToForm(@$el, res.errors) unless res.valid
|
||||||
window.tracker?.trackEvent 'Finished Signup'
|
window.tracker?.trackEvent 'Finished Signup'
|
||||||
@enableModalInProgress(@$el)
|
@enableModalInProgress(@$el)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
mongoose = require('mongoose')
|
mongoose = require('mongoose')
|
||||||
plugins = require('../plugins/plugins')
|
plugins = require('../plugins/plugins')
|
||||||
jsonschema = require('./level_schema')
|
jsonschema = require('../../app/schemas/level_schema')
|
||||||
|
|
||||||
LevelSchema = new mongoose.Schema({
|
LevelSchema = new mongoose.Schema({
|
||||||
description: String
|
description: String
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
mongoose = require('mongoose')
|
mongoose = require('mongoose')
|
||||||
plugins = require('../../plugins/plugins')
|
plugins = require('../../plugins/plugins')
|
||||||
jsonschema = require('./level_component_schema')
|
jsonschema = require('../../../app/schemas/level_component_schema')
|
||||||
|
|
||||||
LevelComponentSchema = new mongoose.Schema {
|
LevelComponentSchema = new mongoose.Schema {
|
||||||
description: String
|
description: String
|
||||||
|
|
|
@ -3,7 +3,7 @@ Handler = require('../../commons/Handler')
|
||||||
|
|
||||||
LevelComponentHandler = class LevelComponentHandler extends Handler
|
LevelComponentHandler = class LevelComponentHandler extends Handler
|
||||||
modelClass: LevelComponent
|
modelClass: LevelComponent
|
||||||
jsonSchema: require './level_component_schema'
|
jsonSchema: require '../../../app/schemas/level_component_schema'
|
||||||
editableProperties: [
|
editableProperties: [
|
||||||
'system'
|
'system'
|
||||||
'description'
|
'description'
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
mongoose = require('mongoose')
|
mongoose = require('mongoose')
|
||||||
plugins = require('../../plugins/plugins')
|
plugins = require('../../plugins/plugins')
|
||||||
jsonschema = require('./level_feedback_schema')
|
jsonschema = require('../../../app/schemas/level_feedback_schema')
|
||||||
|
|
||||||
LevelFeedbackSchema = new mongoose.Schema({
|
LevelFeedbackSchema = new mongoose.Schema({
|
||||||
created:
|
created:
|
||||||
|
|
|
@ -4,7 +4,7 @@ Handler = require('../../commons/Handler')
|
||||||
class LevelFeedbackHandler extends Handler
|
class LevelFeedbackHandler extends Handler
|
||||||
modelClass: LevelFeedback
|
modelClass: LevelFeedback
|
||||||
editableProperties: ['rating', 'review', 'level', 'levelID', 'levelName']
|
editableProperties: ['rating', 'review', 'level', 'levelID', 'levelName']
|
||||||
jsonSchema: require './level_feedback_schema'
|
jsonSchema: require '../../../app/schemas/level_feedback_schema'
|
||||||
|
|
||||||
makeNewInstance: (req) ->
|
makeNewInstance: (req) ->
|
||||||
feedback = super(req)
|
feedback = super(req)
|
||||||
|
|
|
@ -8,7 +8,7 @@ mongoose = require('mongoose')
|
||||||
|
|
||||||
LevelHandler = class LevelHandler extends Handler
|
LevelHandler = class LevelHandler extends Handler
|
||||||
modelClass: Level
|
modelClass: Level
|
||||||
jsonSchema: require './level_schema'
|
jsonSchema: require '../../app/schemas/level_schema'
|
||||||
editableProperties: [
|
editableProperties: [
|
||||||
'description'
|
'description'
|
||||||
'documentation'
|
'documentation'
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
mongoose = require('mongoose')
|
mongoose = require('mongoose')
|
||||||
plugins = require('../../plugins/plugins')
|
plugins = require('../../plugins/plugins')
|
||||||
jsonschema = require('./level_session_schema')
|
jsonschema = require('../../../app/schemas/level_session_schema')
|
||||||
|
|
||||||
LevelSessionSchema = new mongoose.Schema({
|
LevelSessionSchema = new mongoose.Schema({
|
||||||
created:
|
created:
|
||||||
|
|
|
@ -9,7 +9,7 @@ class LevelSessionHandler extends Handler
|
||||||
editableProperties: ['multiplayer', 'players', 'code', 'completed', 'state',
|
editableProperties: ['multiplayer', 'players', 'code', 'completed', 'state',
|
||||||
'levelName', 'creatorName', 'levelID', 'screenshot',
|
'levelName', 'creatorName', 'levelID', 'screenshot',
|
||||||
'chat', 'teamSpells', 'submitted', 'unsubscribed']
|
'chat', 'teamSpells', 'submitted', 'unsubscribed']
|
||||||
jsonSchema: require './level_session_schema'
|
jsonSchema: require '../../../app/schemas/level_session_schema'
|
||||||
|
|
||||||
getByRelationship: (req, res, args...) ->
|
getByRelationship: (req, res, args...) ->
|
||||||
return @getActiveSessions req, res if args.length is 2 and args[1] is 'active'
|
return @getActiveSessions req, res if args.length is 2 and args[1] is 'active'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
mongoose = require('mongoose')
|
mongoose = require('mongoose')
|
||||||
plugins = require('../../plugins/plugins')
|
plugins = require('../../plugins/plugins')
|
||||||
jsonschema = require('./level_system_schema')
|
jsonschema = require('../../../app/schemas/level_system_schema')
|
||||||
|
|
||||||
LevelSystemSchema = new mongoose.Schema {
|
LevelSystemSchema = new mongoose.Schema {
|
||||||
description: String
|
description: String
|
||||||
|
|
|
@ -13,7 +13,7 @@ LevelSystemHandler = class LevelSystemHandler extends Handler
|
||||||
'configSchema'
|
'configSchema'
|
||||||
]
|
]
|
||||||
postEditableProperties: ['name']
|
postEditableProperties: ['name']
|
||||||
jsonSchema: require './level_system_schema'
|
jsonSchema: require '../../../app/schemas/level_system_schema'
|
||||||
|
|
||||||
getEditableProperties: (req, document) ->
|
getEditableProperties: (req, document) ->
|
||||||
props = super(req, document)
|
props = super(req, document)
|
||||||
|
|
|
@ -3,7 +3,7 @@ Handler = require('../../commons/Handler')
|
||||||
|
|
||||||
ThangTypeHandler = class ThangTypeHandler extends Handler
|
ThangTypeHandler = class ThangTypeHandler extends Handler
|
||||||
modelClass: ThangType
|
modelClass: ThangType
|
||||||
jsonSchema: require './thang_type_schema'
|
jsonSchema: require '../../../app/schemas/thang_type_schema'
|
||||||
editableProperties: [
|
editableProperties: [
|
||||||
'name',
|
'name',
|
||||||
'raw',
|
'raw',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Patch = require('./Patch')
|
Patch = require('./Patch')
|
||||||
Handler = require('../commons/Handler')
|
Handler = require('../commons/Handler')
|
||||||
schema = require './patch_schema'
|
schema = require '../../app/schemas/patch_schema'
|
||||||
{handlers} = require '../commons/mapping'
|
{handlers} = require '../commons/mapping'
|
||||||
mongoose = require('mongoose')
|
mongoose = require('mongoose')
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ PatchHandler = class PatchHandler extends Handler
|
||||||
modelClass: Patch
|
modelClass: Patch
|
||||||
editableProperties: []
|
editableProperties: []
|
||||||
postEditableProperties: ['delta', 'target', 'commitMessage']
|
postEditableProperties: ['delta', 'target', 'commitMessage']
|
||||||
jsonSchema: require './patch_schema'
|
jsonSchema: require '../../app/schemas/patch_schema'
|
||||||
|
|
||||||
makeNewInstance: (req) ->
|
makeNewInstance: (req) ->
|
||||||
patch = super(req)
|
patch = super(req)
|
||||||
|
|
|
@ -47,8 +47,8 @@ module.exports.setup = (app) ->
|
||||||
|
|
||||||
getSchema = (req, res, moduleName) ->
|
getSchema = (req, res, moduleName) ->
|
||||||
try
|
try
|
||||||
name = schemas[moduleName.replace '.', '_']
|
name = moduleName.replace '.', '_'
|
||||||
schema = require('../' + name)
|
schema = require('../../app/schemas/' + name + '_schema')
|
||||||
|
|
||||||
res.send(JSON.stringify(schema, null, '\t'))
|
res.send(JSON.stringify(schema, null, '\t'))
|
||||||
res.end()
|
res.end()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mongoose = require('mongoose')
|
mongoose = require('mongoose')
|
||||||
jsonschema = require('./user_schema')
|
jsonschema = require('../../app/schemas/user_schema')
|
||||||
crypto = require('crypto')
|
crypto = require('crypto')
|
||||||
{salt, isProduction} = require('../../server_config')
|
{salt, isProduction} = require('../../server_config')
|
||||||
mail = require '../commons/mail'
|
mail = require '../commons/mail'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
schema = require './user_schema'
|
schema = require '../../app/schemas/user_schema'
|
||||||
crypto = require 'crypto'
|
crypto = require 'crypto'
|
||||||
request = require 'request'
|
request = require 'request'
|
||||||
User = require './User'
|
User = require './User'
|
||||||
|
|
Loading…
Reference in a new issue