mirror of
https://github.com/flarum/framework.git
synced 2025-04-25 22:24:04 +08:00
Add uncategorized filter, enable gambit to parse multiple categories
This commit is contained in:
parent
bf87662511
commit
97dd5bb795
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('uncategorized', CategoryNavItem.component({params: this.stickyParams()}), {last: true});
|
||||
|
||||
app.store.all('categories').forEach(category => {
|
||||
items.add('category'+category.id(), CategoryNavItem.component({category, params: this.stickyParams()}), {last: true});
|
||||
});
|
||||
|
@ -5,17 +5,17 @@ export default class CategoryNavItem extends NavItem {
|
||||
view() {
|
||||
var category = this.props.category;
|
||||
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'}),
|
||||
category.title()
|
||||
this.props.label
|
||||
]));
|
||||
}
|
||||
|
||||
static props(props) {
|
||||
var category = props.category;
|
||||
props.params.categories = category.slug();
|
||||
props.params.categories = category ? category.slug() : 'uncategorized';
|
||||
props.href = app.route('category', props.params);
|
||||
props.label = category.title();
|
||||
props.label = category ? category.title() : 'Uncategorized';
|
||||
|
||||
return props;
|
||||
}
|
||||
|
@ -30,6 +30,10 @@
|
||||
display: inline-block;
|
||||
vertical-align: -3px;
|
||||
margin-left: 1px;
|
||||
|
||||
&.uncategorized {
|
||||
border: 1px dotted @fl-body-muted-color;
|
||||
}
|
||||
}
|
||||
|
||||
.categories-area .container {
|
||||
|
@ -13,7 +13,7 @@ class AddCategoryToDiscussions extends Migration
|
||||
public function up()
|
||||
{
|
||||
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)
|
||||
{
|
||||
$slug = trim($matches[1], '"');
|
||||
$slugs = explode(',', trim($matches[1], '"'));
|
||||
|
||||
$id = $this->categories->getIdForSlug($slug);
|
||||
|
||||
$searcher->query()->where('category_id', $id);
|
||||
$searcher->query()->where(function ($query) use ($slugs) {
|
||||
foreach ($slugs as $slug) {
|
||||
if ($slug === 'uncategorized') {
|
||||
$query->orWhereNull('category_id');
|
||||
} else {
|
||||
$id = $this->categories->getIdForSlug($slug);
|
||||
$query->orWhere('category_id', $id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user