implemented theme changer
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s

This commit is contained in:
Chris 2023-10-31 20:29:17 +00:00
parent 3614ba829c
commit 9bded6133e
4 changed files with 53 additions and 5 deletions

View File

@ -15,8 +15,9 @@ class User extends Model {
'token' => ['type'=>'text','required','unique','autoValMethod'=>'uuid4'], 'token' => ['type'=>'text','required','unique','autoValMethod'=>'uuid4'],
'timezone' => ['type'=>'int'], 'timezone' => ['type'=>'int'],
'dogs' => ['type'=> 'array','default'=>[]], 'dogs' => ['type'=> 'array','default'=>[]],
'tournaments' => ['type'=> 'array','default'=>[]], 'tournaments' =>['type'=> 'array','default'=>[]],
'photo' => ['type'=>'text','default'=>'https://pictshare.net/pj7vzx.jpg'], 'photo' => ['type'=>'text','default'=>'https://pictshare.net/pj7vzx.jpg'],
'theme' => ['type'=>'text','default'=>'light'], //light/dark
'active' => ['type'=>'int','default'=>0] 'active' => ['type'=>'int','default'=>0]
); );
protected $hidden = ['password','token']; protected $hidden = ['password','token'];

View File

@ -0,0 +1,34 @@
<?php
class Settings extends Page {
function index()
{
$this->set('userdata', $_SESSION['user']->data);
$this->set('template', "settings.html");
}
function edit()
{
$theme = $_REQUEST['theme'];
switch($theme)
{
case 'light':
case 'dark':
$_SESSION['user']->data['theme'] = $theme;
$_SESSION['user']->save();
$this->redirect('/settings');
break;
default:
return partial('error.html', ['errorMessage' => 'Dieses Theme existiert nicht']);
}
}
function maySeeThisPage(){
if($_SESSION['user'])
return true;
else return false;
}
}

View File

@ -0,0 +1,13 @@
<form hx-post="/settings/edit" hx-target="#response">
<div>
<label for="theme">Farbschema</label>
<select name="theme">
<option value="light" <?= $_SESSION['user']->data['theme']=='light'?'selected':''; ?>>Hell</option>
<option value="dark" <?= $_SESSION['user']->data['theme']=='dark'?'selected':''; ?>>Dunkel</option>
</select>
</div>
<div id="response"></div>
<button type="submit" name="submit" value="true" class="btn btn-primary">Speichern</button>
</form>

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" class="h-100" data-bs-theme="auto"> <html lang="en" class="h-100" data-bs-theme="<?= ($_SESSION['user'] && $_SESSION['user']->theme)?$_SESSION['user']->theme:'autoy' ?>">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
@ -35,7 +35,7 @@
<script src="/js/htmx.min.js"></script> <script src="/js/htmx.min.js"></script>
<script src="/js/bootstrap.bundle.min.js"></script> <script src="/js/bootstrap.bundle.min.js"></script>
<script src="/js/color-modes.js"></script> <?php if((!$_SESSION['user'] || !$_SESSION['user']->theme)): ?><script src="/js/color-modes.js"></script><?php endif; ?>
</body> </body>
</html> </html>