|
@@ -48,6 +48,7 @@ class GenerateTreeCommand extends Command
|
|
|
$currentSubController = new GenController();
|
|
|
$currentSubType = "";
|
|
|
$currentView = "";
|
|
|
+ $currentMethod = null;
|
|
|
|
|
|
foreach ($lines as $line) {
|
|
|
|
|
@@ -128,17 +129,30 @@ class GenerateTreeCommand extends Command
|
|
|
case 12: // subs and actions
|
|
|
|
|
|
if($currentSubType === 'ACTIONS') {
|
|
|
- $currentSubController->addMethod(
|
|
|
+ $currentMethod = $currentSubController->addMethod(
|
|
|
"ACTION_" . $line,
|
|
|
"/ACTION_" . $line
|
|
|
);
|
|
|
+ $currentMethod->type = 'action';
|
|
|
+ $currentMethod->data = [];
|
|
|
}
|
|
|
else if($currentSubType === 'SUB') {
|
|
|
- $currentSubController->addMethod(
|
|
|
+ $currentMethod = $currentSubController->addMethod(
|
|
|
"SUB_" . $line,
|
|
|
"/SUB_" . $line
|
|
|
);
|
|
|
+ $currentMethod->type = 'sub';
|
|
|
+ $currentMethod->data = [];
|
|
|
}
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 16: // data for actions and subs
|
|
|
+
|
|
|
+ if(!empty($currentMethod)) {
|
|
|
+ $currentMethod->data[] = $line;
|
|
|
+ }
|
|
|
+
|
|
|
break;
|
|
|
|
|
|
}
|
|
@@ -184,6 +198,8 @@ class GenController {
|
|
|
public $hasView = false;
|
|
|
public $sub = false;
|
|
|
public $parentControllerName = '';
|
|
|
+ public $subLinksSaved = false;
|
|
|
+ public $actionLinksSaved = false;
|
|
|
public function __construct($root = null, $name = null)
|
|
|
{
|
|
|
$this->root = $root;
|
|
@@ -203,7 +219,7 @@ class GenController {
|
|
|
$this->saveController();
|
|
|
$this->saveRoutes();
|
|
|
$this->saved = true;
|
|
|
-// $this->log();
|
|
|
+ $this->log();
|
|
|
}
|
|
|
}
|
|
|
public function saveController() {
|
|
@@ -240,13 +256,18 @@ class GenController {
|
|
|
}
|
|
|
public function saveView(GenController $controller, GenControllerMethod $method) {
|
|
|
|
|
|
- /*
|
|
|
- $x = DB::getSchemaBuilder()->getColumnListing('client');
|
|
|
- print_r($x);
|
|
|
- */
|
|
|
-
|
|
|
if($controller->sub) {
|
|
|
- $this->saveSubView($controller, $method);
|
|
|
+ $controller->saveSubLinks($controller, $method);
|
|
|
+ $controller->saveActionLinks($controller, $method);
|
|
|
+ if($method->type === 'action') {
|
|
|
+ $this->saveSubActionView($controller, $method);
|
|
|
+ }
|
|
|
+ else if($method->type === 'sub' && count($method->data)) {
|
|
|
+ $this->saveSubSubView($controller, $method);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $this->saveSubDefaultView($controller, $method);
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
if($method->name === 'view' && $controller->hasView) {
|
|
@@ -306,47 +327,72 @@ class GenController {
|
|
|
$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)
|
|
|
+ public function saveSubLinks(GenController $controller, GenControllerMethod $method)
|
|
|
{
|
|
|
-
|
|
|
- // generate sub links if not existing
|
|
|
+ if ($controller->subLinksSaved) return;
|
|
|
$subLinksView = resource_path("views/{$controller->root}/{$controller->parentControllerName}/subs.blade.php");
|
|
|
- //if(!file_exists($subLinksView)) {
|
|
|
- $subLinks = [];
|
|
|
- foreach ($controller->methods as $meth) {
|
|
|
- if(strpos($meth->name, "SUB_") !== 0) continue;
|
|
|
- $display = $this->snakeToTitleCase(substr($meth->name, 4));
|
|
|
- $subLinks[] = "<a " .
|
|
|
- "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
|
|
|
- "class='d-block p-3 py-2 border-bottom " .
|
|
|
- "{{ request()->route()->getActionMethod() === '{$meth->name}' ? 'bg-secondary text-white' : '' }}" .
|
|
|
- ($meth->name === 'SUB_dashboard' ? "{{ strpos(request()->route()->getActionMethod(), 'ACTION_') === 0 ? 'bg-secondary text-white' : '' }}" : "")
|
|
|
- . "'>$display</a>";
|
|
|
- }
|
|
|
- file_put_contents($subLinksView, implode("\n", $subLinks));
|
|
|
-// echo "Generated " . $subLinksView . "\n";
|
|
|
- //}
|
|
|
-
|
|
|
- // generate action links if not existing
|
|
|
+ $subLinks = [];
|
|
|
+ foreach ($controller->methods as $meth) {
|
|
|
+ if (strpos($meth->name, "SUB_") !== 0) continue;
|
|
|
+ $display = $this->snakeToTitleCase(substr($meth->name, 4));
|
|
|
+ $subLinks[] = "<a " .
|
|
|
+ "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
|
|
|
+ "class='d-block p-3 py-2 border-bottom " .
|
|
|
+ "{{ request()->route()->getActionMethod() === '{$meth->name}' ? 'bg-secondary text-white' : '' }}" .
|
|
|
+ ($meth->name === 'SUB_dashboard' ? "{{ strpos(request()->route()->getActionMethod(), 'ACTION_') === 0 ? 'bg-secondary text-white' : '' }}" : "")
|
|
|
+ . "'>$display</a>";
|
|
|
+ }
|
|
|
+ file_put_contents($subLinksView, implode("\n", $subLinks));
|
|
|
+ echo "Generated " . $subLinksView . "\n";
|
|
|
+ $controller->subLinksSaved = true;
|
|
|
+ }
|
|
|
+ public function saveActionLinks(GenController $controller, GenControllerMethod $method)
|
|
|
+ {
|
|
|
+ if ($controller->actionLinksSaved) return;
|
|
|
$actionLinksView = resource_path("views/{$controller->root}/{$controller->parentControllerName}/actions.blade.php");
|
|
|
- //if(!file_exists($actionLinksView)) {
|
|
|
- $actionLinks = [];
|
|
|
- foreach ($controller->methods as $meth) {
|
|
|
- if(strpos($meth->name, "ACTION_") !== 0) continue;
|
|
|
- $display = $this->camelToTitleCase(substr($meth->name, 7));
|
|
|
- $actionLinks[] = "<a " .
|
|
|
- "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
|
|
|
- "class='d-block btn btn-sm btn-default mb-3'>$display</a>";
|
|
|
- }
|
|
|
- file_put_contents($actionLinksView, implode("\n", $actionLinks));
|
|
|
-// echo "Generated " . $actionLinksView . "\n";
|
|
|
- //}
|
|
|
-
|
|
|
+ $actionLinks = [];
|
|
|
+ foreach ($controller->methods as $meth) {
|
|
|
+ if (strpos($meth->name, "ACTION_") !== 0) continue;
|
|
|
+ $display = $this->camelToTitleCase(substr($meth->name, 7));
|
|
|
+ $actionLinks[] = "<a " .
|
|
|
+ "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
|
|
|
+ "class='d-block btn btn-sm btn-default mb-3'>$display</a>";
|
|
|
+ }
|
|
|
+ file_put_contents($actionLinksView, implode("\n", $actionLinks));
|
|
|
+ echo "Generated " . $actionLinksView . "\n";
|
|
|
+ $controller->actionLinksSaved = true;
|
|
|
+ }
|
|
|
+ public function saveSubDefaultView(GenController $controller, GenControllerMethod $method)
|
|
|
+ {
|
|
|
$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 saveSubActionView(GenController $controller, GenControllerMethod $method) {
|
|
|
+ $text = file_get_contents(base_path('generatecv/tree-templates/sub-action.template.blade.php'));
|
|
|
+ $text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
|
|
|
+ $text = str_replace("_NAME_", $this->camelToTitleCase($this->snakeToTitleCase($method->name)), $text);
|
|
|
+ $text = str_replace("_BACK_ROUTE_", "{$controller->parentControllerName}-view", $text);
|
|
|
+ $text = str_replace("_API_", "/api/{$controller->dbTable}/" . substr($method->name, 7), $text);
|
|
|
+ $text = str_replace("_RETURN_ROUTE_", "{$controller->name}-{$method->name}", $text);
|
|
|
+ $fields = [];
|
|
|
+ if(count($method->data)) {
|
|
|
+ foreach ($method->data as $field) {
|
|
|
+ $fields[] =
|
|
|
+ "<div class='form-group mb-3'>" .
|
|
|
+ "<label class='control-label'>{$this->camelToTitleCase($this->snakeToTitleCase($field))}</label>" .
|
|
|
+ "<input class='form-control' type='text' name='$field'>" .
|
|
|
+ "</div>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $text = str_replace("<!-- _SCAFFOLD_FIELDS_ -->", implode("\n", $fields), $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 saveSubSubView(GenController $controller, GenControllerMethod $method) {
|
|
|
+
|
|
|
}
|
|
|
public function generateSubContent(GenController $controller, GenControllerMethod $method, $text) {
|
|
|
if($method->name === 'SUB_dashboard') {
|
|
@@ -406,6 +452,7 @@ class GenController {
|
|
|
foreach ($this->methods as $method) {
|
|
|
$this->w('Rout: ' . $method->route, 1);
|
|
|
$this->w('Meth: ' . $method->name . '($request' . ($method->hasUID ? ', $uid' : '') . ')', 1);
|
|
|
+ if(!empty($method->data)) $this->w('Data: ' . implode(", ", $method->data), 1);
|
|
|
if(!$method->redirect) {
|
|
|
$this->w('View: ' . resource_path("views/{$this->root}/{$this->name}/{$method->name}.blade.php"), 1);
|
|
|
}
|
|
@@ -425,7 +472,7 @@ class GenController {
|
|
|
}
|
|
|
public function camelToTitleCase($text) {
|
|
|
$text = preg_replace("/^(SUB|ACTION)_/", "", $text);
|
|
|
- $text = preg_replace("/([a-z])([A-Z])/", "$1 $2", $text);
|
|
|
+ $text = preg_replace("/([a-z])([A-Z0-9])/", "$1 $2", $text);
|
|
|
return ucwords($text);
|
|
|
}
|
|
|
public function snakeToCamelCase($text) {
|
|
@@ -454,6 +501,8 @@ class GenControllerMethod {
|
|
|
public $route;
|
|
|
public $hasUID = false;
|
|
|
public $redirect = false;
|
|
|
+ public $type = '';
|
|
|
+ public $data = [];
|
|
|
public function __construct($name, $route)
|
|
|
{
|
|
|
$this->name = $name;
|