Skip to content

Commit

Permalink
feat: hide deceased people in dashboard / people list (monicahq#1903)
Browse files Browse the repository at this point in the history
  • Loading branch information
oh authored and djaiss committed Oct 27, 2018
1 parent c0099b4 commit fdcefca
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ UNRELEASED CHANGES:
* Fix settings' sidebar links and change security icon
* Fix CSV import
* Highlight buttons when selected using keyboard
* Hide deceased people from dashboard's 'Last Consulted' section
* Filter deceased people from people list by default

RELEASED VERSIONS:

Expand Down
15 changes: 15 additions & 0 deletions app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private function contacts(Request $request, bool $active)
{
$user = $request->user();
$sort = $request->get('sort') ?? $user->contacts_sort_order;
$showDeceased = $request->get('show_dead');

if ($user->contacts_sort_order !== $sort) {
$user->updateContactViewPreference($sort);
Expand Down Expand Up @@ -98,6 +99,18 @@ private function contacts(Request $request, bool $active)
}
$contacts = $contacts->sortedBy($sort)->get();

// count the deceased
$deceasedCount = $contacts->filter(function ($item) {
return $item->is_dead === true;
})->count();

// filter out deceased if necessary
if ($showDeceased != 'true') {
$contacts = $contacts->filter(function ($item) {
return $item->is_dead === false;
});
}

// starred contacts
$starredContacts = $contacts->filter(function ($item) {
return $item->is_starred === true;
Expand All @@ -108,6 +121,8 @@ private function contacts(Request $request, bool $active)
});

return view('people.index')
->with('hidingDeceased', $showDeceased != 'true')
->with('deceasedCount', $deceasedCount)
->withContacts($contacts->unique('id'))
->withUnstarredContacts($unstarredContacts)
->withStarredContacts($starredContacts)
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function index()
->limit(10)
->get();
foreach ($lastUpdatedContacts as $contact) {
if ($contact->is_dead) {
continue;
}

$data = [
'id' => $contact->hashID(),
'has_avatar' => $contact->has_avatar,
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/langs/en.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/js/app.js": "/js/app.js?id=9fb12b7c7e3d4da358eb",
"/js/app.js": "/js/app.js?id=9b31e47402495feaff95",
"/css/app-ltr.css": "/css/app-ltr.css?id=72df74c30fc7f5c2a421",
"/css/app-rtl.css": "/css/app-rtl.css?id=382b6cc7915e4358dbce",
"/css/stripe.css": "/css/stripe.css?id=64c68c04c4e475fcc7c6",
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/people.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
'people_list_filter_tag' => 'Showing all the contacts tagged with',
'people_list_clear_filter' => 'Clear filter',
'people_list_contacts_per_tags' => '1 contact|:count contacts',
'people_list_show_dead' => 'Show deceased people (:count)',
'people_list_hide_dead' => 'Hide deceased people (:count)',
'people_search' => 'Search your contacts...',
'people_search_no_results' => 'No relevant contacts found :(',
'people_list_account_usage' => 'Your account usage: :current/:limit contacts',
Expand Down
18 changes: 14 additions & 4 deletions resources/views/people/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@
{{ trans('people.people_list_blank_cta') }}
</a>

@if ($hasArchived)
@if ($active)
<a href="{{ route('people.archived') }}">@lang('people.list_link_to_archived_contacts')</a>
<ul>
@if ($hasArchived)
@if ($active)
<li><a href="{{ route('people.archived') }}">@lang('people.list_link_to_archived_contacts')</a></li>
@endif
@endif
@endif
</ul>

{{-- Only for subscriptions --}}
@include('partials.components.people-upgrade-sidebar')
Expand All @@ -201,6 +203,14 @@
<a href="{{ route('people.index') }}?no_tag=true">{{ trans('people.people_list_untagged') }}</a>
</li>
@endif

@if ($deceasedCount > 0)
@if ($hidingDeceased)
<li class="f7 mt3"><a href="{{ route('people.index') }}?show_dead=true">{{ trans_choice('people.people_list_show_dead', $deceasedCount, ['count' => $deceasedCount]) }}</a></li>
@else
<li class="f7 mt3"><a href="{{ route('people.index') }}?show_dead=false">{{ trans_choice('people.people_list_hide_dead', $deceasedCount, ['count' => $deceasedCount]) }}</a></li>
@endif
@endif
</ul>
</div>

Expand Down

0 comments on commit fdcefca

Please sign in to comment.