mirror of
https://github.com/flarum/framework.git
synced 2024-11-30 05:13:37 +08:00
Allow tags to be hidden from All Discussions
This commit is contained in:
parent
19ebd19000
commit
ee87ada0af
|
@ -1,5 +1,6 @@
|
|||
import Modal from 'flarum/components/Modal';
|
||||
import Button from 'flarum/components/Button';
|
||||
import Switch from 'flarum/components/Switch';
|
||||
import { slug } from 'flarum/utils/string';
|
||||
|
||||
import tagLabel from 'tags/helpers/tagLabel';
|
||||
|
@ -18,6 +19,7 @@ export default class EditTagModal extends Modal {
|
|||
this.slug = m.prop(this.tag.slug() || '');
|
||||
this.description = m.prop(this.tag.description() || '');
|
||||
this.color = m.prop(this.tag.color() || '');
|
||||
this.isHidden = m.prop(this.tag.isHidden() || '');
|
||||
}
|
||||
|
||||
className() {
|
||||
|
@ -60,11 +62,20 @@ export default class EditTagModal extends Modal {
|
|||
<input className="FormControl" placeholder="#aaaaaa" value={this.color()} oninput={m.withAttr('value', this.color)}/>
|
||||
</div>
|
||||
|
||||
<div className="Form-group">
|
||||
<div>
|
||||
<label className="checkbox">
|
||||
<input type="checkbox" value="1" checked={this.isHidden()} onchange={m.withAttr('checked', this.isHidden)}/>
|
||||
Hide from All Discussions
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="Form-group">
|
||||
{Button.component({
|
||||
type: 'submit',
|
||||
className: 'Button Button--primary EditTagModal-save',
|
||||
loading: this._loading,
|
||||
loading: this.loading,
|
||||
children: 'Save Changes'
|
||||
})}
|
||||
{this.tag.exists ? (
|
||||
|
@ -81,17 +92,18 @@ export default class EditTagModal extends Modal {
|
|||
onsubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
this._loading = true;
|
||||
this.loading = true;
|
||||
|
||||
this.tag.save({
|
||||
name: this.name(),
|
||||
slug: this.slug(),
|
||||
description: this.description(),
|
||||
color: this.color()
|
||||
color: this.color(),
|
||||
isHidden: this.isHidden()
|
||||
}).then(
|
||||
() => this.hide(),
|
||||
() => {
|
||||
this._loading = false;
|
||||
this.loading = false;
|
||||
m.redraw();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -10,12 +10,12 @@ export default class Tag extends mixin(Model, {
|
|||
color: Model.attribute('color'),
|
||||
backgroundUrl: Model.attribute('backgroundUrl'),
|
||||
backgroundMode: Model.attribute('backgroundMode'),
|
||||
iconUrl: Model.attribute('iconUrl'),
|
||||
|
||||
position: Model.attribute('position'),
|
||||
parent: Model.hasOne('parent'),
|
||||
defaultSort: Model.attribute('defaultSort'),
|
||||
isChild: Model.attribute('isChild'),
|
||||
isHidden: Model.attribute('isHidden'),
|
||||
|
||||
discussionsCount: Model.attribute('discussionsCount'),
|
||||
lastTime: Model.attribute('lastTime', Model.transformDate),
|
||||
|
|
|
@ -21,12 +21,12 @@ class CreateTagsTable extends Migration
|
|||
$table->string('color', 50)->nullable();
|
||||
$table->string('background_path', 100)->nullable();
|
||||
$table->string('background_mode', 100)->nullable();
|
||||
$table->string('icon_path', 100)->nullable();
|
||||
|
||||
$table->integer('position')->nullable();
|
||||
$table->integer('parent_id')->unsigned()->nullable();
|
||||
$table->string('default_sort', 50)->nullable();
|
||||
$table->boolean('is_restricted')->default(0);
|
||||
$table->boolean('is_hidden')->default(0);
|
||||
|
||||
$table->integer('discussions_count')->unsigned()->default(0);
|
||||
$table->integer('last_time')->unsigned()->nullable();
|
||||
|
|
|
@ -20,6 +20,7 @@ class TagSerializer extends Serializer
|
|||
'position' => $tag->position === null ? null : (int) $tag->position,
|
||||
'defaultSort' => $tag->default_sort,
|
||||
'isChild' => (bool) $tag->parent_id,
|
||||
'isHidden' => (bool) $tag->is_hidden,
|
||||
'lastTime' => $tag->last_time ? $tag->last_time->toRFC3339String() : null,
|
||||
'canStartDiscussion' => $tag->can($this->actor, 'startDiscussion')
|
||||
];
|
||||
|
|
|
@ -34,7 +34,8 @@ class CreateTagHandler
|
|||
array_get($data, 'attributes.name'),
|
||||
array_get($data, 'attributes.slug'),
|
||||
array_get($data, 'attributes.description'),
|
||||
array_get($data, 'attributes.color')
|
||||
array_get($data, 'attributes.color'),
|
||||
array_get($data, 'attributes.isHidden')
|
||||
);
|
||||
|
||||
$tag->save();
|
||||
|
|
|
@ -50,6 +50,10 @@ class EditTagHandler
|
|||
$tag->color = $attributes['color'];
|
||||
}
|
||||
|
||||
if (isset($attributes['isHidden'])) {
|
||||
$tag->is_hidden = (bool) $attributes['isHidden'];
|
||||
}
|
||||
|
||||
if (isset($attributes['isRestricted'])) {
|
||||
$tag->is_restricted = (bool) $attributes['isRestricted'];
|
||||
}
|
||||
|
|
|
@ -1,17 +1,39 @@
|
|||
<?php namespace Flarum\Tags\Listeners;
|
||||
|
||||
use Flarum\Events\RegisterDiscussionGambits;
|
||||
use Flarum\Events\DiscussionSearchWillBePerformed;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Flarum\Tags\Gambits\TagGambit;
|
||||
use Flarum\Tags\Tag;
|
||||
|
||||
class AddTagGambit
|
||||
{
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(RegisterDiscussionGambits::class, [$this, 'registerTagGambit']);
|
||||
$events->listen(DiscussionSearchWillBePerformed::class, [$this, 'hideTags']);
|
||||
}
|
||||
|
||||
public function registerTagGambit(RegisterDiscussionGambits $event)
|
||||
{
|
||||
$event->gambits->add('Flarum\Tags\Gambits\TagGambit');
|
||||
}
|
||||
|
||||
public function hideTags(DiscussionSearchWillBePerformed $event)
|
||||
{
|
||||
$query = $event->search->getQuery();
|
||||
|
||||
foreach ($event->search->getActiveGambits() as $gambit) {
|
||||
if ($gambit instanceof TagGambit) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$query->whereNotExists(function ($query) {
|
||||
return $query->select(app('flarum.db')->raw(1))
|
||||
->from('discussions_tags')
|
||||
->whereIn('tag_id', Tag::where('is_hidden', 1)->lists('id'))
|
||||
->whereRaw('discussion_id = discussions.id');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,10 @@ class Tag extends Model
|
|||
* @param string $slug
|
||||
* @param string $description
|
||||
* @param string $color
|
||||
* @param bool $isHidden
|
||||
* @return static
|
||||
*/
|
||||
public static function build($name, $slug, $description, $color)
|
||||
public static function build($name, $slug, $description, $color, $isHidden)
|
||||
{
|
||||
$tag = new static;
|
||||
|
||||
|
@ -55,6 +56,7 @@ class Tag extends Model
|
|||
$tag->slug = $slug;
|
||||
$tag->description = $description;
|
||||
$tag->color = $color;
|
||||
$tag->is_hidden = $isHidden;
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user