From 30eed4c8b46ec6a80dba10116523e1cd52f47f5c Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 10 Sep 2013 20:00:04 -0400 Subject: [PATCH 1/7] FIX: Showing suggested topics when composing a reply --- .../javascripts/discourse/controllers/composer_controller.js | 3 +++ .../discourse/controllers/composer_messages_controller.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/app/assets/javascripts/discourse/controllers/composer_controller.js b/app/assets/javascripts/discourse/controllers/composer_controller.js index 99805553faa..c289c57bb8d 100644 --- a/app/assets/javascripts/discourse/controllers/composer_controller.js +++ b/app/assets/javascripts/discourse/controllers/composer_controller.js @@ -198,6 +198,9 @@ Discourse.ComposerController = Discourse.Controller.extend({ open: function(opts) { if (!opts) opts = {}; + var composerMessages = this.get('controllers.composerMessages'); + composerMessages.reset(); + var promise = opts.promise || Ember.Deferred.create(); opts.promise = promise; this.set('typedReply', false); diff --git a/app/assets/javascripts/discourse/controllers/composer_messages_controller.js b/app/assets/javascripts/discourse/controllers/composer_messages_controller.js index 1f4b1bcf126..ccfe883c656 100644 --- a/app/assets/javascripts/discourse/controllers/composer_messages_controller.js +++ b/app/assets/javascripts/discourse/controllers/composer_messages_controller.js @@ -26,6 +26,11 @@ Discourse.ComposerMessagesController = Ember.ArrayController.extend({ closeMessage: function(message) { this.removeObject(message); + }, + + reset: function() { + this.clear(); + this.set('messagesByTemplate', {}); } }); \ No newline at end of file From e420ce3da362307def7a721e2d5e95778657d566 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 11 Sep 2013 11:24:42 +1000 Subject: [PATCH 2/7] fix regression, 2 people liked this text not expanding correctly --- app/serializers/post_action_user_serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/serializers/post_action_user_serializer.rb b/app/serializers/post_action_user_serializer.rb index ff1b1b42149..6b791d8c630 100644 --- a/app/serializers/post_action_user_serializer.rb +++ b/app/serializers/post_action_user_serializer.rb @@ -14,7 +14,7 @@ class PostActionUserSerializer < BasicUserSerializer end def post_url - object.related_post.url if object.related_post.id + object.related_post.url if object.related_post_id && object.related_post end end From 681ff74cb81f91215e902466d6da97dc68fcc1da Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 11 Sep 2013 13:26:46 +1000 Subject: [PATCH 3/7] Revert "inject currentUser into controllers & routes" This reverts commit 7ec34b205ac3ee98dece108033fee339667fb4be. --- app/assets/javascripts/discourse.js | 18 ----------- .../controllers/composer_controller.js | 2 +- .../discourse/controllers/controller.js | 2 +- .../controllers/header_controller.js | 4 +-- .../discourse/controllers/list_controller.js | 8 ++--- .../controllers/object_controller.js | 4 ++- .../controllers/quote_button_controller.js | 2 +- .../discourse/controllers/topic_controller.js | 10 +++--- .../discourse/mixins/has_current_user.js | 31 +++++++++++++++++++ .../discourse/routes/user_routes.js | 4 +-- 10 files changed, 50 insertions(+), 35 deletions(-) create mode 100644 app/assets/javascripts/discourse/mixins/has_current_user.js diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index 7fb9937720b..f71d9d104f6 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -229,21 +229,3 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, { Discourse.Router = Discourse.Router.reopen({ location: 'discourse_location' }); -Discourse.initializer({ - name: 'currentUser', - - initialize: function(container) { - container.register('user:current', Discourse.User.current(), { instantiate: false }); - } -}); - -Discourse.initializer({ - name: 'injectCurrentUser', - - initialize: function(container) { - if (container.lookup('user:current')) { - container.injection('controller', 'currentUser', 'user:current'); - container.injection('route', 'currentUser', 'user:current'); - } - } -}); diff --git a/app/assets/javascripts/discourse/controllers/composer_controller.js b/app/assets/javascripts/discourse/controllers/composer_controller.js index c289c57bb8d..7732468f5e3 100644 --- a/app/assets/javascripts/discourse/controllers/composer_controller.js +++ b/app/assets/javascripts/discourse/controllers/composer_controller.js @@ -103,7 +103,7 @@ Discourse.ComposerController = Discourse.Controller.extend({ opts = opts || {}; composerController.close(); - var currentUser = this.get('currentUser'); + var currentUser = Discourse.User.current(); if (composer.get('creatingTopic')) { currentUser.set('topic_count', currentUser.get('topic_count') + 1); } else { diff --git a/app/assets/javascripts/discourse/controllers/controller.js b/app/assets/javascripts/discourse/controllers/controller.js index 2c73a1a6dbe..ce298bced04 100644 --- a/app/assets/javascripts/discourse/controllers/controller.js +++ b/app/assets/javascripts/discourse/controllers/controller.js @@ -7,4 +7,4 @@ @uses Discourse.Presence @module Discourse **/ -Discourse.Controller = Ember.Controller.extend(Discourse.Presence); +Discourse.Controller = Ember.Controller.extend(Discourse.Presence, Discourse.HasCurrentUser); diff --git a/app/assets/javascripts/discourse/controllers/header_controller.js b/app/assets/javascripts/discourse/controllers/header_controller.js index bf52f41a984..4612ee7194c 100644 --- a/app/assets/javascripts/discourse/controllers/header_controller.js +++ b/app/assets/javascripts/discourse/controllers/header_controller.js @@ -21,8 +21,8 @@ Discourse.HeaderController = Discourse.Controller.extend({ }.property(), showFavoriteButton: function() { - return this.get('currentUser') && !this.get('topic.isPrivateMessage'); - }.property('currentUser', 'topic.isPrivateMessage'), + return Discourse.User.current() && !this.get('topic.isPrivateMessage'); + }.property('topic.isPrivateMessage'), mobileDevice: function() { return Discourse.Mobile.isMobileDevice; diff --git a/app/assets/javascripts/discourse/controllers/list_controller.js b/app/assets/javascripts/discourse/controllers/list_controller.js index f1bf12c90d8..0fb4fd9292e 100644 --- a/app/assets/javascripts/discourse/controllers/list_controller.js +++ b/app/assets/javascripts/discourse/controllers/list_controller.js @@ -13,7 +13,7 @@ Discourse.ListController = Discourse.Controller.extend({ needs: ['composer', 'modal', 'listTopics'], availableNavItems: function() { - var loggedOn = !!this.get('currentUser'); + var loggedOn = !!Discourse.User.current(); return Discourse.SiteSettings.top_menu.split("|").map(function(i) { return Discourse.NavItem.fromText(i, { @@ -22,7 +22,7 @@ Discourse.ListController = Discourse.Controller.extend({ }).filter(function(i) { return i !== null; }); - }.property('currentUser'), + }.property(), createTopicText: function() { if (this.get('category.name')) { @@ -125,12 +125,12 @@ Discourse.ListController = Discourse.Controller.extend({ canEditCategory: function() { if( this.present('category') ) { - var u = this.get('currentUser'); + var u = Discourse.User.current(); return u && u.staff; } else { return false; } - }.property('currentUser', 'category') + }.property('category') }); diff --git a/app/assets/javascripts/discourse/controllers/object_controller.js b/app/assets/javascripts/discourse/controllers/object_controller.js index 5d8136703f3..966c9c52fde 100644 --- a/app/assets/javascripts/discourse/controllers/object_controller.js +++ b/app/assets/javascripts/discourse/controllers/object_controller.js @@ -7,4 +7,6 @@ @uses Discourse.Presence @module Discourse **/ -Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence); +Discourse.ObjectController = Ember.ObjectController.extend(Discourse.Presence, Discourse.HasCurrentUser); + + diff --git a/app/assets/javascripts/discourse/controllers/quote_button_controller.js b/app/assets/javascripts/discourse/controllers/quote_button_controller.js index e8bb225fe88..e0713bb8945 100644 --- a/app/assets/javascripts/discourse/controllers/quote_button_controller.js +++ b/app/assets/javascripts/discourse/controllers/quote_button_controller.js @@ -31,7 +31,7 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({ **/ selectText: function(postId) { // anonymous users cannot "quote-reply" - if (!this.get('currentUser')) return; + if (!Discourse.User.current()) return; // don't display the "quote-reply" button if we can't create a post if (!this.get('controllers.topic.model.details.can_create_post')) return; diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 27cc245c530..e6a01bbe405 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -260,8 +260,8 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }, showFavoriteButton: function() { - return this.get('currentUser') && !this.get('isPrivateMessage'); - }.property('currentUser', 'isPrivateMessage'), + return Discourse.User.current() && !this.get('isPrivateMessage'); + }.property('isPrivateMessage'), recoverTopic: function() { this.get('content').recover(); @@ -269,7 +269,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected deleteTopic: function() { this.unsubscribe(); - this.get('content').destroy(this.get('currentUser')); + this.get('content').destroy(Discourse.User.current()); }, resetRead: function() { @@ -417,7 +417,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }, toggleBookmark: function(post) { - if (!this.get('currentUser')) { + if (!Discourse.User.current()) { alert(I18n.t("bookmarks.not_bookmarked")); return; } @@ -439,7 +439,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }, deletePost: function(post) { - var user = this.get('currentUser'), + var user = Discourse.User.current(), replyCount = post.get('reply_count'), self = this; diff --git a/app/assets/javascripts/discourse/mixins/has_current_user.js b/app/assets/javascripts/discourse/mixins/has_current_user.js new file mode 100644 index 00000000000..b23d3a28761 --- /dev/null +++ b/app/assets/javascripts/discourse/mixins/has_current_user.js @@ -0,0 +1,31 @@ +/** + This mixin provides a `currentUser` property that can be used to retrieve information + about the currently logged in user. It is mostly useful to controllers so it can be + exposted to templates. + + Outside of templates, code should probably use `Discourse.User.current()` instead of + this property. + + @class Discourse.HasCurrentUser + @extends Ember.Mixin + @namespace Discourse + @module HasCurrentUser +**/ +Discourse.HasCurrentUser = Em.Mixin.create({ + + /** + Returns a reference to the currently logged in user. + + @method currentUser + @return {Discourse.User} the currently logged in user if present. + */ + currentUser: function() { + return Discourse.User.current(); + }.property().volatile() + +}); + + + + + diff --git a/app/assets/javascripts/discourse/routes/user_routes.js b/app/assets/javascripts/discourse/routes/user_routes.js index d5dd07f7541..ab8d8699bf4 100644 --- a/app/assets/javascripts/discourse/routes/user_routes.js +++ b/app/assets/javascripts/discourse/routes/user_routes.js @@ -12,7 +12,7 @@ Discourse.UserRoute = Discourse.Route.extend({ // If we're viewing the currently logged in user, return that object // instead. - var currentUser = this.get('currentUser'); + var currentUser = Discourse.User.current(); if (currentUser && (params.username.toLowerCase() === currentUser.get('username_lower'))) { return currentUser; } @@ -95,7 +95,7 @@ Discourse.UserActivityRoute = Discourse.Route.extend({ var composerController = this.controllerFor('composer'); controller.set('model', user); - if (this.get('currentUser')) { + if (Discourse.User.current()) { Discourse.Draft.get('new_private_message').then(function(data) { if (data.draft) { composerController.open({ From a8bc789b81689a35c699893f2f0f091d340fdaa5 Mon Sep 17 00:00:00 2001 From: Kris Aubuchon Date: Tue, 10 Sep 2013 23:56:55 -0400 Subject: [PATCH 4/7] reducing margins on mobile --- app/assets/stylesheets/mobile/compose.css.scss | 7 +++---- app/assets/stylesheets/mobile/discourse.css.scss | 2 +- app/assets/stylesheets/mobile/header.css.scss | 6 +++--- app/assets/stylesheets/mobile/topic-post.css.scss | 12 ++++++------ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/assets/stylesheets/mobile/compose.css.scss b/app/assets/stylesheets/mobile/compose.css.scss index bf1c19abad5..f279e195b24 100644 --- a/app/assets/stylesheets/mobile/compose.css.scss +++ b/app/assets/stylesheets/mobile/compose.css.scss @@ -381,8 +381,8 @@ div.ac-wrap { } } .wmd-controls { - left: 30px; - right: 30px; + left: 10px; + right: 10px; position: absolute; top: 60px; bottom: 54px; @@ -455,8 +455,7 @@ div.ac-wrap { } .control-row.reply-area { - padding-left: 20px; - padding-right: 20px; + } @media screen and (min-width: 1550px) { diff --git a/app/assets/stylesheets/mobile/discourse.css.scss b/app/assets/stylesheets/mobile/discourse.css.scss index c1104ef41ec..ac26fbb9798 100644 --- a/app/assets/stylesheets/mobile/discourse.css.scss +++ b/app/assets/stylesheets/mobile/discourse.css.scss @@ -83,7 +83,7 @@ body { height: 100%; @include border-radius-all(5px); .contents { - padding: 10px 20px 10px 20px; + padding: 10px 10px 10px 10px; } &.white { background-color: $white; diff --git a/app/assets/stylesheets/mobile/header.css.scss b/app/assets/stylesheets/mobile/header.css.scss index ffa99685569..29a7b283be0 100644 --- a/app/assets/stylesheets/mobile/header.css.scss +++ b/app/assets/stylesheets/mobile/header.css.scss @@ -6,8 +6,8 @@ // -------------------------------------------------- .d-header { - padding-left: 20px !important; - padding-right: 40px; + padding-left: 10px !important; + padding-right: 10px !important; min-width: 100%; position: absolute; top: 0; @@ -43,7 +43,7 @@ box-shadow: 0 0 3px #aaa; .panel { float: right; position: relative; - margin-right: 30px; + margin-right: 20px; } .current-username { float: left; diff --git a/app/assets/stylesheets/mobile/topic-post.css.scss b/app/assets/stylesheets/mobile/topic-post.css.scss index 991d6708867..e528063f63f 100644 --- a/app/assets/stylesheets/mobile/topic-post.css.scss +++ b/app/assets/stylesheets/mobile/topic-post.css.scss @@ -99,7 +99,7 @@ button { } .post-actions { - margin-left: 20px; + margin-left: 10px; margin-top: 2px; } @@ -133,7 +133,7 @@ a.star { } border-radius: 5px; - margin: 15px 20px 20px 20px; + margin: 15px 10px 20px 10px; border: 1px solid #ddd; h3 { @@ -246,16 +246,16 @@ a.star { #topic-footer-buttons { border-top: 1px solid #ddd; - padding: 20px 20px 0 20px; + padding: 20px 10px 0 10px; } #suggested-topics { float: left; clear: left; margin-top: 10px; - padding: 0 20px 0 20px; + padding: 0 10px 0 10px; - th.views, td.views, td.activity, th.activity { + th.views, td.views, td.activity, th.activity, th.likes, td.likes { display: none; } @@ -289,7 +289,7 @@ span.post-count { z-index: 1000; background: #eee; margin: 0 0 0 0 !important; - padding: 15px 20px 15px 20px; + padding: 15px 10px 15px 10px; } .topic-post article.boxed img { From 85160590257f44f585d7d269d78fcdea3f3d13a8 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 11 Sep 2013 15:58:55 +1000 Subject: [PATCH 5/7] remove global check --- .../javascripts/discourse/templates/topic.js.handlebars | 4 +++- app/assets/javascripts/discourse/views/quote_button_view.js | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/topic.js.handlebars b/app/assets/javascripts/discourse/templates/topic.js.handlebars index 0554adf5507..c6c17ffde32 100644 --- a/app/assets/javascripts/discourse/templates/topic.js.handlebars +++ b/app/assets/javascripts/discourse/templates/topic.js.handlebars @@ -125,7 +125,9 @@ {{render share}} -{{render quoteButton}} +{{#if currentUser.enable_quoting}} + {{render quoteButton}} +{{/if}} {{#if currentUser.staff}} {{render topicAdminMenu content}} diff --git a/app/assets/javascripts/discourse/views/quote_button_view.js b/app/assets/javascripts/discourse/views/quote_button_view.js index 9f2b1a4b01c..e85f5ac7d10 100644 --- a/app/assets/javascripts/discourse/views/quote_button_view.js +++ b/app/assets/javascripts/discourse/views/quote_button_view.js @@ -47,8 +47,6 @@ Discourse.QuoteButtonView = Discourse.View.extend({ .on("mousedown.quote-button", function(e) { view.set('isMouseDown', true); if ($(e.target).hasClass('quote-button') || $(e.target).hasClass('create')) return; - // do *not* deselect when quoting has been disabled by the user - if (!Discourse.User.currentProp('enable_quoting')) return; // deselects only when the user left click // (allows anyone to `extend` their selection using shift+click) if (e.which === 1 && !e.shiftKey) controller.deselectText(); From efb15af2090b98cc8f3758fb037a57920d9d5ee4 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 11 Sep 2013 16:18:17 +1000 Subject: [PATCH 6/7] not needed, already in private section --- app/controllers/topics_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 125b24ece62..8dddd4b00ac 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -329,8 +329,6 @@ class TopicsController < ApplicationController end end - private - def move_posts_to_destination(topic) args = {} args[:title] = params[:title] if params[:title].present? From e26b3662eefbde50088fdbdf7b83df2d848b49b8 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 11 Sep 2013 16:18:46 +1000 Subject: [PATCH 7/7] drafts were saving but client was failing to parse --- app/controllers/draft_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/draft_controller.rb b/app/controllers/draft_controller.rb index fad27991b2b..3dd165b44b7 100644 --- a/app/controllers/draft_controller.rb +++ b/app/controllers/draft_controller.rb @@ -9,12 +9,12 @@ class DraftController < ApplicationController def update Draft.set(current_user, params[:draft_key], params[:sequence].to_i, params[:data]) - render text: 'ok' + render json: success_json end def destroy Draft.clear(current_user, params[:draft_key], params[:sequence].to_i) - render text: 'ok' + render json: success_json end end