2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Input;
|
|
|
|
use Lang;
|
|
|
|
use App\Models\Statuslabel;
|
2016-05-24 16:06:09 -07:00
|
|
|
use App\Models\Asset;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Redirect;
|
|
|
|
use DB;
|
|
|
|
use App\Models\Setting;
|
|
|
|
use Str;
|
|
|
|
use View;
|
|
|
|
use App\Helpers\Helper;
|
|
|
|
use Auth;
|
2016-06-28 14:52:11 -07:00
|
|
|
use Illuminate\Http\Request;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
|
|
2016-04-07 13:21:09 -07:00
|
|
|
/**
|
|
|
|
* This controller handles all actions related to Status Labels for
|
|
|
|
* the Snipe-IT Asset Management application.
|
|
|
|
*
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
class StatuslabelsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Show a list of all the statuslabels.
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
|
2016-12-15 18:18:13 -08:00
|
|
|
public function index()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Show the page
|
|
|
|
return View::make('statuslabels/index', compact('statuslabels'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-24 16:06:09 -07:00
|
|
|
/**
|
|
|
|
* Show a count of assets by status label
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getAssetCountByStatuslabel()
|
|
|
|
{
|
|
|
|
$colors = [];
|
|
|
|
|
2016-08-02 13:25:50 -07:00
|
|
|
$statuslabels = Statuslabel::with('assets')->get();
|
2016-05-24 16:06:09 -07:00
|
|
|
$labels=[];
|
|
|
|
$points=[];
|
2016-08-02 13:25:50 -07:00
|
|
|
$colors=[];
|
2016-05-24 16:06:09 -07:00
|
|
|
foreach ($statuslabels as $statuslabel) {
|
2016-08-02 13:25:50 -07:00
|
|
|
if ($statuslabel->assets->count() > 0) {
|
|
|
|
$labels[]=$statuslabel->name;
|
|
|
|
$points[]=$statuslabel->assets()->whereNull('assigned_to')->count();
|
|
|
|
if ($statuslabel->color!='') {
|
|
|
|
$colors[]=$statuslabel->color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-24 16:06:09 -07:00
|
|
|
}
|
|
|
|
$labels[]='Deployed';
|
|
|
|
$points[]=Asset::whereNotNull('assigned_to')->count();
|
|
|
|
|
2016-08-02 13:25:50 -07:00
|
|
|
$colors_array = array_merge($colors, Helper::chartColors());
|
|
|
|
|
2016-05-24 16:06:09 -07:00
|
|
|
$result= [
|
|
|
|
"labels" => $labels,
|
|
|
|
"datasets" => [ [
|
|
|
|
"data" => $points,
|
2016-08-02 13:25:50 -07:00
|
|
|
"backgroundColor" => $colors_array,
|
|
|
|
"hoverBackgroundColor" => $colors_array
|
2016-05-24 16:06:09 -07:00
|
|
|
]]
|
|
|
|
];
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
/**
|
|
|
|
* Statuslabel create.
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-12-15 18:18:13 -08:00
|
|
|
public function create()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Show the page
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
$item = new Statuslabel;
|
|
|
|
$use_statuslabel_type = $item->getStatuslabelType();
|
2016-03-25 01:18:05 -07:00
|
|
|
$statuslabel_types = Helper::statusTypeList();
|
|
|
|
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
return View::make('statuslabels/edit', compact('statuslabel_types', 'item'))->with('use_statuslabel_type', $use_statuslabel_type);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Statuslabel create form processing.
|
|
|
|
*
|
|
|
|
* @return Redirect
|
|
|
|
*/
|
2016-12-15 18:18:13 -08:00
|
|
|
public function store(Request $request)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
// create a new model instance
|
|
|
|
$statuslabel = new Statuslabel();
|
2016-06-28 14:52:11 -07:00
|
|
|
|
|
|
|
if (!$request->has('statuslabel_types')) {
|
|
|
|
return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$statustype = Statuslabel::getStatuslabelTypesForDB($request->input('statuslabel_types'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Save the Statuslabel data
|
|
|
|
$statuslabel->name = e(Input::get('name'));
|
|
|
|
$statuslabel->user_id = Auth::user()->id;
|
|
|
|
$statuslabel->notes = e(Input::get('notes'));
|
|
|
|
$statuslabel->deployable = $statustype['deployable'];
|
|
|
|
$statuslabel->pending = $statustype['pending'];
|
|
|
|
$statuslabel->archived = $statustype['archived'];
|
2016-08-02 13:25:50 -07:00
|
|
|
$statuslabel->color = e(Input::get('color'));
|
2016-08-23 18:52:42 -07:00
|
|
|
$statuslabel->show_in_nav = e(Input::get('show_in_nav'),0);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
// Was the asset created?
|
|
|
|
if ($statuslabel->save()) {
|
|
|
|
// Redirect to the new Statuslabel page
|
2016-12-15 18:23:26 -08:00
|
|
|
return redirect()->route('statuslabels.index')->with('success', trans('admin/statuslabels/message.create.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($statuslabel->getErrors());
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-15 18:18:13 -08:00
|
|
|
public function apiStore(Request $request)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
$statuslabel = new Statuslabel();
|
2016-06-28 14:52:11 -07:00
|
|
|
if (!$request->has('statuslabel_types')) {
|
|
|
|
return JsonResponse::create(["error" => trans('validation.statuslabel_type')], 500);
|
|
|
|
}
|
|
|
|
|
2016-06-28 12:19:05 -07:00
|
|
|
$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
|
|
|
|
$statuslabel->name = e(Input::get('name'));
|
|
|
|
$statuslabel->user_id = Auth::user()->id;
|
|
|
|
$statuslabel->notes = '';
|
|
|
|
$statuslabel->deployable = $statustype['deployable'];
|
|
|
|
$statuslabel->pending = $statustype['pending'];
|
|
|
|
$statuslabel->archived = $statustype['archived'];
|
|
|
|
|
|
|
|
|
|
|
|
if ($statuslabel->isValid()) {
|
|
|
|
$statuslabel->save();
|
|
|
|
// Redirect to the new Statuslabel page
|
|
|
|
return JsonResponse::create($statuslabel);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-06-28 14:52:11 -07:00
|
|
|
return JsonResponse::create(["error" => $statuslabel->getErrors()->first()], 500);
|
2016-06-28 12:19:05 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Statuslabel update.
|
|
|
|
*
|
|
|
|
* @param int $statuslabelId
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-12-15 18:18:13 -08:00
|
|
|
public function edit($statuslabelId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Check if the Statuslabel exists
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
if (is_null($item = Statuslabel::find($statuslabelId))) {
|
2016-03-25 01:18:05 -07:00
|
|
|
// Redirect to the blogs management page
|
2016-12-15 18:23:26 -08:00
|
|
|
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
$use_statuslabel_type = $item->getStatuslabelType();
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-04-07 13:39:35 -07:00
|
|
|
$statuslabel_types = array('' => trans('admin/hardware/form.select_statustype')) + array('undeployable' => trans('admin/hardware/general.undeployable')) + array('pending' => trans('admin/hardware/general.pending')) + array('archived' => trans('admin/hardware/general.archived')) + array('deployable' => trans('admin/hardware/general.deployable'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
return View::make('statuslabels/edit', compact('item', 'statuslabel_types'))->with('use_statuslabel_type', $use_statuslabel_type);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Statuslabel update form processing page.
|
|
|
|
*
|
|
|
|
* @param int $statuslabelId
|
|
|
|
* @return Redirect
|
|
|
|
*/
|
2016-12-15 18:18:13 -08:00
|
|
|
public function update(Request $request, $statuslabelId = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Check if the Statuslabel exists
|
|
|
|
if (is_null($statuslabel = Statuslabel::find($statuslabelId))) {
|
|
|
|
// Redirect to the blogs management page
|
2016-12-15 18:23:26 -08:00
|
|
|
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.does_not_exist'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-06-28 14:52:11 -07:00
|
|
|
if (!$request->has('statuslabel_types')) {
|
|
|
|
return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]);
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Update the Statuslabel data
|
|
|
|
$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
|
|
|
|
$statuslabel->name = e(Input::get('name'));
|
|
|
|
$statuslabel->notes = e(Input::get('notes'));
|
|
|
|
$statuslabel->deployable = $statustype['deployable'];
|
|
|
|
$statuslabel->pending = $statustype['pending'];
|
|
|
|
$statuslabel->archived = $statustype['archived'];
|
2016-08-02 13:25:50 -07:00
|
|
|
$statuslabel->color = e(Input::get('color'));
|
2016-08-23 18:52:42 -07:00
|
|
|
$statuslabel->show_in_nav = e(Input::get('show_in_nav'),0);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
// Was the asset created?
|
|
|
|
if ($statuslabel->save()) {
|
|
|
|
// Redirect to the saved Statuslabel page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/settings/statuslabels/")->with('success', trans('admin/statuslabels/message.update.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($statuslabel->getErrors());
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Redirect to the Statuslabel management page
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->to("admin/settings/statuslabels/$statuslabelId/edit")->with('error', trans('admin/statuslabels/message.update.error'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the given Statuslabel.
|
|
|
|
*
|
|
|
|
* @param int $statuslabelId
|
|
|
|
* @return Redirect
|
|
|
|
*/
|
2016-12-15 18:18:13 -08:00
|
|
|
public function destroy($statuslabelId)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
|
|
|
// Check if the Statuslabel exists
|
|
|
|
if (is_null($statuslabel = Statuslabel::find($statuslabelId))) {
|
|
|
|
// Redirect to the blogs management page
|
2016-12-15 18:23:26 -08:00
|
|
|
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.not_found'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($statuslabel->has_assets() > 0) {
|
|
|
|
|
|
|
|
// Redirect to the asset management page
|
2016-12-15 18:23:26 -08:00
|
|
|
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.assoc_assets'));
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
|
|
|
|
|
|
|
$statuslabel->delete();
|
|
|
|
|
|
|
|
// Redirect to the statuslabels management page
|
2016-12-15 18:23:26 -08:00
|
|
|
return redirect()->route('statuslabels.index')->with('success', trans('admin/statuslabels/message.delete.success'));
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getDatatable()
|
|
|
|
{
|
2016-08-23 18:52:42 -07:00
|
|
|
$statuslabels = Statuslabel::select(array('id','name','deployable','pending','archived','color','show_in_nav'))
|
2016-03-25 01:18:05 -07:00
|
|
|
->whereNull('deleted_at');
|
|
|
|
|
|
|
|
if (Input::has('search')) {
|
|
|
|
$statuslabels = $statuslabels->TextSearch(e(Input::get('search')));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('offset')) {
|
|
|
|
$offset = e(Input::get('offset'));
|
|
|
|
} else {
|
|
|
|
$offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::has('limit')) {
|
|
|
|
$limit = e(Input::get('limit'));
|
|
|
|
} else {
|
|
|
|
$limit = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
$allowed_columns = ['id','name'];
|
|
|
|
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
|
|
|
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
|
|
|
|
|
|
|
|
$statuslabels->orderBy($sort, $order);
|
|
|
|
|
|
|
|
$statuslabelsCount = $statuslabels->count();
|
|
|
|
$statuslabels = $statuslabels->skip($offset)->take($limit)->get();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
|
|
|
foreach ($statuslabels as $statuslabel) {
|
|
|
|
|
|
|
|
if ($statuslabel->deployable == 1) {
|
2016-04-07 13:39:35 -07:00
|
|
|
$label_type = trans('admin/statuslabels/table.deployable');
|
2016-03-25 01:18:05 -07:00
|
|
|
} elseif ($statuslabel->pending == 1) {
|
2016-04-07 13:39:35 -07:00
|
|
|
$label_type = trans('admin/statuslabels/table.pending');
|
2016-03-25 01:18:05 -07:00
|
|
|
} elseif ($statuslabel->archived == 1) {
|
2016-04-07 13:39:35 -07:00
|
|
|
$label_type = trans('admin/statuslabels/table.archived');
|
2016-03-25 01:18:05 -07:00
|
|
|
} else {
|
2016-04-07 13:39:35 -07:00
|
|
|
$label_type = trans('admin/statuslabels/table.undeployable');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-12-15 18:18:13 -08:00
|
|
|
$actions = '<a href="'.route('statuslabels.edit', $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('statuslabels.destroy', $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>';
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-08-02 13:25:50 -07:00
|
|
|
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 = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
$rows[] = array(
|
2016-03-25 15:24:12 -07:00
|
|
|
'id' => e($statuslabel->id),
|
|
|
|
'type' => e($label_type),
|
2016-03-25 01:18:05 -07:00
|
|
|
'name' => e($statuslabel->name),
|
2016-08-02 13:25:50 -07:00
|
|
|
'color' => $color,
|
2016-08-23 18:52:42 -07:00
|
|
|
'show_in_nav' => ($statuslabel->show_in_nav=='1') ? trans('general.yes') : trans('general.no'),
|
2016-03-25 01:18:05 -07:00
|
|
|
'actions' => $actions
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array('total' => $statuslabelsCount, 'rows' => $rows);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|