mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
Route and controller for dashboard chart
This commit is contained in:
parent
3b838ca867
commit
4edc2a7a66
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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' ]);
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue