Skip to content

A free open source IT asset/license management system

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

snipeca8ca8995545
diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php
index 88fb6c0398..fb4cab69ef 100755
--- a/app/Http/Controllers/StatuslabelsController.php
+++ b/app/Http/Controllers/StatuslabelsController.php
@@ -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
);
}
diff --git a/database/migrations/2016_08_02_124944_add_color_to_statuslabel.php b/database/migrations/2016_08_02_124944_add_color_to_statuslabel.php
new file mode 100644
index 0000000000..9c58c2ec65
--- /dev/null
+++ b/database/migrations/2016_08_02_124944_add_color_to_statuslabel.php
@@ -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');
+ });
+ }
+}
diff --git a/resources/lang/en/admin/statuslabels/table.php b/resources/lang/en/admin/statuslabels/table.php
index dd21781115..bd5d544fa5 100644
--- a/resources/lang/en/admin/statuslabels/table.php
+++ b/resources/lang/en/admin/statuslabels/table.php
@@ -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',
diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php
index e8d78fc37d..f59ad3d516 100755
--- a/resources/views/dashboard.blade.php
+++ b/resources/views/dashboard.blade.php
@@ -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>
diff --git a/resources/views/settings/edit.blade.php b/resources/views/settings/edit.blade.php
index bf86e36464..0d4c3f4d7f 100755
--- a/resources/views/settings/edit.blade.php
+++ b/resources/views/settings/edit.blade.php
@@ -15,9 +15,11 @@
.checkbox label {
padding-right: 40px;
}
-.input-group {
- padding-left: 15px;
+
+.input-group-addon {
+ width: 30px;
}
+
</style>
<!-- Bootstrap Color Picker -->
diff --git a/resources/views/statuslabels/edit.blade.php b/resources/views/statuslabels/edit.blade.php
index ea5896ea44..0cec6ac2e3 100755
--- a/resources/views/statuslabels/edit.blade.php
+++ b/resources/views/statuslabels/edit.blade.php
@@ -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
diff --git a/resources/views/statuslabels/index.blade.php b/resources/views/statuslabels/index.blade.php
index e1957ea00d..6541bb35da 100755
--- a/resources/views/statuslabels/index.blade.php
+++ b/resources/views/statuslabels/index.blade.php
@@ -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>