Browse Source

Add searchable and paged model update and deletation

Remove flash function call
tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
52b42d88d3
  1. 16
      src/stubs/controller.model.stub
  2. 2
      src/stubs/test-feature.stub
  3. 17
      src/stubs/view-forms.stub
  4. 14
      src/stubs/view-index.stub
  5. 16
      tests/Generators/ControllerGeneratorTest.php
  6. 2
      tests/Generators/FeatureTestGeneratorTest.php
  7. 31
      tests/Generators/ViewsGeneratorTest.php

16
src/stubs/controller.model.stub

@ -39,8 +39,6 @@ class MastersController extends Controller
Master::create($request->only('name', 'description')); Master::create($request->only('name', 'description'));
flash(trans('master.created'), 'success');
return redirect()->route('masters.index'); return redirect()->route('masters.index');
} }
@ -58,11 +56,11 @@ class MastersController extends Controller
'description' => 'required|max:255', 'description' => 'required|max:255',
]); ]);
$master = $master->update($request->only('name', 'description'));
$routeParam = request()->only('page', 'q');
flash(trans('master.updated'), 'success');
$master = $master->update($request->only('name', 'description'));
return redirect()->route('masters.index');
return redirect()->route('masters.index', $routeParam);
} }
/** /**
@ -77,14 +75,12 @@ class MastersController extends Controller
'master_id' => 'required', 'master_id' => 'required',
]); ]);
if (request('master_id') == $master->id && $master->delete()) {
flash(trans('master.deleted'), 'success');
$routeParam = request()->only('page', 'q');
return redirect()->route('masters.index');
if (request('master_id') == $master->id && $master->delete()) {
return redirect()->route('masters.index', $routeParam);
} }
flash(trans('master.undeleted'), 'error');
return back(); return back();
} }
} }

2
src/stubs/test-feature.stub

@ -59,7 +59,7 @@ class ManageMastersTest extends TestCase
$this->type('Master 1 description', 'description'); $this->type('Master 1 description', 'description');
$this->press(trans('master.update')); $this->press(trans('master.update'));
$this->visit(route('masters.index', ['q' => '123']));
$this->seePageIs(route('masters.index', ['q' => '123']));
$this->seeInDatabase('masters', [ $this->seeInDatabase('masters', [
'name' => 'Master 1 name', 'name' => 'Master 1 name',

17
src/stubs/view-forms.stub

@ -11,6 +11,12 @@
{!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster->id],'method' => 'patch']) !!} {!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster->id],'method' => 'patch']) !!}
{!! FormField::text('name') !!} {!! FormField::text('name') !!}
{!! FormField::textarea('description') !!} {!! FormField::textarea('description') !!}
@if (request('q'))
{{ Form::hidden('q', request('q')) }}
@endif
@if (request('page'))
{{ Form::hidden('page', request('page')) }}
@endif
{!! Form::submit(trans('master.update'), ['class' => 'btn btn-success']) !!} {!! Form::submit(trans('master.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!} {!! Form::close() !!}
@ -26,7 +32,16 @@
<hr style="margin:0"> <hr style="margin:0">
<div class="panel-body">{{ trans('app.delete_confirm') }}</div> <div class="panel-body">{{ trans('app.delete_confirm') }}</div>
<div class="panel-footer"> <div class="panel-footer">
{!! FormField::delete(['route'=>['masters.destroy',$editableMaster->id]], trans('app.delete_confirm_button'), ['class'=>'btn btn-danger'], ['master_id' => $editableMaster->id]) !!}
{!! FormField::delete(
['route'=>['items.destroy',$editableItem->id]],
trans('app.delete_confirm_button'),
['class'=>'btn btn-danger'],
[
'item_id' => $editableItem->id,
'page' => request('page'),
'q' => request('q'),
]
) !!}
{{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
</div> </div>
</div> </div>

14
src/stubs/view-index.stub

@ -24,8 +24,18 @@
<td>{{ $master->name }}</td> <td>{{ $master->name }}</td>
<td>{{ $master->description }}</td> <td>{{ $master->description }}</td>
<td class="text-center"> <td class="text-center">
{!! link_to_route('masters.index', trans('app.edit'), ['action' => 'edit', 'id' => $master->id], ['id' => 'edit-master-' . $master->id]) !!} |
{!! link_to_route('masters.index', trans('app.delete'), ['action' => 'delete', 'id' => $master->id], ['id' => 'del-master-' . $master->id]) !!}
{!! link_to_route(
'items.index',
trans('app.edit'),
['action' => 'edit', 'id' => $item->id] + Request::only('page', 'q'),
['id' => 'edit-item-' . $item->id]
) !!} |
{!! link_to_route(
'items.index',
trans('app.delete'),
['action' => 'delete', 'id' => $item->id] + Request::only('page', 'q'),
['id' => 'del-item-' . $item->id]
) !!}
</td> </td>
</tr> </tr>
@endforeach @endforeach

16
tests/Generators/ControllerGeneratorTest.php

@ -53,8 +53,6 @@ class ItemsController extends Controller
Item::create(\$request->only('name', 'description')); Item::create(\$request->only('name', 'description'));
flash(trans('item.created'), 'success');
return redirect()->route('items.index'); return redirect()->route('items.index');
} }
@ -72,11 +70,11 @@ class ItemsController extends Controller
'description' => 'required|max:255', 'description' => 'required|max:255',
]); ]);
\$item = \$item->update(\$request->only('name', 'description'));
\$routeParam = request()->only('page', 'q');
flash(trans('item.updated'), 'success');
\$item = \$item->update(\$request->only('name', 'description'));
return redirect()->route('items.index');
return redirect()->route('items.index', \$routeParam);
} }
/** /**
@ -91,14 +89,12 @@ class ItemsController extends Controller
'item_id' => 'required', 'item_id' => 'required',
]); ]);
if (request('item_id') == \$item->id && \$item->delete()) {
flash(trans('item.deleted'), 'success');
\$routeParam = request()->only('page', 'q');
return redirect()->route('items.index');
if (request('item_id') == \$item->id && \$item->delete()) {
return redirect()->route('items.index', \$routeParam);
} }
flash(trans('item.undeleted'), 'error');
return back(); return back();
} }
} }

2
tests/Generators/FeatureTestGeneratorTest.php

@ -110,7 +110,7 @@ class ManageItemsTest extends TestCase
\$this->type('Item 1 description', 'description'); \$this->type('Item 1 description', 'description');
\$this->press(trans('item.update')); \$this->press(trans('item.update'));
\$this->visit(route('items.index', ['q' => '123']));
\$this->seePageIs(route('items.index', ['q' => '123']));
\$this->seeInDatabase('items', [ \$this->seeInDatabase('items', [
'name' => 'Item 1 name', 'name' => 'Item 1 name',

31
tests/Generators/ViewsGeneratorTest.php

@ -39,8 +39,18 @@ class ViewsGeneratorTest extends TestCase
<td>{{ \$item->name }}</td> <td>{{ \$item->name }}</td>
<td>{{ \$item->description }}</td> <td>{{ \$item->description }}</td>
<td class=\"text-center\"> <td class=\"text-center\">
{!! link_to_route('items.index', trans('app.edit'), ['action' => 'edit', 'id' => \$item->id], ['id' => 'edit-item-' . \$item->id]) !!} |
{!! link_to_route('items.index', trans('app.delete'), ['action' => 'delete', 'id' => \$item->id], ['id' => 'del-item-' . \$item->id]) !!}
{!! link_to_route(
'items.index',
trans('app.edit'),
['action' => 'edit', 'id' => \$item->id] + Request::only('page', 'q'),
['id' => 'edit-item-' . \$item->id]
) !!} |
{!! link_to_route(
'items.index',
trans('app.delete'),
['action' => 'delete', 'id' => \$item->id] + Request::only('page', 'q'),
['id' => 'del-item-' . \$item->id]
) !!}
</td> </td>
</tr> </tr>
@endforeach @endforeach
@ -77,6 +87,12 @@ class ViewsGeneratorTest extends TestCase
{!! Form::model(\$editableItem, ['route' => ['items.update', \$editableItem->id],'method' => 'patch']) !!} {!! Form::model(\$editableItem, ['route' => ['items.update', \$editableItem->id],'method' => 'patch']) !!}
{!! FormField::text('name') !!} {!! FormField::text('name') !!}
{!! FormField::textarea('description') !!} {!! FormField::textarea('description') !!}
@if (request('q'))
{{ Form::hidden('q', request('q')) }}
@endif
@if (request('page'))
{{ Form::hidden('page', request('page')) }}
@endif
{!! Form::submit(trans('item.update'), ['class' => 'btn btn-success']) !!} {!! Form::submit(trans('item.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
{!! Form::close() !!} {!! Form::close() !!}
@ -92,7 +108,16 @@ class ViewsGeneratorTest extends TestCase
<hr style=\"margin:0\"> <hr style=\"margin:0\">
<div class=\"panel-body\">{{ trans('app.delete_confirm') }}</div> <div class=\"panel-body\">{{ trans('app.delete_confirm') }}</div>
<div class=\"panel-footer\"> <div class=\"panel-footer\">
{!! FormField::delete(['route'=>['items.destroy',\$editableItem->id]], trans('app.delete_confirm_button'), ['class'=>'btn btn-danger'], ['item_id' => \$editableItem->id]) !!}
{!! FormField::delete(
['route'=>['items.destroy',\$editableItem->id]],
trans('app.delete_confirm_button'),
['class'=>'btn btn-danger'],
[
'item_id' => \$editableItem->id,
'page' => request('page'),
'q' => request('q'),
]
) !!}
{{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {{ link_to_route('items.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
</div> </div>
</div> </div>

Loading…
Cancel
Save