DEV: Allow topics to register default topic order criteria. (#7158)

This commit is contained in:
Dan Ungureanu 2019-03-13 17:44:08 +02:00 committed by Régis Hanol
parent c773f82ba1
commit 91bd0becaa
2 changed files with 21 additions and 5 deletions

View File

@ -2,6 +2,11 @@ import { setting } from "discourse/lib/computed";
import { buildCategoryPanel } from "discourse/components/edit-category-panel";
import computed from "ember-addons/ember-computed-decorators";
const categorySortCriteria = [];
export function addCategorySortCriteria(criteria) {
categorySortCriteria.push(criteria);
}
export default buildCategoryPanel("settings", {
emailInEnabled: setting("email_in"),
showPositionInput: setting("fixed_category_positions"),
@ -64,10 +69,9 @@ export default buildCategoryPanel("settings", {
"category",
"created"
]
.concat(categorySortCriteria)
.map(s => ({ name: I18n.t("category.sort_options." + s), value: s }))
.sort((a, b) => {
return a.name > b.name;
});
.sort((a, b) => a.name.localeCompare(b.name));
},
@computed

View File

@ -41,9 +41,10 @@ import { disableNameSuppression } from "discourse/widgets/poster-name";
import { registerCustomPostMessageCallback as registerCustomPostMessageCallback1 } from "discourse/controllers/topic";
import Sharing from "discourse/lib/sharing";
import { addComposerUploadHandler } from "discourse/components/composer-editor";
import { addCategorySortCriteria } from "discourse/components/edit-category-settings";
// If you add any methods to the API ensure you bump up this number
const PLUGIN_API_VERSION = "0.8.29";
const PLUGIN_API_VERSION = "0.8.30";
class PluginApi {
constructor(version, container) {
@ -801,7 +802,6 @@ class PluginApi {
}
/**
*
* Registers a function to handle uploads for specified file types
* The normal uploading functionality will be bypassed if function returns
* a falsy value.
@ -817,6 +817,18 @@ class PluginApi {
addComposerUploadHandler(extensions, method);
}
/**
* Registers a criteria that can be used as default topic order on category
* pages.
*
* Example:
*
* categorySortCriteria("votes");
*/
addCategorySortCriteria(criteria) {
addCategorySortCriteria(criteria);
}
/**
* Registers a renderer that overrides the display of category links.
*