|
@@ -96,6 +96,11 @@ class GenerateTreeCommand extends Command
|
|
$hasView = in_array("view", $tokens);
|
|
$hasView = in_array("view", $tokens);
|
|
$hasRemove = in_array("remove", $tokens);
|
|
$hasRemove = in_array("remove", $tokens);
|
|
|
|
|
|
|
|
+ $icon = "user";
|
|
|
|
+ if(strpos($tokens[count($tokens) - 1], "icon:") === 0) {
|
|
|
|
+ $icon = substr($tokens[count($tokens) - 1], 5);
|
|
|
|
+ }
|
|
|
|
+
|
|
switch($ls) {
|
|
switch($ls) {
|
|
|
|
|
|
case 4: // top level controller OR top level controller action
|
|
case 4: // top level controller OR top level controller action
|
|
@@ -133,13 +138,13 @@ class GenerateTreeCommand extends Command
|
|
if(!empty($currentController)) {
|
|
if(!empty($currentController)) {
|
|
$currentController->save();
|
|
$currentController->save();
|
|
}
|
|
}
|
|
- $currentController = new GenController($currentRoot, $line);
|
|
|
|
|
|
+ $currentController = new GenController($currentRoot, $line, $icon);
|
|
$currentController->dbTable = $dbTable;
|
|
$currentController->dbTable = $dbTable;
|
|
$currentController->condition = $condition;
|
|
$currentController->condition = $condition;
|
|
$currentController->hasAdd = $hasAdd;
|
|
$currentController->hasAdd = $hasAdd;
|
|
$currentController->hasView = $hasView;
|
|
$currentController->hasView = $hasView;
|
|
$currentController->hasRemove = $hasRemove;
|
|
$currentController->hasRemove = $hasRemove;
|
|
- $currentController->addMethod("index", "/$line");
|
|
|
|
|
|
+ $currentMethod = $currentController->addMethod("index", "/$line");
|
|
if(!empty($currentSubController)) {
|
|
if(!empty($currentSubController)) {
|
|
$currentSubController->save();
|
|
$currentSubController->save();
|
|
}
|
|
}
|
|
@@ -149,17 +154,37 @@ class GenerateTreeCommand extends Command
|
|
$sideLinks[] = "<li class='nav-item'><a href='/{$currentController->name}' " .
|
|
$sideLinks[] = "<li class='nav-item'><a href='/{$currentController->name}' " .
|
|
"class='nav-link " .
|
|
"class='nav-link " .
|
|
"{{ (isset(request()->route()->getController()->selfName) && strpos(request()->route()->getController()->selfName, '{$currentController->name}') === 0 ? 'active' : '') }}" . " '>" .
|
|
"{{ (isset(request()->route()->getController()->selfName) && strpos(request()->route()->getController()->selfName, '{$currentController->name}') === 0 ? 'active' : '') }}" . " '>" .
|
|
- "<i class='nav-icon fa fa-user'></i>" .
|
|
|
|
|
|
+ "<i class='nav-icon fa fa-$icon'></i>" .
|
|
"<p>" . $currentController->snakeToTitleCase($currentController->name) . "</p>" .
|
|
"<p>" . $currentController->snakeToTitleCase($currentController->name) . "</p>" .
|
|
"</a></li>";
|
|
"</a></li>";
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
- case 8: // sub-type declaration | add_new fields
|
|
|
|
|
|
+ case 8: // sub-type declaration | add_new fields | !inc/!exc
|
|
|
|
|
|
if($line === 'ACTIONS' || $line === 'SUB') {
|
|
if($line === 'ACTIONS' || $line === 'SUB') {
|
|
$currentSubType = $line;
|
|
$currentSubType = $line;
|
|
}
|
|
}
|
|
|
|
+ else if(strpos($line, "!inc:") === 0) { // !inc:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setIncFields('include', explode(",", substr($line, 5)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!exc:") === 0) { // !exc:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setIncFields('exclude', explode(",", substr($line, 5)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!lnk:") === 0) { // !lnk:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->viewLinkField = substr($line, 5);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!col:") === 0) { // !col:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setColumnSpec(substr($line, 5), $exitURL, 'record');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
else if (!empty($currentMethod) &&
|
|
else if (!empty($currentMethod) &&
|
|
(strpos($currentMethod->name, 'add_new') === 0 ||
|
|
(strpos($currentMethod->name, 'add_new') === 0 ||
|
|
$currentMethod->name === 'remove')) { // this is a field in add_new
|
|
$currentMethod->name === 'remove')) { // this is a field in add_new
|
|
@@ -199,17 +224,54 @@ class GenerateTreeCommand extends Command
|
|
break;
|
|
break;
|
|
|
|
|
|
case 16: // data for actions and subs
|
|
case 16: // data for actions and subs
|
|
- if(!empty($currentMethod)) {
|
|
|
|
- $currentMethod->data[] = $line;
|
|
|
|
- if($exitURL) {
|
|
|
|
- if(strpos("=", $line) !== FALSE) {
|
|
|
|
- $currentMethod->viewURL = $exitURL;
|
|
|
|
|
|
+ if(strpos($line, "!inc:") === 0) { // !inc:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setIncFields('include', explode(",", substr($line, 5)));
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- $currentMethod->exitURL = $exitURL;
|
|
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!exc:") === 0) { // !exc:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setIncFields('exclude', explode(",", substr($line, 5)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!lnk:") === 0) { // !lnk:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->viewLinkField = substr($line, 5);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!col:") === 0) { // !col:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->setColumnSpec(substr($line, 5), $exitURL,
|
|
|
|
+ $currentMethod->dashboard ? 'record' : 'subRecord'
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!grp:") === 0) { // !grp:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->addGroup(substr($line, 5), $exitURL);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!act:") === 0) { // !act:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->addAction(substr($line, 5), $exitURL);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(strpos($line, "!nal:") === 0) { // !nal:
|
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->noActionLinks = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if(!empty($currentMethod)) {
|
|
|
|
+ $currentMethod->data[] = $line;
|
|
|
|
+ if($exitURL) {
|
|
|
|
+ if(strpos("=", $line) !== FALSE) {
|
|
|
|
+ $currentMethod->viewURL = $exitURL;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $currentMethod->exitURL = $exitURL;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
case 20: // SUB add_new fields
|
|
case 20: // SUB add_new fields
|
|
@@ -270,10 +332,12 @@ class GenController {
|
|
public $parentControllerName = '';
|
|
public $parentControllerName = '';
|
|
public $subLinksSaved = false;
|
|
public $subLinksSaved = false;
|
|
public $actionLinksSaved = false;
|
|
public $actionLinksSaved = false;
|
|
- public function __construct($root = null, $name = null)
|
|
|
|
|
|
+ public $icon = "user";
|
|
|
|
+ public function __construct($root = null, $name = null, $icon = "user")
|
|
{
|
|
{
|
|
$this->root = $root;
|
|
$this->root = $root;
|
|
$this->name = $name;
|
|
$this->name = $name;
|
|
|
|
+ $this->icon = $icon;
|
|
$this->methods = [];
|
|
$this->methods = [];
|
|
}
|
|
}
|
|
public function addMethod($method, $route) {
|
|
public function addMethod($method, $route) {
|
|
@@ -456,12 +520,43 @@ class GenController {
|
|
"<i class='fa fa-trash'></i>" .
|
|
"<i class='fa fa-trash'></i>" .
|
|
"</a></td>";
|
|
"</a></td>";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // !inc/!exc
|
|
|
|
+ if($method->incType === "include") {
|
|
|
|
+ $columns = $method->incFields;
|
|
|
|
+ }
|
|
|
|
+ else if($method->incType === "exclude") {
|
|
|
|
+ $columns = array_filter($columns, function($item) use ($method) {
|
|
|
|
+ return in_array($item, $method->incFields) === FALSE;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
foreach ($columns as $column) {
|
|
foreach ($columns as $column) {
|
|
- $ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
|
|
|
|
+
|
|
|
|
+ $columnTitle = $this->snakeToTitleCase($column);
|
|
|
|
+ $columnValue = "<?= \$record->$column ?>";
|
|
|
|
+ $hasLink = $controller->hasView && $column === $method->viewLinkField;
|
|
|
|
+ $linkTarget = "/{$controller->name}/view/<?= \$record->uid ?>";
|
|
|
|
+
|
|
|
|
+ // check if this column has column spec
|
|
|
|
+ if(isset($method->columns[$column])) {
|
|
|
|
+ $columnTitle = $method->columns[$column]["label"];
|
|
|
|
+ if(isset($method->columns[$column]["query"])) {
|
|
|
|
+ $columnValue = "<?php \$_r = \Illuminate\Support\Facades\DB::" .
|
|
|
|
+ "select(\"{$method->columns[$column]["query"]}\");\n" .
|
|
|
|
+ "echo (\$_r && count(\$_r)) ? \$_r[0]->result : '-'; ?>";
|
|
|
|
+ }
|
|
|
|
+ if(isset($method->columns[$column]["link"])) {
|
|
|
|
+ $hasLink = true;
|
|
|
|
+ $linkTarget = $method->columns[$column]["link"];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $ths[] = "<th>$columnTitle</th>";
|
|
$tds[] = "<td>" .
|
|
$tds[] = "<td>" .
|
|
- ($controller->hasView && $column === 'uid' ? '<a href="/' . $controller->name . '/view/<?= $record->uid ?>">' : '') .
|
|
|
|
- "<?= \$record->$column ?>" .
|
|
|
|
- ($controller->hasView && $column === 'uid' ? '</a>' : '') .
|
|
|
|
|
|
+ ($hasLink ? "<a href=\"{$linkTarget}\">" : "") .
|
|
|
|
+ $columnValue .
|
|
|
|
+ ($hasLink ? "</a>" : "") .
|
|
"</td>";
|
|
"</td>";
|
|
}
|
|
}
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
@@ -479,11 +574,21 @@ class GenController {
|
|
unlink(resource_path("views/{$controller->root}/{$controller->parentControllerName}/actions.blade.php"));
|
|
unlink(resource_path("views/{$controller->root}/{$controller->parentControllerName}/actions.blade.php"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // write info view
|
|
|
|
+ $text = file_get_contents(base_path('generatecv/tree-templates/info.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);
|
|
|
|
+ $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/info.blade.php"), $text);
|
|
|
|
+ echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/info.blade.php") . "\n";
|
|
|
|
+
|
|
|
|
+ // write main view
|
|
$text = file_get_contents(base_path('generatecv/tree-templates/show.template.blade.php'));
|
|
$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("_NAME_", $this->snakeToTitleCase($controller->name), $text);
|
|
$text = str_replace("_UID_", '<?= $record->uid ?>', $text);
|
|
$text = str_replace("_UID_", '<?= $record->uid ?>', $text);
|
|
$text = str_replace("_INDEX_ROUTE_", $controller->name . '-index', $text);
|
|
$text = str_replace("_INDEX_ROUTE_", $controller->name . '-index', $text);
|
|
$text = str_replace("_SUB_LINKS_VIEW_", "{$controller->root}/{$controller->name}/subs", $text);
|
|
$text = str_replace("_SUB_LINKS_VIEW_", "{$controller->root}/{$controller->name}/subs", $text);
|
|
|
|
+ $text = str_replace("_INFO_VIEW_", "{$controller->root}/{$controller->name}/info", $text);
|
|
$this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $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";
|
|
echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
|
|
}
|
|
}
|
|
@@ -589,13 +694,45 @@ class GenController {
|
|
|
|
|
|
$ths = [];
|
|
$ths = [];
|
|
$tds = [];
|
|
$tds = [];
|
|
|
|
+
|
|
|
|
+ // !inc/!exc
|
|
|
|
+ if($method->incType === "include") {
|
|
|
|
+ $columns = $method->incFields;
|
|
|
|
+ }
|
|
|
|
+ else if($method->incType === "exclude") {
|
|
|
|
+ $columns = array_filter($columns, function($item) use ($method) {
|
|
|
|
+ return in_array($item, $method->incFields) === FALSE;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
foreach ($columns as $column) {
|
|
foreach ($columns as $column) {
|
|
- $ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
|
|
|
|
+
|
|
|
|
+ $columnTitle = $this->snakeToTitleCase($column);
|
|
|
|
+ $columnValue = "<?= \$subRecord->$column ?>";
|
|
|
|
+ $hasLink = $method->exitURL && $column === $method->viewLinkField;
|
|
|
|
+ $linkTarget = $method->exitURL;
|
|
|
|
+
|
|
|
|
+ // check if this column has column spec
|
|
|
|
+ if(isset($method->columns[$column])) {
|
|
|
|
+ $columnTitle = $method->columns[$column]["label"];
|
|
|
|
+ if(isset($method->columns[$column]["query"])) {
|
|
|
|
+ $columnValue = "<?php \$_r = \Illuminate\Support\Facades\DB::" .
|
|
|
|
+ "select(\"{$method->columns[$column]["query"]}\");\n" .
|
|
|
|
+ "echo (\$_r && count(\$_r)) ? \$_r[0]->result : '-'; ?>";
|
|
|
|
+ }
|
|
|
|
+ if(isset($method->columns[$column]["link"])) {
|
|
|
|
+ $hasLink = true;
|
|
|
|
+ $linkTarget = $method->columns[$column]["link"];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $ths[] = "<th>$columnTitle</th>";
|
|
$tds[] = "<td>" .
|
|
$tds[] = "<td>" .
|
|
- ($method->exitURL && $column === 'uid' ? '<a href="' . $method->exitURL . '">' : '') .
|
|
|
|
- "<?= \$subRecord->$column ?>" .
|
|
|
|
- ($method->exitURL && $column === 'uid' ? '</a>' : '') .
|
|
|
|
|
|
+ ($hasLink ? "<a href=\"{$linkTarget}\">" : "") .
|
|
|
|
+ $columnValue .
|
|
|
|
+ ($hasLink ? "</a>" : "") .
|
|
"</td>";
|
|
"</td>";
|
|
|
|
+
|
|
}
|
|
}
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_TDS__ -->", implode("\n", $tds), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_TDS__ -->", implode("\n", $tds), $text);
|
|
@@ -603,18 +740,114 @@ class GenController {
|
|
echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
|
|
echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
|
|
}
|
|
}
|
|
public function generateSubContent(GenController $controller, GenControllerMethod $method, $text) {
|
|
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'));
|
|
|
|
|
|
+ if($method->dashboard) {
|
|
|
|
+ if(!isset($method->groups) || !count($method->groups)) {
|
|
|
|
+ $html = file_get_contents(base_path('generatecv/tree-templates/dashboard' . ($method->noActionLinks ? '-nal' : '') . '.template.blade.php'));
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $html = file_get_contents(base_path('generatecv/tree-templates/dashboard-grouped' . ($method->noActionLinks ? '-nal' : '') . '.template.blade.php'));
|
|
|
|
+ $groupsHtml = [];
|
|
|
|
+ $groupTemplate = file_get_contents(base_path('generatecv/tree-templates/dashboard-group.template.blade.php'));
|
|
|
|
+ foreach ($method->groups as $group) {
|
|
|
|
+ $groupHtml = $groupTemplate;
|
|
|
|
+ $groupHtml = str_replace("<!-- __GROUP_NAME__ -->", $group["name"], $groupHtml);
|
|
|
|
+ if (isset($group["action"])) {
|
|
|
|
+ $action = $group["action"];
|
|
|
|
+ $actionLine = [];
|
|
|
|
+ if (isset($action["condition"])) {
|
|
|
|
+ if ($action["condition"] === "if") {
|
|
|
|
+ $actionLine[] = "@if(";
|
|
|
|
+ } else {
|
|
|
|
+ $actionLine[] = "@if(!";
|
|
|
|
+ }
|
|
|
|
+ $actionLine[] = "\$record->{$action["field"]})";
|
|
|
|
+ }
|
|
|
|
+ $actionLine[] = "<a " .
|
|
|
|
+ 'up-modal=".form-contents" up-width="800" up-history="false" ' .
|
|
|
|
+ "href='{$action["link"]}' title='{$action["label"]}' class='ml-2 text-dark font-weight-normal'>" .
|
|
|
|
+ "<i class='fa fa-{$action["icon"]} text-sm'></i>" .
|
|
|
|
+ "</a>";
|
|
|
|
+ if (isset($action["condition"])) {
|
|
|
|
+ $actionLine[] = "@endif";
|
|
|
|
+ }
|
|
|
|
+ $actionLine = implode(" ", $actionLine);
|
|
|
|
+ $groupHtml = str_replace("<!-- __GROUP_ACTION__ -->", $actionLine, $groupHtml);
|
|
|
|
+ }
|
|
|
|
+ $fields = [];
|
|
|
|
+ foreach ($group["fields"] as $field) {
|
|
|
|
+
|
|
|
|
+ $columnTitle = $this->snakeToTitleCase($field);
|
|
|
|
+ $columnValue = "<?= \$record->$field ?>";
|
|
|
|
+ $hasLink = false;
|
|
|
|
+ $linkTarget = null;
|
|
|
|
+ $actions = [];
|
|
|
|
+
|
|
|
|
+ // check if this column has column spec
|
|
|
|
+ if(isset($method->columns[$field])) {
|
|
|
|
+ $columnTitle = $method->columns[$field]["label"];
|
|
|
|
+ if(isset($method->columns[$field]["query"])) {
|
|
|
|
+ $columnValue = "<?php \$_r = \Illuminate\Support\Facades\DB::" .
|
|
|
|
+ "select(\"{$method->columns[$field]["query"]}\");\n" .
|
|
|
|
+ "echo (\$_r && count(\$_r)) ? \$_r[0]->result : '-'; ?>";
|
|
|
|
+ }
|
|
|
|
+ if(isset($method->columns[$field]["link"])) {
|
|
|
|
+ $hasLink = true;
|
|
|
|
+ $linkTarget = $method->columns[$field]["link"];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(isset($method->columnActions[$field])) {
|
|
|
|
+ foreach($method->columnActions[$field] as $action) {
|
|
|
|
+ $actionLine = [];
|
|
|
|
+ if(isset($action["condition"])) {
|
|
|
|
+ if($action["condition"] === "if") {
|
|
|
|
+ $actionLine[] = "@if(";
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $actionLine[] = "@if(!";
|
|
|
|
+ }
|
|
|
|
+ $actionLine[] = "\$record->{$action["field"]})";
|
|
|
|
+ }
|
|
|
|
+ $actionLine[] = "<a " .
|
|
|
|
+ 'up-modal=".form-contents" up-width="800" up-history="false" ' .
|
|
|
|
+ "href='{$action["link"]}' title='{$action["label"]}' class='ml-2 text-dark font-weight-normal'>" .
|
|
|
|
+ "<i class='fa fa-{$action["icon"]} text-sm'></i>" .
|
|
|
|
+ "</a>";
|
|
|
|
+ if(isset($action["condition"])) {
|
|
|
|
+ $actionLine[] = "@endif";
|
|
|
|
+ }
|
|
|
|
+ $actionLine = implode(" ", $actionLine);
|
|
|
|
+ $actions[] = $actionLine;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $actions = implode("\n", $actions);
|
|
|
|
+
|
|
|
|
+ $fields[] = "<tr>" .
|
|
|
|
+ "<td class=\"w-25 px-2 text-secondary border-right\">$columnTitle</td>" .
|
|
|
|
+ "<td class=\"w-75 px-2 font-weight-bold\">" .
|
|
|
|
+ ($hasLink ? "<a href=\"{$linkTarget}\">" : "") .
|
|
|
|
+ $columnValue .
|
|
|
|
+ ($hasLink ? "</a>" : "") .
|
|
|
|
+ $actions .
|
|
|
|
+ "</td>" .
|
|
|
|
+ "</tr>";
|
|
|
|
+ }
|
|
|
|
+ $groupHtml = str_replace("<!-- __GROUP_FIELDS__ -->", implode("\n", $fields), $groupHtml);
|
|
|
|
+ $groupsHtml[] = $groupHtml;
|
|
|
|
+ }
|
|
|
|
+ $groupsHtml = implode("\n", $groupsHtml);
|
|
|
|
+ $html = str_replace("<!-- _GROUPS_ -->", $groupsHtml, $html);
|
|
|
|
+ }
|
|
$text = str_replace("_SUB_VIEW_", $html, $text);
|
|
$text = str_replace("_SUB_VIEW_", $html, $text);
|
|
$text = str_replace("_ACTION_LINKS_VIEW_", "{$controller->root}/{$controller->parentControllerName}/actions", $text);
|
|
$text = str_replace("_ACTION_LINKS_VIEW_", "{$controller->root}/{$controller->parentControllerName}/actions", $text);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
$text = str_replace("_SUB_VIEW_",
|
|
$text = str_replace("_SUB_VIEW_",
|
|
- "<h4 class='py-3 border-bottom'>" .
|
|
|
|
- $this->camelToTitleCase($this->snakeToTitleCase($method->name)) . "</h4>" .
|
|
|
|
|
|
+ "<h5 class='py-3 border-bottom'>" .
|
|
|
|
+ $this->camelToTitleCase($this->snakeToTitleCase($method->name)) . "</h5>" .
|
|
"Controller: <b>{$controller->name}</b><br>" .
|
|
"Controller: <b>{$controller->name}</b><br>" .
|
|
"Action: <b>{$method->name}()</b><br>" .
|
|
"Action: <b>{$method->name}()</b><br>" .
|
|
- "View: <b>{$controller->root}/{$controller->name}/{$method->name}.blade.php</b><br>",
|
|
|
|
|
|
+ "View: <b>{$controller->root}/{$controller->name}/{$method->name}.blade.php</b><br><br>",
|
|
$text);
|
|
$text);
|
|
}
|
|
}
|
|
return $text;
|
|
return $text;
|
|
@@ -707,6 +940,11 @@ class GenController {
|
|
}
|
|
}
|
|
$tokens = explode(":", $tokens[0]);
|
|
$tokens = explode(":", $tokens[0]);
|
|
$name = $tokens[0];
|
|
$name = $tokens[0];
|
|
|
|
+ $required = false;
|
|
|
|
+ if($name[strlen($name) - 1] === '*') { // required field?
|
|
|
|
+ $required = true;
|
|
|
|
+ $name = substr($name, 0, strlen($name) - 1);
|
|
|
|
+ }
|
|
$display = $name;
|
|
$display = $name;
|
|
$dotPos = strpos($name, ".");
|
|
$dotPos = strpos($name, ".");
|
|
if($dotPos !== FALSE) {
|
|
if($dotPos !== FALSE) {
|
|
@@ -731,12 +969,15 @@ class GenController {
|
|
}
|
|
}
|
|
if($type !== 'hidden' && $type !== 'bool') {
|
|
if($type !== 'hidden' && $type !== 'bool') {
|
|
$code[] = "<div class='form-group mb-3'>";
|
|
$code[] = "<div class='form-group mb-3'>";
|
|
- $code[] = "<label class='control-label'>{$this->camelToTitleCase($this->snakeToTitleCase($display))}</label>";
|
|
|
|
|
|
+ $code[] = "<label class='control-label'>{$this->camelToTitleCase($this->snakeToTitleCase($display))} " .
|
|
|
|
+ ($required ? "*" : "") .
|
|
|
|
+ "</label>";
|
|
}
|
|
}
|
|
$valueLine = "value='{{ old('$name') ? old('$name') : " . ($default ? "\$record->$default" : '\'\'') . " }}' ";
|
|
$valueLine = "value='{{ old('$name') ? old('$name') : " . ($default ? "\$record->$default" : '\'\'') . " }}' ";
|
|
switch ($type) {
|
|
switch ($type) {
|
|
case "select":
|
|
case "select":
|
|
$code[] = "<select class='form-control' name='$name' " . $valueLine .
|
|
$code[] = "<select class='form-control' name='$name' " . $valueLine .
|
|
|
|
+ ($required ? "required" : "") .
|
|
">";
|
|
">";
|
|
$code[] = "<option value=''>-- Select --</option>";
|
|
$code[] = "<option value=''>-- Select --</option>";
|
|
foreach ($options as $o) {
|
|
foreach ($options as $o) {
|
|
@@ -748,6 +989,7 @@ class GenController {
|
|
break;
|
|
break;
|
|
case "record":
|
|
case "record":
|
|
$code[] = "<select class='form-control' name='$name' " . $valueLine .
|
|
$code[] = "<select class='form-control' name='$name' " . $valueLine .
|
|
|
|
+ ($required ? "required" : "") .
|
|
">";
|
|
">";
|
|
$code[] = "<option value=''>-- Select --</option>";
|
|
$code[] = "<option value=''>-- Select --</option>";
|
|
$code[] = "<?php \$dbOptions = \Illuminate\Support\Facades\DB::table('{$options['table']}')->get(); ?>";
|
|
$code[] = "<?php \$dbOptions = \Illuminate\Support\Facades\DB::table('{$options['table']}')->get(); ?>";
|
|
@@ -760,12 +1002,17 @@ class GenController {
|
|
break;
|
|
break;
|
|
case "bool":
|
|
case "bool":
|
|
$code[] = "<div class='form-group mb-3'>";
|
|
$code[] = "<div class='form-group mb-3'>";
|
|
- $code[] = "<label class='control-label'>{$this->camelToTitleCase($this->snakeToTitleCase($display))} ";
|
|
|
|
- $code[] = "<input class='ml-2' type='checkbox' name='$name'>";
|
|
|
|
|
|
+ $code[] = "<label class='control-label'>{$this->camelToTitleCase($this->snakeToTitleCase($display))} " .
|
|
|
|
+ ($required ? "*" : "");
|
|
|
|
+ $code[] = "<input class='ml-2' type='checkbox' name='$name' " .
|
|
|
|
+ ($required ? "required" : "") .
|
|
|
|
+ ">";
|
|
$code[] = "</label>";
|
|
$code[] = "</label>";
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
- $code[] = "<input class='form-control' type='$type' name='$name' " . $valueLine . ">";
|
|
|
|
|
|
+ $code[] = "<input class='form-control' type='$type' name='$name' " . $valueLine .
|
|
|
|
+ ($required ? "required" : "") .
|
|
|
|
+ ">";
|
|
}
|
|
}
|
|
if($type !== 'hidden') {
|
|
if($type !== 'hidden') {
|
|
$code[] = "</div>";
|
|
$code[] = "</div>";
|
|
@@ -789,6 +1036,14 @@ class GenControllerMethod {
|
|
public $viewURL = false;
|
|
public $viewURL = false;
|
|
public $exitURL = false;
|
|
public $exitURL = false;
|
|
public $showLink = true;
|
|
public $showLink = true;
|
|
|
|
+ public $incType = null;
|
|
|
|
+ public $incFields = null;
|
|
|
|
+ public $viewLinkField = 'uid';
|
|
|
|
+ public $columns = [];
|
|
|
|
+ public $columnActions = [];
|
|
|
|
+ public $groups = [];
|
|
|
|
+ public $dashboard = false;
|
|
|
|
+ public $noActionLinks = false;
|
|
public function __construct($name, $route)
|
|
public function __construct($name, $route)
|
|
{
|
|
{
|
|
$this->name = $name;
|
|
$this->name = $name;
|
|
@@ -797,4 +1052,71 @@ class GenControllerMethod {
|
|
$this->hasUID = true;
|
|
$this->hasUID = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ public function setIncFields($type, $fields) {
|
|
|
|
+ $this->incType = $type;
|
|
|
|
+ $this->incFields = $fields;
|
|
|
|
+ for ($i = 0; $i < count($this->incFields); $i++) {
|
|
|
|
+ if($this->incFields[$i][0] === '@') {
|
|
|
|
+ $this->incFields[$i] = substr($this->incFields[$i], 1);
|
|
|
|
+ $this->viewLinkField = $this->incFields[$i];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public function setColumnSpec($line, $link, $recordVariable) {
|
|
|
|
+ // ally_pro_id:Ally Pro:select name_display as 'result' from pro where id = $ally_pro_id limit 1
|
|
|
|
+ $parts = explode(":", $line);
|
|
|
|
+ $spec = [
|
|
|
|
+ "label" => $parts[1]
|
|
|
|
+ ];
|
|
|
|
+ if(count($parts) > 2) {
|
|
|
|
+ $query = $parts[2];
|
|
|
|
+ $query = preg_replace("/\\$([a-zA-Z0-9_]+)/", "\" . ($$recordVariable->$1 ? $$recordVariable->$1 : -1) . \"", $query);
|
|
|
|
+ $spec['query'] = $query;
|
|
|
|
+ }
|
|
|
|
+ if($link) {
|
|
|
|
+ $spec['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "<?= \$$recordVariable->$1 ?>", $link);
|
|
|
|
+ }
|
|
|
|
+ $this->columns[$parts[0]] = $spec;
|
|
|
|
+ }
|
|
|
|
+ public function addGroup($line, $link) {
|
|
|
|
+ // Basic Details:id,uid,created_at,clients_count
|
|
|
|
+ $parts = explode(":", $line);
|
|
|
|
+ $group = [
|
|
|
|
+ "name" => $parts[0],
|
|
|
|
+ "fields" => explode(",", $parts[1])
|
|
|
|
+ ];
|
|
|
|
+ // is there a group action
|
|
|
|
+ if(count($parts) > 2) {
|
|
|
|
+ $actionParts = ["-"];
|
|
|
|
+ for($i = 2; $i < count($parts); $i++) {
|
|
|
|
+ $actionParts[] = $parts[$i];
|
|
|
|
+ }
|
|
|
|
+ $actionParts = implode(":", $actionParts);
|
|
|
|
+ $group["action"] = $this->addAction($actionParts, $link, true);
|
|
|
|
+ }
|
|
|
|
+ $this->groups[] = $group;
|
|
|
|
+ $this->dashboard = true;
|
|
|
|
+ }
|
|
|
|
+ public function addAction($line, $link, $group = false) {
|
|
|
|
+ // is_active:Deactivate:deactivate:edit:if:is_active
|
|
|
|
+ $parts = explode(":", $line);
|
|
|
|
+ $action = [
|
|
|
|
+ "label" => $parts[1],
|
|
|
|
+ "icon" => isset($parts[2]) ? $parts[2] : 'edit'
|
|
|
|
+ ];
|
|
|
|
+ if(count($parts) >= 5 ) {
|
|
|
|
+ $action["condition"] = $parts[3];
|
|
|
|
+ $action["field"] = $parts[4];
|
|
|
|
+ }
|
|
|
|
+ if($link) {
|
|
|
|
+ $action['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "<?= \$record->$1 ?>", $link);
|
|
|
|
+ }
|
|
|
|
+ if(!$group) {
|
|
|
|
+ if(!isset($this->columnActions[$parts[0]])) {
|
|
|
|
+ $this->columnActions[$parts[0]] = [];
|
|
|
|
+ }
|
|
|
|
+ $this->columnActions[$parts[0]][] = $action;
|
|
|
|
+ }
|
|
|
|
+ return $action;
|
|
|
|
+ }
|
|
}
|
|
}
|