Skip to content

Commit

Permalink
Change the structure of the dashboard (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Jan 6, 2018
1 parent 0424be2 commit fe974db
Show file tree
Hide file tree
Showing 32 changed files with 81,205 additions and 904 deletions.
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;
}
}
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 (count($relatedContact) != 0) {
return \App\Contact::find($relatedContact->contact_id);
}

// Look in the Offspring table
$relatedContact = \App\Offspring::where('contact_id', $this->id)->first();
if (count($relatedContact) != 0) {
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;
}
}
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(),
'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' => [
'contact_id' => $note->contact->id,
'has_avatar' => $note->contact->has_avatar,
'avatar_url' => $note->contact->getAvatarURL(),
'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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddDashboardTabToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('dashboard_active_tab')->default('calls')->after('invited_by_user_id');
});
}
}
11 changes: 11 additions & 0 deletions database/seeds/FakeContentTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function run()
$this->populateActivities();
$this->populateTasks();
$this->populateDebts();
$this->populateCalls();
$this->populateGifts();
$this->populateAddresses();
$this->populateContactFields();
Expand Down Expand Up @@ -476,4 +477,14 @@ public function changeUpdatedAt()
$this->contact->last_consulted_at = $this->faker->dateTimeThisYear();
$this->contact->save();
}

public function populateCalls()
{
if (rand(1, 3) == 1) {
$calls = $this->contact->calls()->create([
'account_id' => $this->contact->account_id,
'called_at' => $this->faker->dateTimeThisYear(),
]);
}
}
}
19,642 changes: 19,633 additions & 9 deletions public/css/app.css

Large diffs are not rendered by default.

60,950 changes: 60,948 additions & 2 deletions public/js/app.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"/js/app.js": "/js/app.js?id=add66bd4d66fd8e26f4c",
"/css/app.css": "/css/app.css?id=0a25d8cfce9c8cb33447",
"/js/app.js.map": "/js/app.js.map?id=d41602915a27ee1daf44",
"/css/app.css.map": "/css/app.css.map?id=516bf3da4d93de8e038d"
"/js/app.js": "/js/app.js?id=6771eb533b49d76c502e",
"/css/app.css": "/css/app.css?id=2f09d692c045efab3e48"
}
12 changes: 12 additions & 0 deletions resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ Vue.component(
require('./components/passport/PersonalAccessTokens.vue')
);

// Partials
Vue.component(
'avatar',
require('./components/partials/Avatar.vue')
);

// Dashboard
Vue.component(
'dashboard-log',
require('./components/dashboard/DashboardLog.vue')
);

// Contacts
Vue.component(
'contact-address',
Expand Down
Loading

0 comments on commit fe974db

Please sign in to comment.