Backend for songs.zachdecook.com
homepage: add server-side sorting
Zach DeCook 2021-02-12
parent b1859f4 · commit d99588a
-rwxr-xr-xlaravel/public/index.gmi11
-rw-r--r--laravel/resources/views/welcome.blade.php12
2 files changed, 20 insertions, 3 deletions
diff --git a/laravel/public/index.gmi b/laravel/public/index.gmi
index 89db27b..492ed92 100755
--- a/laravel/public/index.gmi
+++ b/laravel/public/index.gmi
@@ -9,8 +9,15 @@ $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
use App\Song;
printf("20 text/gemini\r\n");
?>
-<?php foreach(Song::all()->pluck('title','id') as $id => $title): ?>
-=> /song.gmi.php/<?= $id ?> <?= $title ?>
+# Prosongsa Songs
+
+<?php foreach(['title','author'] as $key): ?>
+=> /?<?=$key?> Sort by <?=$key?>
+
+<?php endforeach; ?>
+
+<?php foreach(Song::all()->sortBy(getenv('QUERY_STRING')??'title')->pluck('title','id') as $id => $title): ?>
+=> /song.gmi.php/<?=$id?> <?= $title ?>
<?php endforeach; ?>
diff --git a/laravel/resources/views/welcome.blade.php b/laravel/resources/views/welcome.blade.php
index cc0e5d3..27167fe 100644
--- a/laravel/resources/views/welcome.blade.php
+++ b/laravel/resources/views/welcome.blade.php
@@ -8,8 +8,18 @@
<form>
<input id='toc-filter' placeholder='filter songs'>
</form>
+ Sort by:
+ @foreach(['id','title','author'] as $key)
+ <a href='/?sort={{$key}}'>
+ @if(($_GET['sort'] ??'title') ==$key)
+ <i>{{$key}}</i>
+ @else
+ <b>{{$key}}</b>
+ @endif
+ </a>
+ @endforeach
<ul id='toc'>
- @foreach( App\Song::all() as $song )
+ @foreach( App\Song::orderBy($_GET['sort']??'title')->get() as $song )
<li>
<a href='{{ route('song.show', ['song' => $song]) }}'>
{{ $song->name }}