add different table sort options, change default to last-updated

master
Ondřej Hruška 6 years ago
parent 83392e07ac
commit a9426759d2
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 51
      app/Http/Controllers/DashController.php
  2. 2
      app/Models/Table.php
  3. 26
      resources/views/welcome.blade.php

@ -20,16 +20,53 @@ class DashController extends Controller
return back();
}
$users = User::orderBy('updated_at', 'desc')
$data['tableSort'] = $sort = \Input::get('tableSort', 'last-updated');
$data['sortOptions'] = [
'most-visited' => 'Most Visited',
'last-updated' => 'Last Updated',
'most-updated' => 'Most Updated',
// 'most-discussed' => 'Most Discussed',
// 'most-liked' => 'Most Liked',
'newest' => 'Newest',
'oldest' => 'Oldest',
];
$data['users'] = User::orderBy('updated_at', 'desc')
->withCount(['tables'])
->paginate(10, ['id', 'title', 'name', 'tables_count'], 'pageu');
->paginate(10, ['id', 'title', 'name', 'tables_count'], 'userPage')
->appends(\Input::except('userPage'));
$tableQuery = Table::forList();
switch ($sort) {
case 'most-visited':
$tableQuery = $tableQuery->orderBy('visits', 'desc');
break;
case 'last-updated':
$tableQuery = $tableQuery->orderBy('updated_at', 'desc');
break;
case 'most-updated':
$tableQuery = $tableQuery->orderBy('revisions_count', 'desc');
break;
case 'most-discussed':
$tableQuery = $tableQuery->orderBy('comments_count', 'desc');
break;
case 'most-liked':
$tableQuery = $tableQuery->orderBy('favourites_count', 'desc');
break;
case 'newest':
$tableQuery = $tableQuery->orderBy('created_at', 'desc');
break;
case 'oldest':
$tableQuery = $tableQuery->orderBy('created_at', 'asc');
break;
}
$tables = Table::forList()
->orderBy('visits', 'desc')
->paginate(10, ['*'], 'paget');
$data['tables'] = $tableQuery->paginate(10, ['*'], 'tablePage')
->appends(\Input::except('tablePage'));
$showGreeter = !$dismiss && !$request->cookie('dismiss-greeter', false);
$data['showGreeter'] = !$dismiss && !$request->cookie('dismiss-greeter', false);
return view('welcome', compact('users', 'tables', 'showGreeter'));
return view('welcome', $data);
}
}

@ -189,6 +189,6 @@ class Table extends BaseModel
public function scopeForList(Builder $query)
{
return $query->with('revision:id,row_count')->with('owner:id,name,title')
->withCount(['favourites', 'forks', 'revisions', 'proposals']);
->withCount(['favourites', 'forks', 'revisions', 'proposals', 'comments']);
}
}

@ -1,5 +1,10 @@
{{-- Public landing page --}}
@php
/** @var \App\Models\User[]|\Illuminate\Support\Collection|\Illuminate\Pagination\LengthAwarePaginator $users */
/** @var \App\Models\Table[]|\Illuminate\Support\Collection|\Illuminate\Pagination\LengthAwarePaginator $tables */
@endphp
@extends('layouts.app')
@section('content')
@ -44,10 +49,27 @@
<div class="card">
<div class="card-header card-header-extra">
@icon(fa-table fa-pr fa-large)
<h2>Popular Tables</h2>
<h2>Tables:</h2>
<span>
<a class="nav-link dropdown-toggle link-no-color pl-1 ml-1 pr-2"
data-toggle="dropdown" href="#" role="button" aria-haspopup="true"
aria-expanded="false">{{ $sortOptions[$tableSort] }}</a>
<div class="dropdown-menu">
@foreach($sortOptions as $k => $label)
{{--@if($k != $tableSort)--}}
<a class="dropdown-item"
href="{{ route('dash', Input::except(['tableSort', 'tablePage']) + ['tableSort' => $k]) }}">
{{ $label }}
</a>
{{--@endif--}}
@endforeach
</div>
</span>
<nav class="ml-auto" aria-label="Pages of the table list">
{{ $tables->links(null, ['ulClass' => 'pagination-sm mb-0 pagination-outline-light']) }}
{{ $tables->links(null, [
'ulClass' => 'pagination-sm mb-0 pagination-outline-light'
]) }}
</nav>
@if(authed() && user()->confirmed)

Loading…
Cancel
Save