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..95cbf488 100644 --- a/modules/Contribution/Components/FillList.php +++ b/modules/Contribution/Components/FillList.php @@ -2,14 +2,107 @@ 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(); + } + + /** @todo implement compilation of document */ + public function submit(): 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; }