From 4edc2a7a666247e49a073d0acb65379aa8324549 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 May 2016 16:06:09 -0700 Subject: [PATCH] Route and controller for dashboard chart --- .../Controllers/StatuslabelsController.php | 34 +++++++++++++++++++ app/Http/routes.php | 1 + 2 files changed, 35 insertions(+) diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php index 3033471920..89542d1127 100755 --- a/app/Http/Controllers/StatuslabelsController.php +++ b/app/Http/Controllers/StatuslabelsController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use Input; use Lang; use App\Models\Statuslabel; +use App\Models\Asset; use Redirect; use DB; use App\Models\Setting; @@ -35,6 +36,39 @@ class StatuslabelsController extends Controller } + /** + * Show a count of assets by status label + * + * @return View + */ + + public function getAssetCountByStatuslabel() + { + $colors = []; + + $statuslabels = Statuslabel::get(); + $labels=[]; + $points=[]; + + foreach ($statuslabels as $statuslabel) { + $labels[]=$statuslabel->name; + $points[]=$statuslabel->assets()->whereNull('assigned_to')->count(); + } + $labels[]='Deployed'; + $points[]=Asset::whereNotNull('assigned_to')->count(); + + $result= [ + "labels" => $labels, + "datasets" => [ [ + "data" => $points, + "backgroundColor" => Helper::chartColors(), + "hoverBackgroundColor" => Helper::chartBackgroundColors() + ]] + ]; + return $result; + } + + /** * Statuslabel create. * diff --git a/app/Http/routes.php b/app/Http/routes.php index 850eed2d56..3d05b0c6ca 100755 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -35,6 +35,7 @@ Route::group([ 'prefix' => 'api', 'middleware' => 'auth' ], function () { }); Route::get('list', [ 'as' => 'api.statuslabels.list', 'uses' => 'StatuslabelsController@getDatatable' ]); + Route::get('assets', [ 'as' => 'api.statuslabels.assets', 'uses' => 'StatuslabelsController@getAssetCountByStatuslabel' ]); });