From eda377aba3802c8059d1def2a4b312847182f1fd Mon Sep 17 00:00:00 2001 From: ro Date: Tue, 19 Mar 2024 15:34:01 -0600 Subject: [PATCH] publish site from settings active with the setting page set up, now the the settings api can be added, beginning with the ability to render all files from settings. the base settings api class is set up, so now the rest of the methods can be added --- .../Controllers/API/SettingsAPIController.php | 27 ++++++ app/Services/RenderService.php | 29 +++++++ .../assets/scripts/dash/app/EditSettings.js | 9 ++ .../assets/scripts/dash/app/actions/Mailer.js | 82 +++++++++---------- .../dash/app/controllers/SettingsIndex.js | 12 +-- .../scripts/dash/libraries/FipamoAdminAPI.js | 2 +- resources/views/back/settings.blade.php | 3 + routes/api.php | 3 + 8 files changed, 119 insertions(+), 48 deletions(-) create mode 100644 app/Http/Controllers/API/SettingsAPIController.php create mode 100644 public/assets/scripts/dash/app/EditSettings.js diff --git a/app/Http/Controllers/API/SettingsAPIController.php b/app/Http/Controllers/API/SettingsAPIController.php new file mode 100644 index 0000000..caf50ca --- /dev/null +++ b/app/Http/Controllers/API/SettingsAPIController.php @@ -0,0 +1,27 @@ +settings = $settingsService; + $this->render = $renderService; + } + + public function publish(Request $request) + { + $body = json_decode($request->getContent()); + $result = $this->render->publishAll(); + return response()->json($result)->header('Content-Type', 'application/json'); + } +} diff --git a/app/Services/RenderService.php b/app/Services/RenderService.php index f0ea49b..63fd4dd 100644 --- a/app/Services/RenderService.php +++ b/app/Services/RenderService.php @@ -25,6 +25,35 @@ class RenderService $this->theme = $this->settings->getGlobal()['theme']; } + public function publishAll() + { + $message = []; + $dynamicRender = $this->settings->getGlobal()['dynamicRender']; + if (isset($dynamicRender) && $dynamicRender === 'true') { + $message = [ + 'message' => 'Auto Rendering is already enabled!', + 'type' => 'RENDER_SUCCESS', + ]; + } else { + try { + $this->archive(); + $this->tags(); + $this->pages(); + $message = [ + 'message' => 'Site Rendered. GOOD EFFORT', + 'type' => 'RENDER_SUCCESS', + ]; + } catch (Error $error) { + $message = [ + 'message' => 'Issue With Rendering. DONT PANIC', + 'type' => 'RENDER_ERROR', + ]; + } + } + + return $message; + } + public function archive() { $template = $this->theme . '.archive'; diff --git a/public/assets/scripts/dash/app/EditSettings.js b/public/assets/scripts/dash/app/EditSettings.js new file mode 100644 index 0000000..bf352ad --- /dev/null +++ b/public/assets/scripts/dash/app/EditSettings.js @@ -0,0 +1,9 @@ +import Settings from './controllers/SettingsIndex.js'; + +document.addEventListener( + 'DOMContentLoaded', + function () { + new Settings(); + }, + false +); diff --git a/public/assets/scripts/dash/app/actions/Mailer.js b/public/assets/scripts/dash/app/actions/Mailer.js index 20e1eb4..d099153 100644 --- a/public/assets/scripts/dash/app/actions/Mailer.js +++ b/public/assets/scripts/dash/app/actions/Mailer.js @@ -1,44 +1,44 @@ -import FipamoAdminAPI from "../../libraries/FipamoAdminAPI"; -import Notficaton from "../ui/Notifications"; +import FipamoAdminAPI from '../../libraries/FipamoAdminAPI.js'; +import Notficaton from '../ui/Notifications.js'; const notify = new Notficaton(); export default class Mailer { - //-------------------------- - // constructor - //-------------------------- - constructor() {} - //-------------------------- - // methods - //-------------------------- - sendMail() { - let mailData = { - content: "This is a test email" - }; - let admin = new FipamoAdminAPI(); - admin - .sendMail(mailData) - .then((result) => { - notify.alert(result.message, true); - }) - .catch((err) => { - notify.alert(err.message, false); - }); - } - testMail() { - let mailData = { - content: "This is a test email", - mail_task: "TESTING" - }; - let admin = new FipamoAdminAPI(); - admin - .sendMail(mailData) - .then((result) => { - notify.alert(result.message, true); - }) - .catch((err) => { - notify.alert(err.message, false); - }); - } - //-------------------------- - // event handlers - //-------------------------- + //-------------------------- + // constructor + //-------------------------- + constructor() {} + //-------------------------- + // methods + //-------------------------- + sendMail() { + let mailData = { + content: 'This is a test email' + }; + let admin = new FipamoAdminAPI(); + admin + .sendMail(mailData) + .then(result => { + notify.alert(result.message, true); + }) + .catch(err => { + notify.alert(err.message, false); + }); + } + testMail() { + let mailData = { + content: 'This is a test email', + mail_task: 'TESTING' + }; + let admin = new FipamoAdminAPI(); + admin + .sendMail(mailData) + .then(result => { + notify.alert(result.message, true); + }) + .catch(err => { + notify.alert(err.message, false); + }); + } + //-------------------------- + // event handlers + //-------------------------- } diff --git a/public/assets/scripts/dash/app/controllers/SettingsIndex.js b/public/assets/scripts/dash/app/controllers/SettingsIndex.js index e6e04eb..b30a938 100644 --- a/public/assets/scripts/dash/app/controllers/SettingsIndex.js +++ b/public/assets/scripts/dash/app/controllers/SettingsIndex.js @@ -1,9 +1,9 @@ -import SettingsActions from '../actions/SettingsActions'; -import Maintenance from './MaintenanceManager'; -import FipamoAdminAPI, { TASK_SYNC_SETTNIGS } from '../../libraries/FipamoAdminAPI'; -import * as DataEvent from '../../../src/com/events/DataEvent'; -import Mailer from '../actions/Mailer'; -import Notifications from '../ui/Notifications'; +import SettingsActions from '../actions/SettingsActions.js'; +import Maintenance from './MaintenanceManager.js'; +import FipamoAdminAPI, { TASK_SYNC_SETTNIGS } from '../../libraries/FipamoAdminAPI.js'; +import * as DataEvent from '../../../dash/app/events/DataEvent.js'; +import Mailer from '../actions/Mailer.js'; +import Notifications from '../ui/Notifications.js'; const notify = new Notifications(); export default class SettingsIndex { //-------------------------- diff --git a/public/assets/scripts/dash/libraries/FipamoAdminAPI.js b/public/assets/scripts/dash/libraries/FipamoAdminAPI.js index d27d7fc..8290439 100644 --- a/public/assets/scripts/dash/libraries/FipamoAdminAPI.js +++ b/public/assets/scripts/dash/libraries/FipamoAdminAPI.js @@ -189,7 +189,7 @@ class FipamoAdminAPI { //API_PUBLISH_PAGES, this.baseURL ? this.baseURL + API_PUBLISH_PAGES : API_PUBLISH_PAGES, TASK_PUBLISH_SITE, - REQUEST_TYPE_POST, + REQUEST_TYPE_PUT, CONTENT_TYPE_JSON, data ) diff --git a/resources/views/back/settings.blade.php b/resources/views/back/settings.blade.php index 684f7a8..897bd2c 100644 --- a/resources/views/back/settings.blade.php +++ b/resources/views/back/settings.blade.php @@ -110,3 +110,6 @@ @endsection + @section('scripting') + + @endsection diff --git a/routes/api.php b/routes/api.php index ee66c67..5a90610 100644 --- a/routes/api.php +++ b/routes/api.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\API\AuthAPIController; use App\Http\Controllers\API\PageAPIController; use App\Http\Controllers\API\FileUploadAPIController; +use App\Http\Controllers\API\SettingsAPIController; /* |-------------------------------------------------------------------------- @@ -23,3 +24,5 @@ Route::put("/v1/page/write", [PageAPIController::class, 'write']); Route::post("/v1/page/create", [PageAPIController::class, 'create']); //handle file uploads Route::post("/v1/files", [FileUploadAPIController::class, 'upload']); +//settings +Route::put("/v1/settings/publish", [SettingsAPIController::class, 'publish']);