|
@@ -49,6 +49,7 @@ class GenerateTreeCommand extends Command
|
|
$currentSubType = "";
|
|
$currentSubType = "";
|
|
$currentView = "";
|
|
$currentView = "";
|
|
$currentMethod = null;
|
|
$currentMethod = null;
|
|
|
|
+ $currentSubAdder = null;
|
|
|
|
|
|
foreach ($lines as $line) {
|
|
foreach ($lines as $line) {
|
|
|
|
|
|
@@ -264,6 +265,7 @@ class GenerateTreeCommand extends Command
|
|
break;
|
|
break;
|
|
|
|
|
|
case 16: // data for actions and subs
|
|
case 16: // data for actions and subs
|
|
|
|
+ $currentSubAdder = null;
|
|
if(strpos($line, "!inc:") === 0) { // !inc:
|
|
if(strpos($line, "!inc:") === 0) { // !inc:
|
|
if (!empty($currentMethod)) {
|
|
if (!empty($currentMethod)) {
|
|
$currentMethod->setIncFields('include', explode(",", substr($line, 5)));
|
|
$currentMethod->setIncFields('include', explode(",", substr($line, 5)));
|
|
@@ -306,6 +308,16 @@ class GenerateTreeCommand extends Command
|
|
$currentMethod->noActionLinks = true;
|
|
$currentMethod->noActionLinks = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ else if(strpos($line, "add_new") === 0) { // sub add_new..
|
|
|
|
+ if(!empty($currentMethod)) {
|
|
|
|
+ $currentSubAdder = $currentMethod->addSubAdder(
|
|
|
|
+ $line,
|
|
|
|
+ $currentSubController->name,
|
|
|
|
+ $currentController->snakeToTitleCase(explode(":", $line)[0]),
|
|
|
|
+ $exitURL
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
else if(!empty($currentMethod)) {
|
|
else if(!empty($currentMethod)) {
|
|
$currentMethod->data[] = $line;
|
|
$currentMethod->data[] = $line;
|
|
if($exitURL) {
|
|
if($exitURL) {
|
|
@@ -320,8 +332,8 @@ class GenerateTreeCommand extends Command
|
|
break;
|
|
break;
|
|
|
|
|
|
case 20: // SUB add_new fields
|
|
case 20: // SUB add_new fields
|
|
- if(!empty($currentMethod)) {
|
|
|
|
- $currentMethod->data[] = $line;
|
|
|
|
|
|
+ if(count($currentMethod->subAdders)) {
|
|
|
|
+ $currentMethod->subAdders[count($currentMethod->subAdders) - 1]["data"][] = $line;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -528,27 +540,25 @@ class GenController {
|
|
// check if any method has a "sub add_new" in it, if yes, add action for the same
|
|
// check if any method has a "sub add_new" in it, if yes, add action for the same
|
|
$newMethods = [];
|
|
$newMethods = [];
|
|
foreach ($this->methods as $method) {
|
|
foreach ($this->methods as $method) {
|
|
- 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;
|
|
|
|
- $parts = explode(":", $method->data[1]);
|
|
|
|
- $newMethod->table = $parts[1];
|
|
|
|
- if(count($parts) === 3) {
|
|
|
|
- $newMethod->api = $parts[2];
|
|
|
|
|
|
+ if($method->type === 'sub' && count($method->subAdders) >= 1) {
|
|
|
|
+ foreach ($method->subAdders as $subAdder) {
|
|
|
|
+ $methodName = "ACTION_" . $subAdder["name"];
|
|
|
|
+ $methodRoute = preg_replace("/\\/SUB_.+$/", '/' . $methodName, $method->route);
|
|
|
|
+ $newMethod = new GenControllerMethod($methodName, $methodRoute);
|
|
|
|
+ $newMethod->hasUID = true;
|
|
|
|
+ $newMethod->redirect = false;
|
|
|
|
+ $newMethod->type = 'action';
|
|
|
|
+ $newMethod->data = $subAdder["data"];
|
|
|
|
+ $newMethod->parentSub = $this->name . '-' . $method->name;
|
|
|
|
+ $newMethod->table = $subAdder["table"];
|
|
|
|
+ if(!empty($subAdder["api"])) {
|
|
|
|
+ $newMethod->api = $subAdder["api"];
|
|
|
|
+ }
|
|
|
|
+ $newMethod->exitURL = $subAdder["link"];
|
|
|
|
+ $newMethod->showLink = false;
|
|
|
|
+ $newMethod->routeName = $this->name . '-' . $methodName;
|
|
|
|
+ $newMethods[] = $newMethod;
|
|
}
|
|
}
|
|
- $newMethod->exitURL = $method->exitURL;
|
|
|
|
- $newMethod->showLink = false;
|
|
|
|
- $newMethods[] = $newMethod;
|
|
|
|
- $method->childAddRoute = $this->name . '-' . $methodName;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$this->methods = array_merge($this->methods, $newMethods);
|
|
$this->methods = array_merge($this->methods, $newMethods);
|
|
@@ -888,12 +898,16 @@ class GenController {
|
|
$text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
|
|
$text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
|
|
$text = str_replace("_NAME_", $this->camelToTitleCase($this->snakeToTitleCase($method->name)), $text);
|
|
$text = str_replace("_NAME_", $this->camelToTitleCase($this->snakeToTitleCase($method->name)), $text);
|
|
|
|
|
|
- if(count($method->data) > 1 && strpos($method->data[1], 'add_new') === 0) {
|
|
|
|
- $addLink = '<a class="btn btn-primary btn-sm" ' .
|
|
|
|
|
|
+ if(count($method->subAdders) >= 1) {
|
|
|
|
+ $addLinks = [];
|
|
|
|
+ foreach ($method->subAdders as $subAdder) {
|
|
|
|
+ $addLink = '<a class="btn btn-primary btn-sm ml-2" ' .
|
|
'up-modal=".form-contents" up-preload up-delay="25" up-width="800" up-history="false" ' .
|
|
'up-modal=".form-contents" up-preload up-delay="25" up-width="800" up-history="false" ' .
|
|
- 'href="{{route(\'' . $method->childAddRoute . '\', [\'uid\' => $record->uid])}}?optimised=1">' .
|
|
|
|
- "<i class='fa fa-plus-circle' aria-hidden='true'></i> Add New</a>";
|
|
|
|
- $text = str_replace("<!-- _ADD_NEW_LINK_ -->", $addLink, $text);
|
|
|
|
|
|
+ 'href="{{route(\'' . $subAdder["routeName"] . '\', [\'uid\' => $record->uid])}}?optimised=1">' .
|
|
|
|
+ "<i class='fa fa-plus-circle' aria-hidden='true'></i> {$subAdder["buttonLabel"]}</a>";
|
|
|
|
+ $addLinks[] = $addLink;
|
|
|
|
+ }
|
|
|
|
+ $text = str_replace("<!-- _ADD_NEW_LINK_ -->", implode("", $addLinks), $text);
|
|
}
|
|
}
|
|
|
|
|
|
$dbParts = explode("=", $method->data[0]);
|
|
$dbParts = explode("=", $method->data[0]);
|
|
@@ -1283,6 +1297,7 @@ class GenControllerMethod {
|
|
public $dashboard = false;
|
|
public $dashboard = false;
|
|
public $noActionLinks = false;
|
|
public $noActionLinks = false;
|
|
public $queries = [];
|
|
public $queries = [];
|
|
|
|
+ public $subAdders = [];
|
|
public function __construct($name, $route)
|
|
public function __construct($name, $route)
|
|
{
|
|
{
|
|
$this->name = $name;
|
|
$this->name = $name;
|
|
@@ -1291,6 +1306,20 @@ class GenControllerMethod {
|
|
$this->hasUID = true;
|
|
$this->hasUID = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ public function addSubAdder($line, $parentControllerName, $label, $link) {
|
|
|
|
+ $parts = explode(":", $line);
|
|
|
|
+ $newSubAdder = [
|
|
|
|
+ "name" => $parts[0],
|
|
|
|
+ "table" => $parts[1],
|
|
|
|
+ "api" => count($parts) >= 3 ? $parts[2] : null,
|
|
|
|
+ "link" => $link,
|
|
|
|
+ "data" => [],
|
|
|
|
+ "routeName" => "$parentControllerName-ACTION_{$parts[0]}",
|
|
|
|
+ "buttonLabel" => $label
|
|
|
|
+ ];
|
|
|
|
+ $this->subAdders[] = $newSubAdder;
|
|
|
|
+ return $newSubAdder;
|
|
|
|
+ }
|
|
public function setIncFields($type, $fields) {
|
|
public function setIncFields($type, $fields) {
|
|
$this->incType = $type;
|
|
$this->incType = $type;
|
|
$this->incFields = $fields;
|
|
$this->incFields = $fields;
|