diff --git a/app/assets/javascripts/discourse/components/d-navigation.js.es6 b/app/assets/javascripts/discourse/components/d-navigation.js.es6 new file mode 100644 index 00000000000..f2467ddcf6c --- /dev/null +++ b/app/assets/javascripts/discourse/components/d-navigation.js.es6 @@ -0,0 +1,22 @@ +import computed from "ember-addons/ember-computed-decorators"; + +export default Ember.Component.extend({ + tagName: '', + + @computed('category') + showCategoryNotifications(category) { + return category && this.currentUser; + }, + + @computed() + categories() { + return Discourse.Category.list(); + }, + + @computed("filterMode") + navItems(filterMode) { + // we don't want to show the period in the navigation bar since it's in a dropdown + if (filterMode.indexOf("top/") === 0) { filterMode = filterMode.replace("top/", ""); } + return Discourse.NavItem.buildList(null, { filterMode }); + } +}); diff --git a/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 b/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 index 93ae014e474..57bb78d156a 100644 --- a/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 +++ b/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 @@ -3,17 +3,4 @@ import computed from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend({ discovery: Ember.inject.controller(), discoveryTopics: Ember.inject.controller('discovery/topics'), - - @computed() - categories() { - return Discourse.Category.list(); - }, - - @computed("filterMode") - navItems(filterMode) { - // we don't want to show the period in the navigation bar since it's in a dropdown - if (filterMode.indexOf("top/") === 0) { filterMode = filterMode.replace("top/", ""); } - return Discourse.NavItem.buildList(null, { filterMode }); - } - }); diff --git a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 index 0f8fb98d398..4b29783e565 100644 --- a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 @@ -49,7 +49,6 @@ export default (filterArg, params) => { category, filterMode: filterMode, noSubcategories: params && params.no_subcategories, - canEditCategory: category.get('can_edit') }); }, diff --git a/app/assets/javascripts/discourse/routes/discovery-categories.js.es6 b/app/assets/javascripts/discourse/routes/discovery-categories.js.es6 index d254e0e6a28..0ba2194e501 100644 --- a/app/assets/javascripts/discourse/routes/discovery-categories.js.es6 +++ b/app/assets/javascripts/discourse/routes/discovery-categories.js.es6 @@ -12,10 +12,6 @@ const DiscoveryCategoriesRoute = Discourse.Route.extend(OpenComposer, { this.render("discovery/categories", { outlet: "list-container" }); }, - beforeModel() { - this.controllerFor("navigation/categories").set("filterMode", "categories"); - }, - model() { const style = !this.site.mobileView && this.siteSettings.desktop_category_page_style; const parentCategory = this.get("model.parentCategory"); @@ -81,7 +77,7 @@ const DiscoveryCategoriesRoute = Discourse.Route.extend(OpenComposer, { controller.set("model", model); this.controllerFor("navigation/categories").setProperties({ - canCreateCategory: model.get("can_create_category"), + showCategoryAdmin: model.get("can_create_category"), canCreateTopic: model.get("can_create_topic"), }); diff --git a/app/assets/javascripts/discourse/templates/components/d-navigation.hbs b/app/assets/javascripts/discourse/templates/components/d-navigation.hbs new file mode 100644 index 00000000000..8297a4f7e1d --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/d-navigation.hbs @@ -0,0 +1,26 @@ +{{bread-crumbs categories=categories category=category noSubcategories=noSubcategories}} + +{{#if showCategoryAdmin}} + {{categories-admin-dropdown + create=createCategory + reorder=reorderCategories}} +{{/if}} + +{{navigation-bar navItems=navItems filterMode=filterMode category=category}} + +{{#if showCategoryNotifications}} + {{category-notifications-button category=category}} +{{/if}} + +{{create-topic-button + canCreateTopic=canCreateTopic + action=createTopic + disabled=createTopicDisabled}} + +{{#if category.can_edit}} + {{d-button + class="btn-default edit-category" + action=editCategory + icon="wrench" + label="category.edit_long"}} +{{/if}} diff --git a/app/assets/javascripts/discourse/templates/navigation/categories.hbs b/app/assets/javascripts/discourse/templates/navigation/categories.hbs index 2a434f30f91..30495333df2 100644 --- a/app/assets/javascripts/discourse/templates/navigation/categories.hbs +++ b/app/assets/javascripts/discourse/templates/navigation/categories.hbs @@ -1,10 +1,9 @@ {{#d-section bodyClass="navigation-categories" class="navigation-container"}} - {{bread-crumbs categories=categories}} - - {{navigation-bar navItems=navItems filterMode=filterMode}} - - {{#if canCreateCategory}} - {{categories-admin-dropdown}} - {{/if}} - {{create-topic-button canCreateTopic=canCreateTopic action=(route-action "createTopic")}} + {{d-navigation + filterMode="categories" + showCategoryAdmin=showCategoryAdmin + createCategory=(route-action "createCategory") + reorderCategories=(route-action "reorderCategories") + canCreateTopic=canCreateTopic + createTopic=(route-action "createTopic")}} {{/d-section}} diff --git a/app/assets/javascripts/discourse/templates/navigation/category.hbs b/app/assets/javascripts/discourse/templates/navigation/category.hbs index 8f1ab92d9b7..d8dcac7040c 100644 --- a/app/assets/javascripts/discourse/templates/navigation/category.hbs +++ b/app/assets/javascripts/discourse/templates/navigation/category.hbs @@ -11,24 +11,14 @@
diff --git a/app/assets/javascripts/discourse/templates/navigation/default.hbs b/app/assets/javascripts/discourse/templates/navigation/default.hbs index e6b81e44b7a..b9d9854295f 100644 --- a/app/assets/javascripts/discourse/templates/navigation/default.hbs +++ b/app/assets/javascripts/discourse/templates/navigation/default.hbs @@ -1,7 +1,6 @@ {{#d-section bodyClass="navigation-topics" class="navigation-container" scrollTop="false"}} - {{bread-crumbs categories=categories}} - - {{navigation-bar navItems=navItems filterMode=filterMode}} - - {{create-topic-button canCreateTopic=canCreateTopic action=(route-action "createTopic")}} + {{d-navigation + filterMode=filterMode + canCreateTopic=canCreateTopic + createTopic=(route-action "createTopic")}} {{/d-section}} diff --git a/app/assets/javascripts/select-box-kit/components/categories-admin-dropdown.js.es6 b/app/assets/javascripts/select-box-kit/components/categories-admin-dropdown.js.es6 index f39d219db68..61ffa1c2253 100644 --- a/app/assets/javascripts/select-box-kit/components/categories-admin-dropdown.js.es6 +++ b/app/assets/javascripts/select-box-kit/components/categories-admin-dropdown.js.es6 @@ -5,7 +5,6 @@ import { on } from "ember-addons/ember-computed-decorators"; export default DropdownSelectBoxComponent.extend({ classNames: "categories-admin-dropdown", - actionNames: { create: "createCategory", reorder: "reorderCategories" }, @on("didReceiveAttrs") _setComponentOptions() { @@ -42,8 +41,7 @@ export default DropdownSelectBoxComponent.extend({ actions: { onSelect(value) { value = this.defaultOnSelect(value); - - this.sendAction(`actionNames.${value}`); + this.get(value)(); this.set("value", null); } }