mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Added custom color to status labels, only show status labels if there are results
This commit is contained in:
parent
30c45442f9
commit
ca8ca89955
|
@ -47,23 +47,32 @@ class StatuslabelsController extends Controller
|
||||||
{
|
{
|
||||||
$colors = [];
|
$colors = [];
|
||||||
|
|
||||||
$statuslabels = Statuslabel::get();
|
$statuslabels = Statuslabel::with('assets')->get();
|
||||||
$labels=[];
|
$labels=[];
|
||||||
$points=[];
|
$points=[];
|
||||||
|
$colors=[];
|
||||||
foreach ($statuslabels as $statuslabel) {
|
foreach ($statuslabels as $statuslabel) {
|
||||||
$labels[]=$statuslabel->name;
|
if ($statuslabel->assets->count() > 0) {
|
||||||
$points[]=$statuslabel->assets()->whereNull('assigned_to')->count();
|
$labels[]=$statuslabel->name;
|
||||||
|
$points[]=$statuslabel->assets()->whereNull('assigned_to')->count();
|
||||||
|
if ($statuslabel->color!='') {
|
||||||
|
$colors[]=$statuslabel->color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
$labels[]='Deployed';
|
$labels[]='Deployed';
|
||||||
$points[]=Asset::whereNotNull('assigned_to')->count();
|
$points[]=Asset::whereNotNull('assigned_to')->count();
|
||||||
|
|
||||||
|
$colors_array = array_merge($colors, Helper::chartColors());
|
||||||
|
|
||||||
$result= [
|
$result= [
|
||||||
"labels" => $labels,
|
"labels" => $labels,
|
||||||
"datasets" => [ [
|
"datasets" => [ [
|
||||||
"data" => $points,
|
"data" => $points,
|
||||||
"backgroundColor" => Helper::chartColors(),
|
"backgroundColor" => $colors_array,
|
||||||
"hoverBackgroundColor" => Helper::chartColors()
|
"hoverBackgroundColor" => $colors_array
|
||||||
]]
|
]]
|
||||||
];
|
];
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -110,6 +119,7 @@ class StatuslabelsController extends Controller
|
||||||
$statuslabel->deployable = $statustype['deployable'];
|
$statuslabel->deployable = $statustype['deployable'];
|
||||||
$statuslabel->pending = $statustype['pending'];
|
$statuslabel->pending = $statustype['pending'];
|
||||||
$statuslabel->archived = $statustype['archived'];
|
$statuslabel->archived = $statustype['archived'];
|
||||||
|
$statuslabel->color = e(Input::get('color'));
|
||||||
|
|
||||||
|
|
||||||
// Was the asset created?
|
// Was the asset created?
|
||||||
|
@ -197,6 +207,7 @@ class StatuslabelsController extends Controller
|
||||||
$statuslabel->deployable = $statustype['deployable'];
|
$statuslabel->deployable = $statustype['deployable'];
|
||||||
$statuslabel->pending = $statustype['pending'];
|
$statuslabel->pending = $statustype['pending'];
|
||||||
$statuslabel->archived = $statustype['archived'];
|
$statuslabel->archived = $statustype['archived'];
|
||||||
|
$statuslabel->color = e(Input::get('color'));
|
||||||
|
|
||||||
|
|
||||||
// Was the asset created?
|
// Was the asset created?
|
||||||
|
@ -247,7 +258,7 @@ class StatuslabelsController extends Controller
|
||||||
|
|
||||||
public function getDatatable()
|
public function getDatatable()
|
||||||
{
|
{
|
||||||
$statuslabels = Statuslabel::select(array('id','name','deployable','pending','archived'))
|
$statuslabels = Statuslabel::select(array('id','name','deployable','pending','archived','color'))
|
||||||
->whereNull('deleted_at');
|
->whereNull('deleted_at');
|
||||||
|
|
||||||
if (Input::has('search')) {
|
if (Input::has('search')) {
|
||||||
|
@ -291,10 +302,18 @@ class StatuslabelsController extends Controller
|
||||||
|
|
||||||
$actions = '<a href="'.route('update/statuslabel', $statuslabel->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/statuslabel', $statuslabel->id).'" data-content="'.trans('admin/statuslabels/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($statuslabel->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
$actions = '<a href="'.route('update/statuslabel', $statuslabel->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/statuslabel', $statuslabel->id).'" data-content="'.trans('admin/statuslabels/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($statuslabel->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
|
||||||
|
|
||||||
|
if ($statuslabel->color!='') {
|
||||||
|
$color = '<div class="pull-left" style="margin-right: 5px; height: 20px; width: 20px; background-color: '.e($statuslabel->color).'"></div>'.e($statuslabel->color);
|
||||||
|
} else {
|
||||||
|
$color = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
'id' => e($statuslabel->id),
|
'id' => e($statuslabel->id),
|
||||||
'type' => e($label_type),
|
'type' => e($label_type),
|
||||||
'name' => e($statuslabel->name),
|
'name' => e($statuslabel->name),
|
||||||
|
'color' => $color,
|
||||||
'actions' => $actions
|
'actions' => $actions
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class AddColorToStatuslabel extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('status_labels', function (Blueprint $table) {
|
||||||
|
$table->string('color', 10)->nullable()->default(NULL);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('status_labels', function ($table) {
|
||||||
|
$table->dropColumn('color');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ return array(
|
||||||
'about' => 'About Status Labels',
|
'about' => 'About Status Labels',
|
||||||
'archived' => 'Archived',
|
'archived' => 'Archived',
|
||||||
'create' => 'Create Status Label',
|
'create' => 'Create Status Label',
|
||||||
|
'color' => 'Chart Color',
|
||||||
'deployable' => 'Deployable',
|
'deployable' => 'Deployable',
|
||||||
'info' => 'Status labels are used to describe the various states your assets could be in. They may be out for repair, lost/stolen, etc. You can create new status labels for deployable, pending and archived assets.',
|
'info' => 'Status labels are used to describe the various states your assets could be in. They may be out for repair, lost/stolen, etc. You can create new status labels for deployable, pending and archived assets.',
|
||||||
'name' => 'Status Name',
|
'name' => 'Status Name',
|
||||||
|
|
|
@ -188,7 +188,7 @@
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="box box-default">
|
<div class="box box-default">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ trans('general.status') }}</h3>
|
<h3 class="box-title">{{ trans('general.assets') }}</h3>
|
||||||
|
|
||||||
<div class="box-tools pull-right">
|
<div class="box-tools pull-right">
|
||||||
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
|
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
|
||||||
|
|
|
@ -15,9 +15,11 @@
|
||||||
.checkbox label {
|
.checkbox label {
|
||||||
padding-right: 40px;
|
padding-right: 40px;
|
||||||
}
|
}
|
||||||
.input-group {
|
|
||||||
padding-left: 15px;
|
.input-group-addon {
|
||||||
|
width: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- Bootstrap Color Picker -->
|
<!-- Bootstrap Color Picker -->
|
||||||
|
|
|
@ -19,6 +19,14 @@
|
||||||
{{-- Page content --}}
|
{{-- Page content --}}
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.input-group-addon {
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<!-- Bootstrap Color Picker -->
|
||||||
|
<link rel="stylesheet" href="{{ asset('assets/js/plugins/colorpicker/bootstrap-colorpicker.min.css') }}">
|
||||||
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-md-9">
|
||||||
|
@ -43,13 +51,26 @@
|
||||||
<div class="form-group {{ $errors->has('statuslabel_types') ? 'has-error' : '' }}">
|
<div class="form-group {{ $errors->has('statuslabel_types') ? 'has-error' : '' }}">
|
||||||
<label for="statuslabel_types" class="col-md-3 control-label">{{ trans('admin/statuslabels/table.status_type') }}
|
<label for="statuslabel_types" class="col-md-3 control-label">{{ trans('admin/statuslabels/table.status_type') }}
|
||||||
</label>
|
</label>
|
||||||
</label>
|
|
||||||
<div class="col-md-7 required">
|
<div class="col-md-7 required">
|
||||||
{{ Form::select('statuslabel_types', $statuslabel_types, $statuslabel->getStatuslabelType(), array('class'=>'select2', 'style'=>'min-width:400px')) }}
|
{{ Form::select('statuslabel_types', $statuslabel_types, $statuslabel->getStatuslabelType(), array('class'=>'select2', 'style'=>'min-width:400px')) }}
|
||||||
{!! $errors->first('statuslabel_types', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('statuslabel_types', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Chart color -->
|
||||||
|
<div class="form-group{{ $errors->has('color') ? ' has-error' : '' }}">
|
||||||
|
{{ Form::label('color', trans('admin/statuslabels/table.color'), ['class' => 'col-md-3 control-label']) }}
|
||||||
|
<div class="col-md-2">
|
||||||
|
<div class="input-group color">
|
||||||
|
{{ Form::text('color', Input::old('color', $statuslabel->color), array('class' => 'form-control', 'style' => 'width: 100px;', 'maxlength'=>'10')) }}
|
||||||
|
<div class="input-group-addon"><i></i></div>
|
||||||
|
</div><!-- /.input group -->
|
||||||
|
|
||||||
|
|
||||||
|
{!! $errors->first('header_color', '<span class="alert-msg">:message</span>') !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Note -->
|
<!-- Note -->
|
||||||
<div class="form-group {{ $errors->has('notes') ? 'has-error' : '' }}">
|
<div class="form-group {{ $errors->has('notes') ? 'has-error' : '' }}">
|
||||||
<label for="notes" class="col-md-3 control-label">{{ trans('admin/hardware/form.notes') }}</label>
|
<label for="notes" class="col-md-3 control-label">{{ trans('admin/hardware/form.notes') }}</label>
|
||||||
|
@ -77,5 +98,11 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@section('moar_scripts')
|
||||||
|
<!-- bootstrap color picker -->
|
||||||
|
<script>
|
||||||
|
//color picker with addon
|
||||||
|
$(".color").colorpicker();
|
||||||
|
</script>
|
||||||
|
@stop
|
||||||
@stop
|
@stop
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
||||||
<th data-sortable="true" data-field="name">{{ trans('admin/statuslabels/table.name') }}</th>
|
<th data-sortable="true" data-field="name">{{ trans('admin/statuslabels/table.name') }}</th>
|
||||||
<th data-sortable="false" data-field="type">{{ trans('admin/statuslabels/table.status_type') }}</th>
|
<th data-sortable="false" data-field="type">{{ trans('admin/statuslabels/table.status_type') }}</th>
|
||||||
|
<th data-sortable="false" data-field="color">{{ trans('admin/statuslabels/table.color') }}</th>
|
||||||
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
|
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
Loading…
Reference in a new issue