Working on the calendar

This commit is contained in:
Hillel Coren 2017-09-13 00:20:18 +03:00
parent 9b370a3e8d
commit 5d3bad8331
7 changed files with 41 additions and 12 deletions

View File

@ -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);
}
}
}

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)) {