added the favourites feature

master
Ondřej Hruška 6 years ago
parent 86b7db48b3
commit 3f69ef3390
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 40
      app/Http/Controllers/ProfileController.php
  2. 65
      app/Http/Controllers/TableController.php
  3. 2
      app/helpers.php
  4. 4
      resources/assets/sass/_helpers.scss
  5. 69
      resources/views/profile/_profile-card.blade.php
  6. 22
      resources/views/profile/_table-list.blade.php
  7. 108
      resources/views/profile/view.blade.php
  8. 10
      resources/views/table/_table-subpage-header.blade.php
  9. 8
      resources/views/table/_view-action-buttons.blade.php
  10. 44
      resources/views/table/favourites.blade.php
  11. 11
      resources/views/table/revisions.blade.php
  12. 4
      routes/web.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);
}

@ -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 */

@ -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;

@ -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;
}

@ -0,0 +1,69 @@
@php
/** @var \App\Models\User $user */
@endphp
<div class="card">
<div class="card-header card-header-extra">
@icon(fa-user-circle-o fa-pr fa-large)
<h1>
@if(authed() && user()->is($user))
@sr(Your dashboard -)
@else
@sr(User's page -)
@endif
{{ $user->title }}
</h1>
@if(authed() && user()->is($user))
<a href="{{route('profile.edit')}}" class="btn ml-auto" aria-label="Edit Profile">Edit</a>
@endif
</div>
<div class="card-body">
@if($user->bio)
<div class="mb-3">
{!! Widget::collapsible($user->bio, 350, '8em')->srPrefix('About me:') !!}
</div>
@endif
<div class="mb-3">
@if($tables_count)
<a href="{{ route('profile.view', $user->name) }}" class="btn btn-sm btn-outline-primary">
@icon(fa-table fa-pr)Tables <span class="badge">{{$tables_count}}</span>
</a>
@endif
@if($favourites_count)
<a href="{{ route('profile.view-favourites', $user->name) }}" class="btn btn-sm btn-outline-primary">
@icon(fa-star fa-pr)Favourites <span class="badge">{{$favourites_count}}</span>
</a>
@endif
</div>
<table class="bio-table">
<tbody>
@if($user->website)
<tr>
<td class="text-center pr-2">@icon(fa-link, User's Website:)</td>
<td>{!! Widget::tryLink($user->website) !!}</td>
</tr>
@endif
<tr>
<td class="text-center pr-2">@icon(fa-vcard-o, User's handle:)</td>
<td>{{ $user->handle }}</td>
</tr>
<tr>
<td class="text-center pr-2">@icon(fa-calendar, Join date:)</td>
<td>
<span class="pr-1" data-toggle="tooltip" data-placement="right"
title="{{ $user->created_at->format('M n, Y \\a\\t G:i') }}">
Joined {{ $user->created_at->diffForHumans() }}
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>

@ -8,7 +8,7 @@
<div class="list-group list-group-flush">
@if(count($tables) == 0)
<span class="list-group-item">No tables yet.</span>
<span class="list-group-item">Nothing to show yet.</span>
@else
@foreach($tables as $table)
@php
@ -26,22 +26,22 @@
!!}<b>{{ $table->title }}</b>
</span>
<div class="d-flex justify-content-end col-5 small text-right">
<span title="Visits" class="d-inline-block pl-2" style="min-width: 50px;">
{{ $table->visits }}@icon(fa-eye fa-pl, ~Visits~~)
</span>
@if(FEATURE_FORKS)
<span title="Forks" class="d-inline-block pl-2 {{$forks==0?'hidden':''}}" style="min-width: 50px;">
{{ $forks }}@icon(fa-code-fork fa-pl, ~Forks~~)
</span>
<span title="Forks" class="d-inline-block pl-2 {{$forks==0?'hidden':''}}" style="min-width: 50px;">
{{ $forks }}@icon(fa-code-fork fa-pl, ~Forks~~)
</span>
@endif
@if(FEATURE_FAVES)
<span title="Favourites" class="d-inline-block pl-2 {{$faves==0?'hidden':''}}" style="min-width: 50px;">
{{ $faves }}@icon(fa-star fa-pl, ~Favourites~~)
</span>
<span title="Favourites" class="d-inline-block pl-2 {{$faves==0?'hidden':''}}" style="min-width: 50px;">
{{ $faves }}@icon(fa-star fa-pl, ~Favourites~~)
</span>
@endif
<span title="Visits" class="d-inline-block pl-2" style="min-width: 50px;">
{{ $table->visits }}@icon(fa-eye fa-pl, ~Visits~~)
</span>
<span title="Revisions" class="d-inline-block pl-2" style="min-width: 50px;">
{{ $revs }}@icon(fa-history fa-pl, ~Revisions~~)
</span>

@ -12,89 +12,57 @@
{{-- Dash card --}}
<div class="col-md-4">
@include('profile._profile-card')
</div>
{{-- Table list card --}}
<div class="col-md-8 mt-2 mt-md-0">
<div class="card">
<div class="card-header card-header-extra">
@icon(fa-user-circle-o fa-pr fa-large)
<h1>
@if(authed() && user()->is($user))
@sr(Your dashboard -)
@else
@sr(User's page -)
@endif
{{ $user->title }}
</h1>
@if($pageVariant == 'tables')
@if(authed() && user()->is($user))
<a href="{{route('profile.edit')}}" class="btn ml-auto" aria-label="Edit Profile">Edit</a>
@endif
</div>
@icon(fa-table fa-pr fa-large)
<h2>
@if(authed() && user()->is($user))
Your Tables:
@else
User's Tables:
@endif
</h2>
<div class="card-body">
@if($user->bio)
<div class="mb-3">
{!! Widget::collapsible($user->bio, 350, '8em')->srPrefix('About me:') !!}
</div>
@endif
@include('table._sort-dropdown', [
'link' => route('profile.view',
Input::except(['tableSort', 'page'])
+ ['tableSort' => '__sort'] + ['user' => $user->name])
])
<table class="bio-table">
<tbody>
@if($user->website)
<tr>
<td class="text-center pr-2">@icon(fa-link, User's Website:)</td>
<td>{!! Widget::tryLink($user->website) !!}</td>
</tr>
@endif
@elseif($pageVariant == 'favourites')
<tr>
<td class="text-center pr-2">@icon(fa-vcard-o, User's handle:)</td>
<td>{{ $user->handle }}</td>
</tr>
@icon(fa-star fa-pr fa-large)
<h2>
@if(authed() && user()->is($user))
Your Favourites:
@else
User's Favourites:
@endif
</h2>
<tr>
<td class="text-center pr-2">@icon(fa-table, Tables:)</td>
<td>{{ $tables_count }} table{{$tables_count!=1?'s':''}}</td>
</tr>
@include('table._sort-dropdown', [
'link' => route('profile.view-favourites',
Input::except(['tableSort', 'page'])
+ ['tableSort' => '__sort'] + ['user' => $user->name])
])
<tr>
<td class="text-center pr-2">@icon(fa-calendar, Join date:)</td>
<td>
<span class="pr-1" data-toggle="tooltip" data-placement="right"
title="{{ $user->created_at->format('M n, Y \\a\\t G:i') }}">
Joined {{ $user->created_at->diffForHumans() }}
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
{{-- Table list card --}}
<div class="col-md-8 mt-2 mt-md-0">
<div class="card">
<div class="card-header card-header-extra">
@icon(fa-table fa-pr fa-large)
<h2>
@if(authed() && user()->is($user))
Your Tables:
@else
User's Tables:
@endif
</h2>
@include('table._sort-dropdown', [
'link' => route('profile.view',
Input::except(['tableSort', 'page'])
+ ['tableSort' => '__sort'] + ['user' => $user->name])
])
@endif
<nav class="ml-auto" aria-label="Pages of the table list">
{{ $tables->links(null, ['ulClass' => 'pagination-sm mb-0 pagination-outline-light']) }}
</nav>
@if(authed() && user()->is($user) && user()->confirmed)
<a href="{{route('table.create')}}" class="btn ml-3" aria-label="New Table">New</a>
@if($pageVariant == 'tables')
@if(authed() && user()->is($user) && user()->confirmed)
<a href="{{route('table.create')}}" class="btn ml-3" aria-label="New Table">New</a>
@endif
@endif
</div>

@ -0,0 +1,10 @@
<div class="row justify-content-start px-3">
<div class="d-flex w-100 align-items-center">
@include('table._header-handle')
<h1 class="mx-3" id="table-title">{{ $table->title }}</h1>
<a href="{{ $table->viewRoute }}" class="btn btn-outline-primary py-1 btn-sm" @tooltip(Back to Table)>
@icon(fa-reply, sr:Back to Table)
</a>
</div>
</div>

@ -22,7 +22,7 @@
@if(FEATURE_FAVES)
{{-- Passive favourite buttons with counter --}}
<a href="" class="btn btn-outline-primary py-1 btn-sm" @tooltip(Favourites)>
<a href="{{ $table->actionRoute('favourites') }}" class="btn btn-outline-primary py-1 btn-sm" @tooltip(Favourites)>
@icon(fa-star, sr:Favourites)&nbsp;
{{ $table->favourites_count ?: '–' }}
</a>
@ -47,15 +47,15 @@
{{-- Active favourite button | counter --}}
<div class="btn-group" role="group" aria-label="Favourite">
@if(user()->favouritesTable($table))
<a href="" class="btn btn-outline-primary py-1 btn-sm btn-square" @tooltip(Un-favourite)>
<a href="{{ $table->actionRoute('unfavourite') }}" class="btn btn-outline-primary py-1 btn-sm btn-square" @tooltip(Un-favourite)>
@icon(fa-star, sr:Un-favourite)
</a>
@else
<a href="" class="btn btn-outline-primary py-1 btn-sm btn-square" @tooltip(Favourite)>
<a href="{{ $table->actionRoute('favourite') }}" class="btn btn-outline-primary py-1 btn-sm btn-square" @tooltip(Favourite)>
@icon(fa-star-o, sr:Favourite)
</a>
@endif
<a href="" class="btn btn-outline-primary py-1 btn-sm" @tooltip(Favourite Count)>
<a href="{{ $table->actionRoute('favourites') }}" class="btn btn-outline-primary py-1 btn-sm" @tooltip(Favourite Count)>
{{ $table->favourites_count ?: '–' }}
</a>
</div>

@ -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')
<div class="row px-3 border-top pt-3">
<div class="col-md-12">
<h2>Favouriting Users</h2>
</div>
<div class="col-md-12 d-flex flex-wrap">
@foreach($users as $user)
<div class="col-md-4 px-0">
<div class="rounded border box-shadow-thin m-1 px-2 d-flex align-items-center py-1">
<span class="flex-grow-1" style="font-size:140%;font-weight:bold">
{{ $user->title }}
</span>
<span>
<a href="{{route('profile.view', $user->name)}}"
class="btn btn-outline-secondary btn-sm"
>
@icon(fa-user fa-pr)Profile
</a>
<a href="{{route('profile.view-favourites', $user->name)}}"
class="btn btn-outline-secondary btn-sm"
>
@icon(fa-star fa-pr)Faves
</a>
</span>
</div>
</div>
@endforeach
</div>
</div>
@endsection

@ -9,16 +9,7 @@
@endphp
@section('content')
<div class="row justify-content-start px-3">
<div class="d-flex w-100 align-items-center">
@include('table._header-handle')
<h1 class="mx-3" id="table-title">{{ $table->title }}</h1>
<a href="{{ $table->viewRoute }}" class="btn btn-outline-primary py-1 btn-sm" @tooltip(Back to Table)>
@icon(fa-reply, sr:Back to Table)
</a>
</div>
</div>
@include('table._table-subpage-header')
<div class="row px-3 border-top pt-3">
<div class="col-md-12">

@ -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

Loading…
Cancel
Save