A free open source IT asset/license management system
Updated resources, named routes, tests for Locations
snipec308fbce0dc3
diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.phpindex 0daaeb390b..6345c67efd 100755--- a/app/Http/Controllers/LocationsController.php+++ b/app/Http/Controllers/LocationsController.php@@ -33,7 +33,7 @@ class LocationsController extends Controller* @since [v1.0]* @return View*/- public function getIndex()+ public function index(){// Grab all the locations$locations = Location::orderBy('created_at', 'DESC')->with('parent', 'assets', 'assignedassets')->get();@@ -51,7 +51,7 @@ class LocationsController extends Controller* @since [v1.0]* @return View*/- public function getCreate()+ public function create(){$locations = Location::orderBy('name', 'ASC')->get();@@ -74,14 +74,11 @@ class LocationsController extends Controller* @since [v1.0]* @return Redirect*/- public function postCreate()+ public function store(){- // create a new location instance$location = new Location();-- // Save the location data$location->name = e(Input::get('name'));if (Input::get('parent_id')=='') {$location->parent_id = null;@@ -98,10 +95,8 @@ class LocationsController extends Controller$location->user_id = Auth::user()->id;if ($location->save()) {- // Redirect to the new location page- return redirect()->to("admin/settings/locations")->with('success', trans('admin/locations/message.create.success'));+ return redirect()->route("locations.index")->with('success', trans('admin/locations/message.create.success'));}-return redirect()->back()->withInput()->withErrors($location->getErrors());}@@ -115,7 +110,7 @@ class LocationsController extends Controller* @since [v1.0]* @return String JSON*/- public function store()+ public function apiStore(){$new['currency']=Setting::first()->default_currency;@@ -156,7 +151,7 @@ class LocationsController extends Controller* @since [v1.0]* @return View*/- public function getEdit($locationId = null)+ public function edit($locationId = null){// Check if the location existsif (is_null($item = Location::find($locationId))) {@@ -182,7 +177,7 @@ class LocationsController extends Controller* @since [v1.0]* @return Redirect*/- public function postEdit($locationId = null)+ public function update($locationId = null){// Check if the location existsif (is_null($location = Location::find($locationId))) {@@ -224,7 +219,7 @@ class LocationsController extends Controller* @since [v1.0]* @return Redirect*/- public function getDelete($locationId)+ public function destroy($locationId){// Check if the location existsif (is_null($location = Location::find($locationId))) {@@ -262,7 +257,7 @@ class LocationsController extends Controller* @since [v1.0]* @return View*/- public function getView($locationId = null)+ public function show($locationId = null){$location = Location::find($locationId);@@ -332,11 +327,11 @@ class LocationsController extends Controller$rows = array();foreach ($locations as $location) {- $actions = '<nobr><a href="'.route('update/location', $location->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/location', $location->id).'" data-content="'.trans('admin/locations/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($location->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>';+ $actions = '<nobr><a href="'.route('locations.edit', ['location' => $location->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('locations.destroy', ['location' => $location->id]).'" data-content="'.trans('admin/locations/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($location->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>';$rows[] = array('id' => $location->id,- 'name' => (string)link_to('admin/settings/locations/'.$location->id.'/view', e($location->name)),+ 'name' => (string)link_to_route('locations.show', e($location->name), ['location' => $location->id]),'parent' => ($location->parent) ? e($location->parent->name) : '',// 'assets' => ($location->assets->count() + $location->assignedassets->count()),'assets_default' => $location->assignedassets->count(),diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.phpindex c79e9e3944..720e9bdec4 100644--- a/resources/views/layouts/default.blade.php+++ b/resources/views/layouts/default.blade.php@@ -352,7 +352,7 @@</a></li><li {!! (Request::is('settings/locations*') ? ' class="active"' : '') !!}>- <a href="{{ url('admin/settings/locations') }}">+ <a href="{{ route('locations.index') }}"><i class="fa fa-globe fa-fw"></i> @lang('general.locations')</a></li>diff --git a/resources/views/locations/edit.blade.php b/resources/views/locations/edit.blade.phpindex aa692f4344..d48c345b47 100755--- a/resources/views/locations/edit.blade.php+++ b/resources/views/locations/edit.blade.php@@ -2,7 +2,8 @@'createText' => trans('admin/locations/table.create') ,'updateText' => trans('admin/locations/table.update'),'helpTitle' => trans('admin/locations/table.about_locations_title'),- 'helpText' => trans('admin/locations/table.about_locations')+ 'helpText' => trans('admin/locations/table.about_locations'),+ 'formAction' => ($item) ? route('locations.update', ['location' => $item->id]) : route('locations.store'),]){{-- Page content --}}diff --git a/resources/views/locations/index.blade.php b/resources/views/locations/index.blade.phpindex d97400c5cc..2f226f5701 100755--- a/resources/views/locations/index.blade.php+++ b/resources/views/locations/index.blade.php@@ -7,7 +7,7 @@@stop@section('header_right')-<a href="{{ route('create/location') }}" class="btn btn-primary pull-right">+<a href="{{ route('locations.create') }}" class="btn btn-primary pull-right">{{ trans('general.create') }}</a>@stop{{-- Page content --}}diff --git a/routes/web.php b/routes/web.phpindex 11d59b1cfa..46194494cb 100644--- a/routes/web.php+++ b/routes/web.php@@ -27,6 +27,14 @@ Route::resource('companies', 'CompaniesController', ['parameters' => ['category' => 'category_id']]);+ /*+ * Locations+ */+ Route::resource('locations', 'LocationsController', [+ 'parameters' => ['location' => 'location_id']+ ]);++/*@@ -222,23 +230,7 @@ Route::group([ 'prefix' => 'admin','middleware' => ['web','auth']], function ());});- # Locations- Route::group([ 'prefix' => 'locations' ], function () {- Route::get('/', [ 'as' => 'locations', 'uses' => 'LocationsController@getIndex' ]);- Route::get('create', [ 'as' => 'create/location', 'uses' => 'LocationsController@getCreate' ]);- Route::post('create', 'LocationsController@postCreate');- Route::get(- '{locationId}/edit',- [ 'as' => 'update/location', 'uses' => 'LocationsController@getEdit' ]- );- Route::post('{locationId}/edit', 'LocationsController@postEdit');- Route::get('{locationId}/view', [ 'as' => 'view/location', 'uses' => 'LocationsController@getView' ]);- Route::get(- '{locationId}/delete',- [ 'as' => 'delete/location', 'uses' => 'LocationsController@getDelete' ]- );- });# Status LabelsRoute::group([ 'prefix' => 'statuslabels' ], function () {diff --git a/tests/functional/LocationsCest.php b/tests/functional/LocationsCest.phpindex c6b3ff4dbc..cc38af639a 100644--- a/tests/functional/LocationsCest.php+++ b/tests/functional/LocationsCest.php@@ -20,7 +20,7 @@ class LocationsCest/* Create Form */$I->wantTo('Test Location Creation');$I->lookForwardTo('Finding no Failures');- $I->amOnPage(route('create/location'));+ $I->amOnPage(route('locations.create'));$I->dontSee('Create Location', '.page-header');$I->see('Create Location', 'h1.pull-left');}@@ -28,7 +28,7 @@ class LocationsCestpublic function failsEmptyValidation(FunctionalTester $I){$I->wantTo("Test Validation Fails with blank elements");- $I->amOnPage(route('create/location'));+ $I->amOnPage(route('locations.create'));$I->click('Save');$I->seeElement('.alert-danger');$I->see('The name field is required.', '.alert-msg');@@ -37,7 +37,7 @@ class LocationsCestpublic function failsShortValidation(FunctionalTester $I){$I->wantTo("Test Validation Fails with short values");- $I->amOnPage(route('create/location'));+ $I->amOnPage(route('locations.create'));$I->fillField('name', 't');$I->click('Save');$I->seeElement('.alert-danger');@@ -58,7 +58,7 @@ class LocationsCest'zip' => $location->zip,];$I->wantTo("Test Validation Succeeds");- $I->amOnPage(route('create/location'));+ $I->amOnPage(route('locations.create'));$I->submitForm('form#create-form', $values);$I->seeRecord('locations', $values);$I->seeElement('.alert-success');@@ -67,7 +67,7 @@ class LocationsCestpublic function allowsDelete(FunctionalTester $I){$I->wantTo('Ensure I can delete a location');- $I->amOnPage(route('delete/location', Location::doesntHave('assets')->doesntHave('assignedAssets')->first()->id));+ $I->amOnPage(route('locations.destroy', Location::doesntHave('assets')->doesntHave('assignedAssets')->first()->id));$I->seeElement('.alert-success');}}