-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: view all important dates in the vault (monicahq/chandler#381)
- Loading branch information
Showing
18 changed files
with
329 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
app/Domains/Vault/ManageReports/Web/Controllers/ReportImportantDateSummaryController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Domains\Vault\ManageReports\Web\Controllers; | ||
|
||
use App\Domains\Vault\ManageReports\Web\ViewHelpers\ReportImportantDateSummaryIndexViewHelper; | ||
use App\Domains\Vault\ManageVault\Web\ViewHelpers\VaultIndexViewHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Vault; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Inertia\Inertia; | ||
|
||
class ReportImportantDateSummaryController extends Controller | ||
{ | ||
public function index(Request $request, int $vaultId) | ||
{ | ||
$vault = Vault::findOrFail($vaultId); | ||
|
||
return Inertia::render('Vault/Reports/ImportantDate/Index', [ | ||
'layoutData' => VaultIndexViewHelper::layoutData($vault), | ||
'data' => ReportImportantDateSummaryIndexViewHelper::data($vault, Auth::user()), | ||
]); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...Domains/Vault/ManageReports/Web/ViewHelpers/ReportImportantDateSummaryIndexViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace App\Domains\Vault\ManageReports\Web\ViewHelpers; | ||
|
||
use App\Helpers\ContactCardHelper; | ||
use App\Helpers\DateHelper; | ||
use App\Helpers\ImportantDateHelper; | ||
use App\Models\Contact; | ||
use App\Models\ContactImportantDate; | ||
use App\Models\User; | ||
use App\Models\Vault; | ||
use Carbon\Carbon; | ||
use Illuminate\Support\Collection; | ||
|
||
class ReportImportantDateSummaryIndexViewHelper | ||
{ | ||
/** | ||
* Get all the important dates for a given contact. | ||
* This screen will list all the important dates for the next 12 months. | ||
* | ||
* @param Vault $vault | ||
* @param User $user | ||
* @return Collection | ||
*/ | ||
public static function data(Vault $vault, User $user): Collection | ||
{ | ||
$contactsInVault = $vault->contacts->pluck('id')->toArray(); | ||
$importantDates = ContactImportantDate::whereIn('contact_id', $contactsInVault) | ||
->with('contact') | ||
->orderBy('month', 'asc') | ||
->orderBy('day', 'asc') | ||
->get(); | ||
|
||
// create a loop looping over the next 12 months | ||
$currentDate = Carbon::now(); | ||
$monthsCollection = collect(); | ||
for ($month = 0; $month < 12; $month++) { | ||
$date = $currentDate->copy(); | ||
$date->addMonths($month); | ||
|
||
$importantDatesCollection = collect(); | ||
foreach ($importantDates as $importantDate) { | ||
if ($importantDate->month === $date->month) { | ||
$importantDatesCollection->push([ | ||
'id' => $importantDate->id, | ||
'label' => $importantDate->label, | ||
'happened_at' => ImportantDateHelper::formatDate($importantDate, $user), | ||
'happened_at_age' => ImportantDateHelper::getAge($importantDate), | ||
'contact' => ContactCardHelper::data($importantDate->contact), | ||
]); | ||
} | ||
} | ||
|
||
$monthsCollection->push([ | ||
'id' => $month, | ||
'month' => DateHelper::formatMonthAndYear($date), | ||
'important_dates' => $importantDatesCollection, | ||
]); | ||
} | ||
|
||
return $monthsCollection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
database/migrations/2023_01_06_201951_add_reports_tab_to_vaults.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('vaults', function (Blueprint $table) { | ||
$table->boolean('show_reports_tab')->default(true)->after('show_companies_tab'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('vaults', function (Blueprint $table) { | ||
$table->dropColumn('show_reports_tab'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<script setup> | ||
import Layout from '@/Shared/Layout.vue'; | ||
import ContactCard from '@/Shared/ContactCard.vue'; | ||
defineProps({ | ||
layoutData: Object, | ||
data: Object, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<Layout :layout-data="layoutData" :inside-vault="true"> | ||
<main class="relative sm:mt-24"> | ||
<div class="mx-auto max-w-3xl px-2 py-2 sm:py-6 sm:px-6 lg:px-8"> | ||
<!-- title --> | ||
<div class="mb-5 items-center justify-between border-b border-gray-200 pb-2 dark:border-gray-700 sm:flex"> | ||
<div class="mb-2 sm:mb-0"> | ||
<span class="relative"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke-width="1.5" | ||
stroke="currentColor" | ||
class="icon-sidebar relative inline h-4 w-4 text-gray-300 hover:text-gray-600 dark:text-gray-700 hover:dark:text-gray-400"> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
d="M12 8.25v-1.5m0 1.5c-1.355 0-2.697.056-4.024.166C6.845 8.51 6 9.473 6 10.608v2.513m6-4.87c1.355 0 2.697.055 4.024.165C17.155 8.51 18 9.473 18 10.608v2.513m-3-4.87v-1.5m-6 1.5v-1.5m12 9.75l-1.5.75a3.354 3.354 0 01-3 0 3.354 3.354 0 00-3 0 3.354 3.354 0 01-3 0 3.354 3.354 0 00-3 0 3.354 3.354 0 01-3 0L3 16.5m15-3.38a48.474 48.474 0 00-6-.37c-2.032 0-4.034.125-6 .37m12 0c.39.049.777.102 1.163.16 1.07.16 1.837 1.094 1.837 2.175v5.17c0 .62-.504 1.124-1.125 1.124H4.125A1.125 1.125 0 013 20.625v-5.17c0-1.08.768-2.014 1.837-2.174A47.78 47.78 0 016 13.12M12.265 3.11a.375.375 0 11-.53 0L12 2.845l.265.265zm-3 0a.375.375 0 11-.53 0L9 2.845l.265.265zm6 0a.375.375 0 11-.53 0L15 2.845l.265.265z" /> | ||
</svg> | ||
</span> | ||
|
||
The important dates in the next 12 months | ||
</div> | ||
</div> | ||
|
||
<!-- iteration over the month --> | ||
<div v-for="month in data" :key="month.id" class="mb-6"> | ||
<h2 class="font-bold">{{ month.month }}</h2> | ||
|
||
<!-- important dates --> | ||
<ul | ||
v-if="month.important_dates.length > 0" | ||
class="mb-2 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900"> | ||
<li | ||
v-for="date in month.important_dates" | ||
:key="date.id" | ||
class="item-list flex items-center justify-between border-b border-gray-200 p-3 hover:bg-slate-50 dark:border-gray-700 dark:bg-slate-900 hover:dark:bg-slate-800"> | ||
<div> | ||
<span class="mr-3 font-mono text-xs text-gray-600">{{ date.happened_at }}</span> | ||
<span>{{ date.label }}</span> | ||
</div> | ||
|
||
<div> | ||
<contact-card | ||
:contact="date.contact" | ||
:avatarClasses="'h-5 w-5 rounded-full mr-2'" | ||
:displayName="true" /> | ||
</div> | ||
</li> | ||
</ul> | ||
|
||
<!-- no date in month --> | ||
<div | ||
v-else | ||
class="rounded-lg border border-gray-200 bg-gray-100 p-3 text-center text-sm text-gray-500 dark:border-gray-700 dark:bg-gray-900"> | ||
No dates in this month | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
</Layout> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.icon-sidebar { | ||
color: #737e8d; | ||
top: -2px; | ||
} | ||
.item-list { | ||
&:hover:first-child { | ||
border-top-left-radius: 8px; | ||
border-top-right-radius: 8px; | ||
} | ||
&:last-child { | ||
border-bottom: 0; | ||
} | ||
&:hover:last-child { | ||
border-bottom-left-radius: 8px; | ||
border-bottom-right-radius: 8px; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.