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
This commit is contained in:
ro 2024-03-19 16:35:02 -06:00
parent eda377aba3
commit 252059df19
No known key found for this signature in database
GPG key ID: 29B551CDBD4D3B50
7 changed files with 53 additions and 13 deletions

View file

@ -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');
}
}

View file

@ -54,13 +54,26 @@ class DocService
public static function writeSettings($fileContents)
{
$fileLocation = env('SETTINGS_PATH');
$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)

View file

@ -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);
}
}

View file

@ -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 = '';

View file

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

View file

@ -1,7 +1,3 @@
@php
$renderOnSave = false;
@endphp
<div class="submenu">
<button id="save-toggle" title="save settings">
<i class="ti ti-device-floppy"></i>

View file

@ -26,3 +26,4 @@ Route::post("/v1/page/create", [PageAPIController::class, 'create']);
Route::post("/v1/files", [FileUploadAPIController::class, 'upload']);
//settings
Route::put("/v1/settings/publish", [SettingsAPIController::class, 'publish']);
Route::put("/v1/settings/sync", [SettingsAPIController::class, 'sync']);