Преглед изворни кода

[Feature] Add useful links in top menubar (#662)

Dennis пре 2 година
родитељ
комит
0cfa02b4ce

+ 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 - 1
app/Http/Controllers/Admin/SettingsController.php

@@ -22,7 +22,13 @@ class SettingsController extends Controller
 
         //Get all tabs as laravel view paths
         $tabs = [];
-        foreach (glob(Theme::getViewPaths()[0] . '/admin/settings/tabs/*.blade.php') as $filename) {
+        if(file_exists(Theme::getViewPaths()[0] . '/admin/settings/tabs/')){
+            $tabspath = glob(Theme::getViewPaths()[0] . '/admin/settings/tabs/*.blade.php');
+        }else{
+            $tabspath = glob(Theme::path($path = 'views', $themeName = 'default').'/admin/settings/tabs/*.blade.php');
+        }
+
+          foreach ($tabspath as $filename) {
             $tabs[] = 'admin.settings.tabs.'.basename($filename, '.blade.php');
         }
 

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

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Admin;
 
+use App\Enums\UsefulLinkLocation;
 use App\Http\Controllers\Controller;
 use App\Models\UsefulLink;
 use Illuminate\Contracts\Foundation\Application;
@@ -30,7 +31,8 @@ class UsefulLinkController extends Controller
      */
     public function create()
     {
-        return view('admin.usefullinks.create');
+        $positions = UsefulLinkLocation::cases();
+        return view('admin.usefullinks.create')->with('positions', $positions);
     }
 
     /**
@@ -48,7 +50,14 @@ class UsefulLinkController extends Controller
             'description' => 'required|string|max:2000',
         ]);
 
-        UsefulLink::create($request->all());
+
+        UsefulLink::create([
+            'icon' => $request->icon,
+            'title' => $request->title,
+            'link' => $request->link,
+            'description' => $request->description,
+            'position' => implode(",",$request->position),
+        ]);
 
         return redirect()->route('admin.usefullinks.index')->with('success', __('link has been created!'));
     }
@@ -72,8 +81,10 @@ class UsefulLinkController extends Controller
      */
     public function edit(UsefulLink $usefullink)
     {
+        $positions = UsefulLinkLocation::cases();
         return view('admin.usefullinks.edit', [
             'link' => $usefullink,
+            'positions' => $positions,
         ]);
     }
 
@@ -93,7 +104,13 @@ class UsefulLinkController extends Controller
             'description' => 'required|string|max:2000',
         ]);
 
-        $usefullink->update($request->all());
+        $usefullink->update([
+            'icon' => $request->icon,
+            'title' => $request->title,
+            'link' => $request->link,
+            'description' => $request->description,
+            'position' => implode(",",$request->position),
+        ]);
 
         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([
             'usage' => $usage,
             'credits' => $credits,
-            'useful_links' => UsefulLink::all()->sortBy('id'),
+            'useful_links' => UsefulLink::where("position","like","%dashboard%")->get()->sortby("id"),
             'bg' => $bg,
             'boxText' => $boxText,
             'unit' => $unit,

+ 1 - 0
app/Models/UsefulLink.php

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

+ 7 - 0
app/Providers/AppServiceProvider.php

@@ -3,6 +3,7 @@
 namespace App\Providers;
 
 use App\Models\Settings;
+use App\Models\UsefulLink;
 use Exception;
 use Illuminate\Pagination\Paginator;
 use Illuminate\Support\Facades\Artisan;
@@ -53,6 +54,12 @@ class AppServiceProvider extends ServiceProvider
             return $ok;
         });
 
+
+        if (Schema::hasColumn('useful_links', 'position')) {
+            $useful_links = UsefulLink::where("position","like","%topbar%")->get()->sortby("id");
+            view()->share('useful_links', $useful_links);
+        }
+
         //only run if the installer has been executed
         try {
             $settings = Settings::all();

+ 32 - 0
database/migrations/2023_01_25_204343_useful_links_on_top_navbar.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('useful_links', function (Blueprint $table) {
+            $table->string('position')->after("description")->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('useful_links', function (Blueprint $table) {
+            $table->dropColumn('position');
+        });
+    }
+};

+ 1 - 1
themes/default/views/admin/settings/tabs/system.blade.php

@@ -481,7 +481,7 @@
             </div>
     </form>
 </div>
-<script>tinymce.init({selector:'textarea',skin: "oxide-dark",
+<script>tinymce.init({selector:'textarea',promotion: false,skin: "oxide-dark",
         content_css: "dark",branding: false,  height: 500,
         plugins: ['image','link'],});
 </script>

+ 19 - 0
themes/default/views/admin/usefullinks/create.blade.php

@@ -94,6 +94,22 @@
                                     @enderror
                                 </div>
 
+                                <div class="form-group">
+                                    <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">
+                                        {{$message}}
+                                    </div>
+                                    @enderror
+                                </div>
+
 
                                 <div class="form-group text-right">
                                     <button type="submit" class="btn btn-primary">
@@ -111,6 +127,7 @@
     <!-- END CONTENT -->
     <script>
         document.addEventListener('DOMContentLoaded', (event) => {
+            $('.custom-select').select2();
 // Summernote
             $('#description').summernote({
                 height: 100,
@@ -127,6 +144,8 @@
                 ]
             })
         })
+
+
     </script>
 
 @endsection

+ 17 - 0
themes/default/views/admin/usefullinks/edit.blade.php

@@ -95,6 +95,22 @@
                                     @enderror
                                 </div>
 
+                                <div class="form-group">
+                                    <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">
+                                        {{$message}}
+                                    </div>
+                                    @enderror
+                                </div>
+
 
                                 <div class="form-group text-right">
                                     <button type="submit" class="btn btn-primary">
@@ -113,6 +129,7 @@
 
     <script>
         document.addEventListener('DOMContentLoaded', (event) => {
+            $('.custom-select').select2();
 // Summernote
             $('#description').summernote({
                 height: 100,

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

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

+ 7 - 0
themes/default/views/layouts/main.blade.php

@@ -60,6 +60,7 @@
                                 class="fab fa-discord mr-2"></i>{{ __('Discord') }}</a>
                     </li>
                 @endif
+
                 <!-- Language Selection -->
                 @if (config('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE') == 'true')
                     <li class="nav-item dropdown">
@@ -84,6 +85,12 @@
                     </li>
                     <!-- End Language Selection -->
                 @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
             </ul>
 
             <!-- Right navbar links -->