Skip to content

Commit

Permalink
Litteraturkritikk: Support (soft) deleting record
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Sep 13, 2019
1 parent 02493a5 commit a07b8cb
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 19 deletions.
35 changes: 33 additions & 2 deletions app/Http/Controllers/LitteraturkritikkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ public function store(Request $request, LitteraturkritikkSchema $schema)
*/
public function show(LitteraturkritikkSchema $schema, $id)
{
$record = Record::findOrFail($id);
if (\Auth::check()) {
$record = Record::withTrashed()->findOrFail($id);
} else {
$record = Record::findOrFail($id);
}

$data = [
'title' => $record->tittel ?: '#' . $record->id,
Expand Down Expand Up @@ -352,7 +356,34 @@ public function update(Request $request, LitteraturkritikkSchema $schema, $id)
*/
public function destroy($id)
{
//
$record = Record::findOrFail($id);

$record->delete();

// Refresh view
\DB::unprepared('REFRESH MATERIALIZED VIEW CONCURRENTLY litteraturkritikk_records_search');

return redirect()->action('LitteraturkritikkController@show', $id);
}

/**
* Restore the specified resource from trash.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function restore($id)
{
$record = Record::withTrashed()->findOrFail($id);

$record->restore();

// Refresh view
\DB::unprepared('REFRESH MATERIALIZED VIEW CONCURRENTLY litteraturkritikk_records_search');

return redirect()->action('LitteraturkritikkController@show', $id)
->with('status', 'Posten ble gjenopprettet');
}

/**
Expand Down
72 changes: 55 additions & 17 deletions resources/views/litteraturkritikk/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,63 @@

@section('content')

<p>
<a href="{{ URL::previous() }}"><i class="fa fa-arrow-circle-left"></i> Tilbake</a>
<div class="pb-3">

<a href="{{ URL::previous() }}" class="btn btn-outline-primary">
<em class="fa fa-arrow-circle-left"></em>
Tilbake
</a>

<a href="mailto:[email protected]?subject=Feil%20i%20post&body=Hei%0A%0ADet%20ser%20ut%20som%20det%20er%20en%20feil%20i%20denne%20posten%3A%0A%0Ahttps%3A%2F%2Fub-baser.uio.no%2Fnorsk_litteraturkritikk%2F{{ $record->id }}%0A%0A%5BUtdyp%5D" class="btn btn-outline-primary">
<em class="fa fa-envelope-o"></em>
Meld fra om feil
</a>

@can('litteraturkritikk')
&nbsp;
<a href="{{ action('LitteraturkritikkController@edit', $record->id) }}"><i class="fa fa-edit"></i> Rediger post</a>
@endif
</p>

<a href="{{ action('LitteraturkritikkController@edit', $record->id) }}" class="btn btn-outline-primary">
<i class="fa fa-edit"></i>
Rediger post
</a>

@if ($record->trashed())
<form style="display: inline-block" action="{{ action('LitteraturkritikkController@restore', $record->id) }}" method="post">
@csrf
<button type="submit" class="btn btn-outline-danger btn-xs">
<em class="fa fa-undo"></em>
Gjenopprett
</button>
</form>
@else
<form style="display: inline-block" action="{{ action('LitteraturkritikkController@destroy', $record->id) }}" method="post">
@csrf
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-outline-danger btn-xs">
<em class="fa fa-trash"></em>
Slett
</button>
</form>
@endif
@endcan
</div>


<div class="d-flex flex-column flex-sm-row">

<div class="flex-grow-1">
<h2>
Post {{ $record->id }}
</h2>
@if ($record->trashed())
<h2>
<s>Post {{ $record->id }}</s>
</h2>
<div class="alert alert-danger" role="alert">
Denne posten er mykslettet og vises ikke i søk eller for ikke-innloggede brukere.
Du kan imidlertid enkelt gjenopprette den om du ønsker det.
</div>
@else
<h2>
Post {{ $record->id }}
</h2>
@endif

@foreach ($schema->groups as $group)
<h4 class="mt-4">{{ $group->label }}</h4>
Expand Down Expand Up @@ -103,18 +145,14 @@
<dd class="col-sm-9">{{ $record->created_at }} av {{ $record->createdBy ? $record->createdBy->name : ' (import)' }}</dd>
<dt class="col-sm-3 text-sm-right">Sist endret:</dt>
<dd class="col-sm-9">{{ $record->updated_at }} av {{ $record->updatedBy ? $record->updatedBy->name : ' (import)' }}</dd>
@if ($record->deleted_at)
<dt class="col-sm-3 text-sm-right">Slettet:</dt>
<dd class="col-sm-9">{{ $record->deleted_at }}</dd>
@endif
</dl>
@endif
</div>

<div class="flex-grow-0 flex-shrink-0" style="width: 200px;">
<div class="px-4 py-3">
<a href="mailto:[email protected]?subject=Feil%20i%20post&body=Hei%0A%0ADet%20ser%20ut%20som%20det%20er%20en%20feil%20i%20denne%20posten%3A%0A%0Ahttps%3A%2F%2Fub-baser.uio.no%2Fnorsk_litteraturkritikk%2F{{ $record->id }}%0A%0A%5BUtdyp%5D" class="btn btn-outline-primary">
<em class="fa fa-envelope-o"></em>
Meld fra om feil
</a>
</div>
</div>
</div>

@endsection
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
Route::get('norsk-litteraturkritikk/{id}', 'LitteraturkritikkController@show');
Route::get('norsk-litteraturkritikk/{id}/edit', 'LitteraturkritikkController@edit');
Route::put('norsk-litteraturkritikk/{id}', 'LitteraturkritikkController@update');
Route::delete('norsk-litteraturkritikk/{id}', 'LitteraturkritikkController@destroy');
Route::post('norsk-litteraturkritikk/{id}/restore', 'LitteraturkritikkController@restore');

Route::post('norsk-litteraturkritikk/personer', 'LitteraturkritikkPersonController@store');
Route::get('norsk-litteraturkritikk/personer/{id}', 'LitteraturkritikkPersonController@show');
Expand Down

0 comments on commit a07b8cb

Please sign in to comment.