Skip to content

Commit

Permalink
feat: view all important dates in the vault (monicahq/chandler#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Jan 8, 2023
1 parent 3ba8712 commit 5dd3416
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 1 deletion.
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()),
]);
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function rules(): array
'show_files_tab' => 'required|boolean',
'show_journal_tab' => 'required|boolean',
'show_companies_tab' => 'required|boolean',
'show_reports_tab' => 'required|boolean',
];
}

Expand Down Expand Up @@ -56,6 +57,7 @@ public function execute(array $data): Vault
$this->vault->show_files_tab = $data['show_files_tab'];
$this->vault->show_journal_tab = $data['show_journal_tab'];
$this->vault->show_companies_tab = $data['show_companies_tab'];
$this->vault->show_reports_tab = $data['show_reports_tab'];
$this->vault->save();

return $this->vault;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static function layoutData(Vault $vault = null): array
'show_files_tab' => $vault->show_files_tab,
'show_journal_tab' => $vault->show_journal_tab,
'show_companies_tab' => $vault->show_companies_tab,
'show_reports_tab' => $vault->show_reports_tab,
],
'url' => [
'dashboard' => route('vault.show', [
Expand All @@ -60,6 +61,9 @@ public static function layoutData(Vault $vault = null): array
'files' => route('vault.files.index', [
'vault' => $vault->id,
]),
'reports' => route('vault.reports.index', [
'vault' => $vault->id,
]),
'settings' => route('vault.settings.index', [
'vault' => $vault->id,
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function update(Request $request, int $vaultId)
'show_files_tab' => $request->boolean('show_files_tab'),
'show_journal_tab' => $request->boolean('show_journal_tab'),
'show_companies_tab' => $request->boolean('show_companies_tab'),
'show_reports_tab' => $request->boolean('show_reports_tab'),
];

(new UpdateVaultTabVisibility())->execute($data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public static function data(Vault $vault): array
'show_files_tab' => $vault->show_files_tab,
'show_journal_tab' => $vault->show_journal_tab,
'show_companies_tab' => $vault->show_companies_tab,
'show_reports_tab' => $vault->show_reports_tab,
],
'url' => [
'template_update' => route('vault.settings.template.update', [
Expand Down
1 change: 1 addition & 0 deletions app/Models/Vault.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Vault extends Model
'show_files_tab' => 'boolean',
'show_journal_tab' => 'boolean',
'show_companies_tab' => 'boolean',
'show_reports_tab' => 'boolean',
];

/**
Expand Down
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');
});
}
};
1 change: 1 addition & 0 deletions lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'layout_menu_groups' => 'Groups',
'layout_menu_companies' => 'Companies',
'layout_menu_tasks' => 'Tasks',
'layout_menu_reports' => 'Reports',
'layout_menu_gift_center' => 'Gifts',
'layout_menu_loans' => 'Loans & debts',
'layout_menu_files' => 'Files',
Expand Down
96 changes: 96 additions & 0 deletions resources/js/Pages/Vault/Reports/ImportantDate/Index.vue
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>
16 changes: 16 additions & 0 deletions resources/js/Pages/Vault/Settings/Partials/TabVisibility.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const form = useForm({
show_files_tab: false,
show_journal_tab: false,
show_companies_tab: false,
show_reports_tab: false,
});
onMounted(() => {
Expand All @@ -20,6 +21,7 @@ onMounted(() => {
form.show_files_tab = props.data.visibility.show_files_tab;
form.show_journal_tab = props.data.visibility.show_journal_tab;
form.show_companies_tab = props.data.visibility.show_companies_tab;
form.show_reports_tab = props.data.visibility.show_reports_tab;
});
const update = () => {
Expand Down Expand Up @@ -110,6 +112,20 @@ const update = () => {
<span class="ml-3 dark:text-gray-300"> Show Tasks tab </span>
</label>
</li>
<li
class="item-list border-b border-gray-200 p-3 hover:bg-slate-50 dark:border-gray-700 dark:bg-slate-900 hover:dark:bg-slate-800">
<label for="toggle-reports" class="relative inline-flex cursor-pointer items-center">
<input
id="toggle-reports"
v-model="form.show_reports_tab"
type="checkbox"
class="peer sr-only"
@change="update" />
<div
class="peer h-6 w-11 rounded-full bg-gray-200 after:absolute after:top-[2px] after:left-[2px] after:h-5 after:w-5 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-blue-600 peer-checked:after:translate-x-full peer-checked:after:border-white peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:border-gray-600 dark:bg-gray-800 dark:peer-focus:ring-blue-800" />
<span class="ml-3 dark:text-gray-300"> Show Reports tab </span>
</label>
</li>
<li
class="item-list border-b border-gray-200 p-3 hover:bg-slate-50 dark:border-gray-700 dark:bg-slate-900 hover:dark:bg-slate-800">
<label for="toggle-files" class="relative inline-flex cursor-pointer items-center">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Shared/ContactCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</template>

<!-- default state -->
<div class="inline-flex items-center text-sm">
<div class="inline-flex items-center">
<!-- avatar -->
<div class="img relative">
<inertia-link :href="contact.url">
Expand Down
11 changes: 11 additions & 0 deletions resources/js/Shared/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@
{{ $t('app.layout_menu_tasks') }}
</inertia-link>

<inertia-link
:href="layoutData.vault.url.reports"
v-if="layoutData.vault.visibility.show_reports_tab"
:class="{
'bg-blue-700 text-white dark:bg-blue-300 dark:text-gray-900':
$page.component.startsWith('Vault/Reports'),
}"
class="mr-2 rounded-md px-2 py-1 text-sm font-medium hover:bg-gray-700 hover:text-white dark:bg-sky-400/20 dark:text-slate-400 dark:hover:text-slate-300">
{{ $t('app.layout_menu_reports') }}
</inertia-link>

<!-- <inertia-link
href=""
class="mr-2 rounded-md px-2 py-1 text-sm font-medium hover:bg-gray-700 hover:text-white dark:bg-sky-400/20 dark:text-slate-400 hover:dark:text-slate-300">
Expand Down
7 changes: 7 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
use App\Domains\Vault\ManageJournals\Web\Controllers\PostTagController;
use App\Domains\Vault\ManageJournals\Web\Controllers\SliceOfLifeController;
use App\Domains\Vault\ManageJournals\Web\Controllers\SliceOfLifeCoverImageController;
use App\Domains\Vault\ManageReports\Web\Controllers\ReportImportantDateSummaryController;
use App\Domains\Vault\ManageTasks\Web\Controllers\VaultTaskController;
use App\Domains\Vault\ManageVault\Web\Controllers\VaultController;
use App\Domains\Vault\ManageVault\Web\Controllers\VaultFeedController;
Expand Down Expand Up @@ -173,6 +174,12 @@
// tasks
Route::get('tasks', [VaultTaskController::class, 'index'])->name('vault.tasks.index');

// reports
Route::prefix('reports')->group(function () {
Route::get('', [ReportImportantDateSummaryController::class, 'index'])->name('vault.reports.index');
Route::get('importantDates', [ReportImportantDateSummaryController::class, 'index'])->name('vault.reports.important_dates.index');
});

// vault contacts
Route::prefix('contacts')->group(function () {
Route::get('', [ContactController::class, 'index'])->name('contact.index');
Expand Down
Loading

0 comments on commit 5dd3416

Please sign in to comment.