FIX: Category topics weren't refreshing when changing sort order
This commit is contained in:
parent
09195768be
commit
6ad42d4cd2
|
@ -7,7 +7,7 @@ export default (filter, params) => {
|
|||
queryParams,
|
||||
|
||||
model(modelParams) {
|
||||
return Discourse.Category.findBySlug(modelParams.slug, modelParams.parentSlug);
|
||||
return { category: Discourse.Category.findBySlug(modelParams.slug, modelParams.parentSlug) };
|
||||
},
|
||||
|
||||
afterModel(model, transition) {
|
||||
|
@ -16,27 +16,27 @@ export default (filter, params) => {
|
|||
return;
|
||||
}
|
||||
|
||||
this._setupNavigation(model);
|
||||
return Em.RSVP.all([this._createSubcategoryList(model),
|
||||
this._retrieveTopicList(model, transition)]);
|
||||
this._setupNavigation(model.category);
|
||||
return Em.RSVP.all([this._createSubcategoryList(model.category),
|
||||
this._retrieveTopicList(model.category, transition)]);
|
||||
},
|
||||
|
||||
_setupNavigation(model) {
|
||||
_setupNavigation(category) {
|
||||
const noSubcategories = params && !!params.no_subcategories,
|
||||
filterMode = `c/${Discourse.Category.slugFor(model)}${noSubcategories ? "/none" : ""}/l/${filter}`;
|
||||
filterMode = `c/${Discourse.Category.slugFor(category)}${noSubcategories ? "/none" : ""}/l/${filter}`;
|
||||
|
||||
this.controllerFor('navigation/category').setProperties({
|
||||
category: model,
|
||||
category,
|
||||
filterMode: filterMode,
|
||||
noSubcategories: params && params.no_subcategories,
|
||||
canEditCategory: model.get('can_edit')
|
||||
canEditCategory: category.get('can_edit')
|
||||
});
|
||||
},
|
||||
|
||||
_createSubcategoryList(model) {
|
||||
_createSubcategoryList(category) {
|
||||
this._categoryList = null;
|
||||
if (Em.isNone(model.get('parentCategory')) && Discourse.SiteSettings.show_subcategory_list) {
|
||||
return Discourse.CategoryList.listForParent(this.store, model)
|
||||
if (Em.isNone(category.get('parentCategory')) && Discourse.SiteSettings.show_subcategory_list) {
|
||||
return Discourse.CategoryList.listForParent(this.store, category)
|
||||
.then(list => this._categoryList = list);
|
||||
}
|
||||
|
||||
|
@ -44,28 +44,30 @@ export default (filter, params) => {
|
|||
return Em.RSVP.resolve();
|
||||
},
|
||||
|
||||
_retrieveTopicList(model, transition) {
|
||||
const listFilter = `c/${Discourse.Category.slugFor(model)}/l/${filter}`,
|
||||
_retrieveTopicList(category, transition) {
|
||||
const listFilter = `c/${Discourse.Category.slugFor(category)}/l/${filter}`,
|
||||
findOpts = filterQueryParams(transition.queryParams, params),
|
||||
extras = { cached: this.isPoppedState(transition) };
|
||||
|
||||
return findTopicList(this.store, this.topicTrackingState, listFilter, findOpts, extras).then(list => {
|
||||
Discourse.TopicList.hideUniformCategory(list, model);
|
||||
Discourse.TopicList.hideUniformCategory(list, category);
|
||||
this.set('topics', list);
|
||||
return list;
|
||||
});
|
||||
},
|
||||
|
||||
titleToken() {
|
||||
const filterText = I18n.t('filters.' + filter.replace('/', '.') + '.title', { count: 0 }),
|
||||
model = this.currentModel;
|
||||
category = this.currentModel.category;
|
||||
|
||||
return I18n.t('filters.with_category', { filter: filterText, category: model.get('name') });
|
||||
return I18n.t('filters.with_category', { filter: filterText, category: category.get('name') });
|
||||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
const topics = this.get('topics'),
|
||||
category = model.category,
|
||||
canCreateTopic = topics.get('can_create_topic'),
|
||||
canCreateTopicOnCategory = model.get('permission') === Discourse.PermissionType.FULL;
|
||||
canCreateTopicOnCategory = category.get('permission') === Discourse.PermissionType.FULL;
|
||||
|
||||
this.controllerFor('navigation/category').setProperties({
|
||||
canCreateTopicOnCategory: canCreateTopicOnCategory,
|
||||
|
@ -75,7 +77,7 @@ export default (filter, params) => {
|
|||
|
||||
var topicOpts = {
|
||||
model: topics,
|
||||
category: model,
|
||||
category,
|
||||
period: topics.get('for_period') || (filter.indexOf('/') > 0 ? filter.split('/')[1] : ''),
|
||||
selected: [],
|
||||
noSubcategories: params && !!params.no_subcategories,
|
||||
|
@ -84,7 +86,7 @@ export default (filter, params) => {
|
|||
canCreateTopicOnCategory: canCreateTopicOnCategory
|
||||
};
|
||||
|
||||
const p = model.get('params');
|
||||
const p = category.get('params');
|
||||
if (p && Object.keys(p).length) {
|
||||
if (p.order !== undefined) {
|
||||
topicOpts.order = p.order;
|
||||
|
@ -95,7 +97,7 @@ export default (filter, params) => {
|
|||
}
|
||||
|
||||
this.controllerFor('discovery/topics').setProperties(topicOpts);
|
||||
this.searchService.set('searchContext', model.get('searchContext'));
|
||||
this.searchService.set('searchContext', category.get('searchContext'));
|
||||
this.set('topics', null);
|
||||
|
||||
this.openTopicDraft(topics);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
import OpenComposer from "discourse/mixins/open-composer";
|
||||
import { scrollTop } from "discourse/mixins/scroll-top";
|
||||
|
||||
const DiscoveryRoute = Discourse.Route.extend(OpenComposer, {
|
||||
export default Discourse.Route.extend(OpenComposer, {
|
||||
redirect() {
|
||||
return this.redirectIfLoginRequired();
|
||||
},
|
||||
|
@ -54,5 +54,3 @@ const DiscoveryRoute = Discourse.Route.extend(OpenComposer, {
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
export default DiscoveryRoute;
|
||||
|
|
Loading…
Reference in New Issue