Added custom color to status labels, only show status labels if there are results

This commit is contained in:
snipe 2016-08-02 13:25:50 -07:00
parent 30c45442f9
commit ca8ca89955
7 changed files with 93 additions and 12 deletions

View file

@ -47,23 +47,32 @@ class StatuslabelsController extends Controller
{
$colors = [];
$statuslabels = Statuslabel::get();
$statuslabels = Statuslabel::with('assets')->get();
$labels=[];
$points=[];
$colors=[];
foreach ($statuslabels as $statuslabel) {
$labels[]=$statuslabel->name;
$points[]=$statuslabel->assets()->whereNull('assigned_to')->count();
if ($statuslabel->assets->count() > 0) {
$labels[]=$statuslabel->name;
$points[]=$statuslabel->assets()->whereNull('assigned_to')->count();
if ($statuslabel->color!='') {
$colors[]=$statuslabel->color;
}
}
}
$labels[]='Deployed';
$points[]=Asset::whereNotNull('assigned_to')->count();
$colors_array = array_merge($colors, Helper::chartColors());
$result= [
"labels" => $labels,
"datasets" => [ [
"data" => $points,
"backgroundColor" => Helper::chartColors(),
"hoverBackgroundColor" => Helper::chartColors()
"backgroundColor" => $colors_array,
"hoverBackgroundColor" => $colors_array
]]
];
return $result;
@ -110,6 +119,7 @@ class StatuslabelsController extends Controller
$statuslabel->deployable = $statustype['deployable'];
$statuslabel->pending = $statustype['pending'];
$statuslabel->archived = $statustype['archived'];
$statuslabel->color = e(Input::get('color'));
// Was the asset created?
@ -197,6 +207,7 @@ class StatuslabelsController extends Controller
$statuslabel->deployable = $statustype['deployable'];
$statuslabel->pending = $statustype['pending'];
$statuslabel->archived = $statustype['archived'];
$statuslabel->color = e(Input::get('color'));
// Was the asset created?
@ -247,7 +258,7 @@ class StatuslabelsController extends Controller
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');
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>';
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(
'id' => e($statuslabel->id),
'type' => e($label_type),
'name' => e($statuslabel->name),
'color' => $color,
'actions' => $actions
);
}

View file

@ -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');
});
}
}

View file

@ -4,6 +4,7 @@ return array(
'about' => 'About Status Labels',
'archived' => 'Archived',
'create' => 'Create Status Label',
'color' => 'Chart Color',
'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.',
'name' => 'Status Name',

View file

@ -188,7 +188,7 @@
<div class="col-md-3">
<div class="box box-default">
<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">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>

View file

@ -15,9 +15,11 @@
.checkbox label {
padding-right: 40px;
}
.input-group {
padding-left: 15px;
.input-group-addon {
width: 30px;
}
</style>
<!-- Bootstrap Color Picker -->

View file

@ -19,6 +19,14 @@
{{-- Page 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="col-md-9">
@ -43,13 +51,26 @@
<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>
</label>
<div class="col-md-7 required">
{{ 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>') !!}
</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 -->
<div class="form-group {{ $errors->has('notes') ? 'has-error' : '' }}">
<label for="notes" class="col-md-3 control-label">{{ trans('admin/hardware/form.notes') }}</label>
@ -77,5 +98,11 @@
</div>
</div>
@section('moar_scripts')
<!-- bootstrap color picker -->
<script>
//color picker with addon
$(".color").colorpicker();
</script>
@stop
@stop

View file

@ -31,6 +31,7 @@
<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="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>
</tr>
</thead>