commit 49b1d48f21f90c3584514f8657d1082c7b659e30
Author: zabran <zabran@students.zcu.cz>
Date:   Thu May 14 22:58:04 2020 +0200

    Issue #7959 @1.25h
    Další pokroky v Charts. Zatím stále nefunkční.

diff --git a/app/Http/Controllers/ChartsController.php b/app/Http/Controllers/ChartsController.php
index 40aa33f..dbe3a5d 100644
--- a/app/Http/Controllers/ChartsController.php
+++ b/app/Http/Controllers/ChartsController.php
@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\User;
 use Illuminate\Contracts\Foundation\Application;
 use Illuminate\Contracts\View\Factory;
 use Illuminate\Support\Facades\Auth;
@@ -26,9 +27,12 @@ class ChartsController extends Controller
         if(Auth::check())
         {
             $artefacts = Artefact::all();
+            //$user_likes = User::find(Auth::id())->likesArtefacts();
             foreach($artefacts as $item)
             {
-                $item['likes'] = Artefact::find($item->id)->users()->count();
+                $id = $item->id;
+                $item['likes'] = Artefact::find($id)->users()->count();
+                $item['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
             }
             $artefacts=$artefacts->sortByDesc('likes');
 
@@ -36,7 +40,7 @@ class ChartsController extends Controller
                 'title' => 'Charts',
                 'artefacts' => $artefacts
             );
-            return view('favartefacts.index') -> with($data);
+            return view('charts.index') -> with($data);
         }
         else
         {
@@ -56,9 +60,12 @@ class ChartsController extends Controller
     public function show()
     {
         $artefacts = Artefact::all();
+        //$user_likes = User::find(Auth::id())->likesArtefacts();
         foreach($artefacts as $item)
         {
-            $item['likes'] = Artefact::find($item->id)->users()->count();
+            $id = $item->id;
+            $item['likes'] = Artefact::find($id)->users()->count();
+            $item['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
         }
         $artefacts=$artefacts->sortByDesc('likes');
 
diff --git a/resources/views/charts/index.blade.php b/resources/views/charts/index.blade.php
index 5282182..3d67fa6 100644
--- a/resources/views/charts/index.blade.php
+++ b/resources/views/charts/index.blade.php
@@ -4,9 +4,11 @@
 
 @section('content')
     <div class="container">
-        {{--<p>The id of the user is {{$user->id}}</p>--}}
         @if(isset($artefacts))
             @if(count($artefacts) >= 1)
+                <div class="fav-cat-mybooks">
+                    <h1>Charts</h1>
+                </div>
                 @foreach($artefacts as $artefact)
                     <div class="artefacts-area mb-5">
                         <div class="card">
@@ -14,33 +16,44 @@
                         <a href="{{ url('/artefact/' . $artefact->id) }}">
                             <img class="card-img-top" src="{{asset('images/artefacts/book_cover_01.jpg')}}" width="100%" height=auto>
                         </a>
-                        <div class="container card-cus-bottom">
-                            <div class="flex-row row-list">
-                                <div class="col-xs-2 float-left left_panel_info">
-                                    <h5 class="card-title ">{{$artefact->name}}</h5>
-                                    <h6 class="card-title">{{$artefact->author}}</h6>
-                                </div>
-                                <div class="col-xs-2 float-right right_panel_info">
-                                    <div class="float-left">
-                                        <button id="info_butt_{{$artefact->id}}" type="button" class="btn btn-primary button-image inter_info"></button>
+                            <div class="container card-cus-bottom">
+                                <div class="d-flex flex-row row-list">{{--<div class="flex-row row-list">--}}
+                                    <div class="p-1 flex-fill bd-highlight left_panel_info">{{--<div class="col-xs-2 float-left left_panel_info">--}}
+                                        <h5 class="card-title ">{{$artefact->name}}</h5>
+                                        <h6 class="card-title">{{$artefact->author}}</h6>
                                     </div>
-                                    <div class="float-right text-center">
-                                        <button id="like_butt_{{$artefact->id}}" onclick="myFunction({{$artefact->id}}, 1)" type="button" class="btn btn-primary button-image inter_like"></button>
-                                        <button id="like_butt2_{{$artefact->id}}" onclick="myFunction({{$artefact->id}}, 0)" type="button" class="btn btn-primary button-image inter_like_filled"></button>
-                                        <span class="likes_text">
-                                          <h6>{{$artefact->likes}}</h6>
-                                        </span>
+                                    <div class="p-1 flex-fill bd-highlight float-right">{{--<div class="col-xs-2 float-right right_panel_info">--}}
+                                        <div class="text-right right_panel_info">{{--<div class="float-right text-center">--}}
+                                            <div class="float-left">
+                                                <button id="info_butt_{{$artefact->id}}" type="button" class="btn btn-primary float-left button-image inter_info"></button>
+                                            </div>
+                                            <div class="fav-cat-likes-t float-right">
+                                                @if (!$artefact->favourite)
+                                                <form method="POST" action="{{ url('/artefact/like/' . $artefact->id) }}">
+                                                    @csrf
+                                                    <button id="like_butt_{{$artefact->id}}" type="submit" class="btn btn-primary button-image inter_like"></button>
+                                                </form>
+                                                @else
+                                                <form method="POST" action="{{ url('/artefact/unlike/' . $artefact->id) }}">
+                                                    @csrf
+                                                    <button id="like_butt_{{$artefact->id}}" type="submit" class="btn btn-primary button-image inter_like_filled"></button>
+                                                </form>
+                                                @endif
+                                                <span class="likes_text">
+                                                <h6>{{$artefact->likes}}</h6>
+                                            </span>
+                                            </div>
+                                        </div>
                                     </div>
                                 </div>
                             </div>
-                            </div>
                         </div>
                     </div>
                 @endforeach
             @else
                 <ul class="list-group">
                     <li class="list-group-item">
-                        <h3>No favorites were added!</h3>
+                        <h3>No artefacts were added!</h3>
                     </li>
                 </ul>
             @endif
@@ -53,7 +66,7 @@
         @endif
 	</div>
     <script>
-        function myFunction(id, type)
+        /*function myFunction(id, type)
         {
             if(type === 1)
             {
@@ -65,6 +78,6 @@
                 $('#like_butt_' + id).css('display', "inline");
                 $('#like_butt2_' + id).css('display', "none");
             }
-        }
+        }*/
     </script>
 @endsection
