|
@@ -80,6 +80,7 @@ class GenerateTreeCommand extends Command
|
|
|
$currentSubController = new GenController($currentRoot, $currentController->name . "_SINGLE");
|
|
|
$currentSubController->dbTable = $currentController->dbTable;
|
|
|
$currentSubController->parentRoute = "/" . $line;
|
|
|
+ $currentSubController->parentControllerName = $currentController->name;
|
|
|
$currentSubController->sub = true;
|
|
|
$newMethod->redirect = "/" . $line . "/SUB_dashboard";
|
|
|
}
|
|
@@ -158,6 +159,7 @@ class GenController {
|
|
|
public $parentRoute = "";
|
|
|
public $dbTable = null;
|
|
|
public $sub = false;
|
|
|
+ public $parentControllerName = '';
|
|
|
public function __construct($root = null, $name = null)
|
|
|
{
|
|
|
$this->root = $root;
|
|
@@ -189,7 +191,8 @@ class GenController {
|
|
|
$code[] = "\t" . 'public function ' . $method->name . '(Request $request' . ($method->hasUID ? ', $uid' : '') . ') {';
|
|
|
|
|
|
if($method->redirect) {
|
|
|
- $code[] = "\t\treturn redirect('$method->redirect');";
|
|
|
+ $target = str_replace('{uid}', '$uid', $method->redirect);
|
|
|
+ $code[] = "\t\t" . 'return redirect("' . $target . '");';
|
|
|
}
|
|
|
else {
|
|
|
if($method->hasUID) {
|
|
@@ -200,9 +203,10 @@ class GenController {
|
|
|
$code[] = "\t\t\$records = DB::table('{$this->dbTable}')->get();";
|
|
|
$code[] = "\t\treturn view('{$this->root}/{$this->name}/{$method->name}', compact('records'));";
|
|
|
}
|
|
|
- $this->saveView($this, $method);
|
|
|
}
|
|
|
|
|
|
+ $this->saveView($this, $method);
|
|
|
+
|
|
|
$code[] = "\t}";
|
|
|
}
|
|
|
$text = str_replace("_NAME_", "{$this->name}_Controller", $text);
|
|
@@ -236,14 +240,18 @@ class GenController {
|
|
|
public function saveIndexView(GenController $controller, GenControllerMethod $method)
|
|
|
{
|
|
|
$text = file_get_contents(base_path('generatecv/tree-templates/index.template.blade.php'));
|
|
|
- $text = str_replace("_NAME_", $controller->name, $text);
|
|
|
+ $text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
|
|
|
$text = str_replace("_ADD_NEW_ROUTE_", $controller->name . '-add_new', $text);
|
|
|
$columns = DB::getSchemaBuilder()->getColumnListing($controller->dbTable);
|
|
|
$ths = [];
|
|
|
$tds = [];
|
|
|
foreach ($columns as $column) {
|
|
|
$ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
|
- $tds[] = "<td><?= \$record->$column ?></td>";
|
|
|
+ $tds[] = "<td>" .
|
|
|
+ ($column === 'uid' ? '<a href="/' . $controller->name . '/view/<?= $record->uid ?>">' : '') .
|
|
|
+ "<?= \$record->$column ?>" .
|
|
|
+ ($column === 'uid' ? '</a>' : '') .
|
|
|
+ "</td>";
|
|
|
}
|
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
|
$text = str_replace("<!-- __SCAFFOLD_TDS__ -->", implode("\n", $tds), $text);
|
|
@@ -252,11 +260,48 @@ class GenController {
|
|
|
}
|
|
|
public function saveShowView(GenController $controller, GenControllerMethod $method)
|
|
|
{
|
|
|
-
|
|
|
+ $text = file_get_contents(base_path('generatecv/tree-templates/show.template.blade.php'));
|
|
|
+ $text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
|
|
|
+ $text = str_replace("_UID_", '<?= $record->uid ?>', $text);
|
|
|
+ $text = str_replace("_INDEX_ROUTE_", $controller->name . '-index', $text);
|
|
|
+ $text = str_replace("_SUB_LINKS_VIEW_", "{$controller->root}/{$controller->name}/subs", $text);
|
|
|
+ $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $text);
|
|
|
+ echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
|
|
|
}
|
|
|
public function saveSubView(GenController $controller, GenControllerMethod $method)
|
|
|
{
|
|
|
|
|
|
+ // generate sub links if not existing
|
|
|
+ $subLinksView = resource_path("views/{$controller->root}/{$controller->parentControllerName}/subs.blade.php");
|
|
|
+ //if(!file_exists($subLinksView)) {
|
|
|
+ $subLinks = [];
|
|
|
+ foreach ($controller->methods as $meth) {
|
|
|
+ echo $meth->name . "\n";
|
|
|
+ if(strpos($meth->name, "SUB_") !== 0) continue;
|
|
|
+ $display = substr($meth->name, 4);
|
|
|
+ $subLinks[] = "<a " .
|
|
|
+ "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
|
|
|
+ "class='d-block p-3 py-2 border-bottom'>$display</a>";
|
|
|
+ }
|
|
|
+ file_put_contents($subLinksView, implode("\n", $subLinks));
|
|
|
+ // echo "Generated " . $subLinksView . "\n";
|
|
|
+ //}
|
|
|
+
|
|
|
+ $text = file_get_contents(base_path('generatecv/tree-templates/sub.template.blade.php'));
|
|
|
+ $text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
|
|
|
+ $text = $this->generateSubContent($controller, $method, $text);
|
|
|
+ $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $text);
|
|
|
+ echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
|
|
|
+ }
|
|
|
+ public function generateSubContent(GenController $controller, GenControllerMethod $method, $text) {
|
|
|
+ if($method->name === 'SUB_dashboard') {
|
|
|
+ $html = file_get_contents(base_path('generatecv/tree-templates/dashboard.template.blade.php'));
|
|
|
+ $text = str_replace("_SUB_VIEW_", $html, $text);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $text = str_replace("_SUB_VIEW_", "Content from<br><b>{$controller->root}/{$controller->name}/{$method->name}.blade.php</b>", $text);
|
|
|
+ }
|
|
|
+ return $text;
|
|
|
}
|
|
|
public function saveAddNewView(GenController $controller, GenControllerMethod $method)
|
|
|
{
|