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
$fokus = $request->input('fokus', '');
$url = $request->input('url', '');
// Currently only the setting for quotes is supported
$quotes = $request->input('zitate', '');
if (empty($fokus) || empty($quotes)) {
abort(404);
if(!empty($quotes)){
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"){
$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);
}else{
abort(404);
$darkmode = $request->input('dm');
if(!empty($darkmode)){
if($darkmode === "off"){
Cookie::queue('dark_mode', '1', 0, '/', null, false, false);
}elseif($darkmode === "on") {
Cookie::queue('dark_mode', '2', 0, '/', null, false, false);
}elseif($darkmode === "system"){
Cookie::queue('dark_mode', '', 0, '/', null, false, false);
}
}
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('settings', ["fokus" => $fokus, "url" => $url])));
}
......@@ -408,34 +417,4 @@ class SettingsController extends Controller
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 [
'add' => 'Hinzufügen',
'clear' => 'Blacklist leeren',
'copy' => 'Kopieren',
'darkmode' => 'Dunklen Modus umschalten',
'system' => 'Systemstandard',
'dark' => 'Dunkel',
'light' => 'Hell',
// Translations from the settings overview
'noSettings' => 'Aktuell sind keine Einstellungen gesetzt!',
......
......@@ -25,7 +25,11 @@ return [
'add' => 'Add',
'clear' => 'Clear black list',
'copy' => 'Copy',
'darkmode' => 'Toggle dark mode',
'system' => 'System Default',
'dark' => 'Dark',
'light' => 'Light',
// Translations from the settings overview
'noSettings' => "Currently no settings are set!",
......
......@@ -125,10 +125,18 @@
<div class="card-light">
<h2>Weitere Einstellungen</h2>
@if(LaravelLocalization::getCurrentLocale() === "de")
<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="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">
<label for="zitate">Zitate</label>
<select name="zitate" id="zitate" class="form-control">
......@@ -136,12 +144,9 @@
<option value="off" {{ Cookie::get($fokus . "_setting_zitate") === "off" ? "disabled selected" : "" }}>Nicht Anzeigen</option>
</select>
</div>
@endif
<button type="submit" class="btn btn-default">@lang('settings.save')</button>
</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 class="card-light" id="actions">
@if($settingActive)
......
......@@ -29,7 +29,6 @@ Route::group(
Route::post('all-settings/removeOne', 'SettingsController@removeOneSetting')->name('removeOneSetting');
Route::post('all-settings/removeAll', 'SettingsController@removeAllSettings')->name('removeAllSettings');
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