using enums, adding more positions

This commit is contained in:
1day2die 2023-01-26 15:22:42 +01:00
parent fbc9b53b6c
commit b343134c01
10 changed files with 64 additions and 33 deletions

View file

@ -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";
}

View file

@ -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!'));

View file

@ -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,

View file

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

View file

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

View file

@ -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');
}); });
} }
}; };

View file

@ -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"> <select id="position" style="width:100%" class="custom-select" name="position[]"
<div> required multiple autocomplete="off" @error('position') is-invalid @enderror>
<input value="true" id="navbar" name="navbar" @foreach ($positions as $position)
type="checkbox"> <option id="{{$position->value}}" value="{{ $position->value }}">
<label for="navbar">{{ __('Show link on top Navbar') }} </label> {{ __($position->value) }}
</div> </option>
</div> @endforeach
@error('navbar') </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

View file

@ -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"> <select id="position" style="width:100%" class="custom-select" name="position[]"
<div> required multiple autocomplete="off" @error('position') is-invalid @enderror>
<input value="true" id="navbar" name="navbar" @foreach ($positions as $position)
type="checkbox" @if($link->navbar == "true") checked @endif <option id="{{$position->value}}" value="{{ $position->value }}" @if (strpos($link->position, $position->value) !== false) selected @endif>
<label for="navbar">{{ __('Show link on top Navbar') }} </label> {{ __($position->value) }}
</div> </option>
</div> @endforeach
@error('navbar') </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,

View file

@ -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},
], ],

View file

@ -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 -->