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

Merge Remote #6

Merged
merged 16 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo: required
language: php

php:
Expand All @@ -6,6 +7,9 @@ php:
services:
- mysql

jdk:
- oraclejdk8

before_script:
- cp .env.travis .env
- mysql -e 'create database monica;'
Expand All @@ -15,4 +19,11 @@ before_script:
script:
- php artisan migrate --env=testing --no-interaction -vvv
- php artisan db:seed --env=testing --no-interaction -vvv
- vendor/bin/phpunit
- vendor/bin/phpunit --log-junit junit.xml --coverage-clover clover.xml
- ./travis-sonar.sh

cache:
directories:
- $HOME/.sonar/cache
- $HOME/sonarscanner
- $HOME/sonarlauncher
Binary file added .travis.yml.sig
Binary file not shown.
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
UNRELEASED CHANGES:

*
* Add ability to edit a reminder
* Display missing page when loading a contact that does not exist
* Add ability to filter contacts by more than one tag
* Change the structure of the dashboard

RELEASED VERSIONS:

Expand Down
16 changes: 16 additions & 0 deletions app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,20 @@ public function populateContactFieldTypeTable($ignoreMigratedTable = false)
}
}
}

/**
* Get the reminders for the month given in parameter.
* - 0 means current month
* - 1 means month+1
* - 2 means month+2...
* @param int $month
*/
public function getRemindersForMonth(int $month)
{
$startOfMonth = \Carbon\Carbon::now()->addMonthsNoOverflow($month)->startOfMonth();
$endInThreeMonths = \Carbon\Carbon::now()->addMonthsNoOverflow($month)->endOfMonth();
$reminders = auth()->user()->account->reminders()->whereBetween('next_expected_date', [$startOfMonth, $endInThreeMonths])->orderBy('next_expected_date', 'asc')->get();

return $reminders;
}
}
42 changes: 42 additions & 0 deletions app/Console/Commands/GetVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class GetVersion extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'monica:getversion';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Get current version of monica';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->line(config('monica.app_version'));
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Kernel extends ConsoleKernel
'App\Console\Commands\ImportVCards',
'App\Console\Commands\PingVersionServer',
'App\Console\Commands\SetupTest',
'App\Console\Commands\GetVersion',
];

/**
Expand Down
40 changes: 40 additions & 0 deletions app/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,27 @@ public function getCompleteName($nameOrder = 'firstname_first')
return trim($completeName);
}

/**
* Get the incomplete name of the contact, like `John D.`.
*
* @return string
*/
public function getIncompleteName()
{
$incompleteName = '';
$incompleteName = $this->first_name;

if (! is_null($this->last_name)) {
$incompleteName = $incompleteName.' '.substr($this->last_name, 0, 1);
}

if ($this->is_dead) {
$incompleteName .= ' ⚰';
}

return trim($incompleteName);
}

/**
* Get the initials of the contact, used for avatars.
*
Expand Down Expand Up @@ -1343,4 +1364,23 @@ public function removeSpecialDate($occasion)
$this->save();
}
}

/**
* Gets the contact related to this contact if the current contact is partial.
*/
public function getRelatedRealContact()
{
// Look in the Relationships table
$relatedContact = \App\Relationship::where('with_contact_id', $this->id)->first();

if ($relatedContact) {
return \App\Contact::find($relatedContact->contact_id);
}

// Look in the Offspring table
$relatedContact = \App\Offspring::where('contact_id', $this->id)->first();
if ($relatedContact) {
return self::find($relatedContact->is_the_child_of);
}
}
}
13 changes: 13 additions & 0 deletions app/Helpers/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,17 @@ public static function addTimeAccordingToFrequencyType(Carbon $date, $frequency,

return $date;
}

/**
* Get the name of the month and year of the month given in parameter.
* @param int $month
* @return string
*/
public static function getMonthAndYear(int $month)
{
$month = Carbon::now()->addMonthsNoOverflow($month)->format('M');
$year = Carbon::now()->addMonthsNoOverflow($month)->format('Y');

return $month.' '.$year;
}
}
52 changes: 43 additions & 9 deletions app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,56 @@ public function index(Request $request)
$user->updateContactViewPreference($sort);
}

$tag = null;
$tags = null;
$url = '';
$tagCount = 1;

if ($request->get('tags')) {
$tag = Tag::where('name_slug', $request->get('tags'))
if ($request->get('tag1')) {
$tags = Tag::where('name_slug', $request->get('tag1'))
->where('account_id', auth()->user()->account_id)
->first();
->get();

$count = 2;

while (true) {
if ($request->get('tag'.$count)) {
$tags = $tags->concat(
Tag::where('name_slug', $request->get('tag'.$count))
->where('account_id', auth()->user()->account_id)
->get()
);
} else {
break;
}

if (is_null($tag)) {
$count++;
}
if (is_null($tags)) {
return redirect()->route('people.index');
}

$contacts = $user->account->contacts()->real()->whereHas('tags', function ($query) use ($tag) {
$query->where('id', $tag->id);
})->sortedBy($sort)->get();
$contacts = $user->account->contacts()->real()->sortedBy($sort);

foreach ($tags as $tag) {
$contacts = $contacts->whereHas('tags', function ($query) use ($tag) {
$query->where('id', $tag->id);
});

$url = $url.'tag'.$tagCount.'='.$tag->name_slug.'&';

$tagCount++;
}

$contacts = $contacts->get();
} else {
$contacts = $user->account->contacts()->real()->sortedBy($sort)->get();
}

return view('people.index')
->withContacts($contacts)
->withTag($tag);
->withTags($tags)
->withUrl($url)
->withTagCount($tagCount);
}

/**
Expand All @@ -62,6 +91,11 @@ public function create()
return view('people.create');
}

public function missing()
{
return view('people.missing');
}

/**
* Store a newly created resource in storage.
*
Expand Down
95 changes: 76 additions & 19 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use App\Debt;
use App\Event;
use App\Contact;
use Carbon\Carbon;
use App\Helpers\DateHelper;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
Expand All @@ -24,7 +24,20 @@ public function index()
)->with('debts.contact')
->first();

// Fetch last updated contacts
$lastUpdatedContactsCollection = collect([]);
$lastUpdatedContacts = $account->contacts()->where('is_partial', false)->latest('updated_at')->limit(10)->get();
foreach ($lastUpdatedContacts as $contact) {
$data = [
'id' => $contact->id,
'has_avatar' => $contact->has_avatar,
'avatar_url' => $contact->getAvatarURL(110),
'initials' => $contact->getInitials(),
'default_avatar_color' => $contact->default_avatar_color,
'complete_name' => $contact->getCompleteName(auth()->user()->name_order),
];
$lastUpdatedContactsCollection->push(json_encode($data));
}

// Latest statistics
if ($account->contacts()->count() === 0) {
Expand Down Expand Up @@ -61,24 +74,9 @@ public function index()
];
});

// List of notes
$notes = $account->notes()->favorited()->get();

// List of upcoming reminders
$upcomingReminders = $account->reminders()
->where('next_expected_date', '>', Carbon::now())
->orderBy('next_expected_date', 'asc')
->with('contact')
->limit(10)
->get();

// Active tasks
$tasks = $account->tasks()->with('contact')->where('completed', 0)->get();

$data = [
'events' => $events,
'lastUpdatedContacts' => $lastUpdatedContacts,
'upcomingReminders' => $upcomingReminders,
'lastUpdatedContacts' => $lastUpdatedContactsCollection,
'number_of_contacts' => $account->contacts_count,
'number_of_reminders' => $account->reminders_count,
'number_of_notes' => $account->notes_count,
Expand All @@ -87,12 +85,71 @@ public function index()
'number_of_tasks' => $account->tasks_count,
'debt_due' => $debt_due,
'debt_owed' => $debt_owed,
'tasks' => $tasks,
'debts' => $debt,
'user' => auth()->user(),
'notes' => $notes,
];

return view('dashboard.index', $data);
}

/**
* Get calls for the dashboard.
* @return Collection
*/
public function calls()
{
$callsCollection = collect([]);
$calls = auth()->user()->account->calls()->limit(15)->get();

foreach ($calls as $call) {
$data = [
'id' => $call->id,
'called_at' => \App\Helpers\DateHelper::getShortDate($call->called_at),
'name' => $call->contact->getIncompleteName(),
'contact_id' => $call->contact->id,
];
$callsCollection->push($data);
}

return $callsCollection;
}

/**
* Get notes for the dashboard.
* @return Collection
*/
public function notes()
{
$notesCollection = collect([]);
$notes = auth()->user()->account->notes()->favorited()->get();

foreach ($notes as $note) {
$data = [
'id' => $note->id,
'body' => $note->body,
'created_at' => \App\Helpers\DateHelper::getShortDate($note->created_at),
'name' => $note->contact->getIncompleteName(),
'contact' => [
'id' => $note->contact->id,
'has_avatar' => $note->contact->has_avatar,
'avatar_url' => $note->contact->getAvatarURL(110),
'initials' => $note->contact->getInitials(),
'default_avatar_color' => $note->contact->default_avatar_color,
'complete_name' => $note->contact->getCompleteName(auth()->user()->name_order),
],
];
$notesCollection->push($data);
}

return $notesCollection;
}

/**
* Save the current active tab to the User table.
*/
public function setTab(Request $request)
{
auth()->user()->dashboard_active_tab = $request->get('tab');
auth()->user()->save();
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SettingsController extends Controller
'oauth_personal_access_clients',
'oauth_refresh_tokens',
'password_resets',
'pet_categories',
'sessions',
'statistics',
'subscriptions',
Expand Down
Loading