Fix: Sort participants by created_at
This commit is contained in:
parent
784b49c3dd
commit
a456cc1889
|
@ -20,7 +20,7 @@ class UpdateParticipantSearchIndexAction
|
||||||
[
|
[
|
||||||
'filterableAttributes' => [...$form->getFields()->filterables()->getKeys(), 'parent-id'],
|
'filterableAttributes' => [...$form->getFields()->filterables()->getKeys(), 'parent-id'],
|
||||||
'searchableAttributes' => $form->getFields()->searchables()->getKeys(),
|
'searchableAttributes' => $form->getFields()->searchables()->getKeys(),
|
||||||
'sortableAttributes' => [...$form->getFields()->sortables()->getKeys(), 'id'],
|
'sortableAttributes' => [...$form->getFields()->sortables()->getKeys(), 'id', 'created_at'],
|
||||||
'displayedAttributes' => [...$form->getFields()->filterables()->getKeys(), ...$form->getFields()->searchables()->getKeys(), 'id'],
|
'displayedAttributes' => [...$form->getFields()->filterables()->getKeys(), ...$form->getFields()->searchables()->getKeys(), 'id'],
|
||||||
'pagination' => [
|
'pagination' => [
|
||||||
'maxTotalHits' => 1000000,
|
'maxTotalHits' => 1000000,
|
||||||
|
|
|
@ -112,6 +112,6 @@ class Participant extends Model implements Preventable
|
||||||
/** @return array<string, mixed> */
|
/** @return array<string, mixed> */
|
||||||
public function toSearchableArray(): array
|
public function toSearchableArray(): array
|
||||||
{
|
{
|
||||||
return [...$this->data, 'parent-id' => $this->parent_id];
|
return [...$this->data, 'parent-id' => $this->parent_id, 'created_at' => $this->created_at->timestamp];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
use App\Invoice\Models\Invoice;
|
use App\Invoice\Models\Invoice;
|
||||||
use App\Invoice\Resources\InvoiceResource;
|
use App\Invoice\Resources\InvoiceResource;
|
||||||
use App\Invoice\Scopes\InvoiceFilterScope;
|
use App\Invoice\Scopes\InvoiceFilterScope;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
use Inertia\Response;
|
use Inertia\Response;
|
||||||
|
use Laravel\Scout\Builder;
|
||||||
use Lorisleiva\Actions\ActionRequest;
|
use Lorisleiva\Actions\ActionRequest;
|
||||||
|
|
||||||
class InvoiceIndexAction
|
class InvoiceIndexAction
|
||||||
|
@ -17,9 +17,9 @@ class InvoiceIndexAction
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return LengthAwarePaginator<Invoice>
|
* @return Builder<Invoice>
|
||||||
*/
|
*/
|
||||||
public function handle(InvoiceFilterScope $filter)
|
public function handle(InvoiceFilterScope $filter): Builder
|
||||||
{
|
{
|
||||||
return $filter->getQuery()->query(fn ($q) => $q->with('positions'));
|
return $filter->getQuery()->query(fn ($q) => $q->with('positions'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,15 +122,6 @@ class Invoice extends Model
|
||||||
->where('last_remembered_at', '<=', now()->subWeeks($weeks));
|
->where('last_remembered_at', '<=', now()->subWeeks($weeks));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Builder<self> $query
|
|
||||||
* @return Builder<self>
|
|
||||||
*/
|
|
||||||
public function scopeWithFilter(Builder $query, InvoiceFilterScope $filter): Builder
|
|
||||||
{
|
|
||||||
return $filter->apply($query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMailRecipient(): stdClass
|
public function getMailRecipient(): stdClass
|
||||||
{
|
{
|
||||||
return (object) [
|
return (object) [
|
||||||
|
|
|
@ -12,7 +12,7 @@ use Spatie\LaravelData\Attributes\MapOutputName;
|
||||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends Filter<Invoice>
|
* @extends ScoutFilter<Invoice>
|
||||||
*/
|
*/
|
||||||
#[MapInputName(SnakeCaseMapper::class)]
|
#[MapInputName(SnakeCaseMapper::class)]
|
||||||
#[MapOutputName(SnakeCaseMapper::class)]
|
#[MapOutputName(SnakeCaseMapper::class)]
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Form\Actions\UpdateParticipantSearchIndexAction;
|
||||||
|
use App\Form\Models\Form;
|
||||||
|
use App\Lib\Sorting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
foreach (Form::get() as $form) {
|
||||||
|
UpdateParticipantSearchIndexAction::run($form);
|
||||||
|
foreach ($form->participants as $participant) {
|
||||||
|
$participant->searchable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
};
|
|
@ -80,20 +80,23 @@ it('testItShowsEmptyFilters', function () {
|
||||||
$this->callFilter('form.participant.index', ['data' => []], ['form' => $form])->assertJsonPath('meta.filter.data.check', ParticipantFilterScope::$nan);
|
$this->callFilter('form.participant.index', ['data' => []], ['form' => $form])->assertJsonPath('meta.filter.data.check', ParticipantFilterScope::$nan);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sorts by active colums sorting by default', function () {
|
it('sorts by active colums sorting by default', function (array $sorting, string $by, bool $direction) {
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
$form = Form::factory()->fields([
|
$form = Form::factory()->fields([
|
||||||
$this->checkboxField('check'),
|
$this->checkboxField('check'),
|
||||||
$this->checkboxField('vorname'),
|
$this->checkboxField('vorname'),
|
||||||
])->create();
|
])->create();
|
||||||
$form->update(['meta' => ['active_columns' => [], 'sorting' => ['by' => 'vorname', 'direction' => true]]]);
|
$form->update(['meta' => ['active_columns' => [], 'sorting' => $sorting]]);
|
||||||
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('meta.filter.sort.by', 'vorname')
|
->assertJsonPath('meta.filter.sort.by', $by)
|
||||||
->assertJsonPath('meta.filter.sort.direction', true);
|
->assertJsonPath('meta.filter.sort.direction', $direction);
|
||||||
});
|
})->with([
|
||||||
|
[['by' => 'vorname', 'direction' => true], 'vorname', true],
|
||||||
|
[['by' => 'created_at', 'direction' => true], 'created_at', true],
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
it('testItDisplaysHasNamiField', function () {
|
it('testItDisplaysHasNamiField', function () {
|
||||||
|
|
Loading…
Reference in New Issue