mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Merge pull request #11893 from snipe/features/switch_dash_pie_to_status_type
Fixed #11521 - Add option to switch to using status meta from status label name
This commit is contained in:
commit
9c6fa18454
|
@ -9,6 +9,8 @@ use App\Http\Transformers\StatuslabelsTransformer;
|
|||
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 @@ class StatuslabelsController extends Controller
|
|||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @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);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a count of assets by meta status type for pie chart
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @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 (new PieChartTransformer())->transformPieChartDate($total);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -349,6 +349,7 @@ class SettingsController extends Controller
|
|||
$setting->privacy_policy_link = $request->input('privacy_policy_link');
|
||||
|
||||
$setting->depreciation_method = $request->input('depreciation_method');
|
||||
$setting->dash_chart_type = $request->input('dash_chart_type');
|
||||
|
||||
if ($request->input('per_page') != '') {
|
||||
$setting->per_page = $request->input('per_page');
|
||||
|
|
54
app/Http/Transformers/PieChartTransformer.php
Normal file
54
app/Http/Transformers/PieChartTransformer.php
Normal file
|
@ -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] [<snipe@snipe.net>]
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddChartTypeToSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->string('dash_chart_type')->nullable()->default('name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('settings', 'dash_chart_type')) {
|
||||
$table->dropColumn('dash_chart_type');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -373,6 +373,9 @@ return [
|
|||
'bulk_checkin_success' => 'The items for the selected users have been checked in.',
|
||||
'set_to_null' => 'Delete values for this asset|Delete values for all :asset_count assets ',
|
||||
'na_no_purchase_date' => 'N/A - No purchase date provided',
|
||||
'assets_by_status' => 'Assets by Status',
|
||||
'assets_by_status_type' => 'Assets by Status Type',
|
||||
'pie_chart_type' => 'Dashboard Pie Chart Type',
|
||||
|
||||
|
||||
];
|
|
@ -248,7 +248,9 @@
|
|||
<div class="col-md-4">
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h2 class="box-title">{{ trans('general.assets') }} {{ trans('general.bystatus') }}</h2>
|
||||
<h2 class="box-title">
|
||||
{{ (\App\Models\Setting::getSettings()->dash_chart_type == 'name') ? trans('general.assets_by_status') : trans('general.assets_by_status_type') }}
|
||||
</h2>
|
||||
<div class="box-tools pull-right">
|
||||
<button type="button" class="btn btn-box-tool" data-widget="collapse" aria-hidden="true">
|
||||
<i class="fas fa-minus" aria-hidden="true"></i>
|
||||
|
@ -261,7 +263,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="chart-responsive">
|
||||
<canvas id="statusPieChart" height="290"></canvas>
|
||||
<canvas id="statusPieChart" height="260"></canvas>
|
||||
</div> <!-- ./chart-responsive -->
|
||||
</div> <!-- /.col -->
|
||||
</div> <!-- /.row -->
|
||||
|
@ -430,7 +432,7 @@
|
|||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '{{ route('api.statuslabels.assets.bytype') }}',
|
||||
url: '{{ (\App\Models\Setting::getSettings()->dash_chart_type == 'name') ? route('api.statuslabels.assets.byname') : route('api.statuslabels.assets.bytype') }}',
|
||||
headers: {
|
||||
"X-Requested-With": 'XMLHttpRequest',
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
|
||||
|
@ -438,7 +440,7 @@
|
|||
dataType: 'json',
|
||||
success: function (data) {
|
||||
var myPieChart = new Chart(ctx,{
|
||||
type : 'doughnut',
|
||||
type : 'pie',
|
||||
data : data,
|
||||
options: pieOptions
|
||||
});
|
||||
|
|
|
@ -287,6 +287,21 @@
|
|||
{{ Form::checkbox('show_in_model_list[]', 'model_number', old('show_in_model_list', $snipeSettings->modellistCheckedValue('model_number')),array('class' => 'minimal', 'aria-label'=>'show_in_model_list' )) }} {{ trans('general.model_no') }}<br>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- dash chart -->
|
||||
<div class="form-group {{ $errors->has('dash_chart_type') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
{{ Form::label('show_in_model_list',
|
||||
trans('general.pie_chart_type')) }}
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
{{ Form::select('dash_chart_type', array(
|
||||
'name' => 'Status Label Name',
|
||||
'type' => 'Status Label Type'), Request::old('dash_chart_type', $setting->dash_chart_type), ['class' =>'select2', 'style' => 'width: 80%']) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Depreciation method -->
|
||||
<div class="form-group {{ $errors->has('depreciation_method') ? 'error' : '' }}">
|
||||
|
|
|
@ -859,11 +859,18 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi
|
|||
]
|
||||
)->name('api.statuslabels.selectlist');
|
||||
|
||||
Route::get('assets',
|
||||
Route::get('assets/name',
|
||||
[
|
||||
Api\StatuslabelsController::class,
|
||||
'getAssetCountByStatuslabel'
|
||||
]
|
||||
)->name('api.statuslabels.assets.byname');
|
||||
|
||||
Route::get('assets/type',
|
||||
[
|
||||
Api\StatuslabelsController::class,
|
||||
'getAssetCountByMetaStatus'
|
||||
]
|
||||
)->name('api.statuslabels.assets.bytype');
|
||||
|
||||
Route::get('{id}/assetlist',
|
||||
|
|
Loading…
Reference in a new issue