Skip to content

Commit

Permalink
Updated resources, named routes, tests for Locations
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Dec 16, 2016
1 parent 3e4be66 commit c308fbc
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 40 deletions.
27 changes: 11 additions & 16 deletions app/Http/Controllers/LocationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -51,7 +51,7 @@ public function getIndex()
* @since [v1.0]
* @return View
*/
public function getCreate()
public function create()
{
$locations = Location::orderBy('name', 'ASC')->get();

Expand All @@ -74,14 +74,11 @@ public function getCreate()
* @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;
Expand All @@ -98,10 +95,8 @@ public function postCreate()
$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());

}
Expand All @@ -115,7 +110,7 @@ public function postCreate()
* @since [v1.0]
* @return String JSON
*/
public function store()
public function apiStore()
{

$new['currency']=Setting::first()->default_currency;
Expand Down Expand Up @@ -156,7 +151,7 @@ public function store()
* @since [v1.0]
* @return View
*/
public function getEdit($locationId = null)
public function edit($locationId = null)
{
// Check if the location exists
if (is_null($item = Location::find($locationId))) {
Expand All @@ -182,7 +177,7 @@ public function getEdit($locationId = null)
* @since [v1.0]
* @return Redirect
*/
public function postEdit($locationId = null)
public function update($locationId = null)
{
// Check if the location exists
if (is_null($location = Location::find($locationId))) {
Expand Down Expand Up @@ -224,7 +219,7 @@ public function postEdit($locationId = null)
* @since [v1.0]
* @return Redirect
*/
public function getDelete($locationId)
public function destroy($locationId)
{
// Check if the location exists
if (is_null($location = Location::find($locationId))) {
Expand Down Expand Up @@ -262,7 +257,7 @@ public function getDelete($locationId)
* @since [v1.0]
* @return View
*/
public function getView($locationId = null)
public function show($locationId = null)
{
$location = Location::find($locationId);

Expand Down Expand Up @@ -332,11 +327,11 @@ public function getDatatable()
$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(),
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion resources/views/locations/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 --}}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/locations/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 --}}
Expand Down
24 changes: 8 additions & 16 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
'parameters' => ['category' => 'category_id']
]);

/*
* Locations
*/
Route::resource('locations', 'LocationsController', [
'parameters' => ['location' => 'location_id']
]);




/*
Expand Down Expand Up @@ -222,23 +230,7 @@
);
});

# 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 Labels
Route::group([ 'prefix' => 'statuslabels' ], function () {
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/LocationsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public function tryToTest(FunctionalTester $I)
/* 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');
}

public 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');
Expand All @@ -37,7 +37,7 @@ public function failsEmptyValidation(FunctionalTester $I)
public 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');
Expand All @@ -58,7 +58,7 @@ public function passesCorrectValidation(FunctionalTester $I)
'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');
Expand All @@ -67,7 +67,7 @@ public function passesCorrectValidation(FunctionalTester $I)
public 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');
}
}

0 comments on commit c308fbc

Please sign in to comment.