From 0956944345c39d5ca47ca7e24943a2e5ce50a578 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 4 Oct 2022 11:28:28 +0200 Subject: [PATCH] . --- app/Http/Controllers/FrontController.php | 49 +++++++- app/Models/Song.php | 4 +- composer.json | 148 +++++++++++------------ resources/css/app.css | 9 -- resources/css/app.css.map | 0 resources/css/app.less | 3 - resources/css/app.sass | 4 +- resources/css/app.styl | 9 -- resources/views/menu.blade.php | 36 +++--- routes/web.php | 1 + 10 files changed, 150 insertions(+), 113 deletions(-) delete mode 100644 resources/css/app.css delete mode 100644 resources/css/app.css.map delete mode 100644 resources/css/app.less delete mode 100644 resources/css/app.styl diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index 362a952..9d7bb6c 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -6,6 +6,7 @@ use App\Models\Collection; use App\Models\CollectionList; use App\Models\Song; use Cubist\Backpack\Http\Controllers\CubistPWAController; +use Cubist\Util\Files\Files; use Illuminate\Support\Facades\Session; @@ -52,10 +53,12 @@ class FrontController extends Controller public function song($collection, $song) { + /** @var Collection $collection */ $collection = Collection::where('slug', $collection)->first(); if (null === $collection) { abort(404); } + /** @var Song $song */ $song = Song::where('slug', $song)->first(); if (null === $song) { abort(404); @@ -64,7 +67,24 @@ class FrontController extends Controller return $p; } $lists = CollectionList::where('collection', $collection->id)->get(); - return view('song', ['menu' => true, 'song' => $song, 'collection' => $collection, 'collection_songs' => $this->_getSongsOfCollection($collection->id, $lists), 'collection_lists' => $lists]); + $partition = $song->getFirstMediaInField('partition'); + if ($partition) { + $partition = $partition->getUrl(); + } + $lyrics_html = ''; + $lyrics_doc = $song->getFirstMediaInField('lyrics_doc'); + dd($lyrics_doc); + + if ($lyrics_doc) { + $path = $lyrics_doc->getPath(); + $html_path = $path . '.html'; + dd(`libreoffice --convert-to HTML:HTML --outdir $html_path $path`); + if (!file_exists($html_path)) { + + } + $lyrics_html = file_get_contents($html_path); + } + return view('song', ['menu' => true, 'lyrics_html' => $lyrics_html, 'song' => $song, 'collection' => $collection, 'partition' => $partition, 'collection_songs' => $this->_getSongsOfCollection($collection->id, $lists), 'collection_lists' => $lists]); } protected function _getSongsOfCollection($id, $lists) @@ -110,4 +130,31 @@ class FrontController extends Controller return response(json_encode($res))->header('Content-Type', 'application/manifest+json'); } + + public function downloadAssets($songId) + { + /** @var Song $song */ + $song = Song::find($songId); + $fields = ['partition', 'lyrics_doc']; + $files = []; + $tmp = Files::tempnam() . '.zip'; + $zip = new \ZipArchive(); + $zip->open($tmp, \ZipArchive::CREATE); + foreach ($fields as $field) { + $media = $song->getFirstMediaInField($field); + if ($media) { + $files[] = $media->getPath(); + } + } + foreach ($song->getAudioTracks() as $track) { + $files[] = $track['path']; + } + foreach ($files as $file) { + $f = new \SplFileInfo($file); + $zip->addFile($file, $f->getFilename()); + } + $zip->close(); + return response()->download($tmp, $song->title . '.zip')->deleteFileAfterSend(); + } } + diff --git a/app/Models/Song.php b/app/Models/Song.php index 40ac554..3f72445 100644 --- a/app/Models/Song.php +++ b/app/Models/Song.php @@ -42,8 +42,8 @@ class Song extends CubistMagicAbstractModel $this->addField('chorale', Checkbox::class, 'Chorale', ['default' => false, 'database_default' => false]); $this->addField('collections', \App\Field\CollectionList::class, 'Collections'); $this->addField('tempo', Tempo::class, 'Suggested tempo', ['column' => true, 'default' => 80]); - $this->addField('partition', Files::class, 'Partition', ['acceptedFiles' => '*.pdf', 'when' => ['chorale' => 1]]); - $this->addField('lyrics_doc', Files::class, 'Paroles', ['acceptedFiles' => '*.doc', 'when' => ['chorale' => 1]]); + $this->addField('partition', Files::class, 'Partition', ['acceptedFiles' => 'application/pdf', 'when' => ['chorale' => 1]]); + $this->addField('lyrics_doc', Files::class, 'Paroles', ['acceptedFiles' => 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/plain,text/html', 'when' => ['chorale' => 1]]); $this->addField('audio', BunchOfFieldsMultiple::class, 'Audio tracks', ['bunch' => AudioTrack::class, 'new_label' => 'New audio track']); $this->addField('lyrics', BunchOfFieldsMultiple::class, 'Song Parts', ['bunch' => SongPortion::class, 'new_label' => 'New song part', 'when' => ['chorale' => 0]]); // $this->addField('youtube', URL::class, 'Youtube link'); diff --git a/composer.json b/composer.json index f72de34..3ed4667 100644 --- a/composer.json +++ b/composer.json @@ -1,78 +1,78 @@ { - "name": "enhydra/songbook", - "type": "project", - "description": "Songbook", - "keywords": [ - "framework", - "laravel" - ], - "repositories": [ - { - "type": "composer", - "url": "https://composer.cubedesigners.com/" - } - ], - "license": "MIT", - "require": { - "php": ">=7.4", - "ext-json": "*", - "ext-simplexml": "*", - "ext-tidy": "*", - "ext-zip": "*", - "cubist/cms-back": "dev-master", - "fruitcake/laravel-cors": "^2.2", - "league/csv": "^9.8", - "mxl/laravel-job": "^1.3", - "norkunas/youtube-dl-php": "dev-master", - "php-ffmpeg/php-ffmpeg": "^0.18.0", - "phpoffice/phpspreadsheet": "^1.23", - "predis/predis": "^1.1", - "ext-libxml": "*", - "ext-dom": "*" - }, - "require-dev": { - "barryvdh/laravel-ide-helper": "^2.10", - "facade/ignition": "^2.3", - "filp/whoops": "^2.14", - "laravel/tinker": "^2.1", - "mockery/mockery": "^1.4", - "nunomaduro/collision": "^4.2", - "phpunit/phpunit": "^8.5" - }, - "config": { - "optimize-autoloader": true, - "preferred-install": "dist", - "sort-packages": true - }, - "extra": { - "laravel": { - "dont-discover": [] - } - }, - "autoload": { - "psr-4": { - "App\\": "app/" - }, - "classmap": [ - ] - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/" - } - }, - "minimum-stability": "dev", - "prefer-stable": true, - "scripts": { - "post-autoload-dump": [ - "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", - "@php artisan package:discover --ansi" + "name": "enhydra/songbook", + "type": "project", + "description": "Songbook", + "keywords": [ + "framework", + "laravel" ], - "post-root-package-install": [ - "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" + "repositories": [ + { + "type": "composer", + "url": "https://composer.cubedesigners.com/" + } ], - "post-create-project-cmd": [ - "@php artisan key:generate --ansi" - ] - } + "license": "MIT", + "require": { + "php": ">=7.4", + "ext-json": "*", + "ext-simplexml": "*", + "ext-tidy": "*", + "ext-zip": "*", + "ext-libxml": "*", + "ext-dom": "*", + "ext-redis": "*", + "cubist/cms-back": "dev-master", + "fruitcake/laravel-cors": "^2.2", + "league/csv": "^9.8", + "mxl/laravel-job": "^1.3", + "norkunas/youtube-dl-php": "dev-master", + "php-ffmpeg/php-ffmpeg": "^0.18.0", + "phpoffice/phpspreadsheet": "^1.23" + }, + "require-dev": { + "barryvdh/laravel-ide-helper": "^2.10", + "facade/ignition": "^2.3", + "filp/whoops": "^2.14", + "laravel/tinker": "^2.1", + "mockery/mockery": "^1.4", + "nunomaduro/collision": "^4.2", + "phpunit/phpunit": "^8.5" + }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true + }, + "extra": { + "laravel": { + "dont-discover": [] + } + }, + "autoload": { + "psr-4": { + "App\\": "app/" + }, + "classmap": [ + ] + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "scripts": { + "post-autoload-dump": [ + "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", + "@php artisan package:discover --ansi" + ], + "post-root-package-install": [ + "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" + ], + "post-create-project-cmd": [ + "@php artisan key:generate --ansi" + ] + } } diff --git a/resources/css/app.css b/resources/css/app.css deleted file mode 100644 index b0d51ce..0000000 --- a/resources/css/app.css +++ /dev/null @@ -1,9 +0,0 @@ -body { - font-family: 'Nunito', sans-serif; -} - -main.song { - .lyrics{ - white-space: pre-line; - } -} diff --git a/resources/css/app.css.map b/resources/css/app.css.map deleted file mode 100644 index e69de29..0000000 diff --git a/resources/css/app.less b/resources/css/app.less deleted file mode 100644 index 4709feb..0000000 --- a/resources/css/app.less +++ /dev/null @@ -1,3 +0,0 @@ -body{ - -} diff --git a/resources/css/app.sass b/resources/css/app.sass index 748bac4..d950c13 100644 --- a/resources/css/app.sass +++ b/resources/css/app.sass @@ -48,6 +48,7 @@ $slab: 'Roboto Slab', sans-serif margin: 0 padding: 0 box-sizing: border-box + outline-width: 0 h1, h2, h3, h4, h5, h6 font-family: $slab @@ -463,6 +464,7 @@ form padding: 20px 0 0 0 color: #cc0000 + input display: block margin: 25px auto @@ -478,6 +480,7 @@ form input[type=password] text-align: left + outline-width: 1px outline-color: var(--theme-color) input[type=submit] @@ -485,6 +488,5 @@ form color: #fff cursor: pointer - @import "../../node_modules/mmenu-light/dist/mmenu-light.css" @import "../../node_modules/plyr/dist/plyr.css" diff --git a/resources/css/app.styl b/resources/css/app.styl deleted file mode 100644 index b0d51ce..0000000 --- a/resources/css/app.styl +++ /dev/null @@ -1,9 +0,0 @@ -body { - font-family: 'Nunito', sans-serif; -} - -main.song { - .lyrics{ - white-space: pre-line; - } -} diff --git a/resources/views/menu.blade.php b/resources/views/menu.blade.php index f05a5ef..7409c83 100644 --- a/resources/views/menu.blade.php +++ b/resources/views/menu.blade.php @@ -35,7 +35,6 @@ @if(isset($song)) - @if($song->hasChords())
  • 🎤 {{__('Show lyrics')}}
  • @endif -
  • ↕️ {{__('Key')}}
  • + @if($collection->transpose) +
  • ↕️ {{__('Key')}}
  • + @endif @else @foreach($song->getAudioTracks() as $i=>$track) - @if(isset($track['tone']) && is_numeric($track['tone'])) + @if($collection->transpose && isset($track['tone']) && is_numeric($track['tone']))
  • ↕️{{__('Audio key')}}