Skip to content
Snippets Groups Projects
Commit 1f4f4169 authored by Davide Aprea's avatar Davide Aprea
Browse files

merged darkmode with enable setting function

parent fbd6239a
No related branches found
No related tags found
3 merge requests!1739Development,!1717Resolve "Major Startpage Redesign",!1713Resolve "Add setting to enable darkmode"
...@@ -209,23 +209,32 @@ class SettingsController extends Controller ...@@ -209,23 +209,32 @@ class SettingsController extends Controller
$fokus = $request->input('fokus', ''); $fokus = $request->input('fokus', '');
$url = $request->input('url', ''); $url = $request->input('url', '');
// Currently only the setting for quotes is supported // Currently only the setting for quotes is supported
$quotes = $request->input('zitate', ''); $quotes = $request->input('zitate', '');
if (empty($fokus) || empty($quotes)) { if(!empty($quotes)){
abort(404); if($quotes === "off"){
$path = \Request::path();
$cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5);
Cookie::queue($fokus . "_setting_zitate", "off", 0, $cookiePath, null, false, false);
}elseif($quotes === "on") {
$path = \Request::path();
$cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5);
Cookie::queue($fokus . "_setting_zitate", "", 0, $cookiePath, null, false, false);
}
} }
if($quotes === "off"){ $darkmode = $request->input('dm');
$path = \Request::path(); if(!empty($darkmode)){
$cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5); if($darkmode === "off"){
Cookie::queue($fokus . "_setting_zitate", "off", 0, $cookiePath, null, false, false); Cookie::queue('dark_mode', '1', 0, '/', null, false, false);
}elseif($quotes === "on") { }elseif($darkmode === "on") {
$path = \Request::path(); Cookie::queue('dark_mode', '2', 0, '/', null, false, false);
$cookiePath = "/" . substr($path, 0, strpos($path, "meta/") + 5); }elseif($darkmode === "system"){
Cookie::queue($fokus . "_setting_zitate", "", 0, $cookiePath, null, false, false); Cookie::queue('dark_mode', '', 0, '/', null, false, false);
}else{ }
abort(404);
} }
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url]))); return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url])));
} }
...@@ -408,34 +417,4 @@ class SettingsController extends Controller ...@@ -408,34 +417,4 @@ class SettingsController extends Controller
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), url('/'))); return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), url('/')));
} }
public function darkmode(Request $request)
{
$fokus = $request->input('fokus', '');
$url = $request->input('url', '');
$path = \Request::path();
$cookiePath = "/";
$cookies = Cookie::get();
$setCookie = true;
$darkmode = "0";
if(!empty($cookies)){
foreach($cookies as $key => $value){
if($key === 'dark_mode'){
if($value === "0" || $value == "1"){
$darkmode = "2";
}elseif($value === "2"){
$darkmode = "1";
}
Cookie::queue('dark_mode', $darkmode, 0, $cookiePath, null, false, false);
$setCookie = false;
}
}
}else{
Cookie::queue('dark_mode', "2", 0, $cookiePath, null, false, false);
}
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url]))); }
} }
...@@ -25,7 +25,11 @@ return [ ...@@ -25,7 +25,11 @@ return [
'add' => 'Hinzufügen', 'add' => 'Hinzufügen',
'clear' => 'Blacklist leeren', 'clear' => 'Blacklist leeren',
'copy' => 'Kopieren', 'copy' => 'Kopieren',
'darkmode' => 'Dunklen Modus umschalten', 'darkmode' => 'Dunklen Modus umschalten',
'system' => 'Systemstandard',
'dark' => 'Dunkel',
'light' => 'Hell',
// Translations from the settings overview // Translations from the settings overview
'noSettings' => 'Aktuell sind keine Einstellungen gesetzt!', 'noSettings' => 'Aktuell sind keine Einstellungen gesetzt!',
......
...@@ -25,7 +25,11 @@ return [ ...@@ -25,7 +25,11 @@ return [
'add' => 'Add', 'add' => 'Add',
'clear' => 'Clear black list', 'clear' => 'Clear black list',
'copy' => 'Copy', 'copy' => 'Copy',
'darkmode' => 'Toggle dark mode', 'darkmode' => 'Toggle dark mode',
'system' => 'System Default',
'dark' => 'Dark',
'light' => 'Light',
// Translations from the settings overview // Translations from the settings overview
'noSettings' => "Currently no settings are set!", 'noSettings' => "Currently no settings are set!",
......
...@@ -125,10 +125,18 @@ ...@@ -125,10 +125,18 @@
<div class="card-light"> <div class="card-light">
<h2>Weitere Einstellungen</h2> <h2>Weitere Einstellungen</h2>
@if(LaravelLocalization::getCurrentLocale() === "de")
<form id="setting-form" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('enableSetting')) }}" method="post" class="form"> <form id="setting-form" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('enableSetting')) }}" method="post" class="form">
<input type="hidden" name="fokus" value="{{ $fokus }}"> <input type="hidden" name="fokus" value="{{ $fokus }}">
<input type="hidden" name="url" value="{{ $url }}"> <input type="hidden" name="url" value="{{ $url }}">
<div class="form-group">
<label for="dm">@lang('settings.darkmode')</label>
<select name="dm" id="dm" class="form-control">
<option value="system" {{ !Cookie::has('dark_mode') ? "disabled selected" : "" }}>@lang('settings.system')</option>
<option value="off" {{ Cookie::get('dark_mode') === "1" ? "disabled selected" : "" }}>@lang('settings.light')</option>
<option value="on" {{ Cookie::get('dark_mode') === "2" ? "disabled selected" : "" }}>@lang('settings.dark')</option>
</select>
</div>
@if(LaravelLocalization::getCurrentLocale() === "de")
<div class="form-group"> <div class="form-group">
<label for="zitate">Zitate</label> <label for="zitate">Zitate</label>
<select name="zitate" id="zitate" class="form-control"> <select name="zitate" id="zitate" class="form-control">
...@@ -136,12 +144,9 @@ ...@@ -136,12 +144,9 @@
<option value="off" {{ Cookie::get($fokus . "_setting_zitate") === "off" ? "disabled selected" : "" }}>Nicht Anzeigen</option> <option value="off" {{ Cookie::get($fokus . "_setting_zitate") === "off" ? "disabled selected" : "" }}>Nicht Anzeigen</option>
</select> </select>
</div> </div>
@endif
<button type="submit" class="btn btn-default">@lang('settings.save')</button> <button type="submit" class="btn btn-default">@lang('settings.save')</button>
</form> </form>
@endif
<form id="darkmode" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('darkmode', ["fokus" => $fokus, "url" => $url])) }}" method="post" class="form">
<button type="submit" class="btn btn-default">@lang('settings.darkmode')</button>
</form>
</div> </div>
<div class="card-light" id="actions"> <div class="card-light" id="actions">
@if($settingActive) @if($settingActive)
......
...@@ -29,7 +29,6 @@ Route::group( ...@@ -29,7 +29,6 @@ Route::group(
Route::post('all-settings/removeOne', 'SettingsController@removeOneSetting')->name('removeOneSetting'); Route::post('all-settings/removeOne', 'SettingsController@removeOneSetting')->name('removeOneSetting');
Route::post('all-settings/removeAll', 'SettingsController@removeAllSettings')->name('removeAllSettings'); Route::post('all-settings/removeAll', 'SettingsController@removeAllSettings')->name('removeAllSettings');
Route::get('load-settings', 'SettingsController@loadSettings')->name('loadSettings'); Route::get('load-settings', 'SettingsController@loadSettings')->name('loadSettings');
Route::post('darkmode', 'SettingsController@darkmode')->name('darkmode');
}); });
} }
); );
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment