From b8e58476a492f8637adcb4e522bb44427efcbe29 Mon Sep 17 00:00:00 2001 From: Mazarin Date: Tue, 20 Sep 2022 21:24:58 -0400 Subject: [PATCH] feat: list of groups in the vault (monicahq/chandler#228) --- .../Web/Controllers/GroupController.php | 7 ++ .../Web/ViewHelpers/GroupIndexViewHelper.php | 50 ++++++++++++++ .../Web/ViewHelpers/VaultShowViewHelper.php | 7 +- lang/en/app.php | 1 + lang/en/vault.php | 7 ++ resources/js/Pages/Vault/Group/Index.vue | 69 +++++++++++++++++++ resources/js/Pages/Vault/Group/Show.vue | 3 +- resources/js/Shared/Layout.vue | 7 ++ routes/web.php | 2 +- .../ViewHelpers/GroupIndexViewHelperTest.php | 61 ++++++++++++++++ 10 files changed, 209 insertions(+), 5 deletions(-) create mode 100644 domains/Contact/ManageGroups/Web/ViewHelpers/GroupIndexViewHelper.php create mode 100644 resources/js/Pages/Vault/Group/Index.vue create mode 100644 tests/Unit/Domains/Contact/ManageGroups/Web/ViewHelpers/GroupIndexViewHelperTest.php diff --git a/domains/Contact/ManageGroups/Web/Controllers/GroupController.php b/domains/Contact/ManageGroups/Web/Controllers/GroupController.php index 650f5b589da..835e6ca35d5 100644 --- a/domains/Contact/ManageGroups/Web/Controllers/GroupController.php +++ b/domains/Contact/ManageGroups/Web/Controllers/GroupController.php @@ -2,6 +2,7 @@ namespace App\Contact\ManageGroups\Web\Controllers; +use App\Contact\ManageGroups\Web\ViewHelpers\GroupIndexViewHelper; use App\Contact\ManageGroups\Web\ViewHelpers\GroupShowViewHelper; use App\Http\Controllers\Controller; use App\Models\Group; @@ -15,6 +16,12 @@ class GroupController extends Controller { public function index(Request $request, int $vaultId) { + $vault = Vault::findOrFail($vaultId); + + return Inertia::render('Vault/Group/Index', [ + 'layoutData' => VaultIndexViewHelper::layoutData($vault), + 'data' => GroupIndexViewHelper::data($vault), + ]); } public function show(Request $request, int $vaultId, int $groupId) diff --git a/domains/Contact/ManageGroups/Web/ViewHelpers/GroupIndexViewHelper.php b/domains/Contact/ManageGroups/Web/ViewHelpers/GroupIndexViewHelper.php new file mode 100644 index 00000000000..ad4197537a8 --- /dev/null +++ b/domains/Contact/ManageGroups/Web/ViewHelpers/GroupIndexViewHelper.php @@ -0,0 +1,50 @@ +groups()->with('contacts') + ->orderBy('name') + ->get() + ->map(function (Group $group) { + $contactsCollection = $group->contacts() + ->get() + ->map(fn (Contact $contact) => [ + 'id' => $contact->id, + 'name' => $contact->name, + 'age' => $contact->age, + 'avatar' => $contact->avatar, + 'url' => route('contact.show', [ + 'vault' => $contact->vault_id, + 'contact' => $contact->id, + ]), + ]); + + return [ + 'id' => $group->id, + 'name' => $group->name, + 'url' => [ + 'show' => route('group.show', [ + 'vault' => $group->vault_id, + 'group' => $group->id, + ]), + ], + 'contacts' => $contactsCollection, + ]; + }); + } +} diff --git a/domains/Vault/ManageVault/Web/ViewHelpers/VaultShowViewHelper.php b/domains/Vault/ManageVault/Web/ViewHelpers/VaultShowViewHelper.php index a9eb5212a6f..9a55edb6f41 100644 --- a/domains/Vault/ManageVault/Web/ViewHelpers/VaultShowViewHelper.php +++ b/domains/Vault/ManageVault/Web/ViewHelpers/VaultShowViewHelper.php @@ -36,9 +36,6 @@ public static function upcomingReminders(Vault $vault, User $user): array $currentDate = Carbon::now()->copy(); $currentDate->second = 0; - // this query is a bit long and tough to do, and it could surely - // be optimized if I knew how to properly join queries - // first we get all the user notification channels for the users in the vault $userNotificationChannels = $vault->users->flatMap(fn ($u) => $u->notificationChannels); @@ -79,6 +76,10 @@ public static function upcomingReminders(Vault $vault, User $user): array ]; }); + // this line removes the null values that are added when the contact + // is not in the vault (in the method above) + $remindersCollection = $remindersCollection->filter(fn ($value) => $value != null); + return [ 'reminders' => $remindersCollection, 'url' => [ diff --git a/lang/en/app.php b/lang/en/app.php index 052230a840e..86ddb9143ff 100644 --- a/lang/en/app.php +++ b/lang/en/app.php @@ -7,6 +7,7 @@ 'layout_menu_dashboard' => 'Dashboard', 'layout_menu_reports' => 'Reports', 'layout_menu_contacts' => 'Contacts', + 'layout_menu_groups' => 'Groups', 'layout_menu_tasks' => 'Tasks', 'layout_menu_gift_center' => 'Gifts', 'layout_menu_loans' => 'Loans & debts', diff --git a/lang/en/vault.php b/lang/en/vault.php index f3b534cdaab..bf468fa039e 100644 --- a/lang/en/vault.php +++ b/lang/en/vault.php @@ -34,6 +34,13 @@ 'show_contacts_labels_blank' => 'No labels yet.', 'show_contacts_cta' => 'Add a contact', + /*************************************************************** + * VAULT - GROUP LIST + **************************************************************/ + + 'show_groups_index' => 'All groups in the vault', + 'show_groups_blank' => 'Groups let you put your contacts together in a single place.', + /*************************************************************** * VAULT - ADD A CONTACT **************************************************************/ diff --git a/resources/js/Pages/Vault/Group/Index.vue b/resources/js/Pages/Vault/Group/Index.vue new file mode 100644 index 00000000000..d95823ee4b9 --- /dev/null +++ b/resources/js/Pages/Vault/Group/Index.vue @@ -0,0 +1,69 @@ + + + + + diff --git a/resources/js/Pages/Vault/Group/Show.vue b/resources/js/Pages/Vault/Group/Show.vue index 373795defb8..95f22ef2600 100644 --- a/resources/js/Pages/Vault/Group/Show.vue +++ b/resources/js/Pages/Vault/Group/Show.vue @@ -88,11 +88,12 @@ defineProps({

{{ role.label }}

-
+
+ + {{ $t('app.layout_menu_groups') }} + +