about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@gmail.com>2018-12-27 10:22:36 -0500
committerZach DeCook <zachdecook@gmail.com>2018-12-27 10:22:36 -0500
commit1a9c3529c32df34b92538bb6599cf609fdf9bb3c (patch)
tree83d86919d15598314990cd4bd577c367a6452308
parent7057844718f20f47109549a0f26745d88d66e195 (diff)
downloadprosongsa-1a9c3529c32df34b92538bb6599cf609fdf9bb3c.tar.gz
* Song View: Add 'back to playlist' link
-rw-r--r--laravel/app/Http/Controllers/SongController.php30
-rw-r--r--laravel/resources/views/layouts/app.blade.php4
-rw-r--r--laravel/resources/views/playlist.blade.php11
-rw-r--r--laravel/resources/views/song.blade.php6
-rw-r--r--laravel/routes/web.php1
5 files changed, 48 insertions, 4 deletions
diff --git a/laravel/app/Http/Controllers/SongController.php b/laravel/app/Http/Controllers/SongController.php
index 3f68714..15a9c34 100644
--- a/laravel/app/Http/Controllers/SongController.php
+++ b/laravel/app/Http/Controllers/SongController.php
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Playlist;
 use App\Song;
 use Illuminate\Http\Request;
 
@@ -33,7 +34,11 @@ class SongController extends Controller
             }
         }
         $song['escapedText'] = $newText;
-        return view('song', ['song' => $song, 'transp' => $transp ] );
+        $playlist = NULL;
+        if ( $_GET['playlist'] ){
+            $playlist = Playlist::find($_GET['playlist'] ) ?? NULL;
+        }
+        return view('song', ['song' => $song, 'transp' => $transp, 'playlist' => $playlist ] );
     }
 
     /**
@@ -146,4 +151,27 @@ class SongController extends Controller
         return $ochords[($chords[$fromkey] + $integer + 24)%12];
     }
 
+    public function post()
+    {
+        $songD = [];
+        $songD['title'] = $_POST['title'] ?? '';
+        $songD['text'] = $_POST['text'] ?? '';
+        $songD['key'] = $_POST['key'] ?? NULL;
+        $songD['author'] = $_POST['author'] ?? NULL;
+        $songD['number'] = substr(md5(microtime()),rand(0,26),5);
+        if ( $songD['title'] ) {
+            $song = Song::create( $songD );
+            if ( $_POST['playlist'] ) {
+                $song->playlists()->attach( $_POST['playlist'] );
+            }
+            return redirect()->route('song.show', [
+                'song' => $song->number,
+                'playlist' => $_POST['playlist']
+            ] );
+        }
+        if ($_POST['playlist'] ){
+            return redirect()->route('playlist.show', [ 'playlist' => $_POST['playlist'] ] );
+        }
+        return redirect('/');
+    }
 }
diff --git a/laravel/resources/views/layouts/app.blade.php b/laravel/resources/views/layouts/app.blade.php
index 055df6f..0267aea 100644
--- a/laravel/resources/views/layouts/app.blade.php
+++ b/laravel/resources/views/layouts/app.blade.php
@@ -73,7 +73,9 @@
         </nav>
 
         <main class="py-4">
-            @yield('content')
+            <div class='container'>
+                @yield('content')
+            </div>
         </main>
     </div>
 </body>
diff --git a/laravel/resources/views/playlist.blade.php b/laravel/resources/views/playlist.blade.php
index 3026963..856c81c 100644
--- a/laravel/resources/views/playlist.blade.php
+++ b/laravel/resources/views/playlist.blade.php
@@ -10,4 +10,15 @@
     @endforeach
     </ul>
 
+    <form method="POST" action="/new/song">
+        <h3>Add song to playlist</h3>
+        @csrf
+        <input name='title' placeholder='title' type='text'/>
+        <input name='author' placeholder='author' type='text'/>
+        <input name='key' placeholder='Key (e.g. Am)' type='text' />
+        <input name='playlist' value='{{ $playlist->id }}' hidden/>
+        <br/>
+        <textarea name='text' placeholder='song lyrics/chords' style='width: 100%; height: 200px;' ></textarea>
+        <button type='submit'>Add song!</button>
+    </form>
 @endsection
diff --git a/laravel/resources/views/song.blade.php b/laravel/resources/views/song.blade.php
index 8a5e0f8..d350ff6 100644
--- a/laravel/resources/views/song.blade.php
+++ b/laravel/resources/views/song.blade.php
@@ -3,7 +3,10 @@
 
 @section('content')
 
-<div class='container'>
+    <a href='{{ route('playlist.show', ['playlist' => $playlist->name ] ) }}'>
+        Back to "<i>{{$playlist->name}}</i>" playlist
+    </a>
+
     <h2>{{$song['title']}}</h2>
     <form>
     <select name="transp" id="transp"
@@ -31,7 +34,6 @@
         <canvas id='guitarregion' width="100" height="100" onclick="cycle(guitarObj);"></canvas>
         <canvas id='ukuleleregion' width="100" height="100" onclick="cycle(ukeObj);"></canvas>
     </div>
-</div>
 
 <script src='/js/chordsdata/chords.js'></script>
 <script src='/js/chordsdata/ukulelechords.js'></script>
diff --git a/laravel/routes/web.php b/laravel/routes/web.php
index d11a121..730f622 100644
--- a/laravel/routes/web.php
+++ b/laravel/routes/web.php
@@ -16,6 +16,7 @@ Route::get('/', function () {
 });
 Route::get('/song/{song}', 'SongController@show')->name('song.show');
 Route::get('/playlist/{playlist}', 'PlaylistController@show')->name('playlist.show');
+Route::post('/new/song', 'SongController@post')->name('song.postnew');
 
 Auth::routes();