Merge pull request #13496 from snipe/features/setting_for_name_order

Fixed #13495 added setting for name order
This commit is contained in:
snipe 2023-08-22 12:50:58 +01:00 committed by GitHub
commit a48762c64d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 84 additions and 30 deletions

View file

@ -590,6 +590,7 @@ class SettingsController extends Controller
$setting->date_display_format = $request->input('date_display_format');
$setting->time_display_format = $request->input('time_display_format');
$setting->digit_separator = $request->input('digit_separator');
$setting->name_display_format = $request->input('name_display_format');
if ($setting->save()) {
return redirect()->route('settings.index')

View file

@ -24,7 +24,7 @@ class UsersTransformer
$array = [
'id' => (int) $user->id,
'avatar' => e($user->present()->gravatar),
'name' => e($user->first_name).' '.e($user->last_name),
'name' => e($user->getFullNameAttribute()),
'first_name' => e($user->first_name),
'last_name' => e($user->last_name),
'username' => e($user->username),

View file

@ -247,21 +247,12 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
*/
public function getFullNameAttribute()
{
return $this->first_name.' '.$this->last_name;
}
$setting = Setting::getSettings();
/**
* Returns the complete name attribute with username
*
* @todo refactor this so it's less repetitive and dumb
*
* @author A. Gianotto <snipe@snipe.net>
* @since [v2.0]
* @return string
*/
public function getCompleteNameAttribute()
{
return $this->last_name.', '.$this->first_name.' ('.$this->username.')';
if ($setting->name_display_format=='last_first') {
return ($this->last_name) ? $this->last_name.' '.$this->first_name : $this->first_name;
}
return $this->last_name ? $this->first_name.' '.$this->last_name : $this->first_name;
}

View file

@ -433,7 +433,7 @@ class UserPresenter extends Presenter
*/
public function nameUrl()
{
return (string) link_to_route('users.show', $this->fullName(), $this->id);
return (string) link_to_route('users.show', $this->getFullNameAttribute(), $this->id);
}
/**

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddNameOrderingToSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('settings', function (Blueprint $table) {
$table->string('name_display_format', 10)->after('alert_threshold')->nullable()->default('first_last');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('settings', function (Blueprint $table) {
$table->dropColumn('name_display_format');
});
}
}

View file

@ -120,6 +120,9 @@ return [
'firstname_lastname_underscore_format' => 'First Name Last Name (jane_smith@example.com)',
'lastnamefirstinitial_format' => 'Last Name First Initial (smithj@example.com)',
'firstintial_dot_lastname_format' => 'First Initial Last Name (j.smith@example.com)',
'firstname_lastname_display' => 'First Name Last Name (Jane Smith)',
'lastname_firstname_display' => 'Last Name First Name (Smith Jane)',
'name_display_format' => 'Name Display Format',
'first' => 'First',
'firstnamelastname' => 'First Name Last Name (janesmith@example.com)',
'lastname_firstinitial' => 'Last Name First Initial (smith_j@example.com)',

View file

@ -11,7 +11,7 @@ Form::macro('locales', function ($name = 'locale', $selected = null, $class = nu
$idclause = (!is_null($id)) ? $id : '';
$select = '<select name="'.$name.'" class="'.$class.'" style="min-width:350px"'.$idclause.' aria-label="'.$name.'" data-placeholder="'.trans('localizations.select_language').'">';
$select = '<select name="'.$name.'" class="'.$class.'" style="min-width:100%"'.$idclause.' aria-label="'.$name.'" data-placeholder="'.trans('localizations.select_language').'">';
$select .= '<option value="" role="option">'.trans('localizations.select_language').'</option>';
// Pull the autoglossonym array from the localizations translation file
@ -109,6 +109,23 @@ Form::macro('digit_separator', function ($name = 'digit_separator', $selected =
return $select;
});
Form::macro('name_display_format', function ($name = 'name_display_format', $selected = null, $class = null) {
$formats = [
'first_last' => trans('general.firstname_lastname_display'),
'last_first' => trans('general.lastname_firstname_display'),
];
$select = '<select name="'.$name.'" class="'.$class.'" style="width: 100%" aria-label="'.$name.'">';
foreach ($formats as $format => $label) {
$select .= '<option value="'.$format.'"'.($selected == $format ? ' selected="selected" role="option" aria-selected="true"' : ' aria-selected="false"').'>'.$label.'</option> '."\n";
}
$select .= '</select>';
return $select;
});
/**
* Barcode macro
* Generates the dropdown menu of available 1D barcodes

View file

@ -46,7 +46,7 @@
<!-- Language -->
<div class="form-group {{ $errors->has('locale') ? 'has-error' : '' }}">
<label class="col-md-3 control-label" for="locale">{{ trans('general.language') }}</label>
<div class="col-md-9">
<div class="col-md-7">
@if (!config('app.lock_passwords'))
{!! Form::locales('locale', old('locale', $user->locale), 'select2') !!}

View file

@ -2,7 +2,7 @@
{{-- Page title --}}
@section('title')
{{ trans('general.hello_name', array('name' => $user->present()->fullName())) }}
{{ trans('general.hello_name', array('name' => $user->present()->getFullNameAttribute())) }}
@parent
@stop

View file

@ -328,7 +328,7 @@
<i class="fas fa-users" aria-hidden="true"></i>
@endif
<span class="hidden-xs">{{ Auth::user()->first_name }} <strong
<span class="hidden-xs">{{ Auth::user()->getFullNameAttribute() }} <strong
class="caret"></strong></span>
</a>
<ul class="dropdown-menu">

View file

@ -42,26 +42,39 @@
<!-- Language -->
<div class="form-group {{ $errors->has('site_name') ? 'error' : '' }}">
<div class="col-md-3">
<div class="col-md-3 col-xs-12">
{{ Form::label('site_name', trans('admin/settings/general.default_language')) }}
</div>
<div class="col-md-9">
<div class="col-md-5 col-xs-12">
{!! Form::locales('locale', Request::old('locale', $setting->locale), 'select2') !!}
{!! $errors->first('locale', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
</div>
<!-- name display format -->
<div class="form-group {{ $errors->has('name_display_format') ? 'error' : '' }}">
<div class="col-md-3 col-xs-12">
{{ Form::label('name_display_format', trans('general.name_display_format')) }}
</div>
<div class="col-md-5 col-xs-12">
{!! Form::name_display_format('name_display_format', Request::old('name_display_format', $setting->name_display_format), 'select2') !!}
{!! $errors->first('name_display_format', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
</div>
<!-- Date format -->
<div class="form-group {{ $errors->has('time_display_format') ? 'error' : '' }}">
<div class="col-md-3">
<div class="col-md-3 col-xs-12">
{{ Form::label('time_display_format', trans('general.time_and_date_display')) }}
</div>
<div class="col-md-5">
<div class="col-md-5 col-xs-12">
{!! Form::date_display_format('date_display_format', Request::old('date_display_format', $setting->date_display_format), 'select2') !!}
</div>
<div class="col-md-3">
<div class="col-md-3 col-xs-12">
{!! Form::time_display_format('time_display_format', Request::old('time_display_format', $setting->time_display_format), 'select2') !!}
</div>
@ -71,10 +84,10 @@
<!-- Currency -->
<div class="form-group {{ $errors->has('default_currency') ? 'error' : '' }}">
<div class="col-md-3">
<div class="col-md-3 col-xs-12">
{{ Form::label('default_currency', trans('admin/settings/general.default_currency')) }}
</div>
<div class="col-md-9">
<div class="col-md-9 col-xs-12">
{{ Form::text('default_currency', old('default_currency', $setting->default_currency), array('class' => 'form-control select2-container','placeholder' => 'USD', 'maxlength'=>'3', 'style'=>'width: 60px; display: inline-block; ')) }}
{!! Form::digit_separator('digit_separator', old('digit_separator', $setting->digit_separator), 'select2') !!}
@ -84,9 +97,6 @@
</div>
</div>
</div> <!--/.box-body-->