2024-08-23 19:17:07 +08:00
|
|
|
import { action, computed } from "@ember/object";
|
2020-02-03 21:22:14 +08:00
|
|
|
import { gte, reads } from "@ember/object/computed";
|
2024-08-23 19:17:07 +08:00
|
|
|
import { classNames } from "@ember-decorators/component";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { setting } from "discourse/lib/computed";
|
2018-03-29 14:57:10 +08:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from "discourse-i18n";
|
2023-10-11 02:38:59 +08:00
|
|
|
import ComboBoxComponent from "select-kit/components/combo-box";
|
2024-08-23 19:17:07 +08:00
|
|
|
import {
|
|
|
|
pluginApiIdentifiers,
|
|
|
|
selectKitOptions,
|
|
|
|
} from "select-kit/components/select-kit";
|
2018-03-29 14:57:10 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
@classNames("group-dropdown")
|
|
|
|
@selectKitOptions({
|
|
|
|
caretDownIcon: "caret-right",
|
|
|
|
caretUpIcon: "caret-down",
|
|
|
|
filterable: "hasManyGroups",
|
|
|
|
})
|
|
|
|
@pluginApiIdentifiers("group-dropdown")
|
|
|
|
export default class GroupDropdown extends ComboBoxComponent {
|
|
|
|
@reads("groupsWithShortcut") content;
|
|
|
|
@gte("content.length", 10) hasManyGroups;
|
|
|
|
@setting("enable_group_directory") enableGroupDirectory;
|
2018-03-29 14:57:10 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
valueProperty = null;
|
|
|
|
nameProperty = null;
|
2018-03-29 14:57:10 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
@computed("groups.[]")
|
|
|
|
get groupsWithShortcut() {
|
2020-02-03 21:22:14 +08:00
|
|
|
const shortcuts = [];
|
2018-03-29 14:57:10 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
if (this.enableGroupDirectory || this.get("currentUser.staff")) {
|
2024-11-20 04:45:18 +08:00
|
|
|
shortcuts.push(i18n("groups.index.all"));
|
2018-03-29 14:57:10 +08:00
|
|
|
}
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
return shortcuts.concat(this.groups);
|
2024-08-23 19:17:07 +08:00
|
|
|
}
|
2018-03-29 14:57:10 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
@action
|
|
|
|
onChange(groupName) {
|
|
|
|
if ((this.groups || []).includes(groupName)) {
|
|
|
|
DiscourseURL.routeToUrl(`/g/${groupName}`);
|
|
|
|
} else {
|
|
|
|
DiscourseURL.routeToUrl(`/g`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|