1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Microboard\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
7
|
|
|
use Yajra\DataTables\Generators\DataTablesMakeCommand; |
8
|
|
|
use Microboard\Foundations\Traits\MicroboardPathResolver; |
9
|
|
|
|
10
|
|
|
class ResourceDataTables extends DataTablesMakeCommand |
11
|
|
|
{ |
12
|
|
|
use MicroboardPathResolver; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The name and signature of the console command. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $signature; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The console command name. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $name = 'microboard:datatable'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get the stub file for the generator. |
30
|
|
|
* |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
|
|
protected function getStub() |
34
|
|
|
{ |
35
|
|
|
return $this->resolveStubPath('/stubs/datatable.stub'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Parse array from definition. |
40
|
|
|
* |
41
|
|
|
* @param string $definition |
42
|
|
|
* @param int $indentation |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
protected function parseColumns($definition, $indentation = 12) |
46
|
|
|
{ |
47
|
|
|
$columns = is_array($definition) ? $definition : explode(',', $definition); |
48
|
|
|
$stub = ''; |
49
|
|
|
$model = $this->option('model') ? |
50
|
|
|
Str::of(class_basename($this->option('model')))->slug()->plural() : |
51
|
|
|
''; |
52
|
|
|
|
53
|
|
|
foreach ($columns as $key => $column) { |
54
|
|
|
$stub .= "Column::make('{$column}')->title(trans('{$model}.fields.{$column}')),"; |
55
|
|
|
|
56
|
|
|
if ($key < count($columns) - 1) { |
57
|
|
|
$stub .= PHP_EOL . str_repeat(' ', $indentation); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $stub; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the console command arguments. |
66
|
|
|
* |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
protected function getOptions() |
70
|
|
|
{ |
71
|
|
|
return [ |
72
|
|
|
...$this->pathOptions(), |
|
|
|
|
73
|
|
|
['model', 'm', InputOption::VALUE_NONE, 'The name of the model to be used.'], |
74
|
|
|
['model-namespace', '', InputOption::VALUE_NONE, 'The namespace of the model to be used.'], |
75
|
|
|
['action', '', InputOption::VALUE_NONE, 'The path of the action view.'], |
76
|
|
|
['table', 't', InputOption::VALUE_NONE, 'Scaffold columns from the table.'], |
77
|
|
|
['builder', '', InputOption::VALUE_NONE, 'Extract html() to a Builder class.'], |
78
|
|
|
['dom', '', InputOption::VALUE_NONE, 'The dom of the DataTable.'], |
79
|
|
|
['buttons', '', InputOption::VALUE_NONE, 'The buttons of the DataTable.'], |
80
|
|
|
['columns', '', InputOption::VALUE_NONE, 'The columns of the DataTable.'], |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|