Miglioramento base per componenti Blade

This commit is contained in:
Dasc3er 2021-03-15 14:48:56 +01:00
parent 06439a275f
commit 457acd6f20
25 changed files with 325 additions and 40 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace App\View\Components;
use Illuminate\View\Component;
use Modules\Emails\Mail;
class EmailHistory extends Component
{
protected $emails;
/**
* Create a new component instance.
*
* @param string|int $module
* @param int $record
*/
public function __construct(
$module,
$record
) {
// Visualizzo il log delle operazioni di invio email
$this->emails = Mail::whereRaw('id IN (SELECT id_email FROM zz_operations WHERE id_record = '.prepare($record).' AND id_module = '.prepare($module).' AND id_email IS NOT NULL)')
->orderBy('created_at', 'DESC')
->get();
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|string
*/
public function render()
{
return view('components.email-history', [
'emails' => $this->emails,
]);
}
}

View File

@ -5,7 +5,7 @@ namespace App\View\Components;
use Illuminate\Support\Collection;
use Illuminate\View\Component;
class Input extends Component
class InputWrapper extends Component
{
public $props;
@ -99,6 +99,6 @@ class Input extends Component
*/
public function render()
{
return view('components.input');
return view('components.input-wrapper');
}
}

View File

@ -2,10 +2,10 @@
namespace App\View\Components\Inputs;
use App\View\Components\Input;
use App\View\Components\InputWrapper;
use Illuminate\View\Component;
class Checkbox extends Input
class Checkbox extends InputWrapper
{
public function init()
{

View File

@ -2,10 +2,10 @@
namespace App\View\Components\Inputs;
use App\View\Components\Input;
use App\View\Components\InputWrapper;
use Illuminate\View\Component;
class Editor extends Input
class Editor extends InputWrapper
{
public function init()
{

View File

@ -2,10 +2,10 @@
namespace App\View\Components\Inputs;
use App\View\Components\Input;
use App\View\Components\InputWrapper;
use Illuminate\View\Component;
class File extends Input
class File extends InputWrapper
{
public $type = 'file';

View File

@ -2,10 +2,10 @@
namespace App\View\Components\Inputs;
use App\View\Components\Input;
use App\View\Components\InputWrapper;
use Illuminate\View\Component;
class Image extends Input
class Image extends InputWrapper
{
/**
* Get the view / contents that represent the component.

View File

@ -2,10 +2,10 @@
namespace App\View\Components\Inputs;
use App\View\Components\Input;
use App\View\Components\InputWrapper;
use Illuminate\View\Component;
class Number extends Input
class Number extends InputWrapper
{
/**
* Create a new component instance.

View File

@ -2,9 +2,9 @@
namespace App\View\Components\Inputs;
use App\View\Components\Input;
use App\View\Components\InputWrapper;
class Password extends Input
class Password extends InputWrapper
{
/**
* Get the view / contents that represent the component.

View File

@ -2,17 +2,90 @@
namespace App\View\Components\Inputs;
use AJAX;
use App\View\Components\InputWrapper;
use Illuminate\View\Component;
class Select extends Component
class Select extends InputWrapper
{
/**
* Create a new component instance.
*
* @return void
* @param string $name
* @param string|null $id
* @param string|null $value
* @param bool|string $required
* @param string|null $label
* @param string|null $placeholder
* @param bool $multiple
* @param string $source
* @param string $query
* @param array $values
* @param array $options
*/
public function __construct()
{
public function __construct(
$name,
$id = null,
$value = null,
$required = false,
$label = null,
$placeholder = null,
$multiple = false,
$source = null,
$query = null,
$values = null,
$options = []
) {
parent::__construct($name, $id, $value, $required, $label, $placeholder);
// Aggiunta classe CSS dedicata
$this->get('class')
->add('select-input')
// Individuazione della classe per la corretta gestione JavaScript
->add(!empty($source) ? 'superselectajax' : 'superselect');
// Parsing del campo value come array
$value = $this->get('value');
$value = explode(',', $value);
if (count($value) === 1 && strlen($value[0]) === 0) {
$value = [];
}
// Impostazione dei dati aggiuntivi
$this->set([
'value' => $value,
'multiple' => $multiple,
'options' => $options,
'source' => $source,
]);
// Gestione del caricamento delle opzioni opzioni
if (!empty($source)) {
// Richiamo del file dedicato alle richieste AJAX per ottenere il valore iniziale del select
$response = AJAX::select($source, $value, null, 0, 100, $options);
$values = $response['results'];
} elseif (!empty($query)) {
$values = database()->fetchArray($query);
} else {
$values = isset($values) ? $values : [];
}
// Raggruppamento per campo optgroup
$is_grouped = false;
$groups = collect($values)->mapToGroups(function ($item) {
return [isset($item['optgroup']) ? $item['optgroup'] : '' => $item];
});
if (!($groups->count() == 1 && $groups->keys()->first() == '')) {
$values = $groups;
$is_grouped = true;
}
// Aggiornamento delle informazioni
$this->set([
'values' => $values,
'is_grouped' => $is_grouped,
]);
}
/**

View File

@ -2,10 +2,10 @@
namespace App\View\Components\Inputs;
use App\View\Components\Input;
use App\View\Components\InputWrapper;
use Illuminate\View\Component;
class Text extends Input
class Text extends InputWrapper
{
/**
* Get the view / contents that represent the component.

View File

@ -2,10 +2,10 @@
namespace App\View\Components\Inputs;
use App\View\Components\Input;
use App\View\Components\InputWrapper;
use Illuminate\View\Component;
class Textarea extends Input
class Textarea extends InputWrapper
{
/**
* Get the view / contents that represent the component.

View File

@ -0,0 +1,75 @@
<?php
namespace App\View\Components;
use Illuminate\View\Component;
use Models\Module;
class WidgetGroup extends Component
{
/**
* @var array
*/
protected $widgets;
/**
* @var string
*/
protected $position;
/**
* Create a new component instance.
*
* @param string|int $module
* @param string $place
* @param string $position
* @throws \Exception
*/
public function __construct(
$module,
$place,
$position
) {
$module = module($module);
Module::setCurrent($module->id);
$query = 'SELECT id FROM zz_widgets WHERE id_module = '.prepare($module->id).' AND (|position|) AND enabled = 1 ORDER BY `order` ASC';
// Mobile (tutti i widget a destra)
if (isMobile()) {
if ($position == 'right') {
$position = "location = '".$place."_right' OR location = '".$place."_top'";
} elseif ($position == 'top') {
$position = '1=0';
}
}
// Widget a destra
elseif ($position == 'right') {
$position = "location = '".$place."_right'";
}
// Widget in alto
elseif ($position == 'top') {
$position = "location = '".$place."_top'";
}
$query = str_replace('|position|', $position, $query);
// Individuazione dei widget interessati
$this->widgets = database()->fetchArray($query);
$this->position = $position;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|string
*/
public function render()
{
return view('components.widget-group', [
'widgets' => $this->widgets,
'position' => $this->position,
]);
}
}

View File

@ -0,0 +1,40 @@
@if(!$emails->isEmpty())
<div class="box box-info collapsable collapsed-box">
<div class="box-header with-border">
<h3 class="box-title"><i class="fa fa-envelope"></i> {{ tr('Email inviate: _NUM_', [
'_NUM_' => $emails->count(),
]) }}</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
</div>
</div>
<div class="box-body">
<ul>
@foreach($emails as $email)
<li>
{{ Modules::link('Stato email', $email->id, tr('Email "_EMAIL_" da _USER_', [
'_EMAIL_' => $email->template->name,
'_USER_' => $email->user->username,
])) }} ({{ !empty($email['sent_at']) ? tr('inviata il _DATE_ alle _HOUR_', [
'_DATE_' => dateFormat($email['sent_at']),
'_HOUR_' => timeFormat($email['sent_at']),
]) : tr('in coda di invio') }}).
<ul>
<li><b>{{ tr('Destinatari') }}</b>: {{ $email->receivers->pluck('address')->join(', ') }}.</li>
@if($email->prints->count())
<li><b>{{ tr('Stampe') }}</b>: {{ $email->prints->pluck('title')->join(', ') }}.</li>
@endif
@if($email->uploads->count())
<li><b>{{ tr('Allegati') }}</b>: {{ $email->uploads->pluck('name')->join(', ') }}.</li>
@endif
</ul>
</li>
@endforeach
</ul>
</div>
</div>
@endif

View File

@ -1,4 +1,4 @@
<x-input :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
<x-input-wrapper :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
{{-- "+ this.checked" rende il valore booleano un numero --}}
<div class="form-group checkbox-group">
<input type="hidden" name="{{ $name }}" value="{{ $value }}" class="openstamanager-input">
@ -23,4 +23,4 @@
<x-slot name="before">{{ isset($before) ? $before : null }}</x-slot>
<x-slot name="after">{{ isset($after) ? $after : null }}</x-slot>
</x-input>
</x-input-wrapper>

View File

@ -1,4 +1,4 @@
<x-input :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
<x-input-wrapper :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
<textarea {{ $attributes->merge([
'type' => isset($type) ? $type : 'text',
'name' => $name,
@ -12,4 +12,4 @@
<x-slot name="before">{{ isset($before) ? $before : null }}</x-slot>
<x-slot name="after">{{ isset($after) ? $after : null }}</x-slot>
</x-input>
</x-input-wrapper>

View File

@ -1,4 +1,4 @@
<x-input :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
<x-input-wrapper :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
@if(empty($value))
@php($type = 'file')
@include('components.inputs.standard-input')
@ -12,4 +12,4 @@
<x-slot name="before">{{ isset($before) ? $before : null }}</x-slot>
<x-slot name="after">{{ isset($after) ? $after : null }}</x-slot>
</x-input>
</x-input-wrapper>

View File

@ -2,7 +2,7 @@
$strength = $attributes->has('strength-trigger');
@endphp
<x-input :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
<x-input-wrapper :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
@include('components.inputs.standard-input')
<x-slot name="after">
@ -12,7 +12,7 @@
</x-slot>
<x-slot name="before">{{ isset($before) ? $before : null }}</x-slot>
</x-input>
</x-input-wrapper>
<script>
function togglePassword_{{ $id }}() {

View File

@ -0,0 +1,6 @@
<option value="{{ $option['id'] }}"
{{ in_array($option['id'], $value) ? 'selected' : '' }}
{{ !empty($option['_bgcolor_']) ? 'style="background:'.$element['_bgcolor_'].'; color:'.color_inverse($element['_bgcolor_']).';"' : '' }}
data-select-attributes='{{ replace(json_encode($option), ["'" => "\'"]) }}'>
{{ empty($option['text']) ? $option['descrizione'] : $option['text'] }}
</option>

View File

@ -1,3 +1,37 @@
<div>
<!-- The whole future lies in uncertainty: live immediately. - Seneca -->
</div>
<x-input-wrapper :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
<select {{ $attributes->merge([
'name' => $name,
'id' => $id,
'required' => $required,
'placeholder' => $placeholder,
'data-placeholder' => $placeholder,
'class' => $class,
'data-parsley-errors-container' => '#'.$unique_id.'-errors',
'multiple' => $multiple,
'data-select2-id' => $id.'_'.rand(0, 999),
'data-source' => $source,
'data-select-options' => json_encode($options),
'data-maximum-selection-length' => $attributes->get('maximum-selection-length', null),
]) }}>
@if(!$is_grouped)
@foreach($values as $option)
@include('components.inputs.select-option')
@endforeach
@else
@foreach($values as $group => $elements)
<optgroup label="{{ $group }}"></optgroup>
@foreach($elements as $option)
@include('components.inputs.select-option')
@endforeach
@endforeach
@endif
</select>
@if($attributes->get('disabled') || $attributes->get('readonly'))
<script>input("{{ $name }}").disable();</script>
@endif
<x-slot name="before">{{ isset($before) ? $before : null }}</x-slot>
<x-slot name="after">{{ isset($after) ? $after : null }}</x-slot>
</x-input-wrapper>

View File

@ -6,5 +6,5 @@
'required' => $required,
'placeholder' => $placeholder,
'class' => $class,
'data-parsley-errors-container' => '#'.$unique_id.'-errors'
'data-parsley-errors-container' => '#'.$unique_id.'-errors',
]) }} autocomplete="{{ $attributes->get('autocomplete', 'off') }}">

View File

@ -1,6 +1,6 @@
<x-input :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
<x-input-wrapper :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
@include('components.inputs.standard-input')
<x-slot name="before">{{ isset($before) ? $before : null }}</x-slot>
<x-slot name="after">{{ isset($after) ? $after : null }}</x-slot>
</x-input>
</x-input-wrapper>

View File

@ -1,4 +1,4 @@
<x-input :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
<x-input-wrapper :name="$name" :id="$id" :unique_id="$unique_id" :label="$label">
<textarea {{ $attributes->merge([
'type' => isset($type) ? $type : 'text',
'name' => $name,
@ -11,4 +11,4 @@
<x-slot name="before">{{ isset($before) ? $before : null }}</x-slot>
<x-slot name="after">{{ isset($after) ? $after : null }}</x-slot>
</x-input>
</x-input-wrapper>

View File

@ -0,0 +1,17 @@
@if(!empty($widgets))
@php
$row_max = count($widgets);
if ($row_max > 4) {
$row_max = 4;
} elseif ($row_max < 2) {
$row_max = 2;
}
@endphp
<ul class="row widget" id="widget-{{ $position }}">
@foreach($widgets as $widget)
<li class="col-sm-6 col-md-4 col-lg-{{ intval(12 / $row_max) }} li-widget" id="widget_{{ $widget['id'] }}">
<x-widget :id="$widget['id']"></x-widget>
</li>
@endforeach
</ul>
@endif

View File

@ -53,10 +53,10 @@
@section('top_content')
<!-- Widget in alto -->
{( "name": "widgets", "id_module": "{{ $module->id }}", "id_record": "{{ 1 }}", "position": "top", "place": "controller" )}
<x-widget-group module="{{ $module->id }}" place="controller" position="top"></x-widget-group>
@endsection
@section('bottom_content')
<!-- Widget in alto -->
{( "name": "widgets", "id_module": "{{ $module->id }}", "id_record": "{{ 1 }}", "position": "right", "place": "controller" )}
<x-widget-group module="{{ $module->id }}" place="controller" position="right"></x-widget-group>
@endsection