Merge branch 'issue-9' into 'develop'
Issue 9 - Message Info Closes #9 See merge request ldc-web/projets/support-web!20
This commit is contained in:
commit
4e67acf98b
14 changed files with 484 additions and 17 deletions
90
app/Enums/InfoColors.php
Normal file
90
app/Enums/InfoColors.php
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnumRoutable;
|
||||
|
||||
/**
|
||||
* @method static self primary()
|
||||
* @method static self secondary()
|
||||
* @method static self success()
|
||||
* @method static self danger()
|
||||
* @method static self warning()
|
||||
* @method static self info()
|
||||
* @method static self light()
|
||||
* @method static self dark()
|
||||
* @method static self white()
|
||||
*/
|
||||
class InfoColors extends BaseEnumRoutable
|
||||
{
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'primary' => 0,
|
||||
'secondary' => 1,
|
||||
'success' => 2,
|
||||
'danger' => 3,
|
||||
'warning' => 4,
|
||||
'info' => 5,
|
||||
'light' => 6,
|
||||
'dark' => 7,
|
||||
'white' => 8
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'primary' => trans('Primary'),
|
||||
'secondary' => trans('Secondary'),
|
||||
'success' => trans('Success'),
|
||||
'danger' => trans('Danger'),
|
||||
'warning' => trans('Warning'),
|
||||
'info' => trans('Info'),
|
||||
'light' => trans('Light'),
|
||||
'dark' => trans('Dark'),
|
||||
'white' => trans('white')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum classes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function classes(): array
|
||||
{
|
||||
return [
|
||||
'primary' => 'primary',
|
||||
'secondary' => 'secondary',
|
||||
'success' => 'success',
|
||||
'danger' => 'danger',
|
||||
'warning' => 'warning',
|
||||
'info' => 'info',
|
||||
'light' => 'light',
|
||||
'dark' => 'dark',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $attribute
|
||||
* @return integer|string
|
||||
*/
|
||||
public function __get(string $attribute)
|
||||
{
|
||||
if ($attribute === 'class') {
|
||||
return $this->classes()[$this->getDefinition()];
|
||||
}
|
||||
return parent::__get($attribute);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,23 +3,21 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Dutyhour;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show Home page
|
||||
*
|
||||
* @param Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function home(Request $request)
|
||||
{
|
||||
/**
|
||||
* Get only duty hours for today or later.
|
||||
* @var \Illuminate\Database\Eloquent\Builder $dutyhour
|
||||
*/
|
||||
$dutyhourModels = Dutyhour::where('date', '>', now()->modify('-1 day'))->orderBy('date', 'asc')->limit(10)->get();
|
||||
return view('home', compact('dutyhourModels'));
|
||||
}
|
||||
* Show Home page
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function home()
|
||||
{
|
||||
/**
|
||||
* Get only duty hours for today or later.
|
||||
* @var \Illuminate\Database\Eloquent\Builder $dutyhour
|
||||
*/
|
||||
$dutyhourModels = Dutyhour::where('date', '>', now()->modify('-1 day'))->orderBy('date', 'asc')->limit(10)->get();
|
||||
return view('home', compact('dutyhourModels'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
52
app/Http/Controllers/InformationController.php
Normal file
52
app/Http/Controllers/InformationController.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Information;
|
||||
use Kwaadpepper\CrudPolicies\Traits\CrudController;
|
||||
|
||||
class InformationController extends Controller
|
||||
{
|
||||
use CrudController;
|
||||
|
||||
/** @var \App\Models\MacroSchedule\Marker */
|
||||
public static $modelClass = Information::class;
|
||||
|
||||
/**
|
||||
* Crud Layout
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $layout = 'layout.app';
|
||||
|
||||
/**
|
||||
* After store model middleware
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function storedModel()
|
||||
{
|
||||
cache()->put('infos', Information::all(), 3600);
|
||||
}
|
||||
|
||||
/**
|
||||
* After update model middleware
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updatedModel()
|
||||
{
|
||||
cache()->put('infos', Information::all(), 3600);
|
||||
}
|
||||
|
||||
/**
|
||||
* After delete model middleware
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deletedModel()
|
||||
{
|
||||
cache()->put('infos', Information::all(), 3600);
|
||||
}
|
||||
}
|
||||
120
app/Models/Information.php
Normal file
120
app/Models/Information.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\InfoColors;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudAction;
|
||||
use Kwaadpepper\CrudPolicies\Enums\CrudType;
|
||||
use Kwaadpepper\CrudPolicies\Traits\IsCrudModel;
|
||||
use Kwaadpepper\Enum\Traits\CastsEnums;
|
||||
|
||||
class Information extends Model
|
||||
{
|
||||
use CastsEnums;
|
||||
use HasFactory;
|
||||
use IsCrudModel;
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* Crud label column
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $crudLabelColumn = 'title';
|
||||
|
||||
/**
|
||||
* The table associated with this model
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'informations';
|
||||
|
||||
/**
|
||||
* Crud value column
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $crudValueColumn = 'id';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'message',
|
||||
'type'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $enumCasts = [
|
||||
'type' => InfoColors::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Package
|
||||
*
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
self::$editableProperties = [
|
||||
'title' => [
|
||||
'label' => trans('Titre'),
|
||||
'type' => CrudType::string(),
|
||||
'validate' => [
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view(),
|
||||
CrudAction::update(),
|
||||
CrudAction::create()
|
||||
]
|
||||
],
|
||||
'message' => [
|
||||
'label' => trans('Message'),
|
||||
'type' => CrudType::string(),
|
||||
'validate' => [
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view(),
|
||||
CrudAction::update(),
|
||||
CrudAction::create()
|
||||
]
|
||||
],
|
||||
'type' => [
|
||||
'label' => trans('Type d\'annonce'),
|
||||
'type' => CrudType::enum(),
|
||||
'enum' => InfoColors::class,
|
||||
'nullable' => false,
|
||||
'actions' => [
|
||||
CrudAction::viewAny(),
|
||||
CrudAction::view(),
|
||||
CrudAction::update(),
|
||||
CrudAction::create()
|
||||
]
|
||||
],
|
||||
];
|
||||
parent::__construct($attributes);
|
||||
}
|
||||
}
|
||||
38
app/Policies/InformationPolicy.php
Normal file
38
app/Policies/InformationPolicy.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Policies\Rules\UserRoleRules as URR;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kwaadpepper\CrudPolicies\Policies\RootPolicy;
|
||||
|
||||
class InformationPolicy extends RootPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Init policies on call
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return void
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
||||
*/
|
||||
public function setPolicies(User $user, Model $model = null)
|
||||
{
|
||||
// phpcs:enable
|
||||
/**
|
||||
* This first rule to return true in a policy action authorises the action
|
||||
*/
|
||||
$this->policies = [
|
||||
'information' => [
|
||||
'viewAny' => URR::make('userIsAdmin', $user),
|
||||
'create' => URR::make('userIsAdmin', $user),
|
||||
'update' => URR::make('userIsAdmin', $user),
|
||||
'delete' => URR::make('userIsAdmin', $user)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Information;
|
||||
use App\Models\MacroSchedule\Marker;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
|
@ -51,17 +52,21 @@ class AppServiceProvider extends ServiceProvider
|
|||
});
|
||||
|
||||
if (!app()->runningInConsole()) {
|
||||
$appInfos = Cache::remember('composer', 360, function () {
|
||||
$appInfos = Cache::remember('composer', 3600, function () {
|
||||
return json_decode(File::get(\app_path('../composer.json')));
|
||||
});
|
||||
View::share('name', $appInfos->name);
|
||||
View::share('version', $appInfos->version);
|
||||
View::share('license', $appInfos->license);
|
||||
|
||||
// * Groups
|
||||
View::share('markerLabels', Cache::rememberForever('markerLabels', function () {
|
||||
return Marker::getCachedLabels() ?? [];
|
||||
}));
|
||||
// * Informations
|
||||
$infos = Cache::remember('infos', 3600, function () {
|
||||
return Information::all();
|
||||
});
|
||||
View::share('informations', $infos);
|
||||
}//end if
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Models\Credit\Account;
|
|||
use App\Models\Credit\CreditLog;
|
||||
use App\Models\Dutyhour;
|
||||
use App\Models\File;
|
||||
use App\Models\Information;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Label;
|
||||
use App\Models\Log;
|
||||
|
|
@ -93,6 +94,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||
Route::model('marker', Marker::class);
|
||||
Route::model('package', Package::class);
|
||||
Route::model('dutyhour', Dutyhour::class);
|
||||
Route::model('information', Information::class);
|
||||
Route::model('company', Company::class);
|
||||
Route::model('invoice', Invoice::class);
|
||||
Route::model('file', File::class);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateInformationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('informations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title');
|
||||
$table->string('message');
|
||||
$table->unsignedTinyInteger('type')->comment('Defined by the InfoColors enum.');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('informations');
|
||||
}
|
||||
}
|
||||
|
|
@ -17,5 +17,6 @@ return [
|
|||
'invoices' => 'Invoices',
|
||||
'companies' => 'Companies',
|
||||
'dutyhours' => 'Duty Hours',
|
||||
'informations' => 'Informations',
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -17,5 +17,6 @@ return [
|
|||
'invoices' => 'Devis',
|
||||
'companies' => 'Sociétés',
|
||||
'dutyhours' => 'Permanences',
|
||||
'informations' => 'Informations',
|
||||
]
|
||||
];
|
||||
|
|
|
|||
112
resources/views/informations/index.blade.php
Normal file
112
resources/views/informations/index.blade.php
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
@extends($viewLayout)
|
||||
|
||||
@section('title', sprintf('%s - %s', transFb(sprintf('models.classes.%s', strtolower(Str::plural(class_basename($modelClass)))), Str::plural(class_basename($modelClass))), __('crud-policies::crud.viewAny')))
|
||||
@section('description', sprintf('%s %s', __('crud-policies::crud.viewAny'), trans(Str::plural(class_basename($modelClass)))))
|
||||
@section('metaIndex', 'noindex,nofollow')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
@include('crud-policies::crud.modules.flashMessage')
|
||||
<div class="card-header">
|
||||
@include('crud-policies::crud.modules.breadcrumb', ['action' => CrudAction::viewAny()])
|
||||
@include('crud-policies::crud.modules.actionbar.bar', ['action' => CrudAction::viewAny()])
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col">
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
<div class="col">
|
||||
<form action="{{ url()->current() }}">
|
||||
<div class="input-group mb-3">
|
||||
<input type="search" name="search" class="form-control" value="{{ request()->search }}"/>
|
||||
<input type="text" name="sort_col" class="d-none" value="{{ request()->sort_col }}"/>
|
||||
<input type="text" name="sort_way" class="d-none" value="{{ request()->sort_way }}"/>
|
||||
<a class="btn btn-danger" href="{{ url()->current() }}">{{ __('crud-policies::crud.reset') }}</a>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
{{ __('crud-policies::crud.search') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table text-center">
|
||||
<thead class="thead-dark">
|
||||
@include('crud-policies::crud.modules.sorter')
|
||||
</thead>
|
||||
<tbody>
|
||||
@if(count($models))
|
||||
|
||||
{{-- INIT QUERIES for OPTIMIZING --}}
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if($prop['type']->equals(CrudType::order()))
|
||||
@php ${"$modelTable$fieldName"} = $modelClass::max($fieldName); @endphp
|
||||
@endif
|
||||
@if($prop['type']->equals(CrudType::belongsTo()))
|
||||
@php try { $models->load(Str::singular((new $prop['belongsTo']())->getTable())); } catch(\Exception $e) {} @endphp
|
||||
@endif
|
||||
@if($prop['type']->equals(CrudType::belongsToMany()))
|
||||
@php $models->load("$fieldName"); @endphp
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- DISPLAY MODELS --}}
|
||||
@foreach($models as $model)
|
||||
<tr>
|
||||
@foreach ($modelClass::getEditableProperties() as $fieldName => $prop)
|
||||
@if(in_array(CrudAction::viewAny(), $prop['actions']))
|
||||
@switch($prop['type'])
|
||||
@case(CrudType::password())
|
||||
{{-- Ignore --}}
|
||||
@break
|
||||
@default
|
||||
<td>@include('crud-policies::crud.printfield', [
|
||||
'action' => CrudAction::viewAny(),
|
||||
'field' => $model->{$fieldName},
|
||||
'props' => $prop,
|
||||
"$modelTable$fieldName" => ${"$modelTable$fieldName"} ?? null
|
||||
])</td>
|
||||
@endswitch
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
{{-- MODEL ACTIONS --}}
|
||||
<td>
|
||||
<div class="btn-group" role="group" aria-label="{{ Str::plural(__('crud-policies::crud.action')) }}">
|
||||
@can('view', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.show", $model) }}" class="btn btn-sm btn-primary">{{ __('crud-policies::crud.view') }}</a>
|
||||
@endcan
|
||||
@can('update', $model)
|
||||
<a href="{{ CrudController::getRoutePrefixed("$modelTable.edit", $model) }}" class="btn btn-sm btn-info">{{ __('crud-policies::crud.edit') }}</a>
|
||||
@endcan
|
||||
@can('delete', $model)
|
||||
<form class="CrudConfirmDelete" action="{{ CrudController::getRoutePrefixed("$modelTable.destroy", $model) }}" method="POST">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-sm btn-danger">{{ __('crud-policies::crud.delete') }}</button>
|
||||
</form>
|
||||
@endcan
|
||||
@can('viewAny', \App\Models\Log::class)
|
||||
<a href="{{ CrudController::getRoutePrefixed("informations.logs.index", $model) }}" class="btn btn-sm btn-dark">{{ __('models.classes.logs') }}</a>
|
||||
@endcan
|
||||
@can('viewAny', \App\Models\File::class)
|
||||
<a href="{{ CrudController::getRoutePrefixed("informations.files.index", $model) }}" class="btn btn-sm btn-dark">{{ __('models.classes.files') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
@else
|
||||
<tr>
|
||||
<td colspan="{{ count($modelClass::getEditableProperties()) }}">
|
||||
{{ __('crud-policies::crud.nothingtoshow') }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
{{ $models->links() }}
|
||||
</div>
|
||||
</div>
|
||||
@include('crud-policies::crud.modules.scriptConstants')
|
||||
@endsection
|
||||
|
|
@ -28,6 +28,15 @@
|
|||
<div class="container container-xxl">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-12 @yield('bodyClass')">
|
||||
@auth
|
||||
@foreach ($informations as $information)
|
||||
<div class="alert alert-{{ $information->type->class }}" role="alert">
|
||||
<b>{{ $information->title }}</b><br>
|
||||
{{ $information->message }} - {{ __('Publié le') }} {{ $information->created_at->format('d-m-Y') }}
|
||||
</div>
|
||||
@endforeach
|
||||
@endauth
|
||||
|
||||
@if(!isset($modelClass))
|
||||
{{-- Dont use for crud-policies --}}
|
||||
@include('modules.flashMessage')
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@
|
|||
@can('viewAny', App\Models\Dutyhour::class)
|
||||
<a class="dropdown-item @if(strpos(request()->route()->getName(), 'dutyhours') === 0)active @endif" href="{{ route('dutyhours.index') }}">{{ __('models.classes.dutyhours') }}</a>
|
||||
@endcan
|
||||
@can('viewAny', App\Models\Information::class)
|
||||
<a class="dropdown-item @if(strpos(request()->route()->getName(), 'informations') === 0)active @endif" href="{{ route('informations.index') }}">{{ __('models.classes.informations') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
</li>
|
||||
@endif
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Http\Controllers\Credit\EstimationController;
|
|||
use App\Http\Controllers\DutyhourController;
|
||||
use App\Http\Controllers\FileController;
|
||||
use App\Http\Controllers\HomeController;
|
||||
use App\Http\Controllers\InformationController;
|
||||
use App\Http\Controllers\InvoiceController;
|
||||
use App\Http\Controllers\LabelController;
|
||||
use App\Http\Controllers\LogController;
|
||||
|
|
@ -76,6 +77,7 @@ Route::middleware('auth:web')->group(function () {
|
|||
Route::resource('users', UserController::class);
|
||||
Route::resource('packages', PackageController::class)->except('show');
|
||||
Route::resource('dutyhours', DutyhourController::class)->except('show');
|
||||
Route::resource('informations', InformationController::class)->except('show');
|
||||
Route::resource('companies', CompanyController::class)->except('show');
|
||||
Route::resource('invoices', InvoiceController::class);
|
||||
Route::resource('labels', LabelController::class)->except('show');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue