REFACTOR: Extract navigation into a component

This commit is contained in:
Robin Ward 2017-10-31 14:47:57 -04:00
parent d753adab84
commit 422f990615
9 changed files with 68 additions and 52 deletions

View File

@ -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 });
}
});

View File

@ -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 });
}
});

View File

@ -49,7 +49,6 @@ export default (filterArg, params) => {
category,
filterMode: filterMode,
noSubcategories: params && params.no_subcategories,
canEditCategory: category.get('can_edit')
});
},

View File

@ -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"),
});

View File

@ -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}}

View File

@ -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}}

View File

@ -11,24 +11,14 @@
</section>
<div class='category-navigation'>
{{bread-crumbs categories=categories
category=category
noSubcategories=noSubcategories}}
{{navigation-bar navItems=navItems filterMode=filterMode category=category}}
{{#if currentUser}}
{{category-notifications-button category=category}}
{{/if}}
{{create-topic-button
{{d-navigation
category=category
filterMode=filterMode
noSubcategories=noSubcategories
canCreateTopic=canCreateTopic
disabled=cannotCreateTopicOnCategory
action=(route-action "createTopic")}}
{{#if canEditCategory}}
{{d-button class="btn-default edit-category" action="editCategory" actionParam=category icon="wrench" label="category.edit_long"}}
{{/if}}
createTopic=(route-action "createTopic")
createTopicDisabled=cannotCreateTopicOnCategory
editCategory=(route-action "editCategory" category)}}
{{plugin-outlet name="category-navigation" args=(hash category=category)}}
</div>

View File

@ -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}}

View File

@ -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);
}
}