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:
2
extensions/tags/js/bootstrap.js
vendored
2
extensions/tags/js/bootstrap.js
vendored
@@ -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});
|
||||||
});
|
});
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
@@ -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 {
|
||||||
|
@@ -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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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);
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user