-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #11521 - switch to using status meta from status label name
Signed-off-by: snipe <[email protected]>
- Loading branch information
Showing
5 changed files
with
106 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
use App\Models\Asset; | ||
use App\Models\Statuslabel; | ||
use Illuminate\Http\Request; | ||
use App\Http\Transformers\PieChartTransformer; | ||
use Illuminate\Support\Arr; | ||
|
||
class StatuslabelsController extends Controller | ||
{ | ||
|
@@ -188,43 +190,54 @@ public function destroy($id) | |
* | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @since [v3.0] | ||
* @return \Illuminate\Http\Response | ||
* @return array | ||
*/ | ||
public function getAssetCountByStatuslabel() | ||
{ | ||
$this->authorize('view', Statuslabel::class); | ||
|
||
$statuslabels = Statuslabel::withCount('assets')->get(); | ||
|
||
$labels = []; | ||
$points = []; | ||
$default_color_count = 0; | ||
$colors_array = []; | ||
|
||
foreach ($statuslabels as $statuslabel) { | ||
if ($statuslabel->assets_count > 0) { | ||
$labels[] = $statuslabel->name.' ('.number_format($statuslabel->assets_count).')'; | ||
$points[] = $statuslabel->assets_count; | ||
|
||
if ($statuslabel->color != '') { | ||
$colors_array[] = $statuslabel->color; | ||
} else { | ||
$colors_array[] = Helper::defaultChartColors($default_color_count); | ||
} | ||
$default_color_count++; | ||
|
||
$total[$statuslabel->name]['label'] = $statuslabel->name; | ||
$total[$statuslabel->name]['count'] = $statuslabel->assets_count; | ||
|
||
if ($statuslabel->color != '') { | ||
$total[$statuslabel->name]['color'] = $statuslabel->color; | ||
} | ||
} | ||
|
||
$result = [ | ||
'labels' => $labels, | ||
'datasets' => [[ | ||
'data' => $points, | ||
'backgroundColor' => $colors_array, | ||
'hoverBackgroundColor' => $colors_array, | ||
]], | ||
]; | ||
return (new PieChartTransformer())->transformPieChartDate($total); | ||
|
||
} | ||
|
||
/** | ||
* Show a count of assets by meta status type for pie chart | ||
* | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @since [v6.0.11] | ||
* @return array | ||
*/ | ||
public function getAssetCountByMetaStatus() | ||
{ | ||
$this->authorize('view', Statuslabel::class); | ||
|
||
$total['rtd']['label'] = trans('general.ready_to_deploy'); | ||
$total['rtd']['count'] = Asset::RTD()->count(); | ||
|
||
$total['deployed']['label'] = trans('general.deployed'); | ||
$total['deployed']['count'] = Asset::Deployed()->count(); | ||
|
||
$total['archived']['label'] = trans('general.archived'); | ||
$total['archived']['count'] = Asset::Archived()->count(); | ||
|
||
$total['pending']['label'] = trans('general.pending'); | ||
$total['pending']['count'] = Asset::Pending()->count(); | ||
|
||
$total['undeployable']['label'] = trans('general.undeployable'); | ||
$total['undeployable']['count'] = Asset::Undeployable()->count(); | ||
|
||
return $result; | ||
return (new PieChartTransformer())->transformPieChartDate($total); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Http\Transformers; | ||
|
||
|
||
use App\Helpers\Helper;/** | ||
* Class PieChartTransformer | ||
* | ||
* This handles the standardized formatting of the API response we need to provide for | ||
* the pie charts | ||
* | ||
* @return \Illuminate\Http\Response | ||
*@since [v6.0.11] | ||
* @author [A. Gianotto] [<[email protected]>] | ||
*/ | ||
class PieChartTransformer | ||
{ | ||
public function transformPieChartDate($totals) | ||
{ | ||
|
||
$labels = []; | ||
$counts = []; | ||
$default_color_count = 0; | ||
$colors_array = []; | ||
|
||
foreach ($totals as $total) { | ||
|
||
if ($total['count'] > 0) { | ||
|
||
$labels[] = $total['label']; | ||
$counts[] = $total['count']; | ||
|
||
if (isset($total['color'])) { | ||
$colors_array[] = $total['color']; | ||
} else { | ||
$colors_array[] = Helper::defaultChartColors($default_color_count); | ||
$default_color_count++; | ||
} | ||
} | ||
} | ||
|
||
$results = [ | ||
'labels' => $labels, | ||
'datasets' => [[ | ||
'data' => $counts, | ||
'backgroundColor' => $colors_array, | ||
'hoverBackgroundColor' => $colors_array, | ||
]], | ||
]; | ||
|
||
|
||
return $results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters