FEATURE: new category setting for whether to show latest topics or top topics by default

This commit is contained in:
Neil Lalonde
2017-03-02 10:56:04 -05:00
parent bcf634ca85
commit 6aab8cb331
12 changed files with 74 additions and 13 deletions

View File

@@ -21,5 +21,13 @@ export default buildCategoryPanel('settings', {
{name: I18n.t('category.sort_ascending'), value: 'true'},
{name: I18n.t('category.sort_descending'), value: 'false'}
];
},
@computed
availableViews() {
return [
{name: I18n.t('filters.latest.title'), value: 'latest'},
{name: I18n.t('filters.top.title'), value: 'top'}
];
}
});

View File

@@ -104,7 +104,8 @@ const Category = RestModel.extend({
sort_ascending: this.get('sort_ascending'),
topic_featured_link_allowed: this.get('topic_featured_link_allowed'),
show_subcategory_list: this.get('show_subcategory_list'),
num_featured_topics: this.get('num_featured_topics')
num_featured_topics: this.get('num_featured_topics'),
default_view: this.get('default_view')
},
type: id ? 'PUT' : 'POST'
});

View File

@@ -13,9 +13,9 @@ export default {
app.DiscoveryCategoryNoneController = DiscoverySortableController.extend();
app.DiscoveryCategoryWithIDController = DiscoverySortableController.extend();
app.DiscoveryCategoryRoute = buildCategoryRoute('latest');
app.DiscoveryParentCategoryRoute = buildCategoryRoute('latest');
app.DiscoveryCategoryNoneRoute = buildCategoryRoute('latest', {no_subcategories: true});
app.DiscoveryCategoryRoute = buildCategoryRoute('default');
app.DiscoveryParentCategoryRoute = buildCategoryRoute('default');
app.DiscoveryCategoryNoneRoute = buildCategoryRoute('default', {no_subcategories: true});
const site = Discourse.Site.current();
site.get('filters').forEach(filter => {

View File

@@ -6,7 +6,7 @@ import CategoryList from 'discourse/models/category-list';
import Category from 'discourse/models/category';
// A helper function to create a category route with parameters
export default (filter, params) => {
export default (filterArg, params) => {
return Discourse.Route.extend({
queryParams,
@@ -37,9 +37,13 @@ export default (filter, params) => {
this._retrieveTopicList(model.category, transition)]);
},
filter(category) {
return filterArg === 'default' ? (category.get('default_view') || 'latest') : filterArg;
},
_setupNavigation(category) {
const noSubcategories = params && !!params.no_subcategories,
filterMode = `c/${Discourse.Category.slugFor(category)}${noSubcategories ? "/none" : ""}/l/${filter}`;
filterMode = `c/${Discourse.Category.slugFor(category)}${noSubcategories ? "/none" : ""}/l/${this.filter(category)}`;
this.controllerFor('navigation/category').setProperties({
category,
@@ -60,7 +64,7 @@ export default (filter, params) => {
},
_retrieveTopicList(category, transition) {
const listFilter = `c/${Discourse.Category.slugFor(category)}/l/${filter}`,
const listFilter = `c/${Discourse.Category.slugFor(category)}/l/${this.filter(category)}`,
findOpts = filterQueryParams(transition.queryParams, params),
extras = { cached: this.isPoppedState(transition) };
@@ -72,8 +76,8 @@ export default (filter, params) => {
},
titleToken() {
const filterText = I18n.t('filters.' + filter.replace('/', '.') + '.title'),
category = this.currentModel.category;
const category = this.currentModel.category,
filterText = I18n.t('filters.' + this.filter(category).replace('/', '.') + '.title');
return I18n.t('filters.with_category', { filter: filterText, category: category.get('name') });
},
@@ -82,7 +86,8 @@ export default (filter, params) => {
const topics = this.get('topics'),
category = model.category,
canCreateTopic = topics.get('can_create_topic'),
canCreateTopicOnCategory = category.get('permission') === PermissionType.FULL;
canCreateTopicOnCategory = category.get('permission') === PermissionType.FULL,
filter = this.filter(category);
this.controllerFor('navigation/category').setProperties({
canCreateTopicOnCategory: canCreateTopicOnCategory,

View File

@@ -56,6 +56,13 @@
</label>
</section>
<section class="field default-view-field">
<label>
{{i18n "category.default_view"}}
{{combo-box valueAttribute="value" content=availableViews value=category.default_view}}
</label>
</section>
{{#if emailInEnabled}}
<section class='field'>
<label>