Skip to content

Commit

Permalink
Added status label functionality
Browse files Browse the repository at this point in the history
remember to run artisan DB migrations to make this work
  • Loading branch information
snipe committed Nov 21, 2013
1 parent f7cdc8d commit 5fae91d
Show file tree
Hide file tree
Showing 19 changed files with 371 additions and 96 deletions.
17 changes: 15 additions & 2 deletions app/controllers/admin/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Input;
use Lang;
use Asset;
use Statuslabel;
use User;
use Redirect;
use DB;
Expand Down Expand Up @@ -48,7 +49,10 @@ public function getCreate()
$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);

}

Expand Down Expand Up @@ -80,6 +84,7 @@ public function postCreate()
$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';

Expand Down Expand Up @@ -122,9 +127,13 @@ public function getEdit($assetId = null)
// 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);
}


Expand Down Expand Up @@ -171,6 +180,7 @@ public function postEdit($assetId = null)
$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';

Expand Down Expand Up @@ -232,6 +242,9 @@ public function getCheckout($assetId)
// 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);

Expand Down
116 changes: 53 additions & 63 deletions app/controllers/admin/StatuslabelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,46 @@
use AdminController;
use Input;
use Lang;
use Location;
use Statuslabel;
use Redirect;
use DB;
use Sentry;
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
*/
Expand All @@ -54,75 +53,69 @@ public function postCreate()
$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'));
}


Expand All @@ -132,60 +125,57 @@ public function postEdit($locationId = null)


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


Expand Down
36 changes: 36 additions & 0 deletions app/database/migrations/2013_11_21_002321_add_uploads_table.php
Original file line number Diff line number Diff line change
@@ -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');
}

}
Original file line number Diff line number Diff line change
@@ -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');
});
}

}
Loading

0 comments on commit 5fae91d

Please sign in to comment.