diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 0ed0000..a40f362 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -12,6 +12,18 @@ use Illuminate\Http\Request; */ class ProfileController extends Controller { + private function profileTableListPrepareData(User $user) + { + $data['user'] = $user; + $data['tables_count'] = $user->tables()->count(); + $data['favourites_count'] = $user->favouriteTables()->count(); + + $data['tableSort'] = Table::resolveSortType(\Input::get('tableSort')); + $data['sortOptions'] = Table::getSortOptions(); + + return $data; + } + /** * Show the user's profile / dashboard. * @@ -19,13 +31,31 @@ class ProfileController extends Controller */ public function view(User $user) { - $data['user'] = $user; - $data['tables_count'] = $user->tables()->count(); + $data = $this->profileTableListPrepareData($user); - $data['tableSort'] = $sort = Table::resolveSortType(\Input::get('tableSort')); - $data['sortOptions'] = Table::getSortOptions(); + $data['pageVariant'] = 'tables'; + + $data['tables'] = $user->tables()->forList() + ->tableSort($data['tableSort']) + ->paginate(10); + + return view('profile.view', $data); + } + + /** + * Show the user's profile / dashboard. + * + * @return \Illuminate\View\View + */ + public function viewFavourites(User $user) + { + $data = $this->profileTableListPrepareData($user); + + $data['pageVariant'] = 'favourites'; - $data['tables'] = $user->tables()->forList()->tableSort($sort)->paginate(10); + $data['tables'] = $user->favouriteTables()->forList() + ->tableSort($data['tableSort']) + ->paginate(10); return view('profile.view', $data); } diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php index 63c3792..0001f1e 100644 --- a/app/Http/Controllers/TableController.php +++ b/app/Http/Controllers/TableController.php @@ -22,8 +22,19 @@ use MightyPork\Exceptions\NotApplicableException; use MightyPork\Exceptions\SimpleValidationException; use MightyPork\Utils\Utils; +/** + * Table view, creation, settings + */ class TableController extends Controller { + /** + * Helper to fetch a table by user and table name + * + * @param Request $request + * @param User $user + * @param string $table + * @return Table + */ private function resolveTable(Request $request, User $user, string $table) { /** @var Table $tableModel */ @@ -32,6 +43,29 @@ class TableController extends Controller return $tableModel; } + /** + * Favourite a table + */ + public function favouriteTable(Request $request, User $user, string $table) + { + $tableModel = $this->resolveTable($request, $user, $table); + \user()->favouriteTables()->attach($tableModel); + return redirect($tableModel->viewRoute); + } + + /** + * Un-favourite a table + */ + public function unfavouriteTable(Request $request, User $user, string $table) + { + $tableModel = $this->resolveTable($request, $user, $table); + \user()->favouriteTables()->detach($tableModel); + return redirect($tableModel->viewRoute); + } + + /** + * Switch table's current revision + */ public function revertTo(Request $request, User $user, string $table) { $input = $this->validate($request, [ @@ -51,6 +85,9 @@ class TableController extends Controller return redirect($tableModel->revisionsRoute); } + /** + * Show a table + */ public function view(Request $request, User $user, string $table) { $input = $this->validate($request, [ @@ -91,6 +128,9 @@ class TableController extends Controller ]); } + /** + * Delete a table + */ public function delete(Request $request, User $user, string $table) { $tableModel = $this->resolveTable($request, $user, $table); @@ -106,9 +146,7 @@ class TableController extends Controller } /** - * SHow a form for creating a new table - * - * @return \Illuminate\Http\Response + * Show a form for creating a new table */ public function create() { @@ -170,6 +208,9 @@ class TableController extends Controller return redirect($tableModel->viewRoute); // the route now changed } + /** + * List of table revisions + */ public function viewRevisions(Request $request, User $user, string $table) { $tableModel = $this->resolveTable($request, $user, $table); @@ -182,6 +223,24 @@ class TableController extends Controller ]); } + /** + * List of table favouriting users + */ + public function viewFavourites(Request $request, User $user, string $table) + { + $tableModel = $this->resolveTable($request, $user, $table); + + $users = $tableModel->favouritingUsers()->orderBy('title')->get(); + + return view('table.favourites', [ + 'table' => $tableModel, + 'users' => $users, + ]); + } + + /** + * Store a newly created table (save form) + */ public function storeNew(Request $request) { /** @var User $u */ diff --git a/app/helpers.php b/app/helpers.php index 81f0eed..f7b7894 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -7,7 +7,7 @@ const VALI_TEXT = 'string|max:4095'; const VALI_LINE = 'string|max:255'; const FEATURE_FORKS = false; -const FEATURE_FAVES = false; +const FEATURE_FAVES = true; const FEATURE_TABLE_COMMENTS = false; const FEATURE_PROPOSALS = false; diff --git a/resources/assets/sass/_helpers.scss b/resources/assets/sass/_helpers.scss index 2a87d5e..bf0206e 100644 --- a/resources/assets/sass/_helpers.scss +++ b/resources/assets/sass/_helpers.scss @@ -17,6 +17,10 @@ box-shadow: 0 2px 3px rgba(black, .3); } +.box-shadow-thin { + box-shadow: 0 2px 3px rgba(black, .15); +} + .strike { text-decoration: line-through; } diff --git a/resources/views/profile/_profile-card.blade.php b/resources/views/profile/_profile-card.blade.php new file mode 100644 index 0000000..960dcd2 --- /dev/null +++ b/resources/views/profile/_profile-card.blade.php @@ -0,0 +1,69 @@ +@php +/** @var \App\Models\User $user */ +@endphp + +
+
+ @icon(fa-user-circle-o fa-pr fa-large) +

+ @if(authed() && user()->is($user)) + @sr(Your dashboard -) + @else + @sr(User's page -) + @endif + {{ $user->title }} +

+ + @if(authed() && user()->is($user)) + Edit + @endif +
+ +
+ @if($user->bio) +
+ {!! Widget::collapsible($user->bio, 350, '8em')->srPrefix('About me:') !!} +
+ @endif + + + + + + @if($user->website) + + + + + @endif + + + + + + + + + + + +
@icon(fa-link, User's Website:){!! Widget::tryLink($user->website) !!}
@icon(fa-vcard-o, User's handle:){{ $user->handle }}
@icon(fa-calendar, Join date:) + + Joined {{ $user->created_at->diffForHumans() }} + +
+
+
diff --git a/resources/views/profile/_table-list.blade.php b/resources/views/profile/_table-list.blade.php index 391947c..be1a6f4 100644 --- a/resources/views/profile/_table-list.blade.php +++ b/resources/views/profile/_table-list.blade.php @@ -8,7 +8,7 @@
@if(count($tables) == 0) - No tables yet. + Nothing to show yet. @else @foreach($tables as $table) @php @@ -26,22 +26,22 @@ !!}{{ $table->title }}
- - {{ $table->visits }}@icon(fa-eye fa-pl, ~Visits~~) - - @if(FEATURE_FORKS) - - {{ $forks }}@icon(fa-code-fork fa-pl, ~Forks~~) - + + {{ $forks }}@icon(fa-code-fork fa-pl, ~Forks~~) + @endif @if(FEATURE_FAVES) - - {{ $faves }}@icon(fa-star fa-pl, ~Favourites~~) - + + {{ $faves }}@icon(fa-star fa-pl, ~Favourites~~) + @endif + + {{ $table->visits }}@icon(fa-eye fa-pl, ~Visits~~) + + {{ $revs }}@icon(fa-history fa-pl, ~Revisions~~) diff --git a/resources/views/profile/view.blade.php b/resources/views/profile/view.blade.php index f9cf909..9f7c358 100644 --- a/resources/views/profile/view.blade.php +++ b/resources/views/profile/view.blade.php @@ -12,89 +12,57 @@ {{-- Dash card --}}
+ @include('profile._profile-card') +
+ + {{-- Table list card --}} +
- @icon(fa-user-circle-o fa-pr fa-large) -

- @if(authed() && user()->is($user)) - @sr(Your dashboard -) - @else - @sr(User's page -) - @endif - {{ $user->title }} -

+ @if($pageVariant == 'tables') - @if(authed() && user()->is($user)) - Edit - @endif -
+ @icon(fa-table fa-pr fa-large) +

+ @if(authed() && user()->is($user)) + Your Tables: + @else + User's Tables: + @endif +

-
- @if($user->bio) -
- {!! Widget::collapsible($user->bio, 350, '8em')->srPrefix('About me:') !!} -
- @endif + @include('table._sort-dropdown', [ + 'link' => route('profile.view', + Input::except(['tableSort', 'page']) + + ['tableSort' => '__sort'] + ['user' => $user->name]) + ]) - - - @if($user->website) - - - - - @endif + @elseif($pageVariant == 'favourites') - - - - + @icon(fa-star fa-pr fa-large) +

+ @if(authed() && user()->is($user)) + Your Favourites: + @else + User's Favourites: + @endif +

- - - - + @include('table._sort-dropdown', [ + 'link' => route('profile.view-favourites', + Input::except(['tableSort', 'page']) + + ['tableSort' => '__sort'] + ['user' => $user->name]) + ]) - - - - - -
@icon(fa-link, User's Website:){!! Widget::tryLink($user->website) !!}
@icon(fa-vcard-o, User's handle:){{ $user->handle }}
@icon(fa-table, Tables:){{ $tables_count }} table{{$tables_count!=1?'s':''}}
@icon(fa-calendar, Join date:) - - Joined {{ $user->created_at->diffForHumans() }} - -
-
-
-
- - {{-- Table list card --}} -
-
-
- @icon(fa-table fa-pr fa-large) -

- @if(authed() && user()->is($user)) - Your Tables: - @else - User's Tables: - @endif -

- - @include('table._sort-dropdown', [ - 'link' => route('profile.view', - Input::except(['tableSort', 'page']) - + ['tableSort' => '__sort'] + ['user' => $user->name]) - ]) + @endif - @if(authed() && user()->is($user) && user()->confirmed) - New + @if($pageVariant == 'tables') + @if(authed() && user()->is($user) && user()->confirmed) + New + @endif @endif
diff --git a/resources/views/table/_table-subpage-header.blade.php b/resources/views/table/_table-subpage-header.blade.php new file mode 100644 index 0000000..631b587 --- /dev/null +++ b/resources/views/table/_table-subpage-header.blade.php @@ -0,0 +1,10 @@ +
+
+ @include('table._header-handle') + +

{{ $table->title }}

+ + @icon(fa-reply, sr:Back to Table) + +
+
diff --git a/resources/views/table/_view-action-buttons.blade.php b/resources/views/table/_view-action-buttons.blade.php index 9d12d30..f79217c 100644 --- a/resources/views/table/_view-action-buttons.blade.php +++ b/resources/views/table/_view-action-buttons.blade.php @@ -22,7 +22,7 @@ @if(FEATURE_FAVES) {{-- Passive favourite buttons with counter --}} - + @icon(fa-star, sr:Favourites)  {{ $table->favourites_count ?: '–' }} @@ -47,15 +47,15 @@ {{-- Active favourite button | counter --}} diff --git a/resources/views/table/favourites.blade.php b/resources/views/table/favourites.blade.php new file mode 100644 index 0000000..eb060ef --- /dev/null +++ b/resources/views/table/favourites.blade.php @@ -0,0 +1,44 @@ +{{-- List of table revisions --}} + +@extends('layouts.app') +@section('title', "Favouriting Users - $table->title") + +@php +/** @var \App\Models\Table $table */ +/** @var \App\Models\User[]|\Illuminate\Support\Collection $users */ +@endphp + +@section('content') + @include('table._table-subpage-header') + +
+
+

Favouriting Users

+
+ +
+ @foreach($users as $user) + + @endforeach +
+
+@endsection diff --git a/resources/views/table/revisions.blade.php b/resources/views/table/revisions.blade.php index 3ce1337..51e98a2 100644 --- a/resources/views/table/revisions.blade.php +++ b/resources/views/table/revisions.blade.php @@ -9,16 +9,7 @@ @endphp @section('content') -
-
- @include('table._header-handle') - -

{{ $table->title }}

- - @icon(fa-reply, sr:Back to Table) - -
-
+ @include('table._table-subpage-header')
diff --git a/routes/web.php b/routes/web.php index cd93582..c0efe7b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -43,9 +43,13 @@ Route::get('/home', function () { // Table resource Route::get('@{user}', 'ProfileController@view')->name('profile.view'); +Route::get('@{user}/!favourites', 'ProfileController@viewFavourites')->name('profile.view-favourites'); Route::get('@{user}/{table}', 'TableController@view')->name('table.view'); Route::get('@{user}/{table}/revisions', 'TableController@viewRevisions')->name('table.revisions'); Route::get('@{user}/{table}/export', 'TableController@export')->name('table.export'); +Route::get('@{user}/{table}/favourite', 'TableController@favouriteTable')->name('table.favourite'); +Route::get('@{user}/{table}/unfavourite', 'TableController@unfavouriteTable')->name('table.unfavourite'); +Route::get('@{user}/{table}/favourites', 'TableController@viewFavourites')->name('table.favourites'); // Routes for confirmed users