Skip to content

Commit

Permalink
Merge pull request #234 from MineTrax/feature/custom-navigation-maker
Browse files Browse the repository at this point in the history
Feature: Custom Navbar Maker & Other Fixes
  • Loading branch information
Xinecraft authored Feb 19, 2023
2 parents db98279 + 23e881e commit 3fedf90
Show file tree
Hide file tree
Showing 175 changed files with 2,539 additions and 1,676 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function update(Request $request, GeneralSettings $settings): \Illuminate
'photo_light' => 'sometimes|nullable|image|max:100',
'photo_dark' => 'sometimes|nullable|image|max:100',
'enable_status_feed' => 'required|boolean',
'enable_sticky_header_menu' => 'required|boolean',
]);
$settings->site_name = $request->input('site_name');
$settings->enable_mcserver_onlineplayersbox = $request->input('enable_mcserver_onlineplayersbox');
Expand Down Expand Up @@ -80,8 +79,6 @@ public function update(Request $request, GeneralSettings $settings): \Illuminate
$settings->enable_donation_box = $request->input('enable_donation_box');
$settings->donation_box_url = $request->input('donation_box_url');

$settings->enable_sticky_header_menu = $request->input('enable_sticky_header_menu');

// Has Photo?
if ($request->hasFile('photo_light')) {
$path = Storage::putFileAs(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Http\Controllers\Admin\Settings;

use App\Http\Controllers\Controller;
use App\Models\CustomPage;
use App\Settings\GeneralSettings;
use App\Settings\NavigationSettings;
use Illuminate\Http\Request;
use Inertia\Inertia;

class NavigationSettingController extends Controller
{
public function __construct()
{
$this->middleware(['can:update settings']);
}

public function show(NavigationSettings $settings, GeneralSettings $generalSettings)
{
// Items which can be added to custom navbar
$availableNavItems = config('minetrax.custom_nav_available_items_array');

// Custom pages which can be added
$customPageItems = CustomPage::select(['id', 'title', 'path'])->get();
foreach ($customPageItems as $item) {
$availableNavItems[] = [
'type' => 'custom-page',
'name' => $item->title,
'title' => $item->title,
'id' => $item->id,
'route' => 'custom-page.show',
'route_params' => [
'path' => $item->path,
],
'key' => 'custom-page-' . $item->id,
];
}

return Inertia::render('Admin/Setting/NavigationSetting', [
'settings' => $settings->toArray(),
'generalSettings' => $generalSettings->toArray(),
'availableNavItems' => $availableNavItems,
]);
}

public function update(Request $request, NavigationSettings $settings, GeneralSettings $generalSettings)
{
$request->validate([
'enable_custom_navbar' => 'required|boolean',
'custom_navbar_data' => 'nullable|array',
'enable_sticky_header_menu' => 'required|boolean',
]);

$navbarData = $request->input('custom_navbar_data');

// Check in array if we have a dropdown type inside a dropdown type then we give error
foreach ($navbarData as $sideList) {
foreach ($sideList as $item) {
if ($item['type'] === 'dropdown') {
foreach ($item['children'] as $child) {
if ($child['type'] === 'dropdown' || $child['type'] === 'component') {
return redirect()->back()
->with(['toast' => ['type' => 'error', 'title' => __('You can not add a dropdown or component inside of a dropdown')]])
->withErrors(['custom_navbar_data' => __('You can not add a dropdown or component inside of a dropdown')]);
}
}
}
}
}

$settings->enable_custom_navbar = $request->input('enable_custom_navbar');
$settings->custom_navbar_data = $navbarData;
$settings->save();

$generalSettings->enable_sticky_header_menu = $request->input('enable_sticky_header_menu');
$generalSettings->save();

return redirect()->back()
->with(['toast' => ['type' => 'success', 'title' => __('Navigation Settings Updated Successfully')]]);
}
}
9 changes: 8 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ public function version()
{
$myVersion = config("app.version");

$latestVersion = Http::withoutVerifying()->timeout(5)->get('https://e74gvrc5hpiyr7wojet23ursau0ehgxd.lambda-url.eu-central-1.on.aws')->json();
$latestVersion = Http::withoutVerifying()->timeout(5)->get('https://e74gvrc5hpiyr7wojet23ursau0ehgxd.lambda-url.eu-central-1.on.aws',
[
'version' => $myVersion,
'from' => 'web',
'appName' => config("app.name"),
'appUrl' => config("app.url"),
]
)->json();
$latestVersion = $latestVersion['web'];

$response = [
Expand Down
1 change: 0 additions & 1 deletion app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function share(Request $request)
return $defaultQueryServer;
},
'generalSettings' => fn (GeneralSettings $generalSettings) => $generalSettings->toArray(),
'customPageList' => CustomPage::visible()->navbar()->select(['id', 'title', 'path', 'is_in_navbar', 'is_visible'])->get(),
'isImpersonating' => $request->user() && $request->user()->isImpersonating(),
'enabledSocialAuths' => function () {
$enabledSocialLogins = [];
Expand Down
16 changes: 16 additions & 0 deletions app/Settings/NavigationSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Settings;

use Spatie\LaravelSettings\Settings;

class NavigationSettings extends Settings
{
public bool $enable_custom_navbar;
public array $custom_navbar_data;

public static function group(): string
{
return 'navigation';
}
}
152 changes: 151 additions & 1 deletion app/View/Components/PhpVarsToJsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,91 @@

namespace App\View\Components;

use App\Models\CustomPage;
use App\Settings\NavigationSettings;
use Illuminate\View\Component;

class PhpVarsToJsTransformer extends Component
{
const DEFAULT_NAV_LEFT = [
[
'type' => 'component',
'name' => 'App Logo',
'title' => 'App Logo',
'component' => 'AppLogoMark',
'key' => 'component-app-icon-01',
'authenticated' => false,
],
[
'type' => 'route',
'name' => 'Statistics',
'title' => 'Statistics',
'route' => 'player.index',
'key' => 'route-stats-01',
'authenticated' => false,
],
[
'type' => 'route',
'name' => 'Polls',
'title' => 'Polls',
'route' => 'poll.index',
'key' => 'route-polls-01',
'authenticated' => false,
],
];
const DEFAULT_NAV_RIGHT = [
[
'type' => 'component',
'name' => 'Search Box',
'title' => 'Search Box',
'component' => 'NavbarSearch',
'key' => 'component-search-01',
'authenticated' => false,
],
[
'type' => 'component',
'name' => 'Notification Bell',
'title' => 'Notification Bell',
'component' => 'NotificationDropdown',
'key' => 'component-notification-dropdown-01',
'authenticated' => true,
],
[
'type' => 'component',
'name' => 'Profile Dropdown',
'title' => 'Profile Dropdown',
'component' => 'ProfileDropdown',
'key' => 'component-user-profile-01',
'authenticated' => true,
],
[
'type' => 'route',
'name' => 'Login',
'title' => 'Login',
'route' => 'login',
'key' => 'route-login-01',
'authenticated' => false,
'guestonly' => true,
],
[
'type' => 'route',
'name' => 'Register',
'title' => 'Register',
'route' => 'register',
'key' => 'route-register-01',
'authenticated' => false,
'guestonly' => true,
],
[
'type' => 'component',
'name' => 'Theme Switcher',
'title' => 'Theme Switcher',
'component' => 'LightDarkSelector',
'key' => 'component-theme-switcher-01',
'authenticated' => false,
],
];

public function render()
{
$useWebsockets = config("broadcasting.default") == "pusher" || config("broadcasting.default") == "ably";
Expand All @@ -20,8 +101,77 @@ public function render()
"VITE_PUSHER_APP_CLUSTER" => config("broadcasting.connections.pusher._pusher_app_cluster"),
];

$navbar = $this->generateCustomNavbarData();

return view('components.php-vars-to-js-transformer', [
'pusher' => $pusher
'pusher' => $pusher,
'customnav' => $navbar
]);
}

private function generateCustomNavbarData()
{
$navbarSettings = app(NavigationSettings::class);
$customNavbarEnabled = $navbarSettings->enable_custom_navbar;

// If custom navbar is disabled, generate default navbar
if (!$customNavbarEnabled) {
$customPagesInNavbar = CustomPage::visible()->navbar()->select(['id', 'title', 'path', 'is_in_navbar', 'is_visible'])->get();

$leftNavbar = self::DEFAULT_NAV_LEFT;
$dropdownList = [
'type' => 'dropdown',
'name' => 'Dropdown',
'title' => 'Others',
'key' => 'dropdown-others-01',
'children' => [
[
'type' => 'route',
'name' => 'News',
'title' => 'News',
'route' => 'news.index',
'key' => 'route-news-01',
'authenticated' => false,
],
[
'type' => 'route',
'name' => 'Staff Members',
'title' => 'Staff Members',
'route' => 'staff.index',
'key' => 'route-staff-members-01',
'authenticated' => false,
],
],
'authenticated' => false,
];

foreach ($customPagesInNavbar as $page) {
$dropdownList['children'][] = [
'type' => 'custom-page',
'name' => $page->title,
'title' => $page->title,
'id' => $page->id,
'route' => 'custom-page.show',
'route_params' => [
'path' => $page->path,
],
'key' => 'custom-page-' . $page->id . '-01',
];
}
$leftNavbar[] = $dropdownList;

$navbarData = [
'left' => $leftNavbar,
'middle' => [],
'right' => self::DEFAULT_NAV_RIGHT,
];
} else {
$navbarData = $navbarSettings->custom_navbar_data;
}

return [
'enabled' => $customNavbarEnabled,
'data' => $navbarData,
];
}
}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
|
*/

'version' => '1.0.10-alpha',
'version' => '1.0.11-alpha',

/*
|--------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 3fedf90

Please sign in to comment.