From a9d7569ddad9adac3b1f35fe2e6870451a3e4777 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 3 Nov 2016 13:09:43 -0400 Subject: [PATCH] Replace computed properties for topic query params --- .../components/toggle-deleted.js.es6 | 12 ---- .../discourse/controllers/topic.js.es6 | 58 +++++-------------- .../discourse/controllers/user-card.js.es6 | 4 +- .../discourse/models/post-stream.js.es6 | 12 +--- .../javascripts/discourse/models/topic.js.es6 | 1 - .../javascripts/discourse/routes/topic.js.es6 | 2 - .../templates/components/toggle-deleted.hbs | 7 --- .../models/post-stream-test.js.es6 | 15 +---- 8 files changed, 21 insertions(+), 90 deletions(-) delete mode 100644 app/assets/javascripts/discourse/components/toggle-deleted.js.es6 delete mode 100644 app/assets/javascripts/discourse/templates/components/toggle-deleted.hbs diff --git a/app/assets/javascripts/discourse/components/toggle-deleted.js.es6 b/app/assets/javascripts/discourse/components/toggle-deleted.js.es6 deleted file mode 100644 index 72ad47d0045..00000000000 --- a/app/assets/javascripts/discourse/components/toggle-deleted.js.es6 +++ /dev/null @@ -1,12 +0,0 @@ -export default Ember.Component.extend({ - layoutName: 'components/toggle-deleted', - tagName: 'section', - classNames: ['information'], - postStream: Em.computed.alias('topic.postStream'), - - actions: { - toggleDeleted: function() { - this.get('postStream').toggleDeleted(); - } - } -}); diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index 787196c4a03..b64e00a3c1d 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -20,7 +20,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { editingTopic: false, selectedPosts: null, selectedReplies: null, - queryParams: ['filter', 'username_filters', 'show_deleted'], + queryParams: ['filter', 'username_filters'], loadedAllPosts: Ember.computed.or('model.postStream.loadedAllPosts', 'model.postStream.loadingLastPost'), enteredAt: null, enteredIndex: null, @@ -29,6 +29,9 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { _progressIndex: null, hasScrolled: null, + username_filters: null, + filter: null, + topicDelegated: [ 'toggleMultiSelect', 'deleteTopic', @@ -53,6 +56,11 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { 'showFlagTopic' ], + updateQueryParams() { + const postStream = this.get('model.postStream'); + this.setProperties(postStream.get('streamFilters')); + }, + _titleChanged: function() { const title = this.get('model.title'); if (!Ember.isEmpty(title)) { @@ -79,32 +87,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { return this.capabilities.isAndroid && loading; }, - @computed('model.postStream.summary') - show_deleted: { - set(value) { - const postStream = this.get('model.postStream'); - if (!postStream) { return; } - postStream.set('show_deleted', value); - return postStream.get('show_deleted') ? true : undefined; - }, - get() { - return this.get('postStream.show_deleted') ? true : undefined; - } - }, - - @computed('model.postStream.summary') - filter: { - set(value) { - const postStream = this.get('model.postStream'); - if (!postStream) { return; } - postStream.set('summary', value === "summary"); - return postStream.get('summary') ? "summary" : undefined; - }, - get() { - return this.get('postStream.summary') ? "summary" : undefined; - } - }, - @computed('model', 'topicTrackingState.messageCount') browseMoreMessage(model) { @@ -157,19 +139,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { I18n.t("suggested_topics.title"); }, - @computed('model.postStream.streamFilters.username_filters') - username_filters: { - set(value) { - const postStream = this.get('model.postStream'); - if (!postStream) { return; } - postStream.set('streamFilters.username_filters', value); - return postStream.get('streamFilters.username_filters'); - }, - get() { - return this.get('postStream.streamFilters.username_filters'); - } - }, - _clearSelected: function() { this.set('selectedPosts', []); this.set('selectedReplies', []); @@ -259,7 +228,9 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { }, toggleSummary() { - return this.get('model.postStream').toggleSummary(); + return this.get('model.postStream').toggleSummary().then(() => { + this.updateQueryParams(); + }); }, removeAllowedUser(user) { @@ -464,7 +435,10 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { }, toggleParticipant(user) { - this.get('model.postStream').toggleParticipant(Em.get(user, 'username')); + const postStream = this.get('model.postStream'); + postStream.toggleParticipant(Ember.get(user, 'username')).then(() => { + this.updateQueryParams(); + }); }, editTopic() { diff --git a/app/assets/javascripts/discourse/controllers/user-card.js.es6 b/app/assets/javascripts/discourse/controllers/user-card.js.es6 index f7d7da11ad1..985d977216c 100644 --- a/app/assets/javascripts/discourse/controllers/user-card.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user-card.js.es6 @@ -130,8 +130,8 @@ export default Ember.Controller.extend({ actions: { togglePosts(user) { - const postStream = this.get('postStream'); - postStream.toggleParticipant(user.get('username')); + const topicController = this.get('topic'); + topicController.send('toggleParticipant', user); this.close(); }, diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index 2473b6660b6..2ce7e1076de 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -80,11 +80,10 @@ export default RestModel.extend({ Returns a JS Object of current stream filter options. It should match the query params for the stream. **/ - @computed('summary', 'show_deleted', 'userFilters.[]') - streamFilters(summary, showDeleted) { + @computed('summary', 'userFilters.[]') + streamFilters(summary) { const result = {}; if (summary) { result.filter = "summary"; } - if (showDeleted) { result.show_deleted = true; } const userFilters = this.get('userFilters'); if (!Ember.isEmpty(userFilters)) { @@ -141,7 +140,6 @@ export default RestModel.extend({ cancelFilter() { this.set('summary', false); - this.set('show_deleted', false); this.get('userFilters').clear(); }, @@ -156,11 +154,6 @@ export default RestModel.extend({ }); }, - toggleDeleted() { - this.toggleProperty('show_deleted'); - return this.refresh(); - }, - jumpToSecondVisible() { const posts = this.get('posts'); if (posts.length > 1) { @@ -173,7 +166,6 @@ export default RestModel.extend({ toggleParticipant(username) { const userFilters = this.get('userFilters'); this.set('summary', false); - this.set('show_deleted', true); let jump = false; if (userFilters.contains(username)) { diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6 index e59c60029dc..139b2ddcf7a 100644 --- a/app/assets/javascripts/discourse/models/topic.js.es6 +++ b/app/assets/javascripts/discourse/models/topic.js.es6 @@ -556,7 +556,6 @@ Topic.reopenClass({ opts.userFilters.forEach(function(username) { data.username_filters.push(username); }); - data.show_deleted = true; } // Add the summary of filter if we have it diff --git a/app/assets/javascripts/discourse/routes/topic.js.es6 b/app/assets/javascripts/discourse/routes/topic.js.es6 index 0ee442dde5b..989d1004325 100644 --- a/app/assets/javascripts/discourse/routes/topic.js.es6 +++ b/app/assets/javascripts/discourse/routes/topic.js.es6 @@ -14,7 +14,6 @@ const TopicRoute = Discourse.Route.extend({ queryParams: { filter: { replace: true }, username_filters: { replace: true }, - show_deleted: { replace: true } }, titleToken() { @@ -140,7 +139,6 @@ const TopicRoute = Discourse.Route.extend({ setupParams(topic, params) { const postStream = topic.get('postStream'); postStream.set('summary', Em.get(params, 'filter') === 'summary'); - postStream.set('show_deleted', !!Em.get(params, 'show_deleted')); const usernames = Em.get(params, 'username_filters'), userFilters = postStream.get('userFilters'); diff --git a/app/assets/javascripts/discourse/templates/components/toggle-deleted.hbs b/app/assets/javascripts/discourse/templates/components/toggle-deleted.hbs deleted file mode 100644 index 5475461580c..00000000000 --- a/app/assets/javascripts/discourse/templates/components/toggle-deleted.hbs +++ /dev/null @@ -1,7 +0,0 @@ -{{#if postStream.show_deleted}} -

{{i18n 'deleted_filter.disabled_description'}}

- -{{else}} -

{{i18n 'deleted_filter.enabled_description'}}

- -{{/if}} diff --git a/test/javascripts/models/post-stream-test.js.es6 b/test/javascripts/models/post-stream-test.js.es6 index 7fa49fea3c7..5f825d9fbcc 100644 --- a/test/javascripts/models/post-stream-test.js.es6 +++ b/test/javascripts/models/post-stream-test.js.es6 @@ -190,20 +190,7 @@ test("streamFilters", function() { postStream.toggleParticipant(participant.username); deepEqual(postStream.get('streamFilters'), { username_filters: 'eviltrout', - show_deleted: true - }, "streamFilters contains the username we filtered and show_deleted"); - - postStream.toggleDeleted(); - deepEqual(postStream.get('streamFilters'), { - username_filters: 'eviltrout' - }, "streamFilters contains the username we filtered without show_deleted"); - - postStream.cancelFilter(); - postStream.toggleDeleted(); - deepEqual(postStream.get('streamFilters'), { - show_deleted: true - }, "streamFilters show_deleted only"); - + }, "streamFilters contains the username we filtered"); }); test("loading", function() {