table deleting

pull/26/head
Ondřej Hruška 6 years ago
parent 8ff10904ce
commit 3bf9b68503
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 16
      app/Http/Controllers/TableController.php
  2. 2
      app/Http/Kernel.php
  3. 3
      app/Models/Concerns/Reportable.php
  4. 4
      app/Models/Table.php
  5. 4
      app/View/WidgetFactory.php
  6. 1
      resources/assets/sass/_helpers.scss
  7. 4
      resources/assets/sass/bootstrap-customizations/_border.scss
  8. 37
      resources/views/table/conf.blade.php
  9. 1
      routes/web.php

@ -43,6 +43,22 @@ class TableController extends Controller
]); ]);
} }
public function delete(Request $request, User $user, string $table)
{
/** @var Table $tableModel */
$tableModel = $user->tables()->where('name', $table)->first();
if ($tableModel === null) abort(404, "No such table.");
$this->authorize('delete', $tableModel);
if ($request->get('table-name', null) !== $table) {
return $this->backWithErrors(['table-name' => 'Fill table name']);
}
$tableModel->delete();
return redirect(route('profile.view', $user->name));
}
/** /**
* SHow a form for creating a new table * SHow a form for creating a new table
* *

@ -28,7 +28,7 @@ class Kernel extends HttpKernel
*/ */
protected $middlewareGroups = [ protected $middlewareGroups = [
'web' => [ 'web' => [
'throttle:60,15', // try to prevent people refresh-spamming the server to game table visit counts 'throttle:120,15', // try to prevent people refresh-spamming the server to game table visit counts
\App\Http\Middleware\EncryptCookies::class, \App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class, \Illuminate\Session\Middleware\StartSession::class,

@ -14,7 +14,8 @@ trait Reportable
{ {
public static function bootReportable() public static function bootReportable()
{ {
static::deleting(function(Reportable $self) { static::deleting(function($self) {
/** @var Reportable $self */
$self->reportsOf()->delete(); $self->reportsOf()->delete();
}); });
} }

@ -131,6 +131,10 @@ class Table extends BaseModel
return route('table.conf', ['user' => $this->cachedOwner()->name, 'table' => $this->name]); return route('table.conf', ['user' => $this->cachedOwner()->name, 'table' => $this->name]);
} }
if ($name == 'deleteRoute') {
return route('table.delete', ['user' => $this->cachedOwner()->name, 'table' => $this->name]);
}
return parent::__get($name); return parent::__get($name);
} }

@ -28,9 +28,11 @@ class WidgetFactory
public function par($text, $extraClasses='', $escape=true) public function par($text, $extraClasses='', $escape=true)
{ {
if (false === strpos($extraClasses, 'mb-')) $extraClasses .= ' mb-2';
return return
"<div class=\"row\">". "<div class=\"row\">".
"<p class=\"col-md-$this->fieldCols offset-md-$this->labelCols mb-2 ".e($extraClasses)."\">". "<p class=\"col-md-$this->fieldCols offset-md-$this->labelCols ".e($extraClasses)."\">".
($escape ? e($text) : $text) . ($escape ? e($text) : $text) .
"</p>". "</p>".
"</div>"; "</div>";

@ -16,4 +16,3 @@
.box-shadow { .box-shadow {
box-shadow: 0 2px 3px rgba(black, .3); box-shadow: 0 2px 3px rgba(black, .3);
} }

@ -11,3 +11,7 @@
border-color: $value !important; border-color: $value !important;
} }
} }
.border-2 {
border-width: 2px !important;
}

@ -25,7 +25,7 @@
</div> </div>
<form method="POST" action="{{$table->settingsRoute}}" class="row justify-content-center" <form method="POST" action="{{$table->settingsRoute}}" class="row justify-content-center"
aria-label="New Table"> aria-label="Change Table Metadata">
@csrf @csrf
<div class="col-md-10"> <div class="col-md-10">
@ -63,4 +63,39 @@
</div> </div>
</div> </div>
</form> </form>
<form method="POST" action="{{$table->deleteRoute}}" class="row justify-content-center mt-3"
aria-label="Delete table">
@csrf
<div class="col-md-6 offset-md-1 border border-danger rounded py-3 border-2">
@php(Widget::setLayout(0, 12))
{!! Widget::header(2, 'Delete Table') !!}
{!! Widget::par(
'Table deletion cannot be undone. However, data from the table may
remain accessible if any users forked it.', 'mb-0') !!}
<hr>
{!! Widget::par(
'Confirm table removal by typing its name:') !!}
<div class="row form-group">
<div class="col-md-12">
<div class="form-inline">
<input name="table-name"
class="form-control {{ $errors->has('table-name') ? ' is-invalid' : '' }}"
value="" placeholder="table-name">
<button type="submit" class="btn btn-danger ml-2">
@icon(fa-save fa-pr)Delete
</button>
</div>
</div>
</div>
</div>
</form>
@endsection @endsection

@ -56,6 +56,7 @@ Route::group(['middleware' => 'auth'], function () {
Route::get('@{user}/{table}/settings', 'TableController@settings')->name('table.conf'); Route::get('@{user}/{table}/settings', 'TableController@settings')->name('table.conf');
Route::post('@{user}/{table}/settings', 'TableController@storeSettings')->name('table.storeConf'); Route::post('@{user}/{table}/settings', 'TableController@storeSettings')->name('table.storeConf');
Route::post('@{user}/{table}/delete', 'TableController@delete')->name('table.delete');
}); });
// Table resource - located at the end to work as a fallback // Table resource - located at the end to work as a fallback

Loading…
Cancel
Save