Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Oct 27, 2018
2 parents 791ae61 + fdcefca commit efa84c7
Show file tree
Hide file tree
Showing 38 changed files with 875 additions and 204 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
UNRELEASED CHANGES:

* Add ability to archive a contact
* Add right-click support on contact list
* Standardize phonenumber format while importing vCard
* Set currency and timezone for new users
* 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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ docker_push_bintray: .deploy.json

.PHONY: docker docker_build docker_tag docker_push docker_push_bintray

build: build-dev
build:
composer install --no-interaction --no-suggest --ignore-platform-reqs
php artisan lang:generate
yarn install
yarn run production

build-prod:
composer install --no-interaction --no-suggest --ignore-platform-reqs --no-dev
Expand Down
29 changes: 29 additions & 0 deletions app/Helpers/LocaleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Matriphe\ISO639\ISO639;
use Illuminate\Support\Facades\Auth;
use libphonenumber\PhoneNumberFormat;

class LocaleHelper
{
Expand Down Expand Up @@ -104,4 +105,32 @@ public static function getLocaleAlpha($locale)

return $lang;
}

/**
* Format phone number by country.
*
* @param string $tel
* @param $iso
* @param int $format
*
* @return null | string
*/
public static function formatTelephoneNumberByISO(string $tel, $iso, int $format = PhoneNumberFormat::INTERNATIONAL)
{
if (empty($iso)) {
return $tel;
}

try {
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();

$phoneInstance = $phoneUtil->parse($tel, strtoupper($iso));

$tel = $phoneUtil->format($phoneInstance, $format);
} catch (\libphonenumber\NumberParseException $e) {
// Do nothing if the number cannot be parsed successfully
}

return $tel;
}
}
18 changes: 18 additions & 0 deletions app/Helpers/VCardHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,22 @@ public static function addAddressToVCard(Contact $contact, VCard $vCard)

return $vCard;
}

/**
* Get country model object from given VCard file.
*
* @param \Sabre\VObject\Component\VCard $VCard
*
* @return null | string
*/
public static function getCountryISOFromSabreVCard(\Sabre\VObject\Component\VCard $VCard)
{
$VCardAddress = $VCard->ADR;

if (empty($VCardAddress)) {
return;
}

return CountriesHelper::find($VCardAddress->getParts()[6]);
}
}
8 changes: 4 additions & 4 deletions app/Http/Controllers/Api/ApiContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public function index(Request $request)
}

try {
$contacts = auth()->user()->account->contacts()->real()
$contacts = auth()->user()->account->contacts()
->real()
->active()
->orderBy($this->sort, $this->sortDirection)
->paginate($this->getLimitPerPage());
} catch (QueryException $e) {
return $this->respondInvalidQuery();
}

$collection = $this->applyWithParameter($contacts, $this->getWithParameter());

return $collection;
return $this->applyWithParameter($contacts, $this->getWithParameter());
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Contacts/RelationshipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function new(Request $request, Contact $contact)
// getting top 100 of existing contacts
$existingContacts = auth()->user()->account->contacts()
->real()
->active()
->select(['id', 'first_name', 'last_name'])
->sortedBy('name')
->take(100)
Expand Down
78 changes: 70 additions & 8 deletions app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,32 @@ class ContactsController extends Controller
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
return $this->contacts($request, true);
}

/**
* Display a listing of the resource.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function archived(Request $request)
{
return $this->contacts($request, false);
}

/**
* Display contacts.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
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 All @@ -37,10 +60,19 @@ public function index(Request $request)
$url = '';
$count = 1;

$contacts = $user->account->contacts()->real();
if ($active) {
$nbArchived = $contacts->count();
$contacts = $contacts->active();
$nbArchived = $nbArchived - $contacts->count();
} else {
$contacts = $contacts->notActive();
$nbArchived = $contacts->count();
}

if ($request->get('no_tag')) {
//get tag less contacts
$contacts = $user->account->contacts()->real()->sortedBy($sort);
$contacts = $contacts->tags('NONE')->get();
$contacts = $contacts->tags('NONE');
} elseif ($request->get('tag1')) {
// get contacts with selected tags

Expand All @@ -63,12 +95,20 @@ public function index(Request $request)
return redirect()->route('people.index');
}

$contacts = $user->account->contacts()->real()->sortedBy($sort);

$contacts = $contacts->tags($tags)->get();
} else {
// get all contacts
$contacts = $user->account->contacts()->real()->sortedBy($sort)->get();
$contacts = $contacts->tags($tags);
}
$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
Expand All @@ -81,9 +121,14 @@ public function index(Request $request)
});

return view('people.index')
->with('hidingDeceased', $showDeceased != 'true')
->with('deceasedCount', $deceasedCount)
->withContacts($contacts->unique('id'))
->withUnstarredContacts($unstarredContacts)
->withStarredContacts($starredContacts)
->withActive($active)
->withHasArchived($nbArchived > 0)
->withArchivedCOntacts($nbArchived)
->withTags($tags)
->withUserTags(auth()->user()->account->tags)
->withUrl($url)
Expand Down Expand Up @@ -562,4 +607,21 @@ public function favorite(Request $request, Contact $contact)
'is_starred' => $bool,
];
}

/**
* Toggle archive state of a contact.
*
* @param Request $request
* @param Contact $contact
* @return array
*/
public function archive(Request $request, Contact $contact)
{
$contact->is_active = ! $contact->is_active;
$contact->save();

return [
'is_active' => $contact->is_active,
];
}
}
15 changes: 12 additions & 3 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ public function index()
)->with('debts.contact')
->first();

if ($account->contacts()->count() === 0) {
if ($account->contacts()->real()->active()->count() === 0) {
return view('dashboard.blank');
}

// Fetch last updated contacts
$lastUpdatedContactsCollection = collect([]);
$lastUpdatedContacts = $account->contacts()->where('is_partial', false)->latest('updated_at')->limit(10)->get();
$lastUpdatedContacts = $account->contacts()
->real()
->active()
->latest('updated_at')
->limit(10)
->get();
foreach ($lastUpdatedContacts as $contact) {
if ($contact->is_dead) {
continue;
}

$data = [
'id' => $contact->hashID(),
'has_avatar' => $contact->has_avatar,
Expand All @@ -60,7 +69,7 @@ public function index()

$data = [
'lastUpdatedContacts' => $lastUpdatedContactsCollection,
'number_of_contacts' => $account->contacts()->real()->count(),
'number_of_contacts' => $account->contacts()->real()->active()->count(),
'number_of_reminders' => $account->reminders_count,
'number_of_notes' => $account->notes_count,
'number_of_activities' => $account->activities_count,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function toArray($request)
'gender' => $this->gender->name,
'is_starred' => (bool) $this->is_starred,
'is_partial' => (bool) $this->is_partial,
'is_active' => (bool) $this->is_active,
'is_dead' => (bool) $this->is_dead,
'last_called' => $this->when(! $this->is_partial, $this->getLastCalled()),
'last_activity_together' => $this->when(! $this->is_partial, $this->getLastActivityDate()),
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/Contact/ContactWithContactFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function toArray($request)
'gender' => $this->gender->name,
'is_starred' => (bool) $this->is_starred,
'is_partial' => (bool) $this->is_partial,
'is_active' => (bool) $this->is_active,
'is_dead' => (bool) $this->is_dead,
'last_called' => $this->when(! $this->is_partial, $this->getLastCalled()),
'last_activity_together' => $this->when(! $this->is_partial, $this->getLastActivityDate()),
Expand Down
Loading

0 comments on commit efa84c7

Please sign in to comment.