From 252059df1988417ad27b7d8cf26a7cba1bcebdbf Mon Sep 17 00:00:00 2001 From: ro Date: Tue, 19 Mar 2024 16:35:02 -0600 Subject: [PATCH] settings syncing active turned on the abiity to save settings to config file via the settings page the current member session needs to updated by the data coming in but that will be handled by a specific member service that hasn't been built yet, so just commenting it out for now also fixed a minor bug that was stopping the save on render toggle from working correctly, so now it's saving and updating the status properly now --- .../Controllers/API/SettingsAPIController.php | 8 +++++- app/Services/DocService.php | 25 ++++++++++++++----- app/Services/SettingsService.php | 24 ++++++++++++++++++ .../dash/app/actions/SettingsActions.js | 2 +- .../scripts/dash/libraries/FipamoAdminAPI.js | 2 +- .../views/includes/submenu-settings.blade.php | 4 --- routes/api.php | 1 + 7 files changed, 53 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/API/SettingsAPIController.php b/app/Http/Controllers/API/SettingsAPIController.php index caf50ca..442dafd 100644 --- a/app/Http/Controllers/API/SettingsAPIController.php +++ b/app/Http/Controllers/API/SettingsAPIController.php @@ -20,8 +20,14 @@ class SettingsAPIController extends Controller public function publish(Request $request) { - $body = json_decode($request->getContent()); $result = $this->render->publishAll(); return response()->json($result)->header('Content-Type', 'application/json'); } + + public function sync(Request $request) + { + $body = json_decode($request->getContent()); + $result = $this->settings->sync($body); + return response()->json($result)->header('Content-Type', 'application/json'); + } } diff --git a/app/Services/DocService.php b/app/Services/DocService.php index f3ff4d7..1afde60 100644 --- a/app/Services/DocService.php +++ b/app/Services/DocService.php @@ -54,13 +54,26 @@ class DocService public static function writeSettings($fileContents) { $fileLocation = env('SETTINGS_PATH'); - if (!is_file($fileLocation)) { - file_put_contents($fileLocation, json_encode($fileContents)); - } else { - ($new = fopen($fileLocation, 'w')) or die('Unable to open file!'); - fwrite($new, json_encode($fileContents)); - fclose($new); + $message = []; + try { + if (!is_file($fileLocation)) { + file_put_contents($fileLocation, json_encode($fileContents)); + } else { + ($new = fopen($fileLocation, 'w')) or die('Unable to open file!'); + fwrite($new, json_encode($fileContents)); + fclose($new); + }$message = [ + 'message' => "Settings Synced. You're doing great!", + 'type' => 'settingsUpdated', + ]; + } catch (Error $error) { + $message = [ + 'message' => "Settings Not Synced. We'll figure it out", + 'type' => 'settingsUpdated', + ]; } + + return $message; } public static function writeHTML($location, $html, $path = null) diff --git a/app/Services/SettingsService.php b/app/Services/SettingsService.php index 586498d..4e5e475 100644 --- a/app/Services/SettingsService.php +++ b/app/Services/SettingsService.php @@ -67,4 +67,28 @@ class SettingsService $this->settings['global'][$key] = $data; $this->docs->writeSettings($this->settings); } + + public function sync($data) + { + //dd($data->global->renderOnSave); + $settings = $this->getSettings(); + $settings['global']['base_url'] = $data->global->base_url; + $settings['global']['title'] = $data->global->title; + $settings['global']['descriptions'] = $data->global->descriptions; + $settings['global']['private'] = $data->global->private; + $settings['global']['renderOnSave'] = $data->global->renderOnSave; + $settings['global']['theme'] = $data->global->theme; + $settings['global']['externalAPI'] = $data->global->externalAPI; + $settings['global']['dynamicRender'] = $data->global->dynamicRender; + + //TODO: This is for to be created MemberServices + //Member::updateData('handle', $data['member']['handle']); + //Member::updateData('email', $data['member']['email']); + + $settings['email']['active'] = $data->email->active; + $settings['email']['smtp'] = $data->email->smtp; + $settings['email']['mailgun'] = $data->email->mailgun; + + return $this->docs->writeSettings($settings); + } } diff --git a/public/assets/scripts/dash/app/actions/SettingsActions.js b/public/assets/scripts/dash/app/actions/SettingsActions.js index 0b48bd1..a8c4128 100644 --- a/public/assets/scripts/dash/app/actions/SettingsActions.js +++ b/public/assets/scripts/dash/app/actions/SettingsActions.js @@ -15,7 +15,7 @@ export default class SettingsActions { //let privacy = document.getElementById('privacy-toggle').getAttribute('data-private'); let render = document.getElementById('render-toggle').getAttribute('data-render'); let background = document - .querySelector('[role="background"]') + .querySelector('.background') .style.backgroundImage.slice(4, -1) .replace(/"/g, ''); let selected = ''; diff --git a/public/assets/scripts/dash/libraries/FipamoAdminAPI.js b/public/assets/scripts/dash/libraries/FipamoAdminAPI.js index 8290439..45d1525 100644 --- a/public/assets/scripts/dash/libraries/FipamoAdminAPI.js +++ b/public/assets/scripts/dash/libraries/FipamoAdminAPI.js @@ -154,7 +154,7 @@ class FipamoAdminAPI { this._request( this.baseURL ? this.baseURL + url : url, TASK_SETTINGS_WRITE, - REQUEST_TYPE_POST, + REQUEST_TYPE_PUT, CONTENT_TYPE_JSON, data ) diff --git a/resources/views/includes/submenu-settings.blade.php b/resources/views/includes/submenu-settings.blade.php index dde40b4..59925e2 100644 --- a/resources/views/includes/submenu-settings.blade.php +++ b/resources/views/includes/submenu-settings.blade.php @@ -1,7 +1,3 @@ -@php - $renderOnSave = false; -@endphp -