Added i18nCoverage backend support.

This commit is contained in:
Scott Erickson 2014-10-17 12:12:06 -04:00
parent 36ea415dbf
commit 0dc050abca
7 changed files with 26 additions and 1 deletions

View file

@ -284,6 +284,7 @@ class CocoModel extends Backbone.Model
if schema.items and _.isArray data
sum += @populateI18N(value, schema.items, path+'/'+index) for value, index in data
@updateI18NCoverage()
sum
@getReferencedModel: (data, schema) ->

View file

@ -253,6 +253,7 @@ c.extendSearchableProperties LevelSchema
c.extendVersionedProperties LevelSchema, 'level'
c.extendPermissionsProperties LevelSchema, 'level'
c.extendPatchableProperties LevelSchema
c.extendTranslationCoverageProperties LevelSchema
module.exports = LevelSchema

View file

@ -144,6 +144,10 @@ me.getLanguageCodeArray = ->
me.getLanguagesObject = -> return Language
me.extendTranslationCoverageProperties = (schema) ->
schema.properties = {} unless schema.properties?
schema.properties.i18nCoverage = { title: 'i18n Coverage', type: 'array', items: { type: 'string' }}
# OTHER
me.classNamePattern = '^[A-Z][A-Za-z0-9]*$' # starts with capital letter; just letters and numbers

View file

@ -11,6 +11,7 @@ LevelSchema.plugin(plugins.PermissionsPlugin)
LevelSchema.plugin(plugins.VersionedPlugin)
LevelSchema.plugin(plugins.SearchablePlugin, {searchable: ['name', 'description']})
LevelSchema.plugin(plugins.PatchablePlugin)
LevelSchema.plugin(plugins.TranslationCoveragePlugin)
LevelSchema.post 'init', (doc) ->
if _.isString(doc.get('nextLevel'))

View file

@ -9,5 +9,6 @@ ThangTypeSchema.plugin plugins.NamedPlugin
ThangTypeSchema.plugin plugins.VersionedPlugin
ThangTypeSchema.plugin plugins.SearchablePlugin, {searchable: ['name']}
ThangTypeSchema.plugin plugins.PatchablePlugin
ThangTypeSchema.plugin plugins.TranslationCoveragePlugin
module.exports = mongoose.model('thang.type', ThangTypeSchema)

View file

@ -35,6 +35,7 @@ ThangTypeHandler = class ThangTypeHandler extends Handler
'rasterIcon'
'featureImage'
'spriteType'
'i18nCoverage'
]
hasAccess: (req) ->

View file

@ -281,7 +281,7 @@ module.exports.SearchablePlugin = (schema, options) ->
searchable = options.searchable
unless searchable
throw Error('SearchablePlugin options must include list of searchable properties.')
throw new Error('SearchablePlugin options must include list of searchable properties.')
index = {}
@ -307,3 +307,19 @@ module.exports.SearchablePlugin = (schema, options) ->
@index = @getOwner() unless access
next()
module.exports.TranslationCoveragePlugin = (schema, options) ->
schema.uses_coco_translation_coverage = true
schema.set('autoIndex', true)
index = {}
if schema.uses_coco_versions
if not schema.uses_coco_names
throw Error('If using translation coverage and versioning, should also use names for indexing.')
index.slug = 1
index.i18nCoverage = 1
schema.index(index, {sparse: true, name: 'translation coverage index', background: true})