From a0e1806239b38fed8eb231918f4b31164e154e73 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Thu, 28 Aug 2014 09:52:51 -0700 Subject: [PATCH 1/2] Fixed a bug with old, un-migrated level-set-playing events in button handlers. --- app/styles/play/level/hud.sass | 1 + app/views/play/level/LevelHUDView.coffee | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/styles/play/level/hud.sass b/app/styles/play/level/hud.sass index 1982f8339..fd30f304f 100644 --- a/app/styles/play/level/hud.sass +++ b/app/styles/play/level/hud.sass @@ -233,6 +233,7 @@ position: relative height: 100% width: 100% + z-index: 1 .bubble position: absolute diff --git a/app/views/play/level/LevelHUDView.coffee b/app/views/play/level/LevelHUDView.coffee index 66d38c6d6..3f5c7f0ba 100644 --- a/app/views/play/level/LevelHUDView.coffee +++ b/app/views/play/level/LevelHUDView.coffee @@ -207,7 +207,8 @@ module.exports = class LevelHUDView extends CocoView if @lastResponses buttons = $('.enter button') for response, i in @lastResponses - f = (r) => => setTimeout((-> Backbone.Mediator.publish(r.channel, r.event or {})), 10) + channel = response.channel.replace 'level-set-playing', 'level:set-playing' # Easier than migrating all those victory buttons. + f = (r) => => setTimeout((-> Backbone.Mediator.publish(channel, r.event or {})), 10) $(buttons[i]).click(f(response)) else $('.enter', @bubble).click(-> Backbone.Mediator.publish('script:end-current-script', {})) @@ -221,7 +222,8 @@ module.exports = class LevelHUDView extends CocoView # If we decide that always having the last one fire is bad, we should make it smarter. return unless @lastResponses?.length r = @lastResponses[@lastResponses.length - 1] - _.delay (-> Backbone.Mediator.publish(r.channel, r.event or {})), 10 + channel = r.channel.replace 'level-set-playing', 'level:set-playing' + _.delay (-> Backbone.Mediator.publish(channel, r.event or {})), 10 onEscapePressed: (e) -> @escapePressed = true From 54207f0f7ddee00f4b4000c6413cdc4407d1ec32 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Thu, 28 Aug 2014 10:50:20 -0700 Subject: [PATCH 2/2] Fixed #1000. --- app/models/CocoModel.coffee | 5 +++++ app/styles/kinds/search.sass | 3 +++ app/templates/editor/article/table.jade | 22 +------------------ app/templates/editor/level/table.jade | 22 +------------------ app/templates/editor/thang/table.jade | 8 +++++-- app/templates/kinds/table.jade | 19 ++++++++-------- .../editor/article/ArticleSearchView.coffee | 1 + app/views/editor/level/LevelSearchView.coffee | 1 + .../editor/thang/ThangTypeSearchView.coffee | 1 + app/views/kinds/SearchView.coffee | 15 ++++++++++--- server/commons/Handler.coffee | 2 +- 11 files changed, 42 insertions(+), 57 deletions(-) diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index 952d807e6..5e94cfd0d 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -212,6 +212,11 @@ class CocoModel extends Backbone.Model return false + getOwner: -> + return null unless permissions = @get 'permissions' + ownerPermission = _.find permissions, access: 'owner' + ownerPermission?.target + getDelta: -> differ = deltasLib.makeJSONDiffer() differ.diff @_revertAttributes, @attributes diff --git a/app/styles/kinds/search.sass b/app/styles/kinds/search.sass index 872d346ee..69b8c11df 100644 --- a/app/styles/kinds/search.sass +++ b/app/styles/kinds/search.sass @@ -16,6 +16,9 @@ overflow: hidden text-overflow: ellipsis + tr.mine + background-color: #f8ecaa + .loading text-align: center diff --git a/app/templates/editor/article/table.jade b/app/templates/editor/article/table.jade index 42b431c32..c3654353c 100755 --- a/app/templates/editor/article/table.jade +++ b/app/templates/editor/article/table.jade @@ -1,21 +1 @@ -table.table - tr - th(colspan=3) - span(data-i18n="general.results") - | Results - span - |: #{documents.length} - - tr - th(data-i18n="general.name") Name - th(data-i18n="general.description") Description - th(data-i18n="general.version") Version - - for data in documents - - data = data.attributes; - tr - td - a(href="/editor/article/#{data.slug || data._id}") - | #{data.name} - td.body-row #{data.description} - td #{data.version.major}.#{data.version.minor} \ No newline at end of file +extends /templates/kinds/table diff --git a/app/templates/editor/level/table.jade b/app/templates/editor/level/table.jade index 594d09ea4..c3654353c 100755 --- a/app/templates/editor/level/table.jade +++ b/app/templates/editor/level/table.jade @@ -1,21 +1 @@ -table.table - tr - th(colspan=3) - span(data-i18n="general.results") - | Results - span - |: #{documents.length} - - tr - th(data-i18n="general.name") Name - th(data-i18n="general.description") Description - th(data-i18n="general.version") Version - - for data in documents - - data = data.attributes; - tr - td - a(href="/editor/level/#{data.slug || data._id}") - | #{data.name} - td.body-row #{data.description} - td #{data.version.major}.#{data.version.minor} +extends /templates/kinds/table diff --git a/app/templates/editor/thang/table.jade b/app/templates/editor/thang/table.jade index 6036bacfd..f4fead3cc 100755 --- a/app/templates/editor/thang/table.jade +++ b/app/templates/editor/thang/table.jade @@ -1,17 +1,21 @@ -table.table +extends /templates/kinds/table + +block tableResultsHeader tr - th(colspan=3) + th(colspan=4) span(data-i18n="general.results") | Results span |: #{documents.length} +block tableHeader tr th#portrait-col th(data-i18n="general.name") Name th(data-i18n="general.description") Description th(data-i18n="general.version") Version +block tableBody for thang in documents tr td diff --git a/app/templates/kinds/table.jade b/app/templates/kinds/table.jade index 6e1653469..bd768ce42 100755 --- a/app/templates/kinds/table.jade +++ b/app/templates/kinds/table.jade @@ -1,10 +1,11 @@ table.table - tr - th(colspan=3) - span(data-i18n="general.results") - | Results - span - |: #{documents.length} + block tableResultsHeader + tr + th(colspan=3) + span(data-i18n="general.results") + | Results + span + |: #{documents.length} block tableHeader tr @@ -13,9 +14,9 @@ table.table th(data-i18n="general.version") Version block tableBody - for data in documents - - data = data.attributes; - tr + for document in documents + - var data = document.attributes; + tr(class=document.getOwner() == me.id ? 'mine' : '') td a(href="/editor/#{page}/#{data.slug || data._id}") | #{data.name} diff --git a/app/views/editor/article/ArticleSearchView.coffee b/app/views/editor/article/ArticleSearchView.coffee index b80423011..834b019f2 100644 --- a/app/views/editor/article/ArticleSearchView.coffee +++ b/app/views/editor/article/ArticleSearchView.coffee @@ -6,6 +6,7 @@ module.exports = class ArticleSearchView extends SearchView model: require 'models/Article' modelURL: '/db/article' tableTemplate: require 'templates/editor/article/table' + page: 'article' getRenderData: -> context = super() diff --git a/app/views/editor/level/LevelSearchView.coffee b/app/views/editor/level/LevelSearchView.coffee index a5dfb21c7..3c8f4a727 100644 --- a/app/views/editor/level/LevelSearchView.coffee +++ b/app/views/editor/level/LevelSearchView.coffee @@ -6,6 +6,7 @@ module.exports = class LevelSearchView extends SearchView model: require 'models/Level' modelURL: '/db/level' tableTemplate: require 'templates/editor/level/table' + page: 'editor' getRenderData: -> context = super() diff --git a/app/views/editor/thang/ThangTypeSearchView.coffee b/app/views/editor/thang/ThangTypeSearchView.coffee index 52807f331..cc1d3ce48 100644 --- a/app/views/editor/thang/ThangTypeSearchView.coffee +++ b/app/views/editor/thang/ThangTypeSearchView.coffee @@ -7,6 +7,7 @@ module.exports = class ThangTypeSearchView extends SearchView modelURL: '/db/thang.type' tableTemplate: require 'templates/editor/thang/table' projection: ['original', 'name', 'version', 'description', 'slug', 'kind', 'rasterIcon'] + page: 'thang' getRenderData: -> context = super() diff --git a/app/views/kinds/SearchView.coffee b/app/views/kinds/SearchView.coffee index 7d5fa8b0f..8bf19c3f9 100644 --- a/app/views/kinds/SearchView.coffee +++ b/app/views/kinds/SearchView.coffee @@ -7,11 +7,19 @@ class SearchCollection extends Backbone.Collection initialize: (modelURL, @model, @term, @projection) -> @url = "#{modelURL}?project=" if @projection? and not (@projection == []) - @url += projection[0] - @url += ',' + projected for projected in projection[1..] + @url += 'created,permissions' + @url += ',' + projected for projected in projection else @url += 'true' @url += "&term=#{term}" if @term + comparator: (a, b) -> + score = 0 + score -= 9001900190019001 if a.getOwner() is me.id + score += 9001900190019001 if b.getOwner() is me.id + score -= new Date(a.get 'created') + score -= -(new Date(b.get 'created')) + if score < 0 then -1 else (if score > 0 then 1 else 0) + module.exports = class SearchView extends RootView template: template className: 'search-view' @@ -67,8 +75,9 @@ module.exports = class SearchView extends RootView onSearchChange: -> @hideLoading() + @collection.sort() documents = @collection.models - table = $(@tableTemplate(documents:documents)) + table = $(@tableTemplate(documents: documents, me: me, page: @page)) @$el.find('table').replaceWith(table) @$el.find('table').i18n() diff --git a/server/commons/Handler.coffee b/server/commons/Handler.coffee index bec7c9063..6b1c110a6 100644 --- a/server/commons/Handler.coffee +++ b/server/commons/Handler.coffee @@ -7,7 +7,7 @@ Patch = require '../patches/Patch' User = require '../users/User' sendwithus = require '../sendwithus' -PROJECT = {original: 1, name: 1, version: 1, description: 1, slug: 1, kind: 1} +PROJECT = {original: 1, name: 1, version: 1, description: 1, slug: 1, kind: 1, created: 1, permissions: 1} FETCH_LIMIT = 300 module.exports = class Handler