|
@@ -122,7 +122,7 @@ class GenerateTreeCommand extends Command
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case 8: // sub-type declaration
|
|
|
+ case 8: // sub-type declaration | add_new fields
|
|
|
|
|
|
if($line === 'ACTIONS' || $line === 'SUB') {
|
|
|
$currentSubType = $line;
|
|
@@ -133,8 +133,7 @@ class GenerateTreeCommand extends Command
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case 12: // ACTIONS | SUB | add_new fields
|
|
|
-
|
|
|
+ case 12: // ACTIONS | SUB
|
|
|
if($currentSubType === 'ACTIONS') {
|
|
|
$currentMethod = $currentSubController->addMethod(
|
|
|
"ACTION_" . $line,
|
|
@@ -151,15 +150,18 @@ class GenerateTreeCommand extends Command
|
|
|
$currentMethod->type = 'sub';
|
|
|
$currentMethod->data = [];
|
|
|
}
|
|
|
-
|
|
|
break;
|
|
|
|
|
|
case 16: // data for actions and subs
|
|
|
-
|
|
|
if(!empty($currentMethod)) {
|
|
|
$currentMethod->data[] = $line;
|
|
|
}
|
|
|
+ break;
|
|
|
|
|
|
+ case 20: // SUB add_new fields
|
|
|
+ if(!empty($currentMethod)) {
|
|
|
+ $currentMethod->data[] = $line;
|
|
|
+ }
|
|
|
break;
|
|
|
|
|
|
}
|
|
@@ -232,6 +234,41 @@ class GenController {
|
|
|
public function saveController() {
|
|
|
$text = file_get_contents(base_path('generatecv/tree-templates/controller.template.php'));
|
|
|
$code = [];
|
|
|
+
|
|
|
+ // 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';
|
|
|
+ $newMethod = new GenControllerMethod($methodName, $methodRoute);
|
|
|
+ $newMethod->hasUID = true;
|
|
|
+ $newMethod->redirect = false;
|
|
|
+ $newMethod->type = 'action';
|
|
|
+ $newMethod->data = [];
|
|
|
+ for($i = 2; $i<count($method->data); $i++) {
|
|
|
+ $newMethod->data[] = $method->data[$i];
|
|
|
+ }
|
|
|
+ $newMethod->parentSub = $this->name . '-' . $method->name;
|
|
|
+ $newMethod->table = explode(":", $method->data[1])[1];
|
|
|
+ $newMethods[] = $newMethod;
|
|
|
+ $method->childAddRoute = $this->name . '-' . $methodName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $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}";
|
|
@@ -394,8 +431,21 @@ class GenController {
|
|
|
$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);
|
|
|
+
|
|
|
+ if(!$method->parentSub) {
|
|
|
+ $text = str_replace("_BACK_ROUTE_", "{$controller->parentControllerName}-view", $text);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $text = str_replace("_BACK_ROUTE_", $method->parentSub, $text);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$method->table) {
|
|
|
+ $text = str_replace("_API_", "/api/{$controller->dbTable}/" . substr($method->name, 7), $text);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $text = str_replace("_API_", "/api/{$method->table}/create", $text);
|
|
|
+ }
|
|
|
+
|
|
|
$text = str_replace("_RETURN_ROUTE_", "{$controller->name}-{$method->name}", $text);
|
|
|
$fields = [];
|
|
|
if(count($method->data)) {
|
|
@@ -412,11 +462,12 @@ class GenController {
|
|
|
$text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
|
|
|
$text = str_replace("_NAME_", $this->camelToTitleCase($this->snakeToTitleCase($method->name)), $text);
|
|
|
|
|
|
- /*if($controller->hasAdd) {
|
|
|
- $addLink = "<a class='btn btn-primary btn-sm' href='/{$controller->name}/add_new'>" .
|
|
|
+ if(count($method->data) > 1 && $method->data[1] === 'add_new') {
|
|
|
+ $addLink = '<a class="btn btn-primary btn-sm" ' .
|
|
|
+ 'href="{{route(\'' . $method->childAddRoute . '\', [\'uid\' => $record->uid])}}">' .
|
|
|
"<i class='fa fa-plus-circle' aria-hidden='true'></i> Add New</a>";
|
|
|
$text = str_replace("<!-- _ADD_NEW_LINK_ -->", $addLink, $text);
|
|
|
- }*/
|
|
|
+ }
|
|
|
|
|
|
$dbParts = explode("=", $method->data[0]);
|
|
|
$dbParts = explode(".", $dbParts[1]);
|
|
@@ -588,6 +639,9 @@ class GenControllerMethod {
|
|
|
public $redirect = false;
|
|
|
public $type = '';
|
|
|
public $data = [];
|
|
|
+ public $parentSub = false;
|
|
|
+ public $childAddRoute = false;
|
|
|
+ public $table = false;
|
|
|
public function __construct($name, $route)
|
|
|
{
|
|
|
$this->name = $name;
|