Add text direction configuration for locales

This commit is contained in:
Moshe Lustigman 2019-07-23 18:05:57 -04:00
parent e1628196a8
commit a0ba845e37
10 changed files with 82 additions and 8 deletions

View File

@ -19,7 +19,7 @@ class LocalesDataGrid extends DataGrid
public function prepareQueryBuilder() public function prepareQueryBuilder()
{ {
$queryBuilder = DB::table('locales')->addSelect('id', 'code', 'name'); $queryBuilder = DB::table('locales')->addSelect('id', 'code', 'name', 'direction');
$this->setQueryBuilder($queryBuilder); $this->setQueryBuilder($queryBuilder);
} }
@ -52,6 +52,15 @@ class LocalesDataGrid extends DataGrid
'sortable' => true, 'sortable' => true,
'filterable' => true 'filterable' => true
]); ]);
$this->addColumn([
'index' => 'direction',
'label' => trans('admin::app.datagrid.direction'),
'type' => 'select',
'searchable' => true,
'sortable' => true,
'filterable' => true
]);
} }
public function prepareActions() { public function prepareActions() {

View File

@ -114,6 +114,7 @@ return [
'code' => 'Code', 'code' => 'Code',
'admin-name' => 'Name', 'admin-name' => 'Name',
'name' => 'Name', 'name' => 'Name',
'direction' => 'Direction',
'fullname' => 'Full Name', 'fullname' => 'Full Name',
'type' => 'Type', 'type' => 'Type',
'required' => 'Required', 'required' => 'Required',
@ -561,6 +562,7 @@ return [
'general' => 'General', 'general' => 'General',
'code' => 'Code', 'code' => 'Code',
'name' => 'Name', 'name' => 'Name',
'direction' => 'Direction',
'create-success' => 'Locale created successfully.', 'create-success' => 'Locale created successfully.',
'update-success' => 'Locale updated successfully.', 'update-success' => 'Locale updated successfully.',
'delete-success' => 'Locale deleted successfully.', 'delete-success' => 'Locale deleted successfully.',

View File

@ -1,3 +1,8 @@
@php
$locale = Webkul\Core\Models\Locale::where('code', app()->getLocale())->first();
@endphp
@endphp
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{{ config('app.locale') }}"> <html lang="{{ config('app.locale') }}">
<head> <head>
@ -67,7 +72,7 @@
{!! view_render_event('bagisto.admin.layout.head') !!} {!! view_render_event('bagisto.admin.layout.head') !!}
</head> </head>
<body @if (app()->getLocale() == 'ar') class="rtl" @endif style="scroll-behavior: smooth;"> <body @if ($locale->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
<div id="app" class="container"> <div id="app" class="container">
<flash-wrapper ref='flashes'></flash-wrapper> <flash-wrapper ref='flashes'></flash-wrapper>

View File

@ -1,3 +1,7 @@
@php
$locale = Webkul\Core\Models\Locale::where('code', app()->getLocale())->first();
@endphp
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{{ config('app.locale') }}"> <html lang="{{ config('app.locale') }}">
<head> <head>
@ -19,7 +23,7 @@
</head> </head>
<body @if (app()->getLocale() == 'ar') class="rtl" @endif style="scroll-behavior: smooth;"> <body @if ($locale->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
{!! view_render_event('bagisto.admin.layout.body.before') !!} {!! view_render_event('bagisto.admin.layout.body.before') !!}
<div id="app"> <div id="app">

View File

@ -41,6 +41,15 @@
<input v-validate="'required'" class="control" id="name" name="name" data-vv-as="&quot;{{ __('admin::app.settings.locales.name') }}&quot;"/> <input v-validate="'required'" class="control" id="name" name="name" data-vv-as="&quot;{{ __('admin::app.settings.locales.name') }}&quot;"/>
<span class="control-error" v-if="errors.has('name')">@{{ errors.first('name') }}</span> <span class="control-error" v-if="errors.has('name')">@{{ errors.first('name') }}</span>
</div> </div>
<div class="control-group" :class="[errors.has('direction') ? 'has-error' : '']">
<label for="direction" class="required">{{ __('admin::app.settings.locales.direction') }}</label>
<select v-validate="'required'" class="control" id="direction" name="direction" data-vv-as="&quot;{{ __('admin::app.settings.locales.direction') }}&quot;">
<option value="ltr" selected title="Text direction left to right">ltr</option>
<option value="rtl" title="Text direction right to left">rtl</option>
</select>
<span class="control-error" v-if="errors.has('direction')">@{{ errors.first('direction') }}</span>
</div>
</div> </div>
</accordian> </accordian>

View File

@ -44,6 +44,15 @@
<input v-validate="'required'" class="control" id="name" name="name" data-vv-as="&quot;{{ __('admin::app.settings.locales.name') }}&quot;" value="{{ old('name') ?: $locale->name }}"/> <input v-validate="'required'" class="control" id="name" name="name" data-vv-as="&quot;{{ __('admin::app.settings.locales.name') }}&quot;" value="{{ old('name') ?: $locale->name }}"/>
<span class="control-error" v-if="errors.has('name')">@{{ errors.first('name') }}</span> <span class="control-error" v-if="errors.has('name')">@{{ errors.first('name') }}</span>
</div> </div>
<div class="control-group" :class="[errors.has('direction') ? 'has-error' : '']">
<label for="direction" class="required">{{ __('admin::app.settings.locales.direction') }}</label>
<select v-validate="'required'" class="control" id="direction" name="direction" data-vv-as="&quot;{{ __('admin::app.settings.locales.direction') }}&quot;">
<option value="ltr" {{ old('direction') == 'ltr' ? 'selected' : '' }} title="Text direction left to right">ltr</option>
<option value="rtl" {{ old('direction') == 'rtl' ? 'selected' : '' }} title="Text direction right to left">rtl</option>
</select>
<span class="control-error" v-if="errors.has('direction')">@{{ errors.first('direction') }}</span>
</div>
</div> </div>
</accordian> </accordian>

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterLocalesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('locales', function (Blueprint $table) {
$table->enum('direction', ['ltr', 'rtl'])->default('ltr');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('locales');
}
}

View File

@ -72,7 +72,8 @@ class LocaleController extends Controller
{ {
$this->validate(request(), [ $this->validate(request(), [
'code' => ['required', 'unique:locales,code', new \Webkul\Core\Contracts\Validations\Code], 'code' => ['required', 'unique:locales,code', new \Webkul\Core\Contracts\Validations\Code],
'name' => 'required' 'name' => 'required',
'direction' => 'in:ltr,rtl'
]); ]);
Event::fire('core.locale.create.before'); Event::fire('core.locale.create.before');
@ -110,7 +111,8 @@ class LocaleController extends Controller
{ {
$this->validate(request(), [ $this->validate(request(), [
'code' => ['required', 'unique:locales,code,' . $id, new \Webkul\Core\Contracts\Validations\Code], 'code' => ['required', 'unique:locales,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
'name' => 'required' 'name' => 'required',
'direction' => 'in:ltr,rtl'
]); ]);
Event::fire('core.locale.update.before', $id); Event::fire('core.locale.update.before', $id);

View File

@ -13,6 +13,6 @@ class Locale extends Model implements LocaleContract
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'code', 'name' 'code', 'name', 'direction'
]; ];
} }

View File

@ -1,3 +1,7 @@
@php
$locale = Webkul\Core\Models\Locale::where('code', app()->getLocale())->first();
@endphp
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{{ app()->getLocale() }}"> <html lang="{{ app()->getLocale() }}">
@ -30,7 +34,7 @@
</head> </head>
<body @if (app()->getLocale() == 'ar') class="rtl" @endif style="scroll-behavior: smooth;"> <body @if ($locale->direction == 'rtl') class="rtl" @endif style="scroll-behavior: smooth;">
{!! view_render_event('bagisto.shop.layout.body.before') !!} {!! view_render_event('bagisto.shop.layout.body.before') !!}