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;
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);
}
/**
@ -54,7 +56,7 @@ class UsefulLinkController extends Controller
'title' => $request->title,
'link' => $request->link,
'description' => $request->description,
'navbar' => $request->navbar,
'position' => implode(",",$request->position),
]);
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)
{
$positions = UsefulLinkLocation::cases();
return view('admin.usefullinks.edit', [
'link' => $usefullink,
'positions' => $positions,
]);
}
@ -105,7 +109,7 @@ class UsefulLinkController extends Controller
'title' => $request->title,
'link' => $request->link,
'description' => $request->description,
'navbar' => $request->navbar,
'position' => implode(",",$request->position),
]);
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([
'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,

View file

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

View file

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

@ -14,7 +14,7 @@ return new class extends Migration
public function up()
{
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()
{
Schema::table('useful_links', function (Blueprint $table) {
$table->dropColumn('navbar');
$table->dropColumn('position');
});
}
};

View file

@ -95,14 +95,15 @@
</div>
<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">
{{$message}}
</div>
@ -126,6 +127,7 @@
<!-- END CONTENT -->
<script>
document.addEventListener('DOMContentLoaded', (event) => {
$('.custom-select').select2();
// Summernote
$('#description').summernote({
height: 100,
@ -142,6 +144,8 @@
]
})
})
</script>
@endsection

View file

@ -96,14 +96,15 @@
</div>
<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">
{{$message}}
</div>
@ -128,6 +129,7 @@
<script>
document.addEventListener('DOMContentLoaded', (event) => {
$('.custom-select').select2();
// Summernote
$('#description').summernote({
height: 100,

View file

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

View file

@ -61,12 +61,6 @@
</li>
@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 -->
@if (config('SETTINGS::LOCALE:CLIENTS_CAN_CHANGE') == 'true')
<li class="nav-item dropdown">
@ -91,6 +85,14 @@
</li>
<!-- End Language Selection -->
@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>
<!-- Right navbar links -->