|
@@ -99,6 +99,9 @@ class GenerateTreeCommand extends Command
|
|
|
$currentSubController->sub = true;
|
|
|
$newMethod->redirect = "/" . $line . "/SUB_dashboard";
|
|
|
}
|
|
|
+ else if(strpos($method, "add_new") === 0) {
|
|
|
+ $newMethod->type = 'add';
|
|
|
+ }
|
|
|
$currentMethod = $newMethod;
|
|
|
}
|
|
|
}
|
|
@@ -132,7 +135,7 @@ class GenerateTreeCommand extends Command
|
|
|
if($line === 'ACTIONS' || $line === 'SUB') {
|
|
|
$currentSubType = $line;
|
|
|
}
|
|
|
- else if (!empty($currentMethod) && $currentMethod->name === 'add_new') { // this is a field in add_new
|
|
|
+ else if (!empty($currentMethod) && strpos($currentMethod->name, 'add_new') === 0) { // this is a field in add_new
|
|
|
$currentMethod->data[] = $line;
|
|
|
}
|
|
|
|
|
@@ -242,13 +245,7 @@ class GenController {
|
|
|
|
|
|
// check if any method has a "sub add_new" in it, if yes, add action for the same
|
|
|
$newMethods = [];
|
|
|
-// echo "--------------------------------------\n";
|
|
|
-// dump($this->name);
|
|
|
-// echo "--------------------------------------\n";
|
|
|
foreach ($this->methods as $method) {
|
|
|
-// dump($method->name);
|
|
|
-// dump($method->type);
|
|
|
-// dump($method->data);
|
|
|
if($method->type === 'sub' && count($method->data) > 1 && strpos($method->data[1], 'add_new') === 0) {
|
|
|
$methodName = preg_replace("/^SUB_/", "ACTION_", $method->name) . 'AddNew';
|
|
|
$methodRoute = str_replace("/SUB_", "/ACTION_", $method->route) . 'AddNew';
|
|
@@ -268,12 +265,6 @@ class GenController {
|
|
|
}
|
|
|
$this->methods = array_merge($this->methods, $newMethods);
|
|
|
|
|
|
-// foreach ($this->methods as $method) {
|
|
|
-// dump($method->name);
|
|
|
-// dump($method->type);
|
|
|
-// dump($method->data);
|
|
|
-// }
|
|
|
-
|
|
|
foreach ($this->methods as $method) {
|
|
|
$code[] = "";
|
|
|
$code[] = "\t// GET {$method->route}";
|
|
@@ -338,7 +329,7 @@ class GenController {
|
|
|
else if($method->name === 'index') {
|
|
|
$this->saveIndexView($controller, $method);
|
|
|
}
|
|
|
- else if($method->name === 'add_new' && $controller->hasAdd) {
|
|
|
+ else if(strpos($method->name, 'add_new') === 0 && $controller->hasAdd) {
|
|
|
$this->saveAddNewView($controller, $method);
|
|
|
}
|
|
|
}
|
|
@@ -350,9 +341,16 @@ class GenController {
|
|
|
$text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
|
|
|
|
|
|
if($controller->hasAdd) {
|
|
|
- $addLink = "<a class='btn btn-primary btn-sm' href='/{$controller->name}/add_new'>" .
|
|
|
- "<i class='fa fa-plus-circle' aria-hidden='true'></i> Add New</a>";
|
|
|
- $text = str_replace("<!-- _ADD_NEW_LINK_ -->", $addLink, $text);
|
|
|
+ $addLinks = [];
|
|
|
+ foreach ($controller->methods as $m) {
|
|
|
+ if($m->type === 'add') {
|
|
|
+ $addLinks[] = "<a class='btn btn-primary btn-sm ml-2' " .
|
|
|
+ "href='/{$controller->name}/{$m->name}'>" .
|
|
|
+ "<i class='fa fa-plus-circle' aria-hidden='true'></i> " .
|
|
|
+ "{$this->snakeToTitleCase($m->name)}</a>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $text = str_replace("<!-- _ADD_NEW_LINK_ -->", implode("\n", $addLinks), $text);
|
|
|
}
|
|
|
|
|
|
$columns = DB::getSchemaBuilder()->getColumnListing($controller->dbTable);
|
|
@@ -515,9 +513,10 @@ class GenController {
|
|
|
{
|
|
|
$text = file_get_contents(base_path('generatecv/tree-templates/add_new.template.blade.php'));
|
|
|
$text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
|
|
|
+ $text = str_replace("_ADD_TITLE_", $this->snakeToTitleCase($method->name), $text);
|
|
|
$text = str_replace("_API_", "/api/{$this->snakeToCamelCase($controller->dbTable)}/{$method->api}", $text);
|
|
|
$text = str_replace("_BACK_ROUTE_", "{$controller->name}-index", $text);
|
|
|
- $text = str_replace("_RETURN_ROUTE_", "{$controller->name}-add_new", $text);
|
|
|
+ $text = str_replace("_RETURN_ROUTE_", "{$controller->name}-{$method->name}", $text);
|
|
|
$columns = $method->data;
|
|
|
$fields = [];
|
|
|
foreach ($columns as $column) {
|