|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+
|
|
|
3
|
+namespace App\DataTables;
|
|
|
4
|
+
|
|
|
5
|
+use App\Models\Impostazioni;
|
|
|
6
|
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
|
|
|
7
|
+use Yajra\DataTables\EloquentDataTable;
|
|
|
8
|
+use Yajra\DataTables\Html\Builder as HtmlBuilder;
|
|
|
9
|
+use Yajra\DataTables\Html\Button;
|
|
|
10
|
+use Yajra\DataTables\Html\Column;
|
|
|
11
|
+use Yajra\DataTables\Html\Editor\Editor;
|
|
|
12
|
+use Yajra\DataTables\Html\Editor\Fields;
|
|
|
13
|
+use Yajra\DataTables\Services\DataTable;
|
|
|
14
|
+use Illuminate\Support\Facades\Auth;
|
|
|
15
|
+
|
|
|
16
|
+class ImpostazioniDataTable extends DataTable
|
|
|
17
|
+{
|
|
|
18
|
+ public function __construct(){
|
|
|
19
|
+ $this->dataTableVariable = 'dataTable_impostazioni';
|
|
|
20
|
+ }
|
|
|
21
|
+ /**
|
|
|
22
|
+ * Build the DataTable class.
|
|
|
23
|
+ *
|
|
|
24
|
+ * @param QueryBuilder<Impostazioni> $query Results from query() method.
|
|
|
25
|
+ */
|
|
|
26
|
+ public function dataTable(QueryBuilder $query): EloquentDataTable
|
|
|
27
|
+ {
|
|
|
28
|
+ return (new EloquentDataTable($query))
|
|
|
29
|
+ ->addColumn('action', function($entity){
|
|
|
30
|
+ return view('impostazioni.menu', ['entity' => $entity]);
|
|
|
31
|
+ })
|
|
|
32
|
+ ->setRowId('id');
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ /**
|
|
|
36
|
+ * Get the query source of dataTable.
|
|
|
37
|
+ *
|
|
|
38
|
+ * @return QueryBuilder<Impostazioni>
|
|
|
39
|
+ */
|
|
|
40
|
+ public function query(Impostazioni $model): QueryBuilder
|
|
|
41
|
+ {
|
|
|
42
|
+ if($this->attivita_id){
|
|
|
43
|
+ return $model->newQuery()->where('attivita_id', $this->attivita_id);
|
|
|
44
|
+ }else{
|
|
|
45
|
+ return $model->newQuery()->whereRaw('1 = 0');
|
|
|
46
|
+ }
|
|
|
47
|
+ }
|
|
|
48
|
+
|
|
|
49
|
+ /**
|
|
|
50
|
+ * Optional method if you want to use the html builder.
|
|
|
51
|
+ */
|
|
|
52
|
+ public function html(): HtmlBuilder
|
|
|
53
|
+ {
|
|
|
54
|
+ $buttons = [];
|
|
|
55
|
+ if(Auth::user()->hasRole('superadmin')){
|
|
|
56
|
+ array_push($buttons, Button::make('create')
|
|
|
57
|
+ ->editor('editor')
|
|
|
58
|
+ ->className('btn btn-sm btn-primary mb-4')
|
|
|
59
|
+ ->formTitle('Crea nuova impostazione')
|
|
|
60
|
+ ->text('<i class="fas fa-plus"></i> Nuova impostazione'));
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ $editorFields = [
|
|
|
64
|
+ Fields\Hidden::make('attivita_id')->default($this->attivita_id),
|
|
|
65
|
+ Fields\Text::make('label')->label('Label'),
|
|
|
66
|
+ Fields\Text::make('valore')->label('Valore'),
|
|
|
67
|
+ Fields\Text::make('descrizione')->label('Descrizione'),
|
|
|
68
|
+ Fields\Text::make('opzioni')->label('Opzioni'),
|
|
|
69
|
+ ];
|
|
|
70
|
+
|
|
|
71
|
+ if(Auth::user()->hasRole('superadmin')){
|
|
|
72
|
+ $editorFields[] = Fields\Text::make('chiave')->label('Chiave');
|
|
|
73
|
+ $editorFields[] = Fields\Select::make('tipo')->label('Tipo')->options(Impostazioni::getTipi());
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ return $this->builder()
|
|
|
77
|
+ ->setTableId($this->dataTableVariable)
|
|
|
78
|
+ ->columns($this->getColumns())
|
|
|
79
|
+ ->minifiedAjax()
|
|
|
80
|
+ ->orderBy(1)
|
|
|
81
|
+ ->selectStyleSingle()
|
|
|
82
|
+ ->buttons($buttons)
|
|
|
83
|
+ ->language(asset('assets/Italian.json'))
|
|
|
84
|
+ ->dom(count($buttons) == 0 ? 'rtip' : 'Bfrtip')
|
|
|
85
|
+ ->editor(
|
|
|
86
|
+ Editor::make()->fields($editorFields)
|
|
|
87
|
+ )
|
|
|
88
|
+ ->initComplete("function(settings, json){
|
|
|
89
|
+ initComplete_impostazioni();
|
|
|
90
|
+ }") ;
|
|
|
91
|
+ }
|
|
|
92
|
+
|
|
|
93
|
+ /**
|
|
|
94
|
+ * Get the dataTable columns definition.
|
|
|
95
|
+ */
|
|
|
96
|
+ public function getColumns(): array
|
|
|
97
|
+ {
|
|
|
98
|
+ $columns = [
|
|
|
99
|
+ Column::make('id')->visible(false),
|
|
|
100
|
+ ];
|
|
|
101
|
+
|
|
|
102
|
+ if(Auth::user()->hasRole('superadmin')){
|
|
|
103
|
+ $columns[] = Column::make('chiave');
|
|
|
104
|
+ $columns[] = Column::make('tipo')->title('Tipo');
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ $columns[] = Column::make('label');
|
|
|
108
|
+ $columns[] = Column::make('valore')->title('Valore')->visible(false);
|
|
|
109
|
+ $columns[] = Column::make('descrizione')->title('Descrizione');
|
|
|
110
|
+ $columns[] = Column::make('opzioni')->title('Opzioni')->visible(false);
|
|
|
111
|
+ $columns[] = Column::computed('action')
|
|
|
112
|
+ ->title('')
|
|
|
113
|
+ ->exportable(false)
|
|
|
114
|
+ ->printable(false)
|
|
|
115
|
+ ->width(60)
|
|
|
116
|
+ ->addClass('text-center')
|
|
|
117
|
+ ->responsivePriority(1);
|
|
|
118
|
+
|
|
|
119
|
+ return $columns;
|
|
|
120
|
+ }
|
|
|
121
|
+
|
|
|
122
|
+ /**
|
|
|
123
|
+ * Get the filename for export.
|
|
|
124
|
+ */
|
|
|
125
|
+ protected function filename(): string
|
|
|
126
|
+ {
|
|
|
127
|
+ return 'Impostazioni_' . date('YmdHis');
|
|
|
128
|
+ }
|
|
|
129
|
+}
|