From 5d3bad8331ff5278dc96654b7b498a731381feeb Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 13 Sep 2017 00:20:18 +0300 Subject: [PATCH] Working on the calendar --- app/Jobs/GenerateCalendarEvents.php | 3 ++- app/Libraries/Utils.php | 15 +++++++++++++++ app/Ninja/Presenters/EntityPresenter.php | 2 +- app/Ninja/Presenters/ExpensePresenter.php | 9 +++++++-- app/Ninja/Presenters/InvoicePresenter.php | 4 ++-- app/Ninja/Presenters/PaymentPresenter.php | 4 ++-- app/Ninja/Presenters/TaskPresenter.php | 16 ++++++++++++---- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/app/Jobs/GenerateCalendarEvents.php b/app/Jobs/GenerateCalendarEvents.php index 15087fbcfeeb..044a5aa61899 100644 --- a/app/Jobs/GenerateCalendarEvents.php +++ b/app/Jobs/GenerateCalendarEvents.php @@ -31,7 +31,8 @@ class GenerateCalendarEvents extends Job foreach ($data as $type => $source) { if (! count($filter) || in_array($type, $filter)) { foreach ($source->get() as $entity) { - $events[] = $entity->present()->calendarEvent; + $subColors = count($filter) == 1; + $events[] = $entity->present()->calendarEvent($subColors); } } } diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index ccf2bb162d55..de6239b7df15 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -1304,6 +1304,21 @@ class Utils return $r; } + public static function brewerColor($number) { + $colors = [ + '#377eb8', + '#4daf4a', + '#984ea3', + '#ff7f00', + '#a65628', + '#f781bf', + '#e41a1c', + ]; + $number = ($number-1) % count($colors); + + return $colors[$number]; + } + /** * Replace language-specific characters by ASCII-equivalents. * @param string $s diff --git a/app/Ninja/Presenters/EntityPresenter.php b/app/Ninja/Presenters/EntityPresenter.php index ecc93822a926..b0875eab0344 100644 --- a/app/Ninja/Presenters/EntityPresenter.php +++ b/app/Ninja/Presenters/EntityPresenter.php @@ -69,7 +69,7 @@ class EntityPresenter extends Presenter return sprintf('%s: %s', trans('texts.' . $entityType), $entity->getDisplayName()); } - public function calendarEvent() + public function calendarEvent($subColors = false) { $entity = $this->entity; diff --git a/app/Ninja/Presenters/ExpensePresenter.php b/app/Ninja/Presenters/ExpensePresenter.php index 04745e494690..9f832f2aa6ae 100644 --- a/app/Ninja/Presenters/ExpensePresenter.php +++ b/app/Ninja/Presenters/ExpensePresenter.php @@ -49,7 +49,7 @@ class ExpensePresenter extends EntityPresenter return $this->entity->expense_category ? $this->entity->expense_category->name : ''; } - public function calendarEvent() + public function calendarEvent($subColors = false) { $data = parent::calendarEvent(); $expense = $this->entity; @@ -66,7 +66,12 @@ class ExpensePresenter extends EntityPresenter $data->start = $expense->expense_date; - $data->borderColor = $data->backgroundColor = '#F45D01'; + + if ($subColors && $expense->expense_category_id) { + $data->borderColor = $data->backgroundColor = Utils::brewerColor($expense->expense_category->public_id); + } else { + $data->borderColor = $data->backgroundColor = '#e41a1c'; + } return $data; } diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index eda031a3596d..df508629b6ae 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -324,7 +324,7 @@ class InvoicePresenter extends EntityPresenter return $link; } - public function calendarEvent() + public function calendarEvent($subColors = false) { $data = parent::calendarEvent(); $invoice = $this->entity; @@ -332,7 +332,7 @@ class InvoicePresenter extends EntityPresenter $data->title = trans("texts.{$entityType}") . ' ' . $invoice->invoice_number . ' | ' . $this->amount() . ' | ' . $this->client(); $data->start = $invoice->invoice_date; - $data->borderColor = $data->backgroundColor = $invoice->isQuote() ? '#2D7DD2' : '#474647'; + $data->borderColor = $data->backgroundColor = $invoice->isQuote() ? '#984ea3' : '#377eb8'; return $data; } diff --git a/app/Ninja/Presenters/PaymentPresenter.php b/app/Ninja/Presenters/PaymentPresenter.php index 69afc29090eb..9912d454276b 100644 --- a/app/Ninja/Presenters/PaymentPresenter.php +++ b/app/Ninja/Presenters/PaymentPresenter.php @@ -46,7 +46,7 @@ class PaymentPresenter extends EntityPresenter } } - public function calendarEvent() + public function calendarEvent($subColors = false) { $data = parent::calendarEvent(); $payment = $this->entity; @@ -54,7 +54,7 @@ class PaymentPresenter extends EntityPresenter $data->title = trans('texts.payment') . ' ' . $invoice->invoice_number . ' | ' . $this->amount() . ' | ' . $this->client(); $data->start = $payment->payment_date; - $data->borderColor = $data->backgroundColor = '#7FB800'; + $data->borderColor = $data->backgroundColor = '#4daf4a'; return $data; } diff --git a/app/Ninja/Presenters/TaskPresenter.php b/app/Ninja/Presenters/TaskPresenter.php index 760ef3c69047..a2d499f5ee12 100644 --- a/app/Ninja/Presenters/TaskPresenter.php +++ b/app/Ninja/Presenters/TaskPresenter.php @@ -2,6 +2,8 @@ namespace App\Ninja\Presenters; +use Utils; + /** * Class TaskPresenter. */ @@ -71,7 +73,7 @@ class TaskPresenter extends EntityPresenter return $str . implode("\n", $times); } - public function calendarEvent() + public function calendarEvent($subColors = false) { $data = parent::calendarEvent(); $task = $this->entity; @@ -82,10 +84,16 @@ class TaskPresenter extends EntityPresenter if ($project = $this->project()) { $data->title .= ' | ' . $project; } - $data->title .= ' | ' . $this->description(); - + if ($description = $this->description()) { + $data->title .= ' | ' . $description; + } $data->allDay = false; - $data->borderColor = $data->backgroundColor = '#EEB902'; + + if ($subColors && $task->project_id) { + $data->borderColor = $data->backgroundColor = Utils::brewerColor($task->project->public_id); + } else { + $data->borderColor = $data->backgroundColor = '#ff7f00'; + } $parts = json_decode($task->time_log) ?: []; if (count($parts)) {