Route and controller for dashboard chart

This commit is contained in:
snipe 2016-05-24 16:06:09 -07:00
parent 3b838ca867
commit 4edc2a7a66
2 changed files with 35 additions and 0 deletions

View file

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Input; use Input;
use Lang; use Lang;
use App\Models\Statuslabel; use App\Models\Statuslabel;
use App\Models\Asset;
use Redirect; use Redirect;
use DB; use DB;
use App\Models\Setting; 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. * Statuslabel create.
* *

View file

@ -35,6 +35,7 @@ Route::group([ 'prefix' => 'api', 'middleware' => 'auth' ], function () {
}); });
Route::get('list', [ 'as' => 'api.statuslabels.list', 'uses' => 'StatuslabelsController@getDatatable' ]); Route::get('list', [ 'as' => 'api.statuslabels.list', 'uses' => 'StatuslabelsController@getDatatable' ]);
Route::get('assets', [ 'as' => 'api.statuslabels.assets', 'uses' => 'StatuslabelsController@getAssetCountByStatuslabel' ]);
}); });