A platform for community discussion. Free, open, simple.
DEV: migrate more routes away from the old `actions:` pattern (#15275)
Andrei Prigorshnev6afab87d508a
diff --git a/app/assets/javascripts/discourse/app/routes/build-category-route.js b/app/assets/javascripts/discourse/app/routes/build-category-route.jsindex d07bd3e2c2f..7a994bb83d6 100644--- a/app/assets/javascripts/discourse/app/routes/build-category-route.js+++ b/app/assets/javascripts/discourse/app/routes/build-category-route.js@@ -14,6 +14,7 @@ import DiscourseRoute from "discourse/routes/discourse";import I18n from "I18n";import PermissionType from "discourse/models/permission-type";import TopicList from "discourse/models/topic-list";+import { action } from "@ember/object";// A helper function to create a category route with parametersexport default (filterArg, params) => {@@ -208,17 +209,24 @@ export default (filterArg, params) => {this.searchService.set("searchContext", null);},- actions: {- setNotification(notification_level) {- this.currentModel.setNotification(notification_level);- },+ @action+ setNotification(notification_level) {+ this.currentModel.setNotification(notification_level);+ },++ @action+ triggerRefresh() {+ this.refresh();+ },- triggerRefresh() {- this.refresh();- },+ @action+ changeSort(sortBy) {+ changeSort.call(this, sortBy);+ },- changeSort,- resetParams,+ @action+ resetParams(skipParams = []) {+ resetParams.call(this, skipParams);},});};diff --git a/app/assets/javascripts/discourse/app/routes/build-topic-route.js b/app/assets/javascripts/discourse/app/routes/build-topic-route.jsindex 3905e922bbd..dfc7128fef1 100644--- a/app/assets/javascripts/discourse/app/routes/build-topic-route.js+++ b/app/assets/javascripts/discourse/app/routes/build-topic-route.js@@ -12,6 +12,7 @@ import { deepEqual } from "discourse-common/lib/object";import { defaultHomepage } from "discourse/lib/utilities";import { isEmpty } from "@ember/utils";import { inject as service } from "@ember/service";+import { action } from "@ember/object";// A helper to build a topic route for a filterfunction filterQueryParams(params, defaultParams) {@@ -151,9 +152,14 @@ export default function (filter, extras) {});},- actions: {- changeSort,- resetParams,+ @action+ changeSort(sortBy) {+ changeSort.call(this, sortBy);+ },++ @action+ resetParams(skipParams = []) {+ resetParams.call(this, skipParams);},},extrasdiff --git a/app/assets/javascripts/discourse/app/routes/tag-show.js b/app/assets/javascripts/discourse/app/routes/tag-show.jsindex 74570d4f156..8f4965dae2a 100644--- a/app/assets/javascripts/discourse/app/routes/tag-show.js+++ b/app/assets/javascripts/discourse/app/routes/tag-show.js@@ -16,6 +16,7 @@ import { escapeExpression } from "discourse/lib/utilities";import { makeArray } from "discourse-common/lib/helpers";import { setTopicList } from "discourse/lib/topic-list-tracker";import showModal from "discourse/lib/show-modal";+import { action } from "@ember/object";export default DiscourseRoute.extend(FilterModeMixin, {navMode: "latest",@@ -170,66 +171,72 @@ export default DiscourseRoute.extend(FilterModeMixin, {this.searchService.set("searchContext", null);},- actions: {- renameTag(tag) {- showModal("rename-tag", { model: tag });- },+ @action+ renameTag(tag) {+ showModal("rename-tag", { model: tag });+ },- createTopic() {- if (this.get("currentUser.has_topic_draft")) {- this.openTopicDraft();- } else {- const controller = this.controllerFor("tag.show");- const composerController = this.controllerFor("composer");- composerController- .open({- categoryId: controller.get("category.id"),- action: Composer.CREATE_TOPIC,- draftKey: Composer.NEW_TOPIC_KEY,- })- .then(() => {- // Pre-fill the tags input field- if (composerController.canEditTags && controller.get("model.id")) {- const composerModel = this.controllerFor("composer").get("model");- composerModel.set(- "tags",- [- controller.get("model.id"),- ...makeArray(controller.additionalTags),- ].filter(Boolean)- );- }- });- }- },-- dismissReadTopics(dismissTopics) {- const operationType = dismissTopics ? "topics" : "posts";- this.send("dismissRead", operationType);- },-- dismissRead(operationType) {- const controller = this.controllerFor("tags-show");- let options = {- tagName: controller.get("tag.id"),- };- const categoryId = controller.get("category.id");-- if (categoryId) {- options = Object.assign({}, options, {- categoryId,- includeSubcategories: !controller.noSubcategories,+ @action+ createTopic() {+ if (this.get("currentUser.has_topic_draft")) {+ this.openTopicDraft();+ } else {+ const controller = this.controllerFor("tag.show");+ const composerController = this.controllerFor("composer");+ composerController+ .open({+ categoryId: controller.get("category.id"),+ action: Composer.CREATE_TOPIC,+ draftKey: Composer.NEW_TOPIC_KEY,+ })+ .then(() => {+ // Pre-fill the tags input field+ if (composerController.canEditTags && controller.get("model.id")) {+ const composerModel = this.controllerFor("composer").get("model");+ composerModel.set(+ "tags",+ [+ controller.get("model.id"),+ ...makeArray(controller.additionalTags),+ ].filter(Boolean)+ );+ }});- }+ }+ },- controller.send("dismissRead", operationType, options);- },+ @action+ dismissReadTopics(dismissTopics) {+ const operationType = dismissTopics ? "topics" : "posts";+ this.send("dismissRead", operationType);+ },++ @action+ dismissRead(operationType) {+ const controller = this.controllerFor("tags-show");+ let options = {+ tagName: controller.get("tag.id"),+ };+ const categoryId = controller.get("category.id");++ if (categoryId) {+ options = Object.assign({}, options, {+ categoryId,+ includeSubcategories: !controller.noSubcategories,+ });+ }- resetParams,+ controller.send("dismissRead", operationType, options);+ },++ @action+ resetParams(skipParams = []) {+ resetParams.call(this, skipParams);+ },- didTransition() {- this.controllerFor("tag.show")._showFooter();- return true;- },+ @action+ didTransition() {+ this.controllerFor("tag.show")._showFooter();+ return true;},});