Added status label functionality

remember to run artisan DB migrations to make this work
This commit is contained in:
snipe
2013-11-20 22:06:41 -05:00
parent f7cdc8d5c0
commit 5fae91d4e9
19 changed files with 371 additions and 96 deletions
+15 -2
View File
@@ -4,6 +4,7 @@ use AdminController;
use Input;
use Lang;
use Asset;
use Statuslabel;
use User;
use Redirect;
use DB;
@@ -48,7 +49,10 @@ class AssetsController extends AdminController {
$model_list = array('' => '') + Model::lists('name', 'id');
$depreciation_list = array('' => '') + Depreciation::lists('name', 'id');
return View::make('backend/assets/edit')->with('model_list',$model_list)->with('depreciation_list',$depreciation_list)->with('asset',new Asset);
// Grab the dropdown list of status
$statuslabel_list = array('' => 'Ready to Deploy') + Statuslabel::lists('name', 'id');
return View::make('backend/assets/edit')->with('model_list',$model_list)->with('statuslabel_list',$statuslabel_list)->with('depreciation_list',$depreciation_list)->with('asset',new Asset);
}
@@ -80,6 +84,7 @@ class AssetsController extends AdminController {
$asset->order_number = e(Input::get('order_number'));
$asset->notes = e(Input::get('notes'));
$asset->asset_tag = e(Input::get('asset_tag'));
$asset->status_id = e(Input::get('status_id'));
$asset->user_id = Sentry::getId();
$asset->physical = '1';
@@ -122,9 +127,13 @@ class AssetsController extends AdminController {
// Grab the dropdown list of models
$model_list = array('' => '') + Model::lists('name', 'id');
// Grab the dropdown list of status
$statuslabel_list = array('' => '') + Statuslabel::lists('name', 'id');
// get depreciation list
$depreciation_list = array('' => '') + Depreciation::lists('name', 'id');
return View::make('backend/assets/edit', compact('asset'))->with('model_list',$model_list)->with('depreciation_list',$depreciation_list);
return View::make('backend/assets/edit', compact('asset'))->with('model_list',$model_list)->with('depreciation_list',$depreciation_list)->with('statuslabel_list',$statuslabel_list);
}
@@ -171,6 +180,7 @@ class AssetsController extends AdminController {
$asset->purchase_cost = e(Input::get('purchase_cost'));
$asset->order_number = e(Input::get('order_number'));
$asset->asset_tag = e(Input::get('asset_tag'));
$asset->status_id = e(Input::get('status_id'));
$asset->notes = e(Input::get('notes'));
$asset->physical = '1';
@@ -232,6 +242,9 @@ class AssetsController extends AdminController {
// Get the dropdown of users and then pass it to the checkout view
$users_list = array('' => 'Select a User') + DB::table('users')->select(DB::raw('concat (first_name," ",last_name) as full_name, id'))->lists('full_name', 'id');
//print_r($users);
return View::make('backend/assets/checkout', compact('asset'))->with('users_list',$users_list);
@@ -3,7 +3,7 @@
use AdminController;
use Input;
use Lang;
use Location;
use Statuslabel;
use Redirect;
use DB;
use Sentry;
@@ -11,39 +11,38 @@ use Str;
use Validator;
use View;
class LocationsController extends AdminController {
class StatuslabelsController extends AdminController {
/**
* Show a list of all the locations.
* Show a list of all the statuslabels.
*
* @return View
*/
public function getIndex()
{
// Grab all the locations
$locations = Location::orderBy('created_at', 'DESC')->paginate(10);
// Grab all the statuslabels
$statuslabels = Statuslabel::orderBy('created_at', 'DESC')->paginate(10);
// Show the page
return View::make('backend/locations/index', compact('locations'));
return View::make('backend/statuslabels/index', compact('statuslabels'));
}
/**
* Location create.
* Statuslabel create.
*
* @return View
*/
public function getCreate()
{
// Show the page
$location_options = array('0' => 'Top Level') + Location::lists('name', 'id');
return View::make('backend/locations/edit')->with('location_options',$location_options)->with('location',new Location);
return View::make('backend/statuslabels/edit')->with('statuslabel',new Statuslabel);
}
/**
* Location create form processing.
* Statuslabel create form processing.
*
* @return Redirect
*/
@@ -54,75 +53,69 @@ class LocationsController extends AdminController {
$new = Input::all();
// create a new model instance
$location = new Location();
$statuslabel = new Statuslabel();
// attempt validation
if ($location->validate($new))
if ($statuslabel->validate($new))
{
// Save the location data
$location->name = e(Input::get('name'));
$location->city = e(Input::get('city'));
$location->state = e(Input::get('state'));
$location->country = e(Input::get('country'));
$location->user_id = Sentry::getId();
// Save the Statuslabel data
$statuslabel->name = e(Input::get('name'));
$statuslabel->user_id = Sentry::getId();
// Was the asset created?
if($location->save())
if($statuslabel->save())
{
// Redirect to the new location page
return Redirect::to("admin/settings/locations")->with('success', Lang::get('admin/locations/message.create.success'));
// Redirect to the new Statuslabel page
return Redirect::to("admin/settings/statuslabels")->with('success', Lang::get('admin/statuslabels/message.create.success'));
}
}
else
{
// failure
$errors = $location->errors();
$errors = $statuslabel->errors();
return Redirect::back()->withInput()->withErrors($errors);
}
// Redirect to the location create page
return Redirect::to('admin/settings/locations/create')->with('error', Lang::get('admin/locations/message.create.error'));
// Redirect to the Statuslabel create page
return Redirect::to('admin/settings/statuslabels/create')->with('error', Lang::get('admin/statuslabels/message.create.error'));
}
/**
* Location update.
* Statuslabel update.
*
* @param int $locationId
* @param int $statuslabelId
* @return View
*/
public function getEdit($locationId = null)
public function getEdit($statuslabelId = null)
{
// Check if the location exists
if (is_null($location = Location::find($locationId)))
// Check if the Statuslabel exists
if (is_null($statuslabel = Statuslabel::find($statuslabelId)))
{
// Redirect to the blogs management page
return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.does_not_exist'));
return Redirect::to('admin/settings/statuslabels')->with('error', Lang::get('admin/statuslabels/message.does_not_exist'));
}
// Show the page
//$location_options = array('' => 'Top Level') + Location::lists('name', 'id');
$location_options = array('' => 'Top Level') + DB::table('locations')->where('id', '!=', $locationId)->lists('name', 'id');
return View::make('backend/locations/edit', compact('location'))->with('location_options',$location_options);
return View::make('backend/statuslabels/edit', compact('statuslabel'));
}
/**
* Location update form processing page.
* Statuslabel update form processing page.
*
* @param int $locationId
* @param int $statuslabelId
* @return Redirect
*/
public function postEdit($locationId = null)
public function postEdit($statuslabelId = null)
{
// Check if the location exists
if (is_null($location = Location::find($locationId)))
// Check if the Statuslabel exists
if (is_null($statuslabel = Statuslabel::find($statuslabelId)))
{
// Redirect to the blogs management page
return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.does_not_exist'));
return Redirect::to('admin/settings/statuslabels')->with('error', Lang::get('admin/statuslabels/message.does_not_exist'));
}
@@ -132,60 +125,57 @@ class LocationsController extends AdminController {
// attempt validation
if ($location->validate($new))
if ($statuslabel->validate($new))
{
// Update the location data
$location->name = e(Input::get('name'));
$location->city = e(Input::get('city'));
$location->state = e(Input::get('state'));
$location->country = e(Input::get('country'));
// Update the Statuslabel data
$statuslabel->name = e(Input::get('name'));
// Was the asset created?
if($location->save())
if($statuslabel->save())
{
// Redirect to the saved location page
return Redirect::to("admin/settings/locations/$locationId/edit")->with('success', Lang::get('admin/locations/message.update.success'));
// Redirect to the saved Statuslabel page
return Redirect::to("admin/settings/statuslabels/$statuslabelId/edit")->with('success', Lang::get('admin/statuslabels/message.update.success'));
}
}
else
{
// failure
$errors = $location->errors();
$errors = $statuslabel->errors();
return Redirect::back()->withInput()->withErrors($errors);
}
// Redirect to the location management page
return Redirect::to("admin/settings/locations/$locationId/edit")->with('error', Lang::get('admin/locations/message.update.error'));
// Redirect to the Statuslabel management page
return Redirect::to("admin/settings/statuslabels/$statuslabelId/edit")->with('error', Lang::get('admin/statuslabels/message.update.error'));
}
/**
* Delete the given location.
* Delete the given Statuslabel.
*
* @param int $locationId
* @param int $statuslabelId
* @return Redirect
*/
public function getDelete($locationId)
public function getDelete($statuslabelId)
{
// Check if the location exists
if (is_null($location = Location::find($locationId)))
// Check if the Statuslabel exists
if (is_null($statuslabel = Statuslabel::find($statuslabelId)))
{
// Redirect to the blogs management page
return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.not_found'));
return Redirect::to('admin/settings/statuslabels')->with('error', Lang::get('admin/statuslabels/message.not_found'));
}
if ($location->has_users() > 0) {
if ($statuslabel->has_assets() > 0) {
// Redirect to the asset management page
return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.assoc_users'));
return Redirect::to('admin/settings/statuslabels')->with('error', Lang::get('admin/statuslabels/message.assoc_users'));
} else {
$location->delete();
$statuslabel->delete();
// Redirect to the locations management page
return Redirect::to('admin/settings/locations')->with('success', Lang::get('admin/locations/message.delete.success'));
// Redirect to the statuslabels management page
return Redirect::to('admin/settings/statuslabels')->with('success', Lang::get('admin/statuslabels/message.delete.success'));
}
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
class AddUploadsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('asset_uploads', function($table)
{
$table->increments('id');
$table->integer('user_id');
$table->string('filename');
$table->integer('asset_id');
$table->string('filenotes')->nullable;
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('asset_uploads');
}
}
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
class RemoveDeployableBooleanFromStatusLabels extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('status_labels', function($table)
{
$table->dropColumn('deployable');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('status_labels', function($table)
{
$table->boolean('deployable');
});
}
}
-11
View File
@@ -10,17 +10,9 @@ class StatuslabelsSeeder extends Seeder {
$status = array();
$date = new DateTime;
$status[] = array(
'name' => 'Ready to Deploy',
'deployable' => '1',
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
);
$status[] = array(
'name' => 'Out for Diagnostics',
'deployable' => '0',
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
@@ -29,7 +21,6 @@ class StatuslabelsSeeder extends Seeder {
$status[] = array(
'name' => 'Out for Repair',
'deployable' => '0',
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
@@ -38,7 +29,6 @@ class StatuslabelsSeeder extends Seeder {
$status[] = array(
'name' => 'Broken - Not Fixable',
'deployable' => '0',
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
@@ -46,7 +36,6 @@ class StatuslabelsSeeder extends Seeder {
$status[] = array(
'name' => 'Lost/Stolen',
'deployable' => '0',
'created_at' => $date->modify('-10 day'),
'updated_at' => $date->modify('-3 day'),
'user_id' => 1,
+24
View File
@@ -0,0 +1,24 @@
<?php
return array(
'does_not_exist' => 'Location does not exist.',
'assoc_users' => 'This location is currently associated with at least one user and cannot be deleted. Please update your users to no longer reference this location and try again. ',
'create' => array(
'error' => 'Location was not created, please try again.',
'success' => 'Location created successfully.'
),
'update' => array(
'error' => 'Location was not updated, please try again',
'success' => 'Location updated successfully.'
),
'delete' => array(
'error' => 'There was an issue deleting the location. Please try again.',
'success' => 'The location was deleted successfully.'
)
);
+11
View File
@@ -0,0 +1,11 @@
<?php
return array(
'id' => 'ID',
'name' => 'Name',
'city' => 'City',
'state' => 'State',
'country' => 'Country',
);
+1
View File
@@ -94,6 +94,7 @@ class Asset extends Elegant {
return DB::table('assets')
->where('physical', '=', '1')
->where('assigned_to', '=', '0')
->whereNull('status_id','and')
->whereNull('deleted_at','and')
->count();
+11 -1
View File
@@ -1,6 +1,16 @@
<?php
class Statuslabel extends Elegant {
protected $table = 'status_labels';
protected $table = 'status_labels';
protected $softDelete = true;
protected $rules = array(
'name' => 'required|min:2',
);
public function has_assets()
{
return $this->hasMany('Asset', 'status_id')->count();
}
}
+12
View File
@@ -121,6 +121,18 @@ Route::group(array('prefix' => 'admin'), function()
Route::get('{locationId}/delete', array('as' => 'delete/location', 'uses' => 'Controllers\Admin\LocationsController@getDelete'));
});
# Status Labels
Route::group(array('prefix' => 'statuslabels'), function()
{
Route::get('/', array('as' => 'statuslabels', 'uses' => 'Controllers\Admin\StatuslabelsController@getIndex'));
Route::get('create', array('as' => 'create/statuslabel', 'uses' => 'Controllers\Admin\StatuslabelsController@getCreate'));
Route::post('create', 'Controllers\Admin\StatuslabelsController@postCreate');
Route::get('{statuslabelId}/edit', array('as' => 'update/statuslabel', 'uses' => 'Controllers\Admin\StatuslabelsController@getEdit'));
Route::post('{statuslabelId}/edit', 'Controllers\Admin\StatuslabelsController@postEdit');
Route::get('{statuslabelId}/delete', array('as' => 'delete/statuslabel', 'uses' => 'Controllers\Admin\StatuslabelsController@getDelete'));
});
});
+13 -3
View File
@@ -105,8 +105,6 @@
</div>
</div>
<!-- Depreciation -->
<div class="control-group {{ $errors->has('depreciation_id') ? 'error' : '' }}">
<label class="control-label" for="parent">Depreciation</label>
@@ -118,6 +116,18 @@
</div>
</div>
<!-- Depreciation -->
<div class="control-group {{ $errors->has('status_id') ? 'error' : '' }}">
<label class="control-label" for="parent">Status</label>
<div class="controls">
<div class="field-box">
{{ Form::select('status_id', $statuslabel_list , Input::old('status_id', $asset->status_id), array('class'=>'select2', 'style'=>'width:250px')) }}
{{ $errors->first('depreciation_id', '<span class="help-inline">:message</span>') }}
</div>
</div>
</div>
<!-- Notes -->
<div class="control-group {{ $errors->has('notes') ? 'error' : '' }}">
<label class="control-label" for="notes">Notes</label>
@@ -136,7 +146,7 @@
<div class="control-group">
<div class="controls">
<a class="btn btn-link" href="{{ route('assets') }}">Cancel</a>
<button type="submit" class="btn-flat success"><i class="icon-ok icon-white"></i> Save </button>
<button type="submit" class="btn-flat success"><i class="icon-ok icon-white"></i> Save</button>
</div>
</div>
</form>
-12
View File
@@ -12,7 +12,6 @@ View Asset {{ $asset->asset_tag }} ::
<!-- header -->
<h3 class="name">History for {{ $asset->asset_tag }} ({{ $asset->name }})
<div class="btn-group pull-right">
<button class="btn glow">Actions</button>
<button class="btn glow dropdown-toggle" data-toggle="dropdown">
@@ -26,22 +25,11 @@ View Asset {{ $asset->asset_tag }} ::
<li><a href="{{ route('checkout/asset', $asset->id) }}" class="btn-flat success">Checkout</a></li>
@endif
<li><a href="{{ route('update/asset', $asset->id) }}">Edit Asset</a></li>
<li><a href="#">Out for Disagnostics</a></li>
<li><a href="#">Out for Repair</a></li>
<li><a href="#">Mark as Lost/Stolen</a></li>
</ul>
</div>
</h3>
<div class="row-fluid profile">
<!-- bio, new note & orders column -->
<div class="span9 bio">
+13 -1
View File
@@ -120,7 +120,12 @@
<a href="{{ URL::to('admin/groups') }}">
<i class="icon-group"></i> Groups
</a>
</li>
</li>
<li{{ (Request::is('admin/settings/statuslabels*') ? ' class="active"' : '') }}>
<a href="{{ URL::to('admin/settings/statuslabels') }}">
<i class="icon-list"></i> Status Labels
</a>
</li>
<li{{ (Request::is('admin/settings/manufacturers*') ? ' class="active"' : '') }}>
<a href="{{ URL::to('admin/settings/manufacturers') }}">
<i class="icon-briefcase"></i> Manufacturers
@@ -305,6 +310,10 @@
// jQuery Knobs
$(".knob").knob();
$("#example").popover();
// confirm delete modal
$('.delete-asset').click(function(evnt) {
var href = $(this).attr('href');
@@ -327,6 +336,9 @@
</script>
@@ -26,8 +26,6 @@ View License {{ $license->name }} ::
<li><a href="{{ route('checkout/license', $license->id) }}" class="btn-flat success">Checkout</a></li>
@endif
<li><a href="{{ route('update/license', $license->id) }}">Edit License</a></li>
<li><a href="#">Mark as Lost/Stolen</a></li>
</ul>
</div>
+1 -1
View File
@@ -2,7 +2,7 @@
{{-- Page title --}}
@section('title')
Asset Depreciations ::
Locations ::
@parent
@stop
+74
View File
@@ -0,0 +1,74 @@
@extends('backend/layouts/default')
{{-- Page title --}}
@section('title')
@if ($statuslabel->id)
Update Status Label ::
@else
Create New Status Label ::
@endif
@parent
@stop
{{-- Page content --}}
@section('content')
<div id="pad-wrapper" class="user-profile">
<!-- header -->
<h3 class="name">
@if ($statuslabel->id)
Update Status Label
@else
Create New Status Label
@endif
<div class="pull-right">
<a href="{{ route('statuslabels') }}" class="btn-flat gray"><i class="icon-circle-arrow-left icon-white"></i> Back</a>
</div>
</h3>
<div class="row-fluid profile">
<!-- bio, new note & orders column -->
<div class="span9 bio">
<div class="profile-box">
<br>
<!-- checked out assets table -->
<form class="form-horizontal" method="post" action="" autocomplete="off">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<div class="control-group {{ $errors->has('name') ? 'error' : '' }}">
<label class="control-label" for="name">Status Label</label>
<div class="controls">
<input class="span9" type="text" name="name" id="name" value="{{ Input::old('name', $statuslabel->name) }}" />
{{ $errors->first('name', '<span class="help-inline">:message</span>') }}
</div>
</div>
<!-- Form actions -->
<div class="control-group">
<div class="controls">
<a class="btn btn-link" href="{{ route('statuslabels') }}">@lang('general.cancel')</a>
<button type="submit" class="btn-flat success"><i class="icon-ok icon-white"></i> @lang('general.save')</button>
</div>
</div>
</form>
</div>
</div>
<!-- side address column -->
<div class="span3 address pull-right">
<br /><br />
<h6>About Status Labels</h6>
<p>Status labels are used to describe the various reasons why an asset <strong><em>cannot</em></strong> be deployed. </p>
<p>It could be broken, out for diagnostics, out for
repair, lost or stolen, etc. Status labels allow your team to show the progression.</p>
</div>
@stop
+65
View File
@@ -0,0 +1,65 @@
@extends('backend/layouts/default')
{{-- Page title --}}
@section('title')
Status Labels
@parent
@stop
{{-- Page content --}}
@section('content')
<div id="pad-wrapper" class="user-profile">
<!-- header -->
<h3 class="name">Status Labels
<div class="pull-right">
<a href="{{ route('create/statuslabel') }}" class="btn-flat success"><i class="icon-plus-sign icon-white"></i> Create New</a>
</div>
</h3>
<div class="row-fluid profile">
<!-- bio, new note & orders column -->
<div class="span9 bio">
<div class="profile-box">
<br>
<!-- checked out assets table -->
<table class="table table-hover">
<thead>
<tr>
<th class="span4">@lang('admin/statuslabels/table.name')</th>
<th class="span2"><span class="line"></span>@lang('table.actions')</th>
</tr>
</thead>
<tbody>
@foreach ($statuslabels as $statuslabel)
<tr>
<td>{{ $statuslabel->name }}</td>
<td>
<a href="{{ route('update/statuslabel', $statuslabel->id) }}" class="btn-flat white"> @lang('button.edit')</a>
<a class="btn-flat danger delete-asset" data-toggle="modal" href="{{ route('delete/statuslabel', $statuslabel->id) }}" data-content="Are you sure you wish to delete the {{ $statuslabel->name }} status label?" data-title="Delete {{ $statuslabel->name }}?" onClick="return false;">@lang('button.delete')</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<!-- side address column -->
<div class="span3 address pull-right">
<br><br>
<h6>About Status Labels</h6>
<p>Status labels are used to describe the various reasons why an asset <strong><em>cannot</em></strong> be deployed. </p>
<p>It could be broken, out for diagnostics, out for
repair, lost or stolen, etc. Status labels allow your team to show the progression.</p>
</div>
@stop
+5
View File
@@ -44,6 +44,11 @@
text-decoration: none;
}
#helpicon a:hover {
text-decoration: none;
}
.section {
border-top: 1px solid #edeff1;
margin-top: 100px;
+4
View File
@@ -8,6 +8,10 @@ body {
/*-webkit-font-smoothing: antialiased;*/
}
div.popover-content {
font-size: 12px;
}
h1, h2, h3, h4, h5 {
margin: 0;
line-height: inherit;