From 0dc050abca6d94057e40c41125b212eadfe7837c Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Fri, 17 Oct 2014 12:12:06 -0400 Subject: [PATCH] Added i18nCoverage backend support. --- app/models/CocoModel.coffee | 1 + app/schemas/models/level.coffee | 1 + app/schemas/schemas.coffee | 4 ++++ server/levels/Level.coffee | 1 + server/levels/thangs/ThangType.coffee | 1 + server/levels/thangs/thang_type_handler.coffee | 1 + server/plugins/plugins.coffee | 18 +++++++++++++++++- 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index ebe42cc49..4b7fcbb09 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -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) -> diff --git a/app/schemas/models/level.coffee b/app/schemas/models/level.coffee index 318265cfb..d5d431d8f 100644 --- a/app/schemas/models/level.coffee +++ b/app/schemas/models/level.coffee @@ -253,6 +253,7 @@ c.extendSearchableProperties LevelSchema c.extendVersionedProperties LevelSchema, 'level' c.extendPermissionsProperties LevelSchema, 'level' c.extendPatchableProperties LevelSchema +c.extendTranslationCoverageProperties LevelSchema module.exports = LevelSchema diff --git a/app/schemas/schemas.coffee b/app/schemas/schemas.coffee index 5d30ac865..8a16f830c 100644 --- a/app/schemas/schemas.coffee +++ b/app/schemas/schemas.coffee @@ -143,6 +143,10 @@ me.getLanguageCodeArray = -> return Language.languageCodes me.getLanguagesObject = -> return Language + +me.extendTranslationCoverageProperties = (schema) -> + schema.properties = {} unless schema.properties? + schema.properties.i18nCoverage = { title: 'i18n Coverage', type: 'array', items: { type: 'string' }} # OTHER diff --git a/server/levels/Level.coffee b/server/levels/Level.coffee index dc2020557..95d2bc4b7 100644 --- a/server/levels/Level.coffee +++ b/server/levels/Level.coffee @@ -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')) diff --git a/server/levels/thangs/ThangType.coffee b/server/levels/thangs/ThangType.coffee index 78ee66180..02259caa3 100644 --- a/server/levels/thangs/ThangType.coffee +++ b/server/levels/thangs/ThangType.coffee @@ -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) diff --git a/server/levels/thangs/thang_type_handler.coffee b/server/levels/thangs/thang_type_handler.coffee index 7fa07c491..126e43cf3 100644 --- a/server/levels/thangs/thang_type_handler.coffee +++ b/server/levels/thangs/thang_type_handler.coffee @@ -35,6 +35,7 @@ ThangTypeHandler = class ThangTypeHandler extends Handler 'rasterIcon' 'featureImage' 'spriteType' + 'i18nCoverage' ] hasAccess: (req) -> diff --git a/server/plugins/plugins.coffee b/server/plugins/plugins.coffee index 918055042..9478a4a47 100644 --- a/server/plugins/plugins.coffee +++ b/server/plugins/plugins.coffee @@ -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}) \ No newline at end of file