Explorar o código

Kommentieren und Bewerten hinzugefügt. Einstellungsseite hinzufügt (macht noch nichts).

Daniel hai 1 ano
pai
achega
c689ad7849

+ 6 - 0
app/Models/Film.php

@@ -71,4 +71,10 @@ class Film extends Model
 	public function scopeSuggested($query) {
 		return $query->whereNull('seen')->whereNull('rejected')->orderBy('updated_at', 'DESC');
 	}
+
+    public function userMayEvaluate(int $userid) {
+        if(is_null($this->seen)) return false;
+        if($this->comments()->where('user', $userid)->where('evaluation', '>', 0)->count() > 0) return false;
+        return true;
+    }
 }

+ 1 - 1
app/Providers/RouteServiceProvider.php

@@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider
      *
      * @var string
      */
-    public const HOME = '/dashboard';
+    public const HOME = '/';
 
     /**
      * Define your route model bindings, pattern filters, etc.

+ 52 - 78
public/css/app.css

@@ -643,12 +643,12 @@ select {
 .top-0 {
   top: 0px;
 }
-.right-0 {
-  right: 0px;
-}
 .left-0 {
   left: 0px;
 }
+.right-0 {
+  right: 0px;
+}
 .z-0 {
   z-index: 0;
 }
@@ -670,9 +670,6 @@ select {
 .clear-both {
   clear: both;
 }
-.m-4 {
-  margin: 1rem;
-}
 .mx-auto {
   margin-left: auto;
   margin-right: auto;
@@ -723,6 +720,12 @@ select {
 .mt-2 {
   margin-top: 0.5rem;
 }
+.mr-1 {
+  margin-right: 0.25rem;
+}
+.mb-1 {
+  margin-bottom: 0.25rem;
+}
 .mt-3 {
   margin-top: 0.75rem;
 }
@@ -744,20 +747,11 @@ select {
 .-mr-2 {
   margin-right: -0.5rem;
 }
-.mr-1 {
-  margin-right: 0.25rem;
-}
-.mb-1 {
-  margin-bottom: 0.25rem;
-}
 .ml-\[4\.5rem\] {
   margin-left: 4.5rem;
 }
-.mb-10 {
-  margin-bottom: 2.5rem;
-}
-.mb-12 {
-  margin-bottom: 3rem;
+.mb-8 {
+  margin-bottom: 2rem;
 }
 .block {
   display: block;
@@ -795,6 +789,9 @@ select {
 .h-40 {
   height: 10rem;
 }
+.h-full {
+  height: 100%;
+}
 .h-8 {
   height: 2rem;
 }
@@ -807,9 +804,6 @@ select {
 .h-4 {
   height: 1rem;
 }
-.h-full {
-  height: 100%;
-}
 .max-h-7 {
   max-height: 1.75rem;
 }
@@ -822,8 +816,11 @@ select {
 .min-h-screen {
   min-height: 100vh;
 }
-.min-h-\[4rem\] {
-  min-height: 4rem;
+.min-h-\[6rem\] {
+  min-height: 6rem;
+}
+.min-h-\[5rem\] {
+  min-height: 5rem;
 }
 .w-5 {
   width: 1.25rem;
@@ -846,11 +843,6 @@ select {
 .w-4 {
   width: 1rem;
 }
-.w-fit {
-  width: -webkit-fit-content;
-  width: -moz-fit-content;
-  width: fit-content;
-}
 .w-80 {
   width: 20rem;
 }
@@ -866,29 +858,24 @@ select {
 .w-48 {
   width: 12rem;
 }
-.w-max {
-  width: -webkit-max-content;
-  width: -moz-max-content;
-  width: max-content;
-}
 .max-w-7xl {
   max-width: 80rem;
 }
 .max-w-md {
   max-width: 28rem;
 }
-.max-w-xl {
-  max-width: 36rem;
-}
-.max-w-6xl {
-  max-width: 72rem;
-}
 .max-w-xs {
   max-width: 20rem;
 }
 .max-w-\[100px\] {
   max-width: 100px;
 }
+.max-w-xl {
+  max-width: 36rem;
+}
+.max-w-6xl {
+  max-width: 72rem;
+}
 .flex-1 {
   flex: 1 1 0%;
 }
@@ -982,6 +969,11 @@ select {
   margin-right: calc(0.25rem * var(--tw-space-x-reverse));
   margin-left: calc(0.25rem * calc(1 - var(--tw-space-x-reverse)));
 }
+.space-x-2 > :not([hidden]) ~ :not([hidden]) {
+  --tw-space-x-reverse: 0;
+  margin-right: calc(0.5rem * var(--tw-space-x-reverse));
+  margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse)));
+}
 .space-x-8 > :not([hidden]) ~ :not([hidden]) {
   --tw-space-x-reverse: 0;
   margin-right: calc(2rem * var(--tw-space-x-reverse));
@@ -992,11 +984,6 @@ select {
   margin-top: calc(0.25rem * calc(1 - var(--tw-space-y-reverse)));
   margin-bottom: calc(0.25rem * var(--tw-space-y-reverse));
 }
-.space-x-2 > :not([hidden]) ~ :not([hidden]) {
-  --tw-space-x-reverse: 0;
-  margin-right: calc(0.5rem * var(--tw-space-x-reverse));
-  margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse)));
-}
 .overflow-hidden {
   overflow: hidden;
 }
@@ -1106,14 +1093,14 @@ select {
   --tw-bg-opacity: 1;
   background-color: rgb(104 79 67 / var(--tw-bg-opacity));
 }
-.bg-gray-100 {
-  --tw-bg-opacity: 1;
-  background-color: rgb(243 244 246 / var(--tw-bg-opacity));
-}
 .bg-burnt {
   --tw-bg-opacity: 1;
   background-color: rgb(212 81 19 / var(--tw-bg-opacity));
 }
+.bg-gray-100 {
+  --tw-bg-opacity: 1;
+  background-color: rgb(243 244 246 / var(--tw-bg-opacity));
+}
 .fill-current {
   fill: currentColor;
 }
@@ -1165,6 +1152,12 @@ select {
   padding-top: 0.25rem;
   padding-bottom: 0.25rem;
 }
+.pl-6 {
+  padding-left: 1.5rem;
+}
+.pb-2 {
+  padding-bottom: 0.5rem;
+}
 .pt-1 {
   padding-top: 0.25rem;
 }
@@ -1192,12 +1185,6 @@ select {
 .pb-1 {
   padding-bottom: 0.25rem;
 }
-.pl-6 {
-  padding-left: 1.5rem;
-}
-.pb-2 {
-  padding-bottom: 0.5rem;
-}
 .text-center {
   text-align: center;
 }
@@ -1306,6 +1293,10 @@ select {
   --tw-text-opacity: 1;
   color: rgb(255 255 255 / var(--tw-text-opacity));
 }
+.text-coal {
+  --tw-text-opacity: 1;
+  color: rgb(40 32 29 / var(--tw-text-opacity));
+}
 .text-red-600 {
   --tw-text-opacity: 1;
   color: rgb(220 38 38 / var(--tw-text-opacity));
@@ -1338,10 +1329,6 @@ select {
   --tw-text-opacity: 1;
   color: rgb(17 24 39 / var(--tw-text-opacity));
 }
-.text-coal {
-  --tw-text-opacity: 1;
-  color: rgb(40 32 29 / var(--tw-text-opacity));
-}
 .text-gray-800 {
   --tw-text-opacity: 1;
   color: rgb(31 41 55 / var(--tw-text-opacity));
@@ -1459,14 +1446,14 @@ select {
   --tw-bg-opacity: 1;
   background-color: rgb(212 81 19 / var(--tw-bg-opacity));
 }
-.hover\:bg-coal:hover {
-  --tw-bg-opacity: 1;
-  background-color: rgb(40 32 29 / var(--tw-bg-opacity));
-}
 .hover\:bg-crayola:hover {
   --tw-bg-opacity: 1;
   background-color: rgb(246 245 174 / var(--tw-bg-opacity));
 }
+.hover\:bg-coal:hover {
+  --tw-bg-opacity: 1;
+  background-color: rgb(40 32 29 / var(--tw-bg-opacity));
+}
 .hover\:bg-field:hover {
   --tw-bg-opacity: 1;
   background-color: rgb(104 79 67 / var(--tw-bg-opacity));
@@ -1495,10 +1482,6 @@ select {
   --tw-text-opacity: 1;
   color: rgb(17 24 39 / var(--tw-text-opacity));
 }
-.hover\:text-fogra:hover {
-  --tw-text-opacity: 1;
-  color: rgb(16 14 12 / var(--tw-text-opacity));
-}
 .focus\:z-10:focus {
   z-index: 10;
 }
@@ -1637,11 +1620,6 @@ select {
     margin-bottom: -1px;
   }
 
-  .sm\:mx-4 {
-    margin-left: 1rem;
-    margin-right: 1rem;
-  }
-
   .sm\:mr-2 {
     margin-right: 0.5rem;
   }
@@ -1650,14 +1628,14 @@ select {
     margin-left: 1.5rem;
   }
 
-  .sm\:ml-10 {
-    margin-left: 2.5rem;
-  }
-
   .sm\:ml-0 {
     margin-left: 0px;
   }
 
+  .sm\:ml-10 {
+    margin-left: 2.5rem;
+  }
+
   .sm\:block {
     display: block;
   }
@@ -1786,10 +1764,6 @@ select {
     margin-left: 1.5rem;
   }
 
-  .lg\:mr-6 {
-    margin-right: 1.5rem;
-  }
-
   .lg\:w-1\/4 {
     width: 25%;
   }

+ 20 - 7
resources/views/dashboard.blade.php

@@ -1,16 +1,29 @@
 <x-app-layout>
     <x-slot name="header">
-        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
-            {{ __('Dashboard') }}
+        <h2 class="font-semibold text-xl text-burnt leading-tight">
+            {{ __('Einstellungen') }}
         </h2>
     </x-slot>
 
     <div class="py-12">
-        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
-            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
-                <div class="p-6 bg-white border-b border-gray-200">
-                    You're logged in!
-                </div>
+        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8 text-crayola">
+            <!-- Session Status -->
+            <x-auth-session-status class="mb-4 border border-burnt p-2 rounded-lg bg-coal mx-auto max-w-xs" :status="session('status')" />
+
+            <h2 class="font-semibold text-xl text-crayola leading-tight sm:rounded-lg bg-coal mb-6 p-4">
+                Passwort
+            </h2>
+
+            <div class="px-4 mb-8">
+                Zum Ändern des Passworts, Abmelden und "Passwort vergessen" Funktion benutzen.
+            </div>
+
+            <h2 class="font-semibold text-xl text-crayola leading-tight sm:rounded-lg bg-coal mb-6 p-4">
+                Avatar
+            </h2>
+
+            <div class="px-4">
+                TBA
             </div>
         </div>
     </div>

+ 16 - 5
resources/views/film.blade.php

@@ -243,14 +243,18 @@
                 Kommentare
             </h2>
 
-            <div class="px-2">
+            <div class="px-2" x-data="{xnew: false, comments: {{$film->comments->count()}}}">
             @if (is_null(auth()->user()))
                 <p>Melde Dich an, um diesen Film zu kommentieren.</p>
             @else
-                <div>
+                <button x-show="comments > 0" class="text-yelmax float-right" @@click="xnew = !xnew" x-text="xnew ? 'Abbrechen' : '+ Kommentar und Bewertung hinzufügen'"></button>
+                <div x-show="xnew || comments < 1" x-transition>
                     <img src="/avatar/{{ auth()->user()->getAvatar() }}" alt="User Avatar" class="rounded-lg w-16 float-left mr-2">
                     <div class="">
+                        <form method="POST" action="/comment/new/{{ $film->id }}/">
+                            @csrf
                         <h4 class="font-semibold">Neuer Kommentar</h4>
+                        @if($film->userMayEvaluate(auth()->user()->id))
                         <div class="flex" x-data="{ stars: 0 }">
                             <input type="hidden" name="vote" id="vote" x-bind:value="stars">
                             <p @@click="stars = 0">Bewerten: </p>
@@ -304,14 +308,17 @@
                                     <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
                                   </svg>
                             </div>
+                            <span x-text="' (' + stars + ')'"></span>
                         </div>
-                        <textarea class="block w-[calc(100%-4.5rem)] my-1 rounded-lg border-1 border-field bg-coal"></textarea>
+                        @endif
+                        <textarea name="body" id="body" class="block w-[calc(100%-4.5rem)] my-1 rounded-lg border-1 border-field bg-coal"></textarea>
                         <x-button class="ml-[4.5rem]">Absenden</x-button>
+                        </form>
                     </div>
                 </div>
             @endif
             @foreach ($film->comments()->orderBy('created_at', 'DESC')->get() as $comment)
-                <div class="clear-left my-2 min-h-[4rem]" x-data="{edit: false}">
+                <div class="clear-left my-2 min-h-[5rem]" x-data="{edit: false}">
                     <img src="/avatar/{{ $comment->author->getAvatar() }}" alt="{{ $comment->author->name }} Avatar" class="rounded-lg w-16 float-left mr-2">
                     <h4 class="font-bold">
                         {{ $comment->author->name }}
@@ -336,6 +343,8 @@
                         <button class="text-yelmax float-right" @@click="edit = !edit" x-text="edit ? 'Abbrechen' : 'Bearbeiten'"></button>
                         <p x-show="!edit" x-transition>{{ $comment->body }}</p>
                         <div x-show="edit" x-transition>
+                            <form method="post" action="/comment/edit/{{ $comment->id }}">
+                                @csrf
                             @if($comment->evaluation > 0)
                             <div class="flex" x-data="{ stars: {{ $comment->evaluation }} }">
                                 <input type="hidden" name="vote" id="vote" x-bind:value="stars">
@@ -390,10 +399,12 @@
                                         <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
                                       </svg>
                                 </div>
+                                <span x-text="' (' + stars + ')'"></span>
                             </div>
                             @endif
-                            <textarea class="block w-[calc(100%-4.5rem)] my-1 rounded-lg border-1 border-field bg-coal">{{ $comment->body }}</textarea>
+                            <textarea name="body" id="body" class="block w-[calc(100%-4.5rem)] my-1 rounded-lg border-1 border-field bg-coal">{{ $comment->body }}</textarea>
                             <x-button class="ml-[4.5rem]">Speichern</x-button>
+                            </form>
                         </div>
                     @else
                         <p>{{ $comment->body }}</p>

+ 8 - 3
resources/views/layouts/navigation.blade.php

@@ -44,11 +44,13 @@
                         <!-- Authentication -->
                         <form method="POST" action="{{ route('logout') }}">
                             @csrf
-
+                            <x-dropdown-link :href="route('dashboard')">
+                                {{ __('Einstellungen') }}
+                            </x-dropdown-link>
                             <x-dropdown-link :href="route('logout')"
                                     onclick="event.preventDefault();
                                                 this.closest('form').submit();">
-                                {{ __('Log Out') }}
+                                {{ __('Abmelden') }}
                             </x-dropdown-link>
                         </form>
                     </x-slot>
@@ -97,6 +99,9 @@
             </div>
 
             <div class="mt-3 space-y-1">
+                <x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
+                    {{ __('Einstellungen') }}
+                </x-responsive-nav-link>
                 <!-- Authentication -->
                 <form method="POST" action="{{ route('logout') }}">
                     @csrf
@@ -104,7 +109,7 @@
                     <x-responsive-nav-link :href="route('logout')"
                             onclick="event.preventDefault();
                                         this.closest('form').submit();">
-                        {{ __('Log Out') }}
+                        {{ __('Abmelden') }}
                     </x-responsive-nav-link>
                 </form>
             </div>

+ 1 - 0
routes/auth.php

@@ -8,6 +8,7 @@ use App\Http\Controllers\Auth\NewPasswordController;
 use App\Http\Controllers\Auth\PasswordResetLinkController;
 use App\Http\Controllers\Auth\RegisteredUserController;
 use App\Http\Controllers\Auth\VerifyEmailController;
+use Illuminate\Support\Facades\Request;
 use Illuminate\Support\Facades\Route;
 
 Route::middleware('guest')->group(function () {

+ 25 - 3
routes/web.php

@@ -4,16 +4,16 @@ use App\Models\Film;
 use Illuminate\Support\Facades\Route;
 use Tmdb\Repository\MovieRepository;
 use App\Http\Helpers\TmdbProvider;
+use App\Models\Comment;
 use App\Models\Setting;
 use Tmdb\Helper\ImageHelper;
 use Tmdb\Repository\ConfigurationRepository;
 use Tmdb\Repository\SearchRepository;
 use App\Models\News;
 use App\Models\Vote;
-use Hamcrest\Core\Set;
-use Symfony\Component\EventDispatcher\EventDispatcher;
-use Tmdb\Event\Listener\HydrationListener;
 use Tmdb\Model\Search\SearchQuery\MovieSearchQuery;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
 
 /*
 |--------------------------------------------------------------------------
@@ -225,4 +225,26 @@ Route::get('/vorschlag/{id}/vorschlagen', function($id) {
 
 })->middleware(['auth']);
 
+Route::post('/comment/new/{film}', function($film, Request $request) {
+    $c = new Comment();
+    $c->film = $film;
+    $c->user = Auth::user()->id;
+    $c->body = $request->input('body', '');
+    if(is_null($c->body)) $c->body = "";
+    $c->evaluation = $request->input('vote', 0);
+    $c->save();
+
+    return redirect("/film/" . $film)->with('status', auth()->user()->name . ', Kommentar/Bewertung hinzugefügt.');
+})->middleware(['auth']);
+
+Route::post('/comment/edit/{comment}', function($comment, Request $request) {
+    $c = Comment::findOrFail($comment);
+    $c->body = $request->input('body', '');
+    if(is_null($c->body)) $c->body = "";
+    $c->evaluation = $request->input('vote', $c->evaluation);
+    $c->save();
+
+    return redirect("/film/" . $c->film)->with('status', auth()->user()->name . ', Kommentar/Bewertung hinzugefügt.');
+})->middleware(['auth']);
+
 require __DIR__.'/auth.php';