diff --git a/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs b/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs index 4b78e65ac8c..48eb96f25b7 100644 --- a/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs +++ b/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs @@ -1,19 +1,34 @@ import Component from "@glimmer/component"; -import { action } from "@ember/object"; +import { tracked } from "@glimmer/tracking"; +import { action, computed } from "@ember/object"; import { inject as service } from "@ember/service"; import { Promise } from "rsvp"; +import ChangeTags from "discourse/components/bulk-actions/change-tags"; import DButton from "discourse/components/d-button"; import DModal from "discourse/components/d-modal"; +import RadioButton from "discourse/components/radio-button"; +import { topicLevels } from "discourse/lib/notification-levels"; import Topic from "discourse/models/topic"; import htmlSafe from "discourse-common/helpers/html-safe"; import i18n from "discourse-common/helpers/i18n"; -//import AppendTags from "../bulk-actions/append-tags"; -//import ChangeCategory from "../bulk-actions/change-category"; -//import ChangeTags from "../bulk-actions/change-tags"; -//import NotificationLevel from "../bulk-actions/notification-level"; +import CategoryChooser from "select-kit/components/category-chooser"; +import TagChooser from "select-kit/components/tag-chooser"; export default class BulkTopicActions extends Component { @service router; + @tracked activeComponent = null; + @tracked tags = []; + @tracked categoryId; + + notificationLevelId = null; + + constructor() { + super(...arguments); + + if (this.args.model.initialAction === "set-component") { + this.setComponent(ChangeTags); + } + } async perform(operation) { this.loading = true; @@ -25,7 +40,7 @@ export default class BulkTopicActions extends Component { try { return this._processChunks(operation); } catch { - this.dialog.alert(i18n.t("generic_error")); + this.dialog.alert(i18n("generic_error")); } finally { this.loading = false; this.processedTopicCount = 0; @@ -97,6 +112,54 @@ export default class BulkTopicActions extends Component { case "close": this.forEachPerformed({ type: "close" }, (t) => t.set("closed", true)); break; + case "archive": + this.forEachPerformed({ type: "archive" }, (t) => + t.set("archived", true) + ); + break; + case "unlist": + this.forEachPerformed({ type: "unlist" }, (t) => + t.set("unlisted", true) + ); + break; + case "relist": + this.forEachPerformed({ type: "relist" }, (t) => + t.set("unlisted", false) + ); + break; + case "append-tags": + this.performAndRefresh({ type: "append_tags", tags: this.tags }); + break; + case "replace-tags": + this.performAndRefresh({ type: "change_tags", tags: this.tags }); + break; + case "remove-tags": + this.performAndRefresh({ type: "remove_tags" }); + break; + case "delete": + this.performAndRefresh({ type: "delete" }); + break; + case "reset-bump-dates": + this.performAndRefresh({ type: "reset_bump_dates" }); + break; + case "defer": + this.performAndRefresh({ type: "destroy_post_timing" }); + break; + case "update-notifications": + this.performAndRefresh({ + type: "change_notification_level", + notification_level_id: this.notificationLevelId, + }); + break; + case "update-category": + this.forEachPerformed( + { + type: "change_category", + category_id: this.categoryId, + }, + (t) => t.set("category_id", this.categoryId) + ); + break; } } @@ -118,6 +181,38 @@ export default class BulkTopicActions extends Component { this.args.model.refreshClosure?.(); this.args.closeModal(); + this.args.model.bulkSelectHelper.toggleBulkSelect(); + } + + @computed("action") + get isTagAction() { + return ( + this.args.model.action === "append-tags" || + this.args.model.action === "replace-tags" + ); + } + + @computed("action") + get isNotificationAction() { + return this.args.model.action === "update-notifications"; + } + + @computed("action") + get isCategoryAction() { + return this.args.model.action === "update-category"; + } + + get notificationLevels() { + return topicLevels.map((level) => ({ + id: level.id.toString(), + name: i18n(`topic.notifications.${level.key}.title`), + description: i18n(`topic.notifications.${level.key}.description`), + })); + } + + @action + onCategoryChange(categoryId) { + this.categoryId = categoryId; }