Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function add_edit_collection($collection_id){
}


public function list(){
public function list(Request $request){
$collections = $this->userCollections(['VIEW_OWN','VIEW','MAINTAINER']);
$stats_rows = DB::table('documents')
->select('collection_id', DB::raw('count(*) as cnt'), DB::raw('sum(size) as size'))
Expand All @@ -61,7 +61,32 @@ public function list(){
foreach($stats_rows as $stat){
$stats[$stat->collection_id] = $stat;
}
return view('collections', ['title'=>'Smart Repository','activePage'=>'collections','titlePage'=>'Collections','collections'=>$collections, 'stats'=>$stats]);

// Handle sorting
$sort_by = $request->input('sort_by', 'name_asc'); // default to alphabetical ascending

switch($sort_by) {
case 'name_asc':
$collections = $collections->sortBy('name', SORT_NATURAL|SORT_FLAG_CASE);
break;
case 'name_desc':
$collections = $collections->sortByDesc('name', SORT_NATURAL|SORT_FLAG_CASE);
break;
case 'size_asc':
$collections = $collections->sortBy(function($collection) use ($stats) {
return isset($stats[$collection->id]) ? (int)$stats[$collection->id]->cnt : 0;
});
break;
case 'size_desc':
$collections = $collections->sortByDesc(function($collection) use ($stats) {
return isset($stats[$collection->id]) ? (int)$stats[$collection->id]->cnt : 0;
});
break;
default:
$collections = $collections->sortBy('name', SORT_NATURAL|SORT_FLAG_CASE);
}

return view('collections', ['title'=>'Smart Repository','activePage'=>'collections','titlePage'=>'Collections','collections'=>$collections, 'stats'=>$stats, 'sort_by'=>$sort_by]);
}

public function save(Request $request){
Expand Down
24 changes: 24 additions & 0 deletions resources/views/collections.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
@section('content')
<div class="container">
<div class="container-fluid">
<div class="row justify-content-end mb-3">
<div class="col-auto">
<div class="dropdown">
<button class="btn btn-sm btn-primary dropdown-toggle" type="button" id="sortDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="material-icons" style="font-size: 18px; vertical-align: middle;">settings</i> SORT
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="sortDropdown">
<a class="dropdown-item {{ (isset($sort_by) && $sort_by == 'name_asc') ? 'active' : '' }}" href="/collections?sort_by=name_asc">
<span style="display: inline-block; width: 35px;">A→Z</span> Name (A-Z)
</a>
<a class="dropdown-item {{ (isset($sort_by) && $sort_by == 'name_desc') ? 'active' : '' }}" href="/collections?sort_by=name_desc">
<span style="display: inline-block; width: 35px;">Z→A</span> Name (Z-A)
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item {{ (isset($sort_by) && $sort_by == 'size_desc') ? 'active' : '' }}" href="/collections?sort_by=size_desc">
<i class="material-icons" style="font-size: 16px; vertical-align: middle; display: inline-block; width: 35px;">arrow_downward</i> Documents (High to Low)
</a>
<a class="dropdown-item {{ (isset($sort_by) && $sort_by == 'size_asc') ? 'active' : '' }}" href="/collections?sort_by=size_asc">
<i class="material-icons" style="font-size: 16px; vertical-align: middle; display: inline-block; width: 35px;">arrow_upward</i> Documents (Low to High)
</a>
</div>
</div>
</div>
</div>
<div class="row justify-content-center">
@foreach ($collections as $c)
@if($c->content_type == 'Web resources' && env('SHOW_WEB_RESOURCES') != 1)
Expand Down