From 0080a54aaf9ba58ba5b1ad069c6e67803641c147 Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Wed, 14 Jun 2023 17:29:22 +0200 Subject: [PATCH] Add mailgateway form --- .../Resources/MaildispatcherResource.php | 6 +++ app/Member/FilterScope.php | 51 +++++++++++-------- .../js/components/form/Multipleselect.vue | 2 +- .../maildispatcher/MaildispatcherForm.vue | 18 ++++++- resources/js/views/member/VIndex.vue | 10 +++- 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/app/Maildispatcher/Resources/MaildispatcherResource.php b/app/Maildispatcher/Resources/MaildispatcherResource.php index 5fc1e430..44d0ae83 100644 --- a/app/Maildispatcher/Resources/MaildispatcherResource.php +++ b/app/Maildispatcher/Resources/MaildispatcherResource.php @@ -3,9 +3,12 @@ namespace App\Maildispatcher\Resources; use App\Activity; +use App\Group; use App\Lib\HasMeta; +use App\Mailgateway\Models\Mailgateway; use App\Mailgateway\Resources\MailgatewayResource; use App\Member\FilterScope; +use App\Member\Member; use App\Subactivity; use Illuminate\Http\Resources\Json\JsonResource; @@ -45,6 +48,9 @@ class MaildispatcherResource extends JsonResource ], 'activities' => Activity::pluck('name', 'id'), 'subactivities' => Subactivity::pluck('name', 'id'), + 'members' => Member::ordered()->get()->map(fn ($member) => ['id' => $member->id, 'name' => $member->fullname]), + 'groups' => Group::pluck('name', 'id'), + 'gateways' => Mailgateway::pluck('name', 'id'), ]; } } diff --git a/app/Member/FilterScope.php b/app/Member/FilterScope.php index 19b224f6..aa279879 100644 --- a/app/Member/FilterScope.php +++ b/app/Member/FilterScope.php @@ -19,6 +19,8 @@ class FilterScope extends Filter /** * @param array $activityIds * @param array $subactivityIds + * @param array $groupIds + * @param array $additional */ public function __construct( public bool $ausstand = false, @@ -26,7 +28,8 @@ class FilterScope extends Filter public array $activityIds = [], public array $subactivityIds = [], public string $search = '', - public ?int $groupId = null, + public array $groupIds = [], + public array $additional = [], ) { } @@ -45,29 +48,35 @@ class FilterScope extends Filter */ public function apply(Builder $query): Builder { - if ($this->ausstand) { - $query->whereAusstand(); - } + $query->orWhere(function ($query) { + if ($this->ausstand) { + $query->whereAusstand(); + } - if ($this->billKind) { - $query->where('bill_kind', BillKind::fromValue($this->billKind)); - } + if ($this->billKind) { + $query->where('bill_kind', BillKind::fromValue($this->billKind)); + } - if ($this->groupId) { - $query->where('group_id', $this->groupId); - } + if (count($this->groupIds)) { + $query->whereIn('group_id', $this->groupIds); + } - if (count($this->subactivityIds) + count($this->activityIds) > 0) { - $query->whereHas('memberships', function ($q) { - $q->active(); - if (count($this->subactivityIds)) { - $q->whereIn('subactivity_id', $this->subactivityIds); - } - if (count($this->activityIds)) { - $q->whereIn('activity_id', $this->activityIds); - } - }); - } + if (count($this->subactivityIds) + count($this->activityIds) > 0) { + $query->whereHas('memberships', function ($q) { + $q->active(); + if (count($this->subactivityIds)) { + $q->whereIn('subactivity_id', $this->subactivityIds); + } + if (count($this->activityIds)) { + $q->whereIn('activity_id', $this->activityIds); + } + }); + } + })->orWhere(function ($query) { + if (count($this->additional)) { + $query->whereIn('id', $this->additional); + } + }); return $query; } diff --git a/resources/js/components/form/Multipleselect.vue b/resources/js/components/form/Multipleselect.vue index 37f6a940..09cb67f5 100644 --- a/resources/js/components/form/Multipleselect.vue +++ b/resources/js/components/form/Multipleselect.vue @@ -10,7 +10,7 @@ class="flex items-center border-gray-600 text-gray-300 leading-none border-solid bg-gray-700 w-full appearance-none outline-none rounded-lg size-sm text-xs px-1 border pr-6" v-text="`${value.length} Einträge ausgewählt`" > -
+
diff --git a/resources/js/views/maildispatcher/MaildispatcherForm.vue b/resources/js/views/maildispatcher/MaildispatcherForm.vue index 15a899d0..5916693d 100644 --- a/resources/js/views/maildispatcher/MaildispatcherForm.vue +++ b/resources/js/views/maildispatcher/MaildispatcherForm.vue @@ -5,6 +5,12 @@
+ +
+ + +
+
+ +
diff --git a/resources/js/views/member/VIndex.vue b/resources/js/views/member/VIndex.vue index 30c5b1b2..7393be98 100644 --- a/resources/js/views/member/VIndex.vue +++ b/resources/js/views/member/VIndex.vue @@ -22,7 +22,15 @@
- +