From 29d4752749faf5d4f6dfcccd755042759dcda3bd Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sun, 26 Jan 2025 20:08:17 +0100 Subject: [PATCH] --wip-- [skip ci] --- app/Contribution/ContributionFactory.php | 4 +- app/View/Form/Text.php | 7 +- app/View/Ui/Button.php | 2 +- docker-compose.yml | 2 + modules/Contribution/Components/FillList.php | 89 +++++++++++++++++++ .../ContributionRequestFactory.php | 2 +- 6 files changed, 98 insertions(+), 8 deletions(-) diff --git a/app/Contribution/ContributionFactory.php b/app/Contribution/ContributionFactory.php index ceae2e63..1c2bc29c 100644 --- a/app/Contribution/ContributionFactory.php +++ b/app/Contribution/ContributionFactory.php @@ -32,8 +32,8 @@ class ContributionFactory public function compilerSelect(): Collection { return collect($this->documents)->map(fn ($document) => [ - 'title' => $document::buttonName(), - 'class' => $document, + 'name' => $document::buttonName(), + 'id' => $document, ]); } diff --git a/app/View/Form/Text.php b/app/View/Form/Text.php index 1f274277..713695b6 100644 --- a/app/View/Form/Text.php +++ b/app/View/Form/Text.php @@ -10,17 +10,16 @@ class Text extends Component use HasFormDimensions; - public string $id; - public function __construct( public string $name, public string $size = 'default', public ?string $hint = null, public bool $required = false, public string $label = '', - public string $type = 'text' + public string $type = 'text', + public string $id = '' ) { - $this->id = str()->uuid()->toString(); + $this->id = $this->id ? $this->id : $this->name; } public function render() diff --git a/app/View/Ui/Button.php b/app/View/Ui/Button.php index e1f1129e..37e41f9c 100644 --- a/app/View/Ui/Button.php +++ b/app/View/Ui/Button.php @@ -14,7 +14,7 @@ class Button extends Component public function render() { return <<<'HTML' - HTML; diff --git a/docker-compose.yml b/docker-compose.yml index aa27c717..7defed9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -104,6 +104,8 @@ services: meilisearch: image: getmeili/meilisearch:v1.6 + ports: + - "7700:7700" volumes: - ./data/meilisearch:/meili_data env_file: diff --git a/modules/Contribution/Components/FillList.php b/modules/Contribution/Components/FillList.php index 625dd14e..580ad01f 100644 --- a/modules/Contribution/Components/FillList.php +++ b/modules/Contribution/Components/FillList.php @@ -2,14 +2,103 @@ namespace Modules\Contribution\Components; +use App\Contribution\ContributionFactory; +use App\Country; +use Illuminate\Support\Collection; +use App\Member\Member; use Livewire\Component; class FillList extends Component { + public string $eventName = ''; + public Carbon $dateFrom; + public Carbon $dateUntil; + public int $country; + public $members = []; + + public Collection $countries; + public string $search = ''; + public Collection $compilers; + public Collection $memberResults; + + public function mount(): void + { + $this->compilers = app(ContributionFactory::class)->compilerSelect(); + $this->countries = Country::select('name', 'id')->get()->toBase(); + $this->clearSearch(); + } + + public function submit(string $compiler): void + { + } + + public function updatedSearch(): void + { + $this->memberResults = Member::search($this->search, fn ($engine, $query, $options) => $engine->search($query, [...$options, 'filter' => ['birthday IS NOT NULL', 'address IS NOT EMPTY']]))->get()->toBase(); + } + + public function onSubmitFirstMemberResult(): void + { + if (count ($this->memberResults) === 0) { + $this->clearSearch(); + return; + } + + $this->onSubmitMemberResult($this->memberResults[0]->id); + } + + public function onSubmitMemberResult(int $memberId): void + { + if (in_array($memberId, $this->members)) { + $this->members = array_values(array_filter($this->members, fn ($m) => $m !== $memberId)); + } else { + $this->members[] = $memberId; + } + + $this->js('document.querySelector("#search_input").focus()'); + + $this->clearSearch(); + } + + public function clearSearch(): void + { + $this->search = ''; + $this->memberResults = collect([]); + } + public function render() { return <<<'HTML' +
+ + + + + + + + + +
+ @foreach($memberResults as $member) + + @endforeach +
+
+ + + Formular erstellen +
HTML; } diff --git a/tests/RequestFactories/ContributionRequestFactory.php b/tests/RequestFactories/ContributionRequestFactory.php index ca17ec91..ef3cffbf 100644 --- a/tests/RequestFactories/ContributionRequestFactory.php +++ b/tests/RequestFactories/ContributionRequestFactory.php @@ -12,7 +12,7 @@ class ContributionRequestFactory extends RequestFactory { public function definition(): array { - $compilers = collect(app(ContributionFactory::class)->compilerSelect())->pluck('class'); + $compilers = collect(app(ContributionFactory::class)->compilerSelect())->pluck('id'); return [ 'country' => Country::factory()->create()->id,