Skip to content

Commit dd297dc

Browse files
authored
Merge pull request #18249 from grokability/proper-dark-toggle
Experiment: simpler light/dark toggle
2 parents 89a232a + 1409d01 commit dd297dc

File tree

139 files changed

+1371
-35724
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1371
-35724
lines changed

app/Console/Commands/ResetDemoSettings.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ public function handle()
4949
$settings->logo = 'snipe-logo.png';
5050
$settings->alert_email = '[email protected]';
5151
$settings->login_note = 'Use `admin` / `password` to login to the demo.';
52-
$settings->header_color = null;
52+
$settings->header_color = '#3c8dbc';
53+
$settings->link_dark_color = '#084d73';
54+
$settings->link_light_color = '#86cbf2;';
5355
$settings->label2_2d_type = 'QRCODE';
5456
$settings->default_currency = 'USD';
5557
$settings->brand = 2;
5658
$settings->ldap_enabled = 0;
5759
$settings->full_multiple_companies_support = 0;
5860
$settings->label2_1d_type = 'C128';
59-
$settings->skin = '';
6061
$settings->email_domain = 'snipeitapp.com';
6162
$settings->email_format = 'filastname';
6263
$settings->username_format = 'filastname';
@@ -80,6 +81,8 @@ public function handle()
8081

8182
if ($user = User::where('username', '=', 'admin')->first()) {
8283
$user->locale = 'en-US';
84+
$user->enable_confetti = 1;
85+
$user->enable_sounds = 1;
8386
$user->save();
8487
}
8588

app/Http/Controllers/ProfileController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ public function postIndex(ImageUploadRequest $request) : RedirectResponse
5353
$user->last_name = $request->input('last_name');
5454
$user->website = $request->input('website');
5555
$user->gravatar = $request->input('gravatar');
56-
$user->skin = $request->input('skin');
5756
$user->phone = $request->input('phone');
5857
$user->enable_sounds = $request->input('enable_sounds', false);
5958
$user->enable_confetti = $request->input('enable_confetti', false);
59+
$user->link_light_color = $request->input('link_light_color', '#296282');
60+
$user->link_dark_color = $request->input('link_dark_color', '#296282');
61+
$user->nav_link_color = $request->input('nav_link_color', '#FFFFFF');
6062

6163
if (! config('app.lock_passwords')) {
6264
$user->locale = $request->input('locale');

app/Http/Controllers/SettingsController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,12 @@ public function postBranding(ImageUploadRequest $request) : RedirectResponse
400400

401401
$setting->brand = $request->input('brand', '1');
402402
$setting->header_color = $request->input('header_color');
403+
$setting->link_light_color = $request->input('link_light_color', '#296282');
404+
$setting->link_dark_color = $request->input('link_dark_color', '#296282');
405+
$setting->nav_link_color = $request->input('nav_link_color', '#FFFFFF');
403406
$setting->support_footer = $request->input('support_footer');
404407
$setting->version_footer = $request->input('version_footer');
405408
$setting->footer_text = $request->input('footer_text');
406-
$setting->skin = $request->input('skin');
407-
$setting->allow_user_skin = $request->input('allow_user_skin', '0');
408409
$setting->show_url_in_emails = $request->input('show_url_in_emails', '0');
409410
$setting->logo_print_assets = $request->input('logo_print_assets', '0');
410411
$setting->load_remote = $request->input('load_remote', 0);

app/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Kernel extends HttpKernel
4444
\App\Http\Middleware\CheckForTwoFactor::class,
4545
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
4646
\App\Http\Middleware\AssetCountForSidebar::class,
47+
\App\Http\Middleware\CheckColorSettings::class,
4748
\Illuminate\Session\Middleware\AuthenticateSession::class,
4849
\Illuminate\Routing\Middleware\SubstituteBindings::class,
4950
],
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use App\Models\Setting;
6+
use Closure;
7+
use Illuminate\Contracts\Auth\Guard;
8+
use Illuminate\Support\Facades\Auth;
9+
10+
class CheckColorSettings
11+
{
12+
/**
13+
* The Guard implementation.
14+
*
15+
* @var Guard
16+
*/
17+
protected $auth;
18+
19+
/**
20+
* Create a new filter instance.
21+
*
22+
* @param Guard $auth
23+
* @return void
24+
*/
25+
public function __construct(Guard $auth)
26+
{
27+
$this->auth = $auth;
28+
}
29+
30+
/**
31+
* Handle an incoming request.
32+
*
33+
* @param \Illuminate\Http\Request $request
34+
* @param \Closure $next
35+
* @return mixed
36+
*/
37+
public function handle($request, Closure $next)
38+
{
39+
if ($settings = Setting::getSettings()) {
40+
$nav_color = $settings->nav_link_color;
41+
$link_dark_color = $settings->link_dark_color;
42+
$link_light_color = $settings->link_light_color;
43+
}
44+
45+
46+
// Override system settings
47+
if ($request->user()) {
48+
49+
if ($request->user()->nav_color) {
50+
$nav_color = $request->user()->nav_color;
51+
}
52+
if ($request->user()->link_dark_color) {
53+
$link_dark_color = $request->user()->link_dark_color;
54+
}
55+
if ($request->user()->nav_color) {
56+
$link_light_color = $request->user()->link_light_color;
57+
}
58+
}
59+
60+
61+
view()->share('nav_link_color', $nav_color);
62+
view()->share('link_dark_color', $link_dark_color);
63+
view()->share('link_light_color', $link_light_color);
64+
65+
return $next($request);
66+
67+
}
68+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Support\Facades\DB;
7+
8+
return new class extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*/
13+
public function up(): void
14+
{
15+
$setting = DB::table('settings')->select(['skin', 'header_color'])->first();
16+
17+
Schema::table('settings', function (Blueprint $table) {
18+
$table->string('link_dark_color')->after('header_color')->nullable()->default(null);
19+
$table->string('link_light_color')->after('header_color')->nullable()->default(null);
20+
$table->string('nav_link_color')->after('header_color')->nullable()->default(null);
21+
});
22+
23+
Schema::table('users', function (Blueprint $table) {
24+
$table->string('link_dark_color')->after('skin')->nullable()->default(null);
25+
$table->string('link_light_color')->after('skin')->nullable()->default(null);
26+
$table->string('nav_link_color')->after('skin')->nullable()->default(null);
27+
});
28+
29+
30+
// Set Snipe-IT defaults
31+
$link_dark_color = '#89c9ed';
32+
$link_light_color = '#296282';
33+
$nav_color = '#ffffff';
34+
$header_color = '#3c8dbc';
35+
36+
if ($setting) {
37+
38+
switch ($setting->skin) {
39+
case ('green' || 'green-dark'):
40+
$header_color = '#00a65a';
41+
$link_dark_color = '#00a65a';
42+
$link_light_color = '#00a65a';
43+
$nav_color = '#ffffff';
44+
45+
case ('red' || 'red-dark'):
46+
$header_color = '#dd4b39';
47+
$link_dark_color = '#dd4b39';
48+
$link_light_color = '#dd4b39';
49+
$nav_color = '#ffffff';
50+
51+
case ('orange' || 'orange-dark'):
52+
$header_color = '#FF851B';
53+
$link_dark_color = '#FF851B';
54+
$link_light_color = '#FF851B';
55+
$nav_color = '#ffffff';
56+
57+
case ('black' || 'black-dark'):
58+
$header_color = '#000000';
59+
$link_dark_color = '#111';
60+
$link_light_color = '#111';
61+
$nav_color = '#ffffff';
62+
63+
case ('purple' || 'purple-dark'):
64+
$header_color = '#605ca8';
65+
$link_dark_color = '#605ca8';
66+
$link_light_color = '#605ca8';
67+
$nav_color = '#ffffff';
68+
69+
case ('yellow' || 'yellow-dark') :
70+
$header_color = '#f39c12';
71+
$link_dark_color = '#f39c12';
72+
$link_light_color = '#f39c12';
73+
$nav_color = '#ffffff';
74+
75+
case 'contrast':
76+
$header_color = '#001F3F';
77+
$link_dark_color = '#86cbf2';
78+
$link_light_color = '#084d73';
79+
$nav_color = '#ffffff';
80+
break;
81+
}
82+
83+
// Override the header color if the settings have one
84+
if ($setting->header_color) {
85+
$header_color = $setting->header_color;
86+
\Log::debug('A header color was found, so lets use that instead: '.$setting->header_color);
87+
}
88+
89+
90+
DB::table('settings')->update([
91+
'link_light_color' => $link_light_color,
92+
'link_dark_color' => $link_dark_color,
93+
'nav_link_color' => $nav_color,
94+
'header_color' => $header_color]);
95+
96+
DB::table('users')->whereNull('skin')->update([
97+
'link_light_color' => $link_light_color,
98+
'link_dark_color' => $link_dark_color,
99+
'nav_link_color' => $nav_color]);
100+
}
101+
102+
}
103+
104+
/**
105+
* Reverse the migrations.
106+
*/
107+
public function down(): void
108+
{
109+
Schema::table('settings', function ($table) {
110+
$table->dropColumn('link_dark_color');
111+
$table->dropColumn('link_light_color');
112+
$table->dropColumn('nav_link_color');
113+
});
114+
115+
Schema::table('users', function ($table) {
116+
$table->dropColumn('link_dark_color');
117+
$table->dropColumn('link_light_color');
118+
$table->dropColumn('nav_link_color');
119+
});
120+
}
121+
};

public/css/build/all.css

Lines changed: 0 additions & 617 deletions
This file was deleted.

public/css/build/app.css

Lines changed: 11 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/build/app.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)