|
@@ -236,7 +236,19 @@ class GenerateTreeCommand extends Command
|
|
|
}
|
|
|
else if(strpos($line, "!col:") === 0) { // !col:
|
|
|
if (!empty($currentMethod)) {
|
|
|
- $currentMethod->setColumnSpec(substr($line, 5), $exitURL, 'subRecord');
|
|
|
+ $currentMethod->setColumnSpec(substr($line, 5), $exitURL,
|
|
|
+ $currentMethod->name === 'SUB_dashboard' ? 'record' : 'subRecord'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(strpos($line, "!grp:") === 0) { // !grp:
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
+ $currentMethod->addGroup(substr($line, 5));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(strpos($line, "!act:") === 0) { // !act:
|
|
|
+ if (!empty($currentMethod)) {
|
|
|
+ $currentMethod->addColumnAction(substr($line, 5), $exitURL);
|
|
|
}
|
|
|
}
|
|
|
else if(!empty($currentMethod)) {
|
|
@@ -705,7 +717,90 @@ class GenController {
|
|
|
}
|
|
|
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(!isset($method->groups) || !count($method->groups)) {
|
|
|
+ $html = file_get_contents(base_path('generatecv/tree-templates/dashboard.template.blade.php'));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $html = file_get_contents(base_path('generatecv/tree-templates/dashboard-grouped.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);
|
|
|
+ $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 = "<?= \Illuminate\Support\Facades\DB::" .
|
|
|
+ "select(\"{$method->columns[$field]["query"]}\")[0]->result ?>";
|
|
|
+ }
|
|
|
+ if(isset($method->columns[$field]["link"])) {
|
|
|
+ $hasLink = true;
|
|
|
+ $linkTarget = $method->columns[$field]["link"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ "is_active" => array:1 [
|
|
|
+ 0 => array:5 [
|
|
|
+ "label" => "Deactivate"
|
|
|
+ "icon" => "edit"
|
|
|
+ "condition" => "if"
|
|
|
+ "field" => "is_active"
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ */
|
|
|
+ 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("_ACTION_LINKS_VIEW_", "{$controller->root}/{$controller->parentControllerName}/actions", $text);
|
|
|
}
|
|
@@ -894,6 +989,8 @@ class GenControllerMethod {
|
|
|
public $incFields = null;
|
|
|
public $viewLinkField = 'uid';
|
|
|
public $columns = [];
|
|
|
+ public $columnActions = [];
|
|
|
+ public $groups = [];
|
|
|
public function __construct($name, $route)
|
|
|
{
|
|
|
$this->name = $name;
|
|
@@ -914,23 +1011,45 @@ class GenControllerMethod {
|
|
|
}
|
|
|
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
|
|
|
- /*
|
|
|
- label
|
|
|
- query
|
|
|
- link
|
|
|
- */
|
|
|
$parts = explode(":", $line);
|
|
|
$spec = [
|
|
|
"label" => $parts[1]
|
|
|
];
|
|
|
if(count($parts) > 2) {
|
|
|
$query = $parts[2];
|
|
|
- $query = preg_replace("/\\$(\S+)/", "{\$$recordVariable->$1}", $query);
|
|
|
+ $query = preg_replace("/\\$([a-zA-Z0-9_]+)/", "{\$$recordVariable->$1}", $query);
|
|
|
$spec['query'] = $query;
|
|
|
}
|
|
|
if($link) {
|
|
|
- $spec['link'] = preg_replace("/\\$(\S+)/", "<?= \$$recordVariable->$1 ?>", $link);
|
|
|
+ $spec['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "<?= \$$recordVariable->$1 ?>", $link);
|
|
|
}
|
|
|
$this->columns[$parts[0]] = $spec;
|
|
|
}
|
|
|
+ public function addGroup($line) {
|
|
|
+ // Basic Details:id,uid,created_at,clients_count
|
|
|
+ $parts = explode(":", $line);
|
|
|
+ $this->groups[] = [
|
|
|
+ "name" => $parts[0],
|
|
|
+ "fields" => explode(",", $parts[1])
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ public function addColumnAction($line, $link) {
|
|
|
+ // 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(!isset($this->columnActions[$parts[0]])) {
|
|
|
+ $this->columnActions[$parts[0]] = [];
|
|
|
+ }
|
|
|
+ $this->columnActions[$parts[0]][] = $action;
|
|
|
+ }
|
|
|
}
|