From 37b6bcd6e76488b266a6a45e45d2e31979cd8777 Mon Sep 17 00:00:00 2001 From: cdesmidt Date: Tue, 8 Oct 2019 17:21:54 +0200 Subject: [PATCH 01/14] :ambulance: Modifie des fichiers en urgence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * des fichiers à ne plus avoir sur Git * ajoute bootstrap --- .gitignore | 3 +++ resources/sass/app.scss | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f5b7047..9ccfa09 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ Homestead.yaml npm-debug.log yarn-error.log .idea +/public/css/ +/public/fonts/ +/public/js/ diff --git a/resources/sass/app.scss b/resources/sass/app.scss index dc1c79c..5c1925f 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -11,7 +11,7 @@ } // Bootstrap -//@import '~bootstrap/scss/bootstrap'; +@import '~bootstrap/scss/bootstrap'; @import '~tabler-ui/src/assets/scss/bundle.scss'; // Variables From 9a30d17fe0f9383568e704d5f4b342d2ae64a604 Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Thu, 5 Mar 2020 15:39:35 +0100 Subject: [PATCH 02/14] =?UTF-8?q?:sparkles:=20Permet=20l'=C3=A9dition=20et?= =?UTF-8?q?=20la=20suppression=20du=20post=20du=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #7 --- app/Http/Controllers/HomeController.php | 60 ++++++++++++++++++++ resources/js/components/Autocomplete.vue | 6 ++ resources/sass/_general.scss | 11 ++++ resources/views/home.blade.php | 70 ++++++++++++++---------- routes/web.php | 2 + 5 files changed, 121 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index b4ced9b..85e842f 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -26,6 +26,7 @@ class HomeController extends Controller * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable + * @throws \Exception */ public function index() { @@ -59,6 +60,65 @@ class HomeController extends Controller ]); } + /** + * Edit today's entry + */ + public function edit(TagDetectorService $tag_detector) + { + /** @var Post $today_post */ + $today_post = Post::whereDate('date_post', '=', (new DateTime())->format('Y-m-d')) + ->where('user_id', Auth::user()->getAuthIdentifier()) + ->firstOrFail(); + + $data = request()->validate([ + 'message' => 'required' + ]); + + $tags_to_delete = PostsTag::where('post_id', $today_post->id)->get(); + foreach ($tags_to_delete as $tag_to_delete) { + $tag_to_delete->delete(); + } + + $tags = $tag_detector->detectFrom($data['message']); + + $today_post->content = $data['message']; + $today_post->save(); + $all_tags = Tag::all(); + $all_tags_names = []; + foreach ($all_tags as $tag) { + $all_tags_names[$tag->id] = $tag->name; + } + + foreach ($tags as $tag) { + if (in_array($tag, $all_tags_names)) { + PostsTag::create([ + 'post_id' => $today_post->id, + 'tag_id' => array_search($tag, $all_tags_names), + ]); + } + } + + return Redirect::to('home')->withSuccess('Great! Form successfully submit with validation.'); + } + + /** + * @return \Illuminate\Http\RedirectResponse + * @throws \Exception + */ + public function delete() + { + try { + $today_post = Post::whereDate('date_post', '=', (new DateTime())->format('Y-m-d')) + ->where('user_id', Auth::user()->getAuthIdentifier()) + ->firstOrFail(); + + $today_post->delete(); + return Redirect::to('home')->withSuccess('Great! Your today\'s post is now deleted. You can make a new one!'); + } catch (\ErrorException $e) { + return Redirect::to('home')->withErrors('Oh no! We could\'t find your today\'s post.'); + } + } + public function store(TagDetectorService $tag_detector) { $today = new DateTime(); diff --git a/resources/js/components/Autocomplete.vue b/resources/js/components/Autocomplete.vue index 45b32c8..7486808 100644 --- a/resources/js/components/Autocomplete.vue +++ b/resources/js/components/Autocomplete.vue @@ -51,6 +51,12 @@ } } }); + let already = document.getElementById("collapse").classList.contains("collapse"); + if (already) { + let post = document.querySelector(".already").innerText; + document.querySelector("textarea").innerHTML = post; + this.inputValue = post; + } }, computed: { listToSearch() { diff --git a/resources/sass/_general.scss b/resources/sass/_general.scss index e84e0cc..3da8bb9 100644 --- a/resources/sass/_general.scss +++ b/resources/sass/_general.scss @@ -1,3 +1,14 @@ h1, h2, h3, h4 { font-family: $font-family-base; } + +.card-options .btn-link { + color: #9aa0ac; + text-decoration: none; + min-width: 0; + padding: 0; + margin-left: 5px; + &:hover { + color: #6e7687; + } +} diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 80aca1f..ab38643 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -13,6 +13,16 @@ {{ session('status') }} @endif + @if (session('success')) + + @endif + @if (session('errors')) + + @endif
@@ -70,37 +80,35 @@
@if($already)
L'activité du jour a déjà été entrée.
- @else -
-
-
-
-

{{ strftime('%B %G', $today->format('U')) }}

-
-
-
- @csrf -
-
- -
-
-
- {{ $errors->first('message') }} -
-
-
-
- -
+ @endif +
+
+
+
+

{{ strftime('%B %G', $today->format('U')) }}

+
+
+ + @csrf +
+
+ +
+
+ {{ $errors->first('message') }}
- -
+
+
+ +
+
+
+
- @endif +
@foreach($posts as $post)
@@ -110,10 +118,16 @@

{{ ucfirst(\Carbon\Carbon::instance($post->date_post)->diffForHumans()) }}

- + @if($today->format('Y-m-d') === \Carbon\Carbon::instance($post->date_post)->format('Y-m-d')) + +
+ @csrf + +
+ @endif
-
+
{!! $tag_detector->linkTagFrom($post->content) !!}
-
+ @csrf
@@ -96,6 +96,11 @@
{{ $errors->first('message') }} + +
@@ -128,6 +133,7 @@
+ @if($post->image != '')

@endif {!! $tag_detector->linkTagFrom($post->content) !!}
- @if($post->image != '')

@endif + @if($post->image != '')

@endif {!! $tag_detector->linkTagFrom($post->content) !!}
diff --git a/resources/views/vendor/laravel-menu/bootstrap-navbar-items.blade.php b/resources/views/vendor/laravel-menu/bootstrap-navbar-items.blade.php new file mode 100644 index 0000000..47909dd --- /dev/null +++ b/resources/views/vendor/laravel-menu/bootstrap-navbar-items.blade.php @@ -0,0 +1,20 @@ +@foreach($items as $item) +
  • hasChildren()) class="nav-item dropdown" @endif @lm_endattrs> + @if($item->link) link) @if($item->hasChildren()) class="nav-link dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" @else class="nav-link" @endif @lm_endattrs href="{!! $item->url() !!}"> + {!! $item->title !!} + @if($item->hasChildren()) @endif + + @else + {!! $item->title !!} + @endif + @if($item->hasChildren()) + + @endif +
  • + @if($item->divider) + divider) !!}> + @endif +@endforeach From 18dd6cd92dcc1cd0d86869b9460ede5471d7e510 Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Tue, 10 Mar 2020 18:13:42 +0100 Subject: [PATCH 11/14] :poop: Commence la mise en cache des miniatures Start #9 --- app/Http/Controllers/HomeController.php | 6 ++++ app/Http/Controllers/ImageController.php | 44 +++++++++++++----------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 77307f4..65bde6d 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -10,6 +10,8 @@ use DateTime; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Redirect; +use Intervention\Image\Constraint; +use Intervention\Image\Facades\Image; class HomeController extends Controller { @@ -145,6 +147,10 @@ class HomeController extends Controller $uploaded_document = $validated_data['file']; $file_name = $uploaded_document->getClientOriginalName(); $uploaded_document->storeAs(Auth::user()->getFolder(), $file_name); + $img = Image::make($uploaded_document->getRealPath()); + $img->resize(300, null, static function (Constraint $constraint) { + $constraint->aspectRatio(); + })->save(sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), sprintf('300-%s', $file_name))); $data['image'] = $file_name; } diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php index 57e0daf..8b8a49c 100644 --- a/app/Http/Controllers/ImageController.php +++ b/app/Http/Controllers/ImageController.php @@ -31,38 +31,40 @@ class ImageController extends Controller throw new UnauthorizedHttpException('Cette image ne vous appartient pas.'); } - $path = sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), $image); - if (!is_readable($path)) { - throw new NotFoundHttpException(); - } - - - $img = Image::make($path); - - if ('o:full' !== $options) { + $original = sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), $image); + $thumb = sprintf('%s/%s/300-%s', storage_path('app'), Auth::user()->getFolder(), $image); + $img = Image::make($original); + if ('o:full' === $options) { + if (!is_readable($original)) { + throw new NotFoundHttpException(); + } + } elseif (!is_readable($thumb)) { + if (!is_readable($original)) { + throw new NotFoundHttpException(); + } $options = explode('!', $options); $width = null; $height = null; foreach ($options as $option) { - $current_option = explode(':', $option); - foreach ($current_option as $current_option_name => $current_option_value) { - switch ($current_option_name) { - case 'w': - $width = $current_option_value; - break; - case 'h': - $height = $current_option_value; - break; - } + [$current_option_name, $current_option_value] = explode(':', $option); + switch ($current_option_name) { + case 'w': + $width = $current_option_value; + break; + case 'h': + $height = $current_option_value; + break; } } //http://image.intervention.io/getting_started/ $img->resize($width, $height, static function (Constraint $constraint) { $constraint->aspectRatio(); - }); + })->save(sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), sprintf('300-%s', $image))); + } else { + $img = Image::make($thumb); } - return $img->response(File::extension($path)); + return $img->response(File::extension($original)); } /** From 6f5f362bf9377e3847a915b72e1db833eacbee31 Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Tue, 10 Mar 2020 18:14:19 +0100 Subject: [PATCH 12/14] =?UTF-8?q?:zap:=20Redirige=20l'utilisateur=20connec?= =?UTF-8?q?t=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/WelcomeController.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/WelcomeController.php b/app/Http/Controllers/WelcomeController.php index f7cba65..a1fa40d 100644 --- a/app/Http/Controllers/WelcomeController.php +++ b/app/Http/Controllers/WelcomeController.php @@ -3,13 +3,22 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; class WelcomeController extends Controller { + /** + * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View + * @throws \Exception + */ public function index() { - return view('welcome', [ - 'today' => new \DateTime(), - ]); + if (Auth::guest()) { + return view('welcome', [ + 'today' => new \DateTime(), + ]); + } + + return redirect(route('dashboard')); } } From 020eec2a602a38f767c7a1742b24c400f0650dc7 Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Thu, 12 Mar 2020 17:31:13 +0100 Subject: [PATCH 13/14] :truck: Renomme le controlleur principal --- .../{HomeController.php => DashboardController.php} | 10 ++++------ routes/web.php | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) rename app/Http/Controllers/{HomeController.php => DashboardController.php} (92%) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/DashboardController.php similarity index 92% rename from app/Http/Controllers/HomeController.php rename to app/Http/Controllers/DashboardController.php index 65bde6d..b92e488 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/DashboardController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Post; use App\PostsTag; +use App\Services\ImageService; use App\Services\TagDetectorService; use App\Tag; use DateTime; @@ -13,7 +14,7 @@ use Illuminate\Support\Facades\Redirect; use Intervention\Image\Constraint; use Intervention\Image\Facades\Image; -class HomeController extends Controller +class DashboardController extends Controller { /** * Create a new controller instance. @@ -127,7 +128,7 @@ class HomeController extends Controller * @return mixed * @throws \Exception */ - public function store(TagDetectorService $tag_detector) + public function store(TagDetectorService $tag_detector, ImageService $image_service) { $user_id = Auth::user()->getAuthIdentifier(); @@ -147,10 +148,7 @@ class HomeController extends Controller $uploaded_document = $validated_data['file']; $file_name = $uploaded_document->getClientOriginalName(); $uploaded_document->storeAs(Auth::user()->getFolder(), $file_name); - $img = Image::make($uploaded_document->getRealPath()); - $img->resize(300, null, static function (Constraint $constraint) { - $constraint->aspectRatio(); - })->save(sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), sprintf('300-%s', $file_name))); + $image_service->makeThumbnail($uploaded_document->getRealPath(), ['width' => 300]); $data['image'] = $file_name; } diff --git a/routes/web.php b/routes/web.php index 475d5e2..17626f2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -14,10 +14,10 @@ Auth::routes(); Route::get('/', 'WelcomeController@index')->name('home'); -Route::get('/home', 'HomeController@index')->name('dashboard'); -Route::post('store', 'HomeController@store')->name('store'); -Route::post('delete', 'HomeController@delete')->name('delete'); -Route::post('edit', 'HomeController@edit')->name('edit'); +Route::get('/home', 'DashboardController@index')->name('dashboard'); +Route::post('store', 'DashboardController@store')->name('store'); +Route::post('delete', 'DashboardController@delete')->name('delete'); +Route::post('edit', 'DashboardController@edit')->name('edit'); Route::post('stats', 'StatsController@tag')->name('stats'); // TODO make a group for stats Route::get('/display/{post_id}/{options}/{image_name}', 'ImageController@display')->name('display_image'); Route::get('/gallery', 'ImageController@gallery')->name('gallery'); From 7f1214b96b39d2e74230eaca0142a97cf42e79af Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Thu, 12 Mar 2020 17:31:51 +0100 Subject: [PATCH 14/14] :sparkles: Finalise la mise en cache des images Fix #9 --- app/Http/Controllers/ImageController.php | 34 +++----------- app/Providers/ImageServiceProvider.php | 29 ++++++++++++ app/Services/ImageService.php | 56 ++++++++++++++++++++++++ config/app.php | 1 + 4 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 app/Providers/ImageServiceProvider.php create mode 100644 app/Services/ImageService.php diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php index 8b8a49c..1d97c85 100644 --- a/app/Http/Controllers/ImageController.php +++ b/app/Http/Controllers/ImageController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Post; +use App\Services\ImageService; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\File; use Intervention\Image\Constraint; @@ -16,10 +17,11 @@ class ImageController extends Controller * @param int $post_id * @param string|array $options * @param string $image + * @param ImageService $image_service * * @return mixed */ - public function display($post_id, $options = 'o:full', $image) + public function display($post_id, $options = 'o:full', $image, ImageService $image_service) { if (Auth::guest()) { throw new UnauthorizedHttpException('Vous devez être connecté pour voir cette image.'); @@ -32,36 +34,10 @@ class ImageController extends Controller } $original = sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), $image); - $thumb = sprintf('%s/%s/300-%s', storage_path('app'), Auth::user()->getFolder(), $image); - $img = Image::make($original); if ('o:full' === $options) { - if (!is_readable($original)) { - throw new NotFoundHttpException(); - } - } elseif (!is_readable($thumb)) { - if (!is_readable($original)) { - throw new NotFoundHttpException(); - } - $options = explode('!', $options); - $width = null; - $height = null; - foreach ($options as $option) { - [$current_option_name, $current_option_value] = explode(':', $option); - switch ($current_option_name) { - case 'w': - $width = $current_option_value; - break; - case 'h': - $height = $current_option_value; - break; - } - } - //http://image.intervention.io/getting_started/ - $img->resize($width, $height, static function (Constraint $constraint) { - $constraint->aspectRatio(); - })->save(sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), sprintf('300-%s', $image))); + $img = $image_service->makeThumbnail($original); } else { - $img = Image::make($thumb); + $img = $image_service->makeThumbnail($original, ['width' => 300]); } return $img->response(File::extension($original)); diff --git a/app/Providers/ImageServiceProvider.php b/app/Providers/ImageServiceProvider.php new file mode 100644 index 0000000..2034dff --- /dev/null +++ b/app/Providers/ImageServiceProvider.php @@ -0,0 +1,29 @@ +app->bind(ImageService::class); + } + + /** + * Bootstrap services. + * + * @return void + */ + public function boot() + { + // + } +} diff --git a/app/Services/ImageService.php b/app/Services/ImageService.php new file mode 100644 index 0000000..2e95f20 --- /dev/null +++ b/app/Services/ImageService.php @@ -0,0 +1,56 @@ +basePath()); + $file_name = basename($image); + + $width = null; + if (array_key_exists('width', $options)) { + $width = $options['width']; + $file_name = sprintf('w%u-%s', $width, $file_name); + } + + $height = null; + if (array_key_exists('$height', $options)) { + $height = $options['$height']; + $file_name = sprintf('h%u-%s', $height, $file_name); + } + + $full_path = sprintf('%s/%s', $folder, $file_name); + if (!array_key_exists('force', $options) && is_readable($full_path)) { + return Image::make($full_path); + } + + //http://image.intervention.io/getting_started/ + $img->resize($width, $height, static function (Constraint $constraint) { + $constraint->aspectRatio(); + })->save(sprintf('%s/%s', $folder, $file_name)); + + return $img; + } +} diff --git a/config/app.php b/config/app.php index 54da053..1b675c2 100644 --- a/config/app.php +++ b/config/app.php @@ -176,6 +176,7 @@ return [ App\Providers\RouteServiceProvider::class, \App\Providers\TagDetectorProvider::class, + \App\Providers\ImageServiceProvider::class, Intervention\Image\ImageServiceProvider::class, ],