Working on a widget design for the dashboard index

This commit is contained in:
James Brooks
2015-08-24 13:41:02 +01:00
parent f13b8debe4
commit 70a5022740
10 changed files with 173 additions and 22 deletions

View File

@@ -12,8 +12,11 @@
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\View;
use stdClass;
class DashboardController extends Controller
{
@@ -25,9 +28,11 @@ class DashboardController extends Controller
public function showDashboard()
{
$components = Component::orderBy('order')->get();
$incidents = $this->getIncidents();
return View::make('dashboard.index')
->withComponents($components);
->withComponents($components)
->withIncidents($incidents);
}
/**
@@ -40,4 +45,24 @@ class DashboardController extends Controller
return View::make('dashboard.notifications.index')
->withPageTitle(trans('dashboard.notifications.notifications').' '.trans('dashboard.dashboard'));
}
/**
* Fetches all of the incidents over the last 30 days.
*
* @return \Illuminate\Support\Collection
*/
protected function getIncidents()
{
$incidents = Incident::select(DB::raw('COUNT(id) AS counter'))->groupBy(DB::raw('DATE_FORMAT(created_at, "%d%m%y")'))->get();
$range = (30 - $incidents->count()) - 1;
$fake = new stdClass();
$fake->counter = 0;
foreach (range(1, $range) as $key) {
$incidents->prepend($fake);
}
return $incidents;
}
}