Working on a widget design for the dashboard index
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user