Add a way for a user to override the site skin setting + fix mislabeled comment. (#6891)

* Add a way for a user to override the skin setting.

* Add site setting to allow user to change the skin.

* Fix skin list.

Co-authored-by: NMC <info@nmc-lab.com>
This commit is contained in:
NMC 2021-03-29 22:09:23 -04:00 committed by GitHub
parent 78cc47a859
commit 3e934a1b96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 132 additions and 13 deletions

View file

@ -48,10 +48,9 @@ class ProfileController extends Controller
$user->last_name = $request->input('last_name'); $user->last_name = $request->input('last_name');
$user->website = $request->input('website'); $user->website = $request->input('website');
$user->gravatar = $request->input('gravatar'); $user->gravatar = $request->input('gravatar');
$user->skin = $request->input('skin');
$user->phone = $request->input('phone'); $user->phone = $request->input('phone');
if (!config('app.lock_passwords')) { if (!config('app.lock_passwords')) {
$user->locale = $request->input('locale', 'en'); $user->locale = $request->input('locale', 'en');
} }

View file

@ -400,6 +400,7 @@ class SettingsController extends Controller
$setting->version_footer = $request->input('version_footer'); $setting->version_footer = $request->input('version_footer');
$setting->footer_text = $request->input('footer_text'); $setting->footer_text = $request->input('footer_text');
$setting->skin = $request->input('skin'); $setting->skin = $request->input('skin');
$setting->allow_user_skin = $request->input('allow_user_skin');
$setting->show_url_in_emails = $request->input('show_url_in_emails', '0'); $setting->show_url_in_emails = $request->input('show_url_in_emails', '0');
$setting->logo_print_assets = $request->input('logo_print_assets', '0'); $setting->logo_print_assets = $request->input('logo_print_assets', '0');

View file

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddUserSkinSetting extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Update the users table
Schema::table('users', function ($table) {
$table->string('skin')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Update the users table
Schema::table('users', function ($table) {
$table->dropColumn('skin');
});
}
}

View file

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddSettingAllowUserSkin extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Update the users table
Schema::table('settings', function ($table) {
$table->boolean('allow_user_skin')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Update the users table
Schema::table('settings', function ($table) {
$table->dropColumn('allow_user_skin');
});
}
}

View file

@ -14,6 +14,8 @@ return array(
'alerts_enabled' => 'Email Alerts Enabled', 'alerts_enabled' => 'Email Alerts Enabled',
'alert_interval' => 'Expiring Alerts Threshold (in days)', 'alert_interval' => 'Expiring Alerts Threshold (in days)',
'alert_inv_threshold' => 'Inventory Alert Threshold', 'alert_inv_threshold' => 'Inventory Alert Threshold',
'allow_user_skin' => 'Allow user skin',
'allow_user_skin_help_text' => 'Checking this box will allow a user to change the site skin for himself.' ,
'asset_ids' => 'Asset IDs', 'asset_ids' => 'Asset IDs',
'audit_interval' => 'Audit Interval', 'audit_interval' => 'Audit Interval',
'audit_interval_help' => 'If you are required to regularly physically audit your assets, enter the interval in months.', 'audit_interval_help' => 'If you are required to regularly physically audit your assets, enter the interval in months.',

View file

@ -582,3 +582,34 @@ Form::macro('skin', function ($name = "skin", $selected = null, $class = null) {
return $select; return $select;
}); });
Form::macro('user_skin', function ($name = "skin", $selected = null, $class = null) {
$formats = array(
'' => 'Site Default',
'blue' => 'Default Blue',
'blue-dark' => 'Blue (Dark Mode)',
'green' => 'Green Dark',
'green-dark' => 'Green (Dark Mode)',
'red' => 'Red Dark',
'red-dark' => 'Red (Dark Mode)',
'orange' => 'Orange Dark',
'orange-dark' => 'Orange (Dark Mode)',
'black' => 'Black',
'black-dark' => 'Black (Dark Mode)',
'purple' => 'Purple',
'purple-dark' => 'Purple (Dark Mode)',
'yellow' => 'Yellow',
'yellow-dark' => 'Yellow (Dark Mode)',
'contrast' => 'High Contrast',
);
$select = '<select name="'.$name.'" class="'.$class.'" style="width: 250px">';
foreach ($formats as $format => $label) {
$select .= '<option value="'.$format.'"'.($selected == $format ? ' selected="selected"' : '').'>'.$label.'</option> '."\n";
}
$select .= '</select>';
return $select;
});

View file

@ -58,6 +58,17 @@
</div> </div>
</div> </div>
@if ($snipeSettings->allow_user_skin=='1')
<!-- Skin -->
<div class="form-group {{ $errors->has('skin') ? 'error' : '' }}">
<label for="website" class="col-md-3 control-label">{{ Form::label('skin', trans('general.skin')) }}</label>
<div class="col-md-8">
{!! Form::user_skin('skin', Input::old('skin', $user->skin), 'select2') !!}
{!! $errors->first('skin', '<span class="alert-msg">:message</span>') !!}
</div>
</div>
@endif
<!-- Phone --> <!-- Phone -->
<div class="form-group {{ $errors->has('phone') ? 'has-error' : '' }}"> <div class="form-group {{ $errors->has('phone') ? 'has-error' : '' }}">
<label class="col-md-3 control-label" for="phone">{{ trans('admin/users/table.phone') }}</label> <label class="col-md-3 control-label" for="phone">{{ trans('admin/users/table.phone') }}</label>
@ -67,8 +78,6 @@
</div> </div>
</div> </div>
<!-- Website URL --> <!-- Website URL -->
<div class="form-group {{ $errors->has('website') ? ' has-error' : '' }}"> <div class="form-group {{ $errors->has('website') ? ' has-error' : '' }}">
<label for="website" class="col-md-3 control-label">{{ trans('general.website') }}</label> <label for="website" class="col-md-3 control-label">{{ trans('general.website') }}</label>
@ -114,8 +123,6 @@
<!-- Two factor opt in --> <!-- Two factor opt in -->
@if ($snipeSettings->two_factor_enabled=='1') @if ($snipeSettings->two_factor_enabled=='1')
<div class="form-group {{ $errors->has('avatar') ? 'has-error' : '' }}"> <div class="form-group {{ $errors->has('avatar') ? 'has-error' : '' }}">

View file

@ -28,13 +28,13 @@
</script> </script>
{{-- stylesheets --}} {{-- stylesheets --}}
<link rel="stylesheet" href="{{ mix('css/all.css') }}">
<link rel="stylesheet" href="{{ url(mix('css/dist/all.css')) }}"> @if (($snipeSettings) && ($snipeSettings->allow_user_skin==1) && Auth::check() && Auth::user()->present()->skin != '')
<link rel="stylesheet" href="{{ mix('css/skins/skin-'.Auth::user()->present()->skin.'.min.css') }}">
@elseif (($snipeSettings) && ($snipeSettings->skin!=''))
<link rel="stylesheet" href="{{ url(mix('css/dist/skins/skin-'.($snipeSettings->skin!='' ? $snipeSettings->skin : 'blue').'.css')) }}"> <link rel="stylesheet" href="{{ url(mix('css/dist/skins/skin-'.($snipeSettings->skin!='' ? $snipeSettings->skin : 'blue').'.css')) }}">
@endif
{{-- page level css --}}
{{-- page level css --}}
@stack('css') @stack('css')

View file

@ -150,7 +150,7 @@
</div> </div>
</div> </div>
<!-- Email format --> <!-- Skin -->
<div class="form-group {{ $errors->has('skin') ? 'error' : '' }}"> <div class="form-group {{ $errors->has('skin') ? 'error' : '' }}">
<div class="col-md-3"> <div class="col-md-3">
{{ Form::label('skin', trans('general.skin')) }} {{ Form::label('skin', trans('general.skin')) }}
@ -161,6 +161,17 @@
</div> </div>
</div> </div>
<!-- Allow User Skin -->
<div class="form-group">
<div class="col-md-3">
{{ Form::label('allow_user_skin', trans('admin/settings/general.allow_user_skin')) }}
</div>
<div class="col-md-9">
{{ Form::checkbox('allow_user_skin', '1', Input::old('allow_user_skin', $setting->allow_user_skin),array('class' => 'minimal')) }}
{{ trans('general.yes') }}
<p class="help-block">{{ trans('admin/settings/general.allow_user_skin_help_text') }}</p>
</div>
</div>
<!-- Custom css --> <!-- Custom css -->
<div class="form-group {{ $errors->has('custom_css') ? 'error' : '' }}"> <div class="form-group {{ $errors->has('custom_css') ? 'error' : '' }}">