Replace computed properties for topic query params
This commit is contained in:
parent
beac81d0ee
commit
a9d7569dda
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -20,7 +20,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
editingTopic: false,
|
editingTopic: false,
|
||||||
selectedPosts: null,
|
selectedPosts: null,
|
||||||
selectedReplies: null,
|
selectedReplies: null,
|
||||||
queryParams: ['filter', 'username_filters', 'show_deleted'],
|
queryParams: ['filter', 'username_filters'],
|
||||||
loadedAllPosts: Ember.computed.or('model.postStream.loadedAllPosts', 'model.postStream.loadingLastPost'),
|
loadedAllPosts: Ember.computed.or('model.postStream.loadedAllPosts', 'model.postStream.loadingLastPost'),
|
||||||
enteredAt: null,
|
enteredAt: null,
|
||||||
enteredIndex: null,
|
enteredIndex: null,
|
||||||
|
@ -29,6 +29,9 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
_progressIndex: null,
|
_progressIndex: null,
|
||||||
hasScrolled: null,
|
hasScrolled: null,
|
||||||
|
|
||||||
|
username_filters: null,
|
||||||
|
filter: null,
|
||||||
|
|
||||||
topicDelegated: [
|
topicDelegated: [
|
||||||
'toggleMultiSelect',
|
'toggleMultiSelect',
|
||||||
'deleteTopic',
|
'deleteTopic',
|
||||||
|
@ -53,6 +56,11 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
'showFlagTopic'
|
'showFlagTopic'
|
||||||
],
|
],
|
||||||
|
|
||||||
|
updateQueryParams() {
|
||||||
|
const postStream = this.get('model.postStream');
|
||||||
|
this.setProperties(postStream.get('streamFilters'));
|
||||||
|
},
|
||||||
|
|
||||||
_titleChanged: function() {
|
_titleChanged: function() {
|
||||||
const title = this.get('model.title');
|
const title = this.get('model.title');
|
||||||
if (!Ember.isEmpty(title)) {
|
if (!Ember.isEmpty(title)) {
|
||||||
|
@ -79,32 +87,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
return this.capabilities.isAndroid && loading;
|
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')
|
@computed('model', 'topicTrackingState.messageCount')
|
||||||
browseMoreMessage(model) {
|
browseMoreMessage(model) {
|
||||||
|
|
||||||
|
@ -157,19 +139,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
I18n.t("suggested_topics.title");
|
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() {
|
_clearSelected: function() {
|
||||||
this.set('selectedPosts', []);
|
this.set('selectedPosts', []);
|
||||||
this.set('selectedReplies', []);
|
this.set('selectedReplies', []);
|
||||||
|
@ -259,7 +228,9 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleSummary() {
|
toggleSummary() {
|
||||||
return this.get('model.postStream').toggleSummary();
|
return this.get('model.postStream').toggleSummary().then(() => {
|
||||||
|
this.updateQueryParams();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
removeAllowedUser(user) {
|
removeAllowedUser(user) {
|
||||||
|
@ -464,7 +435,10 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleParticipant(user) {
|
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() {
|
editTopic() {
|
||||||
|
|
|
@ -130,8 +130,8 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
togglePosts(user) {
|
togglePosts(user) {
|
||||||
const postStream = this.get('postStream');
|
const topicController = this.get('topic');
|
||||||
postStream.toggleParticipant(user.get('username'));
|
topicController.send('toggleParticipant', user);
|
||||||
this.close();
|
this.close();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -80,11 +80,10 @@ export default RestModel.extend({
|
||||||
Returns a JS Object of current stream filter options. It should match the query
|
Returns a JS Object of current stream filter options. It should match the query
|
||||||
params for the stream.
|
params for the stream.
|
||||||
**/
|
**/
|
||||||
@computed('summary', 'show_deleted', 'userFilters.[]')
|
@computed('summary', 'userFilters.[]')
|
||||||
streamFilters(summary, showDeleted) {
|
streamFilters(summary) {
|
||||||
const result = {};
|
const result = {};
|
||||||
if (summary) { result.filter = "summary"; }
|
if (summary) { result.filter = "summary"; }
|
||||||
if (showDeleted) { result.show_deleted = true; }
|
|
||||||
|
|
||||||
const userFilters = this.get('userFilters');
|
const userFilters = this.get('userFilters');
|
||||||
if (!Ember.isEmpty(userFilters)) {
|
if (!Ember.isEmpty(userFilters)) {
|
||||||
|
@ -141,7 +140,6 @@ export default RestModel.extend({
|
||||||
|
|
||||||
cancelFilter() {
|
cancelFilter() {
|
||||||
this.set('summary', false);
|
this.set('summary', false);
|
||||||
this.set('show_deleted', false);
|
|
||||||
this.get('userFilters').clear();
|
this.get('userFilters').clear();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -156,11 +154,6 @@ export default RestModel.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleDeleted() {
|
|
||||||
this.toggleProperty('show_deleted');
|
|
||||||
return this.refresh();
|
|
||||||
},
|
|
||||||
|
|
||||||
jumpToSecondVisible() {
|
jumpToSecondVisible() {
|
||||||
const posts = this.get('posts');
|
const posts = this.get('posts');
|
||||||
if (posts.length > 1) {
|
if (posts.length > 1) {
|
||||||
|
@ -173,7 +166,6 @@ export default RestModel.extend({
|
||||||
toggleParticipant(username) {
|
toggleParticipant(username) {
|
||||||
const userFilters = this.get('userFilters');
|
const userFilters = this.get('userFilters');
|
||||||
this.set('summary', false);
|
this.set('summary', false);
|
||||||
this.set('show_deleted', true);
|
|
||||||
|
|
||||||
let jump = false;
|
let jump = false;
|
||||||
if (userFilters.contains(username)) {
|
if (userFilters.contains(username)) {
|
||||||
|
|
|
@ -556,7 +556,6 @@ Topic.reopenClass({
|
||||||
opts.userFilters.forEach(function(username) {
|
opts.userFilters.forEach(function(username) {
|
||||||
data.username_filters.push(username);
|
data.username_filters.push(username);
|
||||||
});
|
});
|
||||||
data.show_deleted = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the summary of filter if we have it
|
// Add the summary of filter if we have it
|
||||||
|
|
|
@ -14,7 +14,6 @@ const TopicRoute = Discourse.Route.extend({
|
||||||
queryParams: {
|
queryParams: {
|
||||||
filter: { replace: true },
|
filter: { replace: true },
|
||||||
username_filters: { replace: true },
|
username_filters: { replace: true },
|
||||||
show_deleted: { replace: true }
|
|
||||||
},
|
},
|
||||||
|
|
||||||
titleToken() {
|
titleToken() {
|
||||||
|
@ -140,7 +139,6 @@ const TopicRoute = Discourse.Route.extend({
|
||||||
setupParams(topic, params) {
|
setupParams(topic, params) {
|
||||||
const postStream = topic.get('postStream');
|
const postStream = topic.get('postStream');
|
||||||
postStream.set('summary', Em.get(params, 'filter') === 'summary');
|
postStream.set('summary', Em.get(params, 'filter') === 'summary');
|
||||||
postStream.set('show_deleted', !!Em.get(params, 'show_deleted'));
|
|
||||||
|
|
||||||
const usernames = Em.get(params, 'username_filters'),
|
const usernames = Em.get(params, 'username_filters'),
|
||||||
userFilters = postStream.get('userFilters');
|
userFilters = postStream.get('userFilters');
|
||||||
|
|
|
@ -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}}
|
|
|
@ -190,20 +190,7 @@ test("streamFilters", function() {
|
||||||
postStream.toggleParticipant(participant.username);
|
postStream.toggleParticipant(participant.username);
|
||||||
deepEqual(postStream.get('streamFilters'), {
|
deepEqual(postStream.get('streamFilters'), {
|
||||||
username_filters: 'eviltrout',
|
username_filters: 'eviltrout',
|
||||||
show_deleted: true
|
}, "streamFilters contains the username we filtered");
|
||||||
}, "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");
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("loading", function() {
|
test("loading", function() {
|
||||||
|
|
Loading…
Reference in New Issue