FEATURE: new category setting to add "Unassigned" navigation menu

When a category is used exclusively for managing topic assignments it can
be very useful to list all the unassigned topics. This introduces a new
category setting that allows admins to opt for this new navigation item.

It works both on mobile and desktop.

This uses an amended nav item API, to experience this fully you need latest
versions of Discourse.
This commit is contained in:
Sam Saffron 2019-11-01 14:15:28 +11:00
parent bc5469c6c6
commit e0de9238a1
6 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<h3>{{i18n 'discourse_assign.assign.title'}}</h3>
<section class='field'>
<div class="enable-accepted-answer">
<label class="checkbox-label">
{{input
type="checkbox"
checked=(readonly category.enable_unassigned_filter)
change=(action "onChangeSetting" value="target.checked")
}}
{{i18n 'discourse_assign.add_unassigned_filter'}}
</label>
</div>
</section>

View File

@ -0,0 +1,10 @@
export default {
actions: {
onChangeSetting(value) {
this.set(
"category.custom_fields.enable_unassigned_filter",
value ? "true" : "false"
);
}
}
};

View File

@ -55,6 +55,29 @@ function registerTopicFooterButtons(api) {
} }
function initialize(api) { function initialize(api) {
api.addNavigationBarItem({
name: "unassigned",
customFilter: category => {
return category && category.enable_unassigned_filter;
},
customHref: category => {
if (category) {
return (
Discourse.getURL(category.url) +
"/l/latest?status=open&assigned=nobody"
);
}
},
forceActive: (category, args, router) => {
return (
router.currentURL &&
router.currentURL.indexOf("assigned=nobody") > -1 &&
router.currentURL.indexOf("status=open") > -1
);
},
before: "top"
});
// You can't act on flags claimed by another user // You can't act on flags claimed by another user
api.modifyClass( api.modifyClass(
"component:flagged-post", "component:flagged-post",

View File

@ -0,0 +1,20 @@
import Category from "discourse/models/category";
export default {
name: "extend-category-for-assign",
before: "inject-discourse-objects",
initialize() {
Category.reopen({
enable_unassigned_filter: Ember.computed(
"custom_fields.enable_unassigned_filter",
{
get(fieldName) {
return Ember.get(this.custom_fields, fieldName) === "true";
}
}
)
});
}
};

View File

@ -1,9 +1,14 @@
en: en:
js: js:
filters:
unassigned:
title: "Unassigned"
help: "Topics that are not assigned"
action_codes: action_codes:
assigned: "assigned %{who} %{when}" assigned: "assigned %{who} %{when}"
unassigned: "unassigned %{who} %{when}" unassigned: "unassigned %{who} %{when}"
discourse_assign: discourse_assign:
add_unassigned_filter: "Add 'unassigned' filter to category"
cant_act: "You cannot act on flags that have been assigned to other users" cant_act: "You cannot act on flags that have been assigned to other users"
cant_act_unclaimed: "You must claim this topic before acting on flags." cant_act_unclaimed: "You must claim this topic before acting on flags."
assigned: "Assigned" assigned: "Assigned"

View File

@ -100,6 +100,7 @@ after_initialize do
end end
TopicList.preloaded_custom_fields << TopicAssigner::ASSIGNED_TO_ID TopicList.preloaded_custom_fields << TopicAssigner::ASSIGNED_TO_ID
Site.preloaded_category_custom_fields << "enable_unassigned_filter" if Site.respond_to? :preloaded_category_custom_fields
TopicList.on_preload do |topics, topic_list| TopicList.on_preload do |topics, topic_list|
if SiteSetting.assign_enabled? if SiteSetting.assign_enabled?