mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
I think this return is needed to prevent sending the i18n query results twice and crashing the server.
This commit is contained in:
parent
cea04d27ad
commit
68ac412f2b
2 changed files with 15 additions and 14 deletions
|
@ -13,30 +13,30 @@ PAGE_SIZE = 100
|
|||
module.exports = class I18NHomeView extends RootView
|
||||
id: "i18n-home-view"
|
||||
template: template
|
||||
|
||||
|
||||
events:
|
||||
'change #language-select': 'onLanguageSelectChanged'
|
||||
|
||||
constructor: (options) ->
|
||||
super(options)
|
||||
@selectedLanguage = me.get('preferredLanguage', true)
|
||||
|
||||
#-
|
||||
|
||||
#-
|
||||
@aggregateModels = new Backbone.Collection()
|
||||
project = ['name', 'components.original', 'i18nCoverage', 'slug']
|
||||
|
||||
|
||||
@thangTypes = new CocoCollection([], { url: '/db/thang.type?view=i18n-coverage', project: project, model: ThangType })
|
||||
@components = new CocoCollection([], { url: '/db/level.component?view=i18n-coverage', project: project, model: LevelComponent })
|
||||
@levels = new CocoCollection([], { url: '/db/level?view=i18n-coverage', project: project, model: Level })
|
||||
@achievements = new CocoCollection([], { url: '/db/achievement?view=i18n-coverage', project: project, model: Achievement })
|
||||
|
||||
|
||||
for c in [@thangTypes, @components, @levels, @achievements]
|
||||
c.skip = 0
|
||||
c.fetch({data: {skip: 0, limit: PAGE_SIZE}, cache:false})
|
||||
@supermodel.loadCollection(c, 'documents')
|
||||
@listenTo c, 'sync', @onCollectionSynced
|
||||
|
||||
|
||||
|
||||
onCollectionSynced: (collection) ->
|
||||
for model in collection.models
|
||||
model.i18nURLBase = switch model.constructor.className
|
||||
|
@ -51,7 +51,7 @@ module.exports = class I18NHomeView extends RootView
|
|||
if getMore
|
||||
collection.skip += PAGE_SIZE
|
||||
collection.fetch({data: {skip: collection.skip, limit: PAGE_SIZE}})
|
||||
|
||||
|
||||
getRenderData: ->
|
||||
c = super()
|
||||
@updateCoverage()
|
||||
|
@ -59,25 +59,25 @@ module.exports = class I18NHomeView extends RootView
|
|||
c.selectedLanguage = @selectedLanguage
|
||||
c.collection = @aggregateModels
|
||||
c
|
||||
|
||||
|
||||
updateCoverage: ->
|
||||
selectedBase = @selectedLanguage[..2]
|
||||
relatedLanguages = (l for l in languages when l.startsWith(selectedBase) and l isnt @selectedLanguage)
|
||||
for model in @aggregateModels.models
|
||||
@updateCoverageForModel(model, relatedLanguages)
|
||||
model.generallyCovered = true if @selectedLanguage.startsWith 'en'
|
||||
|
||||
|
||||
updateCoverageForModel: (model, relatedLanguages) ->
|
||||
model.specificallyCovered = true
|
||||
model.generallyCovered = true
|
||||
coverage = model.get('i18nCoverage')
|
||||
|
||||
|
||||
if @selectedLanguage not in coverage
|
||||
model.specificallyCovered = false
|
||||
if not _.any((l in coverage for l in relatedLanguages))
|
||||
model.generallyCovered = false
|
||||
return
|
||||
|
||||
|
||||
afterRender: ->
|
||||
super()
|
||||
@addLanguagesToSelect(@$el.find('#language-select'), @selectedLanguage)
|
||||
|
|
|
@ -33,14 +33,14 @@ module.exports = class Handler
|
|||
hasAccess: (req) -> true
|
||||
hasAccessToDocument: (req, document, method=null) ->
|
||||
return true if req.user?.isAdmin()
|
||||
|
||||
|
||||
if @modelClass.schema.uses_coco_translation_coverage and (method or req.method).toLowerCase() is 'put'
|
||||
return true if @isJustFillingTranslations(req, document)
|
||||
|
||||
|
||||
if @modelClass.schema.uses_coco_permissions
|
||||
return document.hasPermissionsForMethod?(req.user, method or req.method)
|
||||
return true
|
||||
|
||||
|
||||
isJustFillingTranslations: (req, document) ->
|
||||
differ = deltasLib.makeJSONDiffer()
|
||||
omissions = ['original'].concat(deltasLib.DOC_SKIP_PATHS)
|
||||
|
@ -121,6 +121,7 @@ module.exports = class Handler
|
|||
return @sendDatabaseError(res, err) if err
|
||||
documents = (@formatEntity(req, doc) for doc in documents)
|
||||
@sendSuccess(res, documents)
|
||||
return
|
||||
|
||||
specialParameters = ['term', 'project', 'conditions']
|
||||
|
||||
|
|
Loading…
Reference in a new issue