Add projects to the calendar

This commit is contained in:
Hillel Coren 2017-12-24 17:34:17 +02:00
parent 4e97ec00c7
commit 0af7c15456
4 changed files with 45 additions and 2 deletions

View File

@ -7,6 +7,7 @@ use App\Models\Invoice;
use App\Models\Payment; use App\Models\Payment;
use App\Models\Expense; use App\Models\Expense;
use App\Models\Task; use App\Models\Task;
use App\Models\Project;
class GenerateCalendarEvents extends Job class GenerateCalendarEvents extends Job
{ {
@ -26,6 +27,7 @@ class GenerateCalendarEvents extends Job
ENTITY_TASK => Task::scope()->with(['project']), ENTITY_TASK => Task::scope()->with(['project']),
ENTITY_PAYMENT => Payment::scope()->with(['invoice']), ENTITY_PAYMENT => Payment::scope()->with(['invoice']),
ENTITY_EXPENSE => Expense::scope()->with(['expense_category']), ENTITY_EXPENSE => Expense::scope()->with(['expense_category']),
ENTITY_PROJECT => Project::scope(),
]; ];
foreach ($data as $type => $source) { foreach ($data as $type => $source) {

View File

@ -33,7 +33,7 @@ class Project extends EntityModel
/** /**
* @var string * @var string
*/ */
protected $presenter = 'App\Ninja\Presenters\EntityPresenter'; protected $presenter = 'App\Ninja\Presenters\ProjectPresenter';
/** /**
* @return mixed * @return mixed
@ -51,6 +51,14 @@ class Project extends EntityModel
return "/projects/{$this->public_id}/edit"; return "/projects/{$this->public_id}/edit";
} }
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account()
{
return $this->belongsTo('App\Models\Account');
}
/** /**
* @return mixed * @return mixed
*/ */
@ -66,6 +74,13 @@ class Project extends EntityModel
{ {
return $this->hasMany('App\Models\Task'); return $this->hasMany('App\Models\Task');
} }
public function scopeDateRange($query, $startDate, $endDate)
{
return $query->where(function ($query) use ($startDate, $endDate) {
$query->whereBetween('due_date', [$startDate, $endDate]);
});
}
} }
Project::creating(function ($project) { Project::creating(function ($project) {

View File

@ -0,0 +1,26 @@
<?php
namespace App\Ninja\Presenters;
use Utils;
class ProjectPresenter extends EntityPresenter
{
public function calendarEvent($subColors = false)
{
$data = parent::calendarEvent();
$project = $this->entity;
$data->title = trans('texts.project') . ': ' . $project->name;
$data->start = $project->due_date;
if ($subColors) {
$data->borderColor = $data->backgroundColor = Utils::brewerColor($project->public_id);
} else {
$data->borderColor = $data->backgroundColor = '#676767';
}
return $data;
}
}

View File

@ -26,7 +26,7 @@
@section('top-right') @section('top-right')
<div id="entityTypeFilterWrapper" style="display:none"> <div id="entityTypeFilterWrapper" style="display:none">
<select class="form-control" style="width: 220px;" id="entityTypeFilter" multiple="true"> <select class="form-control" style="width: 220px;" id="entityTypeFilter" multiple="true">
@foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_PAYMENT, ENTITY_TASK, ENTITY_EXPENSE] as $value) @foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_PAYMENT, ENTITY_TASK, ENTITY_EXPENSE, ENTITY_PROJECT] as $value)
<option value="{{ $value }}">{{ trans("texts.{$value}") }}</option> <option value="{{ $value }}">{{ trans("texts.{$value}") }}</option>
@endforeach @endforeach
</select> </select>