1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 15:37:51 +02:00

Add uncategorized filter, enable gambit to parse multiple categories

This commit is contained in:
Toby Zerner
2015-05-06 11:21:23 +09:30
parent bf87662511
commit 97dd5bb795
5 changed files with 22 additions and 9 deletions

View File

@@ -65,6 +65,8 @@ app.initializers.add('categories', function() {
items.add('separator', Separator.component(), {last: true}); items.add('separator', Separator.component(), {last: true});
items.add('uncategorized', CategoryNavItem.component({params: this.stickyParams()}), {last: true});
app.store.all('categories').forEach(category => { app.store.all('categories').forEach(category => {
items.add('category'+category.id(), CategoryNavItem.component({category, params: this.stickyParams()}), {last: true}); items.add('category'+category.id(), CategoryNavItem.component({category, params: this.stickyParams()}), {last: true});
}); });

View File

@@ -5,17 +5,17 @@ export default class CategoryNavItem extends NavItem {
view() { view() {
var category = this.props.category; var category = this.props.category;
var active = this.constructor.active(this.props); var active = this.constructor.active(this.props);
return m('li'+(active ? '.active' : ''), m('a', {href: this.props.href, config: m.route, onclick: () => {app.cache.discussionList = null; m.redraw.strategy('none')}, style: active ? 'color: '+category.color() : ''}, [ return m('li'+(active ? '.active' : ''), m('a', {href: this.props.href, config: m.route, onclick: () => {app.cache.discussionList = null; m.redraw.strategy('none')}, style: (active && category) ? 'color: '+category.color() : '', title: category ? category.description() : ''}, [
categoryIcon(category, {className: 'icon'}), categoryIcon(category, {className: 'icon'}),
category.title() this.props.label
])); ]));
} }
static props(props) { static props(props) {
var category = props.category; var category = props.category;
props.params.categories = category.slug(); props.params.categories = category ? category.slug() : 'uncategorized';
props.href = app.route('category', props.params); props.href = app.route('category', props.params);
props.label = category.title(); props.label = category ? category.title() : 'Uncategorized';
return props; return props;
} }

View File

@@ -30,6 +30,10 @@
display: inline-block; display: inline-block;
vertical-align: -3px; vertical-align: -3px;
margin-left: 1px; margin-left: 1px;
&.uncategorized {
border: 1px dotted @fl-body-muted-color;
}
} }
.categories-area .container { .categories-area .container {

View File

@@ -13,7 +13,7 @@ class AddCategoryToDiscussions extends Migration
public function up() public function up()
{ {
Schema::table('discussions', function (Blueprint $table) { Schema::table('discussions', function (Blueprint $table) {
$table->integer('category_id')->unsigned(); $table->integer('category_id')->unsigned()->nullable();
}); });
} }

View File

@@ -38,10 +38,17 @@ class CategoryGambit extends GambitAbstract
*/ */
public function conditions($matches, SearcherInterface $searcher) public function conditions($matches, SearcherInterface $searcher)
{ {
$slug = trim($matches[1], '"'); $slugs = explode(',', trim($matches[1], '"'));
$searcher->query()->where(function ($query) use ($slugs) {
foreach ($slugs as $slug) {
if ($slug === 'uncategorized') {
$query->orWhereNull('category_id');
} else {
$id = $this->categories->getIdForSlug($slug); $id = $this->categories->getIdForSlug($slug);
$query->orWhere('category_id', $id);
$searcher->query()->where('category_id', $id); }
}
});
} }
} }