]> _ Git - songbook.git/commitdiff
.
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 4 Oct 2022 09:28:28 +0000 (11:28 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 4 Oct 2022 09:28:28 +0000 (11:28 +0200)
app/Http/Controllers/FrontController.php
app/Models/Song.php
composer.json
resources/css/app.css [deleted file]
resources/css/app.css.map [deleted file]
resources/css/app.less [deleted file]
resources/css/app.sass
resources/css/app.styl [deleted file]
resources/views/menu.blade.php
routes/web.php

index 362a95254d32cd89c123f0eb8b042933aa73e8b3..9d7bb6c0b9c78726a2fee417ddadf8f34508e1b4 100644 (file)
@@ -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();
+    }
 }
+
index 40ac55437e9b27fe3b3f56123e0fd1c73e58ea02..3f724453f1db51a94b3e48cc811619c213b7363c 100644 (file)
@@ -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');
index f72de3492409874b210800aff9a6ef5a35b9a58f..3ed4667c5f44f4e218677fe7ebc175a60ce996f2 100644 (file)
@@ -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 (file)
index b0d51ce..0000000
+++ /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 (file)
index e69de29..0000000
diff --git a/resources/css/app.less b/resources/css/app.less
deleted file mode 100644 (file)
index 4709feb..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-body{
-    
-}
index 748bac4776454d75fd0c315befb9f95f1322c150..d950c13fd9c21244129460d409fdaf3c5009ab79 100644 (file)
@@ -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 (file)
index b0d51ce..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-body {
-    font-family: 'Nunito', sans-serif;
-}
-
-main.song {
-    .lyrics{
-        white-space: pre-line;
-    }
-}
index f05a5ef3a0dccc13a2c90910da304e917afa6873..7409c83c0c17be3b425c966b6a064d9dcfa6d4ad 100644 (file)
@@ -35,7 +35,6 @@
                 </ul>
             </li>
             @if(isset($song))
-
                 @if($song->hasChords())
                     <li><a href="#" class="noaction">🎤 {{__('Show lyrics')}} <input type="checkbox"
                                                                                     class="checkbox-switch"
                                                                                                data-default="0"></a>
                         </li>
                     @endif
-                    <li><a href="#" class="clickselect">↕️ {{__('Key')}} <select data-name="tone"
-                                                                                 name="tone_{{$song->id}}">
-                                @for($i=-5;$i<=6;$i++)
-                                    <option value="{{$i}}"
-                                            @if($i===0) selected @endif>{{$tones[(12+$song->key+$i)%12].$song->mode}} @if($i>0)
-                                            (+{{$i}}
-                                            )
-                                        @elseif($i<0)
-                                            ({{$i}})
-                                        @endif </option>
-                                @endfor
-                            </select><span></span></a></li>
+                    @if($collection->transpose)
+                        <li><a href="#" class="clickselect">↕️ {{__('Key')}} <select data-name="tone"
+                                                                                     name="tone_{{$song->id}}">
+                                    @for($i=-5;$i<=6;$i++)
+                                        <option value="{{$i}}"
+                                                @if($i===0) selected @endif>{{$tones[(12+$song->key+$i)%12].$song->mode}} @if($i>0)
+                                                (+{{$i}}
+                                                )
+                                            @elseif($i<0)
+                                                ({{$i}})
+                                            @endif </option>
+                                    @endfor
+                                </select><span></span></a></li>
+                    @endif
                 @else
                     <li class="hidden"><a href="#" class="noaction">{{__('Show chords')}} <input type="checkbox"
                                                                                                  class="checkbox-switch"
@@ -92,7 +93,7 @@
                                 @endforeach
                             </select><span></span></a></li>
                     @foreach($song->getAudioTracks() as $i=>$track)
-                        @if(isset($track['tone']) && is_numeric($track['tone']))
+                        @if($collection->transpose && isset($track['tone']) && is_numeric($track['tone']))
                             <li data-audio="{{$i}}"><a href="#" class="clickselect">↕️{{__('Audio key')}} <select
                                         class="audiotone"
                                         data-name="audio_{{$i}}_tone"
                         @endif
                     @endforeach
                 @endif
+                @if($partition)
+                    <li><a target="_blank" href="{{$partition}}">🎼 {{__('Partition')}}</a></li>
+                @endif
+                @if($collection->download_assets)
+                    <li><a href="/downloadassets/{{$song->id}}">⬇️ &nbsp;{{__('Télécharger')}}</a></li>
+                @endif
             @endif
 
+
             <li>
                 <span><img
                         src="https://api.qrserver.com/v1/create-qr-code/?size=50x50&data={{rawurlencode('https://songbook.enhydra.fr/'.$collection->slug)}}"
index 16ce1df6a0a20e838b5585486a69284dcd4de44d..4015e06af703f1b9d316cf45ae093d60cf0b19e1 100644 (file)
@@ -20,3 +20,4 @@ Route::get('/', function () {
 Route::get('{collection}.webmanifest', [FrontController::class, 'manifest']);
 Route::any('{collection}', [FrontController::class, 'collection']);
 Route::any('{collection}/{song}.html', [FrontController::class, 'song']);
+Route::get('downloadassets/{songid}', [FrontController::class, 'downloadAssets']);