|
@@ -175,6 +175,11 @@ class GenerateTreeCommand extends Command
|
|
$currentMethod->viewLinkField = substr($line, 5);
|
|
$currentMethod->viewLinkField = substr($line, 5);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ else if(strpos($line, "!col:") === 0) { // !col:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setColumnSpec(substr($line, 5), $exitURL);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
else if (!empty($currentMethod) &&
|
|
else if (!empty($currentMethod) &&
|
|
(strpos($currentMethod->name, 'add_new') === 0 ||
|
|
(strpos($currentMethod->name, 'add_new') === 0 ||
|
|
$currentMethod->name === 'remove')) { // this is a field in add_new
|
|
$currentMethod->name === 'remove')) { // this is a field in add_new
|
|
@@ -229,6 +234,11 @@ class GenerateTreeCommand extends Command
|
|
$currentMethod->viewLinkField = substr($line, 5);
|
|
$currentMethod->viewLinkField = substr($line, 5);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ else if(strpos($line, "!col:") === 0) { // !col:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setColumnSpec(substr($line, 5), $exitURL);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
else if(!empty($currentMethod)) {
|
|
else if(!empty($currentMethod)) {
|
|
$currentMethod->data[] = $line;
|
|
$currentMethod->data[] = $line;
|
|
if($exitURL) {
|
|
if($exitURL) {
|
|
@@ -498,11 +508,30 @@ class GenController {
|
|
}
|
|
}
|
|
|
|
|
|
foreach ($columns as $column) {
|
|
foreach ($columns as $column) {
|
|
- $ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
|
|
|
|
+
|
|
|
|
+ $columnTitle = $this->snakeToTitleCase($column);
|
|
|
|
+ $columnValue = "<?= \$record->$column ?>";
|
|
|
|
+ $hasLink = $controller->hasView && $column === $method->viewLinkField;
|
|
|
|
+ $linkTarget = "/{$controller->name}/view/<?= \$record->uid ?>";
|
|
|
|
+
|
|
|
|
+ // check if this column has column spec
|
|
|
|
+ if(isset($method->columns[$column])) {
|
|
|
|
+ $columnTitle = $method->columns[$column]["label"];
|
|
|
|
+ if(isset($method->columns[$column]["query"])) {
|
|
|
|
+ $columnValue = "<?= \Illuminate\Support\Facades\DB::" .
|
|
|
|
+ "select(\"{$method->columns[$column]["query"]}\")[0]->result ?>";
|
|
|
|
+ }
|
|
|
|
+ if(isset($method->columns[$column]["link"])) {
|
|
|
|
+ $hasLink = true;
|
|
|
|
+ $linkTarget = $method->columns[$column]["link"];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $ths[] = "<th>$columnTitle</th>";
|
|
$tds[] = "<td>" .
|
|
$tds[] = "<td>" .
|
|
- ($controller->hasView && $column === $method->viewLinkField ? '<a href="/' . $controller->name . '/view/<?= $record->uid ?>">' : '') .
|
|
|
|
- "<?= \$record->$column ?>" .
|
|
|
|
- ($controller->hasView && $column === $method->viewLinkField ? '</a>' : '') .
|
|
|
|
|
|
+ ($hasLink ? "<a href=\"{$linkTarget}\">" : "") .
|
|
|
|
+ $columnValue .
|
|
|
|
+ ($hasLink ? "</a>" : "") .
|
|
"</td>";
|
|
"</td>";
|
|
}
|
|
}
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
@@ -844,6 +873,7 @@ class GenControllerMethod {
|
|
public $incType = null;
|
|
public $incType = null;
|
|
public $incFields = null;
|
|
public $incFields = null;
|
|
public $viewLinkField = 'uid';
|
|
public $viewLinkField = 'uid';
|
|
|
|
+ public $columns = [];
|
|
public function __construct($name, $route)
|
|
public function __construct($name, $route)
|
|
{
|
|
{
|
|
$this->name = $name;
|
|
$this->name = $name;
|
|
@@ -862,4 +892,25 @@ class GenControllerMethod {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ public function setColumnSpec($line, $link) {
|
|
|
|
+ // ally_pro_id:Ally Pro:select name_display as 'result' from pro where id = $ally_pro_id limit 1
|
|
|
|
+ /*
|
|
|
|
+ label
|
|
|
|
+ query
|
|
|
|
+ link
|
|
|
|
+ */
|
|
|
|
+ $parts = explode(":", $line);
|
|
|
|
+ $spec = [
|
|
|
|
+ "label" => $parts[1]
|
|
|
|
+ ];
|
|
|
|
+ if(count($parts) > 2) {
|
|
|
|
+ $query = $parts[2];
|
|
|
|
+ $query = preg_replace("/\\$(\S+)/", "{\$record->$1}", $query);
|
|
|
|
+ $spec['query'] = $query;
|
|
|
|
+ }
|
|
|
|
+ if($link) {
|
|
|
|
+ $spec['link'] = preg_replace("/\\$(\S+)/", "<?= \$record->$1 ?>", $link);
|
|
|
|
+ }
|
|
|
|
+ $this->columns[$parts[0]] = $spec;
|
|
|
|
+ }
|
|
}
|
|
}
|