diff --git a/app/templates/editor/level/add_thangs.jade b/app/templates/editor/level/add_thangs.jade index 09857d0ad..5b2419072 100644 --- a/app/templates/editor/level/add_thangs.jade +++ b/app/templates/editor/level/add_thangs.jade @@ -1,5 +1,5 @@ h3(data-i18n="editor.level_tab_thangs_add") Add Thangs -input(type="text", id="thang-search") +input(type="search", id="thang-search") #thangs-list for group in groups h4= group.name diff --git a/app/views/editor/level/thangs_tab_view.coffee b/app/views/editor/level/thangs_tab_view.coffee index 3e61df4f8..72f245a7f 100644 --- a/app/views/editor/level/thangs_tab_view.coffee +++ b/app/views/editor/level/thangs_tab_view.coffee @@ -21,7 +21,7 @@ componentOriginals = "physics.Physical" : "524b75ad7fc0f6d519000001" class ThangTypeSearchCollection extends CocoCollection - url: '/db/thang.type/search?project=true' + url: '/db/thang.type/search?project=original,name,version,slug,kind,components' model: ThangType module.exports = class ThangsTabView extends View diff --git a/server/commons/Handler.coffee b/server/commons/Handler.coffee index 3435107cb..21249a039 100644 --- a/server/commons/Handler.coffee +++ b/server/commons/Handler.coffee @@ -2,6 +2,8 @@ async = require 'async' mongoose = require('mongoose') Grid = require 'gridfs-stream' errors = require './errors' +log = require 'winston' + PROJECT = {original:1, name:1, version:1, description: 1, slug:1, kind: 1} FETCH_LIMIT = 150 @@ -99,6 +101,17 @@ module.exports = class Handler filters = [{filter: {index: true}}] if @modelClass.schema.uses_coco_permissions and req.user filters.push {filter: {index: req.user.get('id')}} + projection = null + if req.query.project is 'true' + projection = PROJECT + else if req.query.project + if @modelClass.className is 'User' + projection = PROJECTION + log.warn "Whoa, we haven't yet thought about public properties for User projection yet." + else + projection = {} + for field in req.query.project.split(',') + projection[field] = 1 for filter in filters callback = (err, results) => return @sendDatabaseError(res, err) if err @@ -111,11 +124,11 @@ module.exports = class Handler res.send matchedObjects res.end() if term - filter.project = PROJECT if req.query.project + filter.project = projection @modelClass.textSearch term, filter, callback else args = [filter.filter] - args.push PROJECT if req.query.project + args.push projection if projection @modelClass.find(args...).limit(FETCH_LIMIT).exec callback versions: (req, res, id) ->