Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add notion of _me_ as a contact #2899

Merged
merged 15 commits into from
Aug 17, 2019
Prev Previous commit
Next Next commit
Update UI
  • Loading branch information
asbiin committed Aug 13, 2019
commit 4cf1b29f0ec44919b13fa55de602b54f23a89950
2 changes: 1 addition & 1 deletion app/Http/Resources/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function toArray($request)
'is_partial' => (bool) $this->is_partial,
'is_active' => (bool) $this->is_active,
'is_dead' => (bool) $this->is_dead,
'is_me' => $this->id == auth()->user()->me_contact_id,
'is_me' => $this->isMe(),
'last_called' => $this->when(! $this->is_partial, $this->getLastCalled()),
'last_activity_together' => $this->when(! $this->is_partial, $this->getLastActivityDate()),
'stay_in_touch_frequency' => $this->when(! $this->is_partial, $this->stay_in_touch_frequency),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/Contact/ContactShort.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function toArray($request)
'gender_type' => is_null($this->gender) ? null : $this->gender->type,
'is_partial' => (bool) $this->is_partial,
'is_dead' => (bool) $this->is_dead,
'is_me' => $this->id == auth()->user()->me_contact_id,
'is_me' => $this->isMe(),
'information' => [
'birthdate' => [
'is_age_based' => (is_null($this->birthdate) ? null : (bool) $this->birthdate->is_age_based),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/Contact/ContactWithContactFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function toArray($request)
'is_partial' => (bool) $this->is_partial,
'is_active' => (bool) $this->is_active,
'is_dead' => (bool) $this->is_dead,
'is_me' => $this->id == auth()->user()->me_contact_id,
'is_me' => $this->isMe(),
'last_called' => $this->when(! $this->is_partial, $this->getLastCalled()),
'last_activity_together' => $this->when(! $this->is_partial, $this->getLastActivityDate()),
'stay_in_touch_frequency' => $this->when(! $this->is_partial, $this->stay_in_touch_frequency),
Expand Down
10 changes: 10 additions & 0 deletions app/Models/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,16 @@ public function occupations()
return $this->hasMany(Occupation::class);
}

/**
* Test if this is the 'me' contact
*
* @return bool
*/
public function isMe()
{
return $this->id == auth()->user()->me_contact_id;
}

/**
* Sort the contacts according a given criteria.
* @param Builder $builder
Expand Down
6 changes: 4 additions & 2 deletions app/Models/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Settings\Term;
use App\Helpers\RequestHelper;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use App\Helpers\CountriesHelper;
use App\Models\Settings\Currency;
use Illuminate\Support\Facades\DB;
Expand All @@ -17,6 +18,7 @@
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Validation\UnauthorizedException;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
Expand Down Expand Up @@ -180,11 +182,11 @@ public function account()
/**
* Get the contact record associated with the 'me' contact.
*
* @return BelongsTo
* @return HasOne
*/
public function me()
{
return $this->belongsTo(Contact::class, 'me_contact_id');
return $this->hasOne(Contact::class, 'id', 'me_contact_id');
}

/**
Expand Down
4 changes: 4 additions & 0 deletions resources/views/people/_header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</li>

{{-- LAST ACTIVITY --}}
@if (! $contact->isMe())
<li class="mb2 mb0-ns dn di-ns tc {{ htmldir() == 'ltr' ? 'mr3-ns' : 'ml3-ns' }}">
<span class="{{ htmldir() == 'ltr' ? 'mr1' : 'ml1' }}">@include('partials.icons.header_people')</span>
@if (is_null($contact->getLastActivityDate()))
Expand All @@ -41,8 +42,10 @@
{{ trans('people.last_activity_date', ['date' => \App\Helpers\DateHelper::getShortDate($contact->getLastActivityDate())]) }}
@endif
</li>
@endif

{{-- LAST CALLED --}}
@if (! $contact->isMe())
<li class="mb2 mb0-ns dn di-ns tc {{ htmldir() == 'ltr' ? 'mr3-ns' : 'ml3-ns' }}">
<span class="{{ htmldir() == 'ltr' ? 'mr1' : 'ml1' }}">@include('partials.icons.header_call')</span>
@if (is_null($contact->getLastCalled()))
Expand All @@ -51,6 +54,7 @@
{{ trans('people.last_called', ['date' => \App\Helpers\DateHelper::getShortDate($contact->getLastCalled())]) }}
@endif
</li>
@endif

{{-- DESCRIPTION --}}
@if ($contact->description)
Expand Down
14 changes: 9 additions & 5 deletions resources/views/people/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,26 @@

<div class="flex items-center justify-center flex-column">
<div class='cf dib'>
@if (! $contact->isMe())
<span @click="updateDefaultProfileView('life-events')" :class="[global_profile_default_view == 'life-events' ? 'f6 fl bb bt br bl ph3 pv2 dib b br2 br--left bl mb4 b--gray-monica' : 'f6 fl bb bt br ph3 pv2 dib bg-gray-monica br2 br--left bl pointer mb4 b--gray-monica']">
@if (auth()->user()->profile_new_life_event_badge_seen == false)
<span class="bg-light-green f7 mr2 ph2 pv1 br2">{{ trans('app.new') }}</span>
@endif
{{ trans('people.life_event_list_tab_life_events') }} ({{ $contact->lifeEvents()->count() }})
</span>
@endif
<span @click="updateDefaultProfileView('notes')" :class="[global_profile_default_view == 'notes' ? 'f6 fl bb bt ph3 pv2 dib b br--right br mb4 b--gray-monica' : 'f6 fl bb bt ph3 pv2 dib bg-gray-monica br--right br pointer mb4 b--gray-monica']">{{ trans('people.life_event_list_tab_other') }}</span>
<span @click="updateDefaultProfileView('photos')" :class="[global_profile_default_view == 'photos' ? 'f6 fl bb bt ph3 pv2 dib b br2 br--right br mb4 b--gray-monica' : 'f6 fl bb bt ph3 pv2 dib bg-gray-monica br2 br--right br pointer mb4 b--gray-monica']">Photos</span>
</div>
</div>

@if (! $contact->isMe())
<div v-if="global_profile_default_view == 'life-events'">
<div class="row section">
@include('people.life-events.index')
</div>
</div>
@endif

<div v-if="global_profile_default_view == 'notes'">
@if ($modules->contains('key', 'notes'))
Expand All @@ -107,19 +111,19 @@
</div>
@endif

@if ($modules->contains('key', 'conversations'))
@if ($modules->contains('key', 'conversations') && ! $contact->isMe())
<div class="row section">
@include('people.conversations.index')
</div>
@endif

@if ($modules->contains('key', 'phone_calls'))
@if ($modules->contains('key', 'phone_calls') && ! $contact->isMe())
<div class="row section calls">
@include('people.calls.index')
</div>
@endif

@if ($modules->contains('key', 'activities'))
@if ($modules->contains('key', 'activities') && ! $contact->isMe())
<div class="row section activities">
@include('activities.index')
</div>
Expand All @@ -137,13 +141,13 @@
</div>
@endif

@if ($modules->contains('key', 'gifts'))
@if ($modules->contains('key', 'gifts') && ! $contact->isMe())
<div class="row section">
@include('people.gifts.index')
</div>
@endif

@if ($modules->contains('key', 'debts'))
@if ($modules->contains('key', 'debts') && ! $contact->isMe())
<div class="row section debts">
@include('people.debt.index')
</div>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/people/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@endif

{{-- Introductions --}}
@if ($modules->contains('key', 'how_you_met'))
@if ($modules->contains('key', 'how_you_met') && ! $contact->isMe())
@include('people.introductions.index')
@endif

Expand All @@ -24,6 +24,6 @@
@endif

{{-- Food preferences --}}
@if ($modules->contains('key', 'food_preferences'))
@if ($modules->contains('key', 'food_preferences') && ! $contact->isMe())
@include('people.food-preferences.index')
@endif