From 3c6322ec128bfdd8d4dc8f3485e13adfa03e4a92 Mon Sep 17 00:00:00 2001 From: ro Date: Fri, 22 Mar 2024 14:35:44 -0600 Subject: [PATCH] actived menu editing the last ui page that needed to be added was managing the main navigation menu for rendered pages, so that's been turned on. menu items can be added by pinning pages to the menu when editing them and can be removed by unpinning them or deleting them from the navigation edit ui it touched quite a few systems so all of those classes needed to be edited as well tweaking the front end script to work with the new modular script format --- .../Controllers/API/SettingsAPIController.php | 7 ++ app/Http/Controllers/Dash/IndexController.php | 5 + app/Providers/FipamoServiceProvider.php | 18 +-- app/Repositories/PageRepository.php | 3 +- app/Services/SettingsService.php | 108 +++++++++++++++++- app/Services/SortingService.php | 11 ++ public/assets/css/dash/icons.css | 6 + public/assets/css/dash/navigation.css | 2 +- public/assets/scripts/dash/app/EditNav.js | 9 ++ .../scripts/dash/app/controllers/NavIndex.js | 13 ++- resources/views/back/navigation.blade.php | 33 ++++++ routes/api.php | 1 + routes/web.php | 1 + 13 files changed, 195 insertions(+), 22 deletions(-) create mode 100644 public/assets/scripts/dash/app/EditNav.js create mode 100644 resources/views/back/navigation.blade.php diff --git a/app/Http/Controllers/API/SettingsAPIController.php b/app/Http/Controllers/API/SettingsAPIController.php index 442dafd..d366b3b 100644 --- a/app/Http/Controllers/API/SettingsAPIController.php +++ b/app/Http/Controllers/API/SettingsAPIController.php @@ -30,4 +30,11 @@ class SettingsAPIController extends Controller $result = $this->settings->sync($body); return response()->json($result)->header('Content-Type', 'application/json'); } + + public function navSync(Request $request) + { + $body = json_decode($request->getContent()); + $result = $this->settings->navSync($body); + return response()->json($result)->header('Content-Type', 'application/json'); + } } diff --git a/app/Http/Controllers/Dash/IndexController.php b/app/Http/Controllers/Dash/IndexController.php index 83e27f1..09563ca 100644 --- a/app/Http/Controllers/Dash/IndexController.php +++ b/app/Http/Controllers/Dash/IndexController.php @@ -84,6 +84,11 @@ class IndexController extends Controller ]); } + public function navigation() + { + return view('back.navigation', $this->sort->navigation()); + } + public function settings() { return view('back.settings', $this->sort->settings()); diff --git a/app/Providers/FipamoServiceProvider.php b/app/Providers/FipamoServiceProvider.php index c241733..dece52e 100644 --- a/app/Providers/FipamoServiceProvider.php +++ b/app/Providers/FipamoServiceProvider.php @@ -26,11 +26,11 @@ class FipamoServiceProvider extends ServiceProvider { //services $this->app->bind(SettingsService::class, function ($app) { - return new SettingsService(new DocService()); + return new SettingsService(new DocService(), new ContentService()); }); $this->app->bind(AuthService::class, function ($app) { - return new AuthService(new SettingsService(new DocService())); + return new AuthService(new SettingsService(new DocService(), new ContentService())); }); $this->app->bind(ContentService::class, function ($app) { @@ -38,7 +38,7 @@ class FipamoServiceProvider extends ServiceProvider }); $this->app->bind(ThemeService::class, function ($app) { - return new ThemeService(new SettingsService(new DocService())); + return new ThemeService(new SettingsService(new DocService(), new ContentService())); }); $this->app->bind(PaginateService::class, function ($app) { @@ -60,29 +60,29 @@ class FipamoServiceProvider extends ServiceProvider $this->app->bind(RenderService::class, function ($app) { return new RenderService( new SortingService( - new SettingsService(new DocService()), + new SettingsService(new DocService(), new ContentService()), new ContentService(), new StringService(), - new ThemeService(new SettingsService(new DocService())) + new ThemeService(new SettingsService(new DocService(), new ContentService())) ), - new SettingsService(new DocService()), + new SettingsService(new DocService(), new ContentService()), new ContentService(), ); }); $this->app->bind(SortingService::class, function ($app) { return new SortingService( - new SettingsService(new DocService()), + new SettingsService(new DocService(), new ContentService()), new ContentService(), new StringService(), - new ThemeService(new SettingsService(new DocService())) + new ThemeService(new SettingsService(new DocService(), new ContentService())) ); }); $this->app->bind(AssetService::class, function ($app) { return new AssetService( new ThemeService( - new SettingsService(new DocService()) + new SettingsService(new DocService(), new ContentService()) ) ); }); diff --git a/app/Repositories/PageRepository.php b/app/Repositories/PageRepository.php index cf71f32..a7678f9 100644 --- a/app/Repositories/PageRepository.php +++ b/app/Repositories/PageRepository.php @@ -67,7 +67,6 @@ class PageRepository implements PageRepositoryInterface public function update($page) { return $this->editPage($page, $this->pages->where('uuid', $page->uuid)->first(), 'update'); - //hande result of page update } public function getGroup($num, $limit, $sort = "all") @@ -137,7 +136,7 @@ class PageRepository implements PageRepositoryInterface //upadte settings if needed $body->path = $path; - //Settings::updateMenu($body); + $this->settings->updateMenu($body); //Settings::updateTags(); // if new page added, update current index in Settings file if ($task == 'create') { diff --git a/app/Services/SettingsService.php b/app/Services/SettingsService.php index 4e5e475..ad9f13f 100644 --- a/app/Services/SettingsService.php +++ b/app/Services/SettingsService.php @@ -2,18 +2,24 @@ namespace App\Services; +use Carbon\Carbon; + +use function _\find; + class SettingsService { protected $settings; protected $folks; protected $tags; protected $docs; + protected $contents; - public function __construct(DocService $docService) + public function __construct(DocService $docService, ContentService $contentService) { - $this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true); - $this->tags = json_decode(file_get_contents(env('TAGS_PATH')), true); - $this->docs = $docService; + $this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true); + $this->tags = json_decode(file_get_contents(env('TAGS_PATH')), true); + $this->docs = $docService; + $this->contents = $contentService; } protected function loadSettings() @@ -68,6 +74,29 @@ class SettingsService $this->docs->writeSettings($this->settings); } + public function updateMenu($body) + { + $settings = $this->loadSettings(); + //$menu = $settings["menu"]; + $item = [ + 'title' => $body->title, + 'id' => $body->id, + 'uuid' => $body->uuid, + 'slug' => $body->slug, + 'path' => $body->path, + ]; + if ($body->menu == 'true') { + if (!find($settings['menu'], ['uuid' => $item['uuid']])) { + array_push($settings['menu'], $item); + } + } else { + if (find($settings['menu'], ['uuid' => $item['uuid']])) { + pull($settings['menu'], $item); + } + } + $this->docs->writeSettings($settings); + } + public function sync($data) { //dd($data->global->renderOnSave); @@ -91,4 +120,75 @@ class SettingsService return $this->docs->writeSettings($settings); } + + public function navSync($data) + { + $settings = $this->loadSettings(); + $pages = $this->contents->loadAllPages(); + $remove = $data->remove; + $result = []; + //if remove contains id, find nav item page and set menu to false + if ($remove != null || $remove != '') { + $page = $pages->where('uuid', $remove)->first(); + $page['menu'] = 'false'; + $page['published'] + ? ($page['published'] = 'true') + : ($page['published'] = 'false'); + $page['featured'] + ? ($page['featured'] = 'true') + : ($page['featured'] = 'false'); + $page['deleted'] + ? ($page['deleted'] = 'true') + : ($page['deleted'] = 'false'); + $updated = Carbon::now(); + $created = new Carbon($page['rawCreated']); + $page['created'] = $created->format("Y-m-d\TH:i:sP"); + $page['updated'] = $updated->format("Y-m-d\TH:i:sP"); + + if ($page['layout'] == 'index') { + $writePath = '../content/pages/start/index.md'; + } else { + $writePath = '../content/pages/' . $page['path'] . '/' . $page['slug'] . '.md'; + } + try { + $object = (object) $page; + $object->imageList = $page['feature']; + $object->fileList = $page['files']; + $this->docs::writePages('write', $page['path'], $writePath, $this->docs::objectToMD($object)); + } catch (\Exception $e) { + $result = [ + 'message' => 'Page Was Not Updated. Be cool ', + 'type' => 'pageUpdateError', + 'error' => $e->getMessage(), + ]; + return $result; + } + } + + $settings['menu'] = []; + $items = $data->menu; + foreach ($items as $item) { + array_push($settings['menu'], [ + 'title' => $item->title, + 'id' => $item->id, + 'uuid' => $item->uuid, + 'slug' => $item->slug, + 'path' => $item->path, + ]); + } + try { + $this->docs->writeSettings($settings); + $result = [ + 'message' => 'Navigation updated. Very slick!', + 'type' => 'menuUpdated', + ]; + } catch (\Exception $e) { + $result = [ + 'message' => 'Navigation Update Error. It\'ll be ok!', + 'type' => 'menuUpdateError', + ]; + }; + + return $result; + } } diff --git a/app/Services/SortingService.php b/app/Services/SortingService.php index 80cb885..c9116b0 100644 --- a/app/Services/SortingService.php +++ b/app/Services/SortingService.php @@ -251,6 +251,17 @@ class SortingService return $pageOptions; } + public function navigation() + { + $pageOptions = [ + 'title' => 'Edit Navigation', + 'status' => session('member') != '' ? true : false, + 'menu' => $this->settings->getMenu(), + ]; + + return $pageOptions; + } + public function settings() { $global = $this->settings->getGlobal(); diff --git a/public/assets/css/dash/icons.css b/public/assets/css/dash/icons.css index 7e497c3..b29409b 100644 --- a/public/assets/css/dash/icons.css +++ b/public/assets/css/dash/icons.css @@ -7,6 +7,12 @@ svg[role="icon"] { color: var(--secondary); } +svg#move-menu-item { + fill: var(--secondary-highlight); + top: 8px; + position: relative; +} + button[data-render="true"] { background: var(--primary); } diff --git a/public/assets/css/dash/navigation.css b/public/assets/css/dash/navigation.css index 48d513d..d256d68 100644 --- a/public/assets/css/dash/navigation.css +++ b/public/assets/css/dash/navigation.css @@ -7,7 +7,7 @@ article[role="navigation"] { article[role="navigation"] > section > div.nav-item { display: block; width: 98%; - background: var(--white); + background: var(--secondary); border-radius: 3px; color: var(--secondary-highlight); margin: 0 0 10px; diff --git a/public/assets/scripts/dash/app/EditNav.js b/public/assets/scripts/dash/app/EditNav.js new file mode 100644 index 0000000..c205ffc --- /dev/null +++ b/public/assets/scripts/dash/app/EditNav.js @@ -0,0 +1,9 @@ +import Nav from './controllers/NavIndex.js'; + +document.addEventListener( + 'DOMContentLoaded', + function () { + new Nav(); + }, + false +); diff --git a/public/assets/scripts/dash/app/controllers/NavIndex.js b/public/assets/scripts/dash/app/controllers/NavIndex.js index 9ce29b1..6872fef 100644 --- a/public/assets/scripts/dash/app/controllers/NavIndex.js +++ b/public/assets/scripts/dash/app/controllers/NavIndex.js @@ -1,8 +1,8 @@ -import FipamoAdminAPI, { TASK_SYNC_NAV } from '../../libraries/FipamoAdminAPI'; -import NavActions from '../actions/NavActions'; -import * as DataEvent from '../events/DataEvent'; -import Notifications from '../ui/Notifications'; -import Sortable from 'sortablejs'; +import FipamoAdminAPI, { TASK_SYNC_NAV } from '../../libraries/FipamoAdminAPI.js'; +import NavActions from '../actions/NavActions.js'; +import * as DataEvent from '../events/DataEvent.js'; +import Notifications from '../ui/Notifications.js'; +import Sortable from '../vendor/sortable.core.esm.js'; const notify = new Notifications(); export default class NavIndex { @@ -49,6 +49,7 @@ export default class NavIndex { switch (e.target.id) { case 'remove-item': id = e.target.getAttribute('data-id'); + console.log('object', e); new NavActions().removeItem(id); new NavActions().syncMenu().then(data => { data.remove = e.target.getAttribute('data-uuid'); @@ -59,7 +60,7 @@ export default class NavIndex { if (r.type == DataEvent.MENU_UPDATED) { notify.alert(r.message, true); } else { - notify.alert(r.message, true); + notify.alert(r.message, false); } }); }); diff --git a/resources/views/back/navigation.blade.php b/resources/views/back/navigation.blade.php new file mode 100644 index 0000000..7dda6a4 --- /dev/null +++ b/resources/views/back/navigation.blade.php @@ -0,0 +1,33 @@ +@extends('frame') + +@section('title', 'The Dash | Edit Navigation') + +@section('main-content') +
+ +
+@endsection +@section('scripting') + + @endsection diff --git a/routes/api.php b/routes/api.php index dcc79b9..a7330fe 100644 --- a/routes/api.php +++ b/routes/api.php @@ -27,3 +27,4 @@ Route::post("/v1/files", [FileUploadAPIController::class, 'upload']); //settings Route::put("/v1/settings/publish", [SettingsAPIController::class, 'publish']); Route::put("/v1/settings/sync", [SettingsAPIController::class, 'sync']); +Route::put("/v1/settings/nav-sync", [SettingsAPIController::class, 'navSync']); diff --git a/routes/web.php b/routes/web.php index 3e5dfdd..7ec017d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -31,6 +31,7 @@ Route::group(['prefix' => 'dashboard', 'middleware' => 'member.check'], function Route::get("/pages/{pageFilter?}/{pageNum?}", [IndexController::class, 'book']); Route::get("/page/{mode}/{uuid}", [IndexController::class, 'page']); Route::get("/settings", [IndexController::class, 'settings']); + Route::get("/navigation", [IndexController::class, 'navigation']); Route::get("/logout", [AuthController::class, 'exit']); });