diff --git a/app/assets/javascripts/discourse/app/components/edit-category-tab.js b/app/assets/javascripts/discourse/app/components/edit-category-tab.js index 15875619103..eb0f52c36af 100644 --- a/app/assets/javascripts/discourse/app/components/edit-category-tab.js +++ b/app/assets/javascripts/discourse/app/components/edit-category-tab.js @@ -3,10 +3,14 @@ import discourseComputed from "discourse-common/utils/decorators"; import { scheduleOnce } from "@ember/runloop"; import Component from "@ember/component"; import { propertyEqual } from "discourse/lib/computed"; +import getURL from "discourse-common/lib/get-url"; +import { empty } from "@ember/object/computed"; +import DiscourseURL from "discourse/lib/url"; export default Component.extend({ tagName: "li", classNameBindings: ["active", "tabClassName"], + newCategory: empty("params.slug"), @discourseComputed("tab") tabClassName(tab) { @@ -25,23 +29,32 @@ export default Component.extend({ scheduleOnce("afterRender", this, this._addToCollection); }, + willDestroyElement() { + this._super(...arguments); + + this.setProperties({ + selectedTab: "general", + params: {}, + }); + }, + _addToCollection: function () { this.panels.addObject(this.tabClassName); }, - _resetModalScrollState() { - const $modalBody = $(this.element) - .parents("#discourse-modal") - .find(".modal-body"); - if ($modalBody.length === 1) { - $modalBody.scrollTop(0); - } + @discourseComputed("params.slug", "params.parentSlug") + fullSlug(slug, parentSlug) { + const slugPart = parentSlug && slug ? `${parentSlug}/${slug}` : slug; + return getURL(`/c/${slugPart}/edit/${this.tab}`); }, actions: { select: function () { this.set("selectedTab", this.tab); - this._resetModalScrollState(); + + if (!this.newCategory) { + DiscourseURL.routeTo(this.fullSlug); + } }, }, }); diff --git a/app/assets/javascripts/discourse/app/controllers/edit-category.js b/app/assets/javascripts/discourse/app/controllers/edit-category-tabs.js similarity index 99% rename from app/assets/javascripts/discourse/app/controllers/edit-category.js rename to app/assets/javascripts/discourse/app/controllers/edit-category-tabs.js index 8970521b402..598f0175c9b 100644 --- a/app/assets/javascripts/discourse/app/controllers/edit-category.js +++ b/app/assets/javascripts/discourse/app/controllers/edit-category-tabs.js @@ -15,6 +15,7 @@ export default Controller.extend({ createdCategory: false, expandedMenu: false, mobileView: readOnly("site.mobileView"), + parentParams: null, @on("init") _initPanels() { diff --git a/app/assets/javascripts/discourse/app/models/category.js b/app/assets/javascripts/discourse/app/models/category.js index 5d1c8ce2f2f..f504c9f3688 100644 --- a/app/assets/javascripts/discourse/app/models/category.js +++ b/app/assets/javascripts/discourse/app/models/category.js @@ -485,6 +485,25 @@ Category.reopenClass({ return ajax(`/c/${slugPath}/find_by_slug.json`); }, + reloadCategoryWithPermissions(params, store, site) { + if (params.slug && params.slug.match(/^\d+-category/)) { + const id = parseInt(params.slug, 10); + return this.reloadById(id).then((result) => + this._includePermissions(result.category, store, site) + ); + } + return this.reloadBySlug(params.slug, params.parentSlug).then((result) => + this._includePermissions(result.category, store, site) + ); + }, + + _includePermissions(category, store, site) { + const record = store.createRecord("category", category); + record.setupGroupsAndPermissions(); + site.updateCategory(record); + return record; + }, + search(term, opts) { var limit = 5; diff --git a/app/assets/javascripts/discourse/app/routes/app-route-map.js b/app/assets/javascripts/discourse/app/routes/app-route-map.js index 81b8dec96ba..c3c5f17193f 100644 --- a/app/assets/javascripts/discourse/app/routes/app-route-map.js +++ b/app/assets/javascripts/discourse/app/routes/app-route-map.js @@ -22,6 +22,16 @@ export default function () { this.route("topicBySlugOrId", { path: "/t/:slugOrId", resetNamespace: true }); this.route("newCategory", { path: "/new-category" }); + this.route("editCategory", { path: "/c/:slug/edit" }, function () { + this.route("tabs", { path: "/:tab" }); + }); + this.route( + "editChildCategory", + { path: "/c/:parentSlug/:slug/edit" }, + function () { + this.route("tabs", { path: "/:tab" }); + } + ); this.route("discovery", { path: "/", resetNamespace: true }, function () { // legacy route @@ -65,8 +75,6 @@ export default function () { }); this.route("categories"); - this.route("editCategory", { path: "/c/:slug/edit" }); - this.route("editChildCategory", { path: "/c/:parentSlug/:slug/edit" }); // legacy routes this.route("parentCategory", { path: "/c/:slug" }); diff --git a/app/assets/javascripts/discourse/app/routes/discovery-edit-category.js b/app/assets/javascripts/discourse/app/routes/discovery-edit-category.js deleted file mode 100644 index a30a22713ac..00000000000 --- a/app/assets/javascripts/discourse/app/routes/discovery-edit-category.js +++ /dev/null @@ -1,28 +0,0 @@ -import I18n from "I18n"; -import DiscourseRoute from "discourse/routes/discourse"; -import Category from "discourse/models/category"; - -export default DiscourseRoute.extend({ - model(params) { - return Category.reloadBySlugPath(params.slug).then((result) => { - const record = this.store.createRecord("category", result.category); - record.setupGroupsAndPermissions(); - this.site.updateCategory(record); - return record; - }); - }, - - titleToken() { - return I18n.t("category.edit_dialog_title", { - categoryName: this.currentModel.name, - }); - }, - - renderTemplate() { - this.render("edit-category", { - controller: "edit-category", - outlet: "list-container", - model: this.currentModel, - }); - }, -}); diff --git a/app/assets/javascripts/discourse/app/routes/discovery-edit-child-category.js b/app/assets/javascripts/discourse/app/routes/discovery-edit-child-category.js deleted file mode 100644 index ae147729f5f..00000000000 --- a/app/assets/javascripts/discourse/app/routes/discovery-edit-child-category.js +++ /dev/null @@ -1,30 +0,0 @@ -import I18n from "I18n"; -import DiscourseRoute from "discourse/routes/discourse"; -import Category from "discourse/models/category"; - -export default DiscourseRoute.extend({ - model(params) { - return Category.reloadBySlug(params.slug, params.parentSlug).then( - (result) => { - const record = this.store.createRecord("category", result.category); - record.setupGroupsAndPermissions(); - this.site.updateCategory(record); - return record; - } - ); - }, - - titleToken() { - return I18n.t("category.edit_dialog_title", { - categoryName: this.currentModel.name, - }); - }, - - renderTemplate() { - this.render("edit-category", { - controller: "edit-category", - outlet: "list-container", - model: this.currentModel, - }); - }, -}); diff --git a/app/assets/javascripts/discourse/app/routes/edit-category-index.js b/app/assets/javascripts/discourse/app/routes/edit-category-index.js new file mode 100644 index 00000000000..17d20e52dfd --- /dev/null +++ b/app/assets/javascripts/discourse/app/routes/edit-category-index.js @@ -0,0 +1,8 @@ +import DiscourseRoute from "discourse/routes/discourse"; + +export default DiscourseRoute.extend({ + afterModel() { + const params = this.paramsFor("editCategory"); + this.replaceWith(`/c/${params.slug}/edit/general`); + }, +}); diff --git a/app/assets/javascripts/discourse/app/routes/edit-category-tabs.js b/app/assets/javascripts/discourse/app/routes/edit-category-tabs.js new file mode 100644 index 00000000000..07f8c7243d0 --- /dev/null +++ b/app/assets/javascripts/discourse/app/routes/edit-category-tabs.js @@ -0,0 +1,18 @@ +import DiscourseRoute from "discourse/routes/discourse"; + +export default DiscourseRoute.extend({ + model() { + return this.modelFor("editCategory"); + }, + + setupController(controller, model, transition) { + this._super(...arguments); + + const parentParams = this.paramsFor("editCategory"); + + controller.setProperties({ + parentParams, + selectedTab: transition.to.params.tab, + }); + }, +}); diff --git a/app/assets/javascripts/discourse/app/routes/edit-category.js b/app/assets/javascripts/discourse/app/routes/edit-category.js new file mode 100644 index 00000000000..ae8136c4a0e --- /dev/null +++ b/app/assets/javascripts/discourse/app/routes/edit-category.js @@ -0,0 +1,19 @@ +import I18n from "I18n"; +import DiscourseRoute from "discourse/routes/discourse"; +import Category from "discourse/models/category"; + +export default DiscourseRoute.extend({ + model(params) { + return Category.reloadCategoryWithPermissions( + params, + this.store, + this.site + ); + }, + + titleToken() { + return I18n.t("category.edit_dialog_title", { + categoryName: this.currentModel.name, + }); + }, +}); diff --git a/app/assets/javascripts/discourse/app/routes/edit-child-category-index.js b/app/assets/javascripts/discourse/app/routes/edit-child-category-index.js new file mode 100644 index 00000000000..43c73864de4 --- /dev/null +++ b/app/assets/javascripts/discourse/app/routes/edit-child-category-index.js @@ -0,0 +1,8 @@ +import DiscourseRoute from "discourse/routes/discourse"; + +export default DiscourseRoute.extend({ + afterModel() { + const params = this.paramsFor("editChildCategory"); + this.replaceWith(`/c/${params.parentSlug}/${params.slug}/edit/general`); + }, +}); diff --git a/app/assets/javascripts/discourse/app/routes/edit-child-category-tabs.js b/app/assets/javascripts/discourse/app/routes/edit-child-category-tabs.js new file mode 100644 index 00000000000..402bed4910e --- /dev/null +++ b/app/assets/javascripts/discourse/app/routes/edit-child-category-tabs.js @@ -0,0 +1,19 @@ +import DiscourseRoute from "discourse/routes/discourse"; + +export default DiscourseRoute.extend({ + model() { + return this.modelFor("editChildCategory"); + }, + + renderTemplate() { + this.render("edit-category-tabs", { + controller: "edit-category-tabs", + model: this.currentModel, + }); + + this.controllerFor("editCategory.tabs").set( + "parentParams", + this.paramsFor("editChildCategory") + ); + }, +}); diff --git a/app/assets/javascripts/discourse/app/routes/edit-child-category.js b/app/assets/javascripts/discourse/app/routes/edit-child-category.js new file mode 100644 index 00000000000..ae8136c4a0e --- /dev/null +++ b/app/assets/javascripts/discourse/app/routes/edit-child-category.js @@ -0,0 +1,19 @@ +import I18n from "I18n"; +import DiscourseRoute from "discourse/routes/discourse"; +import Category from "discourse/models/category"; + +export default DiscourseRoute.extend({ + model(params) { + return Category.reloadCategoryWithPermissions( + params, + this.store, + this.site + ); + }, + + titleToken() { + return I18n.t("category.edit_dialog_title", { + categoryName: this.currentModel.name, + }); + }, +}); diff --git a/app/assets/javascripts/discourse/app/routes/new-category.js b/app/assets/javascripts/discourse/app/routes/new-category.js index e4aad400ed3..20ab5603657 100644 --- a/app/assets/javascripts/discourse/app/routes/new-category.js +++ b/app/assets/javascripts/discourse/app/routes/new-category.js @@ -24,8 +24,8 @@ export default DiscourseRoute.extend({ }, renderTemplate() { - this.render("edit-category", { - controller: "edit-category", + this.render("edit-category-tabs", { + controller: "edit-category-tabs", model: this.currentModel, }); }, diff --git a/app/assets/javascripts/discourse/app/templates/edit-category.hbs b/app/assets/javascripts/discourse/app/templates/edit-category-tabs.hbs similarity index 74% rename from app/assets/javascripts/discourse/app/templates/edit-category.hbs rename to app/assets/javascripts/discourse/app/templates/edit-category-tabs.hbs index ff0ed489e31..8615c267a1a 100644 --- a/app/assets/javascripts/discourse/app/templates/edit-category.hbs +++ b/app/assets/javascripts/discourse/app/templates/edit-category-tabs.hbs @@ -1,12 +1,12 @@