Browse Source

using enums, adding more positions

1day2die 2 years ago
parent
commit
b343134c01

+ 19 - 0
app/Enums/UsefulLinkLocation.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Enums;
+
+enum UsefulLinkLocation:String
+{
+    /**
+     * Top bar
+     * Only visible in the dashboard view
+     */
+    case topbar = "topbar";
+
+    /**
+     * Dashboard
+     * Only visible in the dashboard view
+     */
+    case dashboard = "dashboard";
+
+}

+ 7 - 3
app/Http/Controllers/Admin/UsefulLinkController.php

@@ -2,6 +2,7 @@
 
 
 namespace App\Http\Controllers\Admin;
 namespace App\Http\Controllers\Admin;
 
 
+use App\Enums\UsefulLinkLocation;
 use App\Http\Controllers\Controller;
 use App\Http\Controllers\Controller;
 use App\Models\UsefulLink;
 use App\Models\UsefulLink;
 use Illuminate\Contracts\Foundation\Application;
 use Illuminate\Contracts\Foundation\Application;
@@ -30,7 +31,8 @@ class UsefulLinkController extends Controller
      */
      */
     public function create()
     public function create()
     {
     {
-        return view('admin.usefullinks.create');
+        $positions = UsefulLinkLocation::cases();
+        return view('admin.usefullinks.create')->with('positions', $positions);
     }
     }
 
 
     /**
     /**
@@ -54,7 +56,7 @@ class UsefulLinkController extends Controller
             'title' => $request->title,
             'title' => $request->title,
             'link' => $request->link,
             'link' => $request->link,
             'description' => $request->description,
             'description' => $request->description,
-            'navbar' => $request->navbar,
+            'position' => implode(",",$request->position),
         ]);
         ]);
 
 
         return redirect()->route('admin.usefullinks.index')->with('success', __('link has been created!'));
         return redirect()->route('admin.usefullinks.index')->with('success', __('link has been created!'));
@@ -79,8 +81,10 @@ class UsefulLinkController extends Controller
      */
      */
     public function edit(UsefulLink $usefullink)
     public function edit(UsefulLink $usefullink)
     {
     {
+        $positions = UsefulLinkLocation::cases();
         return view('admin.usefullinks.edit', [
         return view('admin.usefullinks.edit', [
             'link' => $usefullink,
             'link' => $usefullink,
+            'positions' => $positions,
         ]);
         ]);
     }
     }
 
 
@@ -105,7 +109,7 @@ class UsefulLinkController extends Controller
             'title' => $request->title,
             'title' => $request->title,
             'link' => $request->link,
             'link' => $request->link,
             'description' => $request->description,
             'description' => $request->description,
-            'navbar' => $request->navbar,
+            'position' => implode(",",$request->position),
         ]);
         ]);
 
 
         return redirect()->route('admin.usefullinks.index')->with('success', __('link has been updated!'));
         return redirect()->route('admin.usefullinks.index')->with('success', __('link has been updated!'));

+ 1 - 1
app/Http/Controllers/HomeController.php

@@ -111,7 +111,7 @@ class HomeController extends Controller
         return view('home')->with([
         return view('home')->with([
             'usage' => $usage,
             'usage' => $usage,
             'credits' => $credits,
             'credits' => $credits,
-            'useful_links' => UsefulLink::all()->sortBy('id'),
+            'useful_links' => UsefulLink::where("position","like","%dashboard%")->get()->sortby("id"),
             'bg' => $bg,
             'bg' => $bg,
             'boxText' => $boxText,
             'boxText' => $boxText,
             'unit' => $unit,
             'unit' => $unit,

+ 1 - 1
app/Models/UsefulLink.php

@@ -16,6 +16,6 @@ class UsefulLink extends Model
         'title',
         'title',
         'link',
         'link',
         'description',
         'description',
-        'navbar',
+        'position',
     ];
     ];
 }
 }

+ 2 - 2
app/Providers/AppServiceProvider.php

@@ -55,8 +55,8 @@ class AppServiceProvider extends ServiceProvider
         });
         });
 
 
 
 
-        if (Schema::hasColumn('useful_links', 'navbar')) {
-            $useful_links = UsefulLink::where("navbar", "true")->get();
+        if (Schema::hasColumn('useful_links', 'position')) {
+            $useful_links = UsefulLink::get();
             view()->share('useful_links', $useful_links);
             view()->share('useful_links', $useful_links);
         }
         }
 
 

+ 2 - 2
database/migrations/2023_01_25_204343_useful_links_on_top_navbar.php

@@ -14,7 +14,7 @@ return new class extends Migration
     public function up()
     public function up()
     {
     {
         Schema::table('useful_links', function (Blueprint $table) {
         Schema::table('useful_links', function (Blueprint $table) {
-            $table->string('navbar')->after("description")->nullable();
+            $table->string('position')->after("description")->nullable();
         });
         });
     }
     }
 
 
@@ -26,7 +26,7 @@ return new class extends Migration
     public function down()
     public function down()
     {
     {
         Schema::table('useful_links', function (Blueprint $table) {
         Schema::table('useful_links', function (Blueprint $table) {
-            $table->dropColumn('navbar');
+            $table->dropColumn('position');
         });
         });
     }
     }
 };
 };

+ 12 - 8
themes/default/views/admin/usefullinks/create.blade.php

@@ -95,14 +95,15 @@
                                 </div>
                                 </div>
 
 
                                 <div class="form-group">
                                 <div class="form-group">
-                                    <div class="col m-0 p-0 d-flex justify-content-between align-items-center">
-                                        <div>
-                                            <input value="true" id="navbar" name="navbar"
-                                                   type="checkbox">
-                                            <label for="navbar">{{ __('Show link on top Navbar') }} </label>
-                                        </div>
-                                    </div>
-                                    @error('navbar')
+                                    <select id="position" style="width:100%" class="custom-select" name="position[]"
+                                            required multiple autocomplete="off" @error('position') is-invalid @enderror>
+                                        @foreach ($positions as $position)
+                                            <option id="{{$position->value}}" value="{{ $position->value }}">
+                                                {{ __($position->value) }}
+                                            </option>
+                                        @endforeach
+                                    </select>
+                                    @error('position')
                                     <div class="text-danger">
                                     <div class="text-danger">
                                         {{$message}}
                                         {{$message}}
                                     </div>
                                     </div>
@@ -126,6 +127,7 @@
     <!-- END CONTENT -->
     <!-- END CONTENT -->
     <script>
     <script>
         document.addEventListener('DOMContentLoaded', (event) => {
         document.addEventListener('DOMContentLoaded', (event) => {
+            $('.custom-select').select2();
 // Summernote
 // Summernote
             $('#description').summernote({
             $('#description').summernote({
                 height: 100,
                 height: 100,
@@ -142,6 +144,8 @@
                 ]
                 ]
             })
             })
         })
         })
+
+
     </script>
     </script>
 
 
 @endsection
 @endsection

+ 10 - 8
themes/default/views/admin/usefullinks/edit.blade.php

@@ -96,14 +96,15 @@
                                 </div>
                                 </div>
 
 
                                 <div class="form-group">
                                 <div class="form-group">
-                                    <div class="col m-0 p-0 d-flex justify-content-between align-items-center">
-                                        <div>
-                                            <input value="true" id="navbar" name="navbar"
-                                                   type="checkbox" @if($link->navbar == "true") checked @endif
-                                            <label for="navbar">{{ __('Show link on top Navbar') }} </label>
-                                        </div>
-                                    </div>
-                                    @error('navbar')
+                                    <select id="position" style="width:100%" class="custom-select" name="position[]"
+                                            required multiple autocomplete="off" @error('position') is-invalid @enderror>
+                                        @foreach ($positions as $position)
+                                            <option id="{{$position->value}}" value="{{ $position->value }}" @if (strpos($link->position, $position->value) !== false)  selected @endif>
+                                                {{ __($position->value) }}
+                                            </option>
+                                        @endforeach
+                                    </select>
+                                    @error('position')
                                     <div class="text-danger">
                                     <div class="text-danger">
                                         {{$message}}
                                         {{$message}}
                                     </div>
                                     </div>
@@ -128,6 +129,7 @@
 
 
     <script>
     <script>
         document.addEventListener('DOMContentLoaded', (event) => {
         document.addEventListener('DOMContentLoaded', (event) => {
+            $('.custom-select').select2();
 // Summernote
 // Summernote
             $('#description').summernote({
             $('#description').summernote({
                 height: 100,
                 height: 100,

+ 2 - 2
themes/default/views/admin/usefullinks/index.blade.php

@@ -41,7 +41,7 @@
                             <th width="50">{{__('Icon')}}</th>
                             <th width="50">{{__('Icon')}}</th>
                             <th>{{__('Title')}}</th>
                             <th>{{__('Title')}}</th>
                             <th>{{__('Link')}}</th>
                             <th>{{__('Link')}}</th>
-                            <th>{{__('Navbar')}}</th>
+                            <th>{{__('Position')}}</th>
                             <th>{{__('Created at')}}</th>
                             <th>{{__('Created at')}}</th>
                             <th></th>
                             <th></th>
                         </tr>
                         </tr>
@@ -80,7 +80,7 @@
                     {data: 'icon'},
                     {data: 'icon'},
                     {data: 'title'},
                     {data: 'title'},
                     {data: 'link'},
                     {data: 'link'},
-                    {data: 'navbar'},
+                    {data: 'position'},
                     {data: 'created_at'},
                     {data: 'created_at'},
                     {data: 'actions', sortable: false},
                     {data: 'actions', sortable: false},
                 ],
                 ],

+ 8 - 6
themes/default/views/layouts/main.blade.php

@@ -61,12 +61,6 @@
                     </li>
                     </li>
                 @endif
                 @endif
 
 
-                @foreach($useful_links as $link)
-                    <li class="nav-item d-none d-sm-inline-block">
-                        <a href="{{ $link->link }}" class="nav-link" target="__blank"><i
-                                class="{{$link->icon}}"></i> {{ $link->title }}</a>
-                    </li>
-                @endforeach
                 <!-- Language Selection -->
                 <!-- Language Selection -->
                 @if (config('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE') == 'true')
                 @if (config('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE') == 'true')
                     <li class="nav-item dropdown">
                     <li class="nav-item dropdown">
@@ -91,6 +85,14 @@
                     </li>
                     </li>
                     <!-- End Language Selection -->
                     <!-- End Language Selection -->
                 @endif
                 @endif
+                @foreach($useful_links as $link)
+                    @if(strpos($link->position,"topbar") !== false)
+                        <li class="nav-item d-none d-sm-inline-block">
+                            <a href="{{ $link->link }}" class="nav-link" target="__blank"><i
+                                    class="{{$link->icon}}"></i> {{ $link->title }}</a>
+                        </li>
+                    @endif
+                @endforeach
             </ul>
             </ul>
 
 
             <!-- Right navbar links -->
             <!-- Right navbar links -->