Replace computed properties for topic query params

This commit is contained in:
Robin Ward 2016-11-03 13:09:43 -04:00
parent beac81d0ee
commit a9d7569dda
8 changed files with 21 additions and 90 deletions

View File

@ -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();
}
}
});

View File

@ -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() {

View File

@ -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();
},

View File

@ -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)) {

View File

@ -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

View File

@ -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');

View File

@ -1,7 +0,0 @@
{{#if postStream.show_deleted}}
<p>{{i18n 'deleted_filter.disabled_description'}}</p>
<button class='btn btn-danger' {{action "toggleDeleted"}}>{{i18n 'deleted_filter.enable'}}</button>
{{else}}
<p>{{i18n 'deleted_filter.enabled_description'}}</p>
<button class='btn btn-danger' {{action "toggleDeleted"}}>{{i18n 'deleted_filter.disable'}}</button>
{{/if}}

View File

@ -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() {