update: sort pinned topics by priority

resolves #3989
This commit is contained in:
Roardom
2024-07-19 16:52:51 +00:00
parent 8665ce0848
commit 340122755c
8 changed files with 83 additions and 43 deletions
+4 -4
View File
@@ -111,7 +111,7 @@ class TopicController extends Controller
'first_post_user_id' => $user->id,
'last_post_user_id' => $user->id,
'views' => 0,
'pinned' => false,
'priority' => 0,
'forum_id' => $forum->id,
'num_post' => 1,
]);
@@ -339,10 +339,10 @@ class TopicController extends Controller
/**
* Pin The Topic.
*/
public function pin(int $id): \Illuminate\Http\RedirectResponse
public function pin(Request $request, int $id): \Illuminate\Http\RedirectResponse
{
$topic = Topic::findOrFail($id);
$topic->pinned = true;
$topic->priority = $request->integer('priority');
$topic->save();
return to_route('topics.show', ['id' => $topic->id])
@@ -355,7 +355,7 @@ class TopicController extends Controller
public function unpin(int $id): \Illuminate\Http\RedirectResponse
{
$topic = Topic::findOrFail($id);
$topic->pinned = false;
$topic->priority = 0;
$topic->save();
return to_route('topics.show', ['id' => $topic->id])
@@ -117,7 +117,7 @@ class ForumCategoryTopicSearch extends Component
fn ($query) => $query
->whereDoesntHave('reads', fn ($query) => $query->whereBelongsTo(auth()->user()))
)
->orderByDesc('pinned')
->orderByDesc('priority')
->orderBy($this->sortField, $this->sortDirection)
->paginate(25);
}
+1 -1
View File
@@ -121,7 +121,7 @@ class ForumTopicSearch extends Component
fn ($query) => $query
->whereDoesntHave('reads', fn ($query) => $query->whereBelongsTo(auth()->user()))
)
->orderByDesc('pinned')
->orderByDesc('priority')
->orderBy($this->sortField, $this->sortDirection)
->paginate(25);
}
+3 -3
View File
@@ -26,7 +26,7 @@ use Illuminate\Database\Eloquent\Model;
* @property int $id
* @property string $name
* @property string|null $state
* @property bool $pinned
* @property int $priority
* @property bool $approved
* @property bool $denied
* @property bool $solved
@@ -54,13 +54,13 @@ class Topic extends Model
/**
* Get the attributes that should be cast.
*
* @return array{last_post_created_at: 'datetime', pinned: 'bool', approved: 'bool', denied: 'bool', solved: 'bool', invalid: 'bool', bug: 'bool', suggestion: 'bool', implemented: 'bool'}
* @return array{last_post_created_at: 'datetime', priority: 'integer', approved: 'bool', denied: 'bool', solved: 'bool', invalid: 'bool', bug: 'bool', suggestion: 'bool', implemented: 'bool'}
*/
protected function casts(): array
{
return [
'last_post_created_at' => 'datetime',
'pinned' => 'bool',
'priority' => 'integer',
'approved' => 'bool',
'denied' => 'bool',
'solved' => 'bool',
+1 -1
View File
@@ -36,7 +36,7 @@ class TopicFactory extends Factory
return [
'name' => $this->faker->name(),
'state' => $this->faker->word(),
'pinned' => $this->faker->boolean(),
'priority' => $this->faker->randomNumber(),
'approved' => $this->faker->boolean(),
'denied' => $this->faker->boolean(),
'solved' => $this->faker->boolean(),
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('topics', function (Blueprint $table): void {
$table->unsignedTinyInteger('pinned')->change();
$table->renameColumn('pinned', 'priority');
});
}
};
@@ -82,9 +82,9 @@
</article>
</header>
<figure class="topic-listing__figure">
@if ($topic->pinned || $topic->state === 'close')
@if ($topic->priority || $topic->state === 'close')
<span class="topic-listing__icon">
@if ($topic->pinned)
@if ($topic->priority)
<abbr title="{{ __('common.sticked') }}">
<i class="{{ config('other.font-awesome') }} fa-thumbtack"></i>
</abbr>
+39 -31
View File
@@ -182,37 +182,6 @@
</button>
</p>
</form>
@if (! $topic->pinned)
<form
class="form"
action="{{ route('topics.pin', ['id' => $topic->id]) }}"
method="POST"
>
@csrf
<p class="form__group form__group--horizontal">
<button
class="form__button form__button--filled form__button--centered"
>
{{ __('forum.pin') }}
</button>
</p>
</form>
@else
<form
class="form"
action="{{ route('topics.unpin', ['id' => $topic->id]) }}"
method="POST"
>
@csrf
<p class="form__group form__group--horizontal">
<button
class="form__button form__button--filled form__button--centered"
>
{{ __('forum.unpin') }}
</button>
</p>
</form>
@endif
@endif
</div>
</section>
@@ -321,5 +290,44 @@
</form>
</div>
</section>
<section class="panelV2">
<h2 class="panel__heading">Edit Topic Priority</h2>
<div class="panel__body">
<form
class="form"
action="{{ route('topics.pin', ['id' => $topic->id]) }}"
method="POST"
>
@csrf
<p class="form__group form__group--horizontal">
<input
type="text"
name="priority"
id="priority"
class="form__text"
inputmode="numeric"
pattern="[0-9]*"
value="{{ $topic->priority }}"
/>
<label class="form__label form__label--floating" for="season_number">
Priority
</label>
</p>
<p class="form__group">
<button class="form__button form__button--filled form__button--centered">
{{ __('forum.pin') }}
</button>
@if ($topic->priority)
<button
class="form__button form__button--filled form__button--centered"
formaction="{{ route('topics.unpin', ['id' => $topic->id]) }}"
>
{{ __('forum.unpin') }}
</button>
@endif
</p>
</form>
</div>
</section>
@endif
@endsection