浏览代码

Support for dashboard group level actions

Vijayakrishnan Krishnan 5 年之前
父节点
当前提交
7b909a9f85

+ 43 - 18
app/Console/Commands/GenerateTreeCommand.php

@@ -248,12 +248,12 @@ class GenerateTreeCommand extends Command
                             }
                             else if(strpos($line, "!grp:") === 0) { // !grp:
                                 if (!empty($currentMethod)) {
-                                    $currentMethod->addGroup(substr($line, 5));
+                                    $currentMethod->addGroup(substr($line, 5), $exitURL);
                                 }
                             }
                             else if(strpos($line, "!act:") === 0) { // !act:
                                 if (!empty($currentMethod)) {
-                                    $currentMethod->addColumnAction(substr($line, 5), $exitURL);
+                                    $currentMethod->addAction(substr($line, 5), $exitURL);
                                 }
                             }
                             else if(strpos($line, "!nal:") === 0) { // !nal:
@@ -751,6 +751,28 @@ class GenController {
                 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) {
 
@@ -774,16 +796,6 @@ class GenController {
                             }
                         }
 
-                        /*
-                        "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 = [];
@@ -1066,16 +1078,26 @@ class GenControllerMethod {
         }
         $this->columns[$parts[0]] = $spec;
     }
-    public function addGroup($line) {
+    public function addGroup($line, $link) {
         // Basic Details:id,uid,created_at,clients_count
         $parts = explode(":", $line);
-        $this->groups[] = [
+        $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 addColumnAction($line, $link) {
+    public function addAction($line, $link, $group = false) {
         // is_active:Deactivate:deactivate:edit:if:is_active
         $parts = explode(":", $line);
         $action = [
@@ -1089,9 +1111,12 @@ class GenControllerMethod {
         if($link) {
             $action['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "<?= \$record->$1 ?>", $link);
         }
-        if(!isset($this->columnActions[$parts[0]])) {
-            $this->columnActions[$parts[0]] = [];
+        if(!$group) {
+            if(!isset($this->columnActions[$parts[0]])) {
+                $this->columnActions[$parts[0]] = [];
+            }
+            $this->columnActions[$parts[0]][] = $action;
         }
-        $this->columnActions[$parts[0]][] = $action;
+        return $action;
     }
 }

+ 3 - 1
generatecv/tree-templates/dashboard-group.template.blade.php

@@ -2,7 +2,9 @@
     <table class="table table-hover text-nowrap table-striped border-left border-right border-bottom">
         <thead>
         <tr>
-            <th colspan="2" class="px-2"><!-- __GROUP_NAME__ --></th>
+            <th colspan="2" class="px-2"><!-- __GROUP_NAME__ -->
+                <span class="ml-auto"><!-- __GROUP_ACTION__ --></span>
+            </th>
         </tr>
         </thead>
         <tbody>

+ 1 - 1
generatecv/tree.txt

@@ -29,7 +29,7 @@ PRO
                 memo=reactivation_memo
         SUB
             dashboard
-                !grp:Basic Details:team_number,created_at,client_count,is_active
+                !grp:Basic Details:team_number,created_at,client_count,is_active:Update Team Number:pencil-alt=>/my_teams/view/$uid/ACTION_updateTeamNumber
                 !grp:Associated Pros:hcp_pro_id,ally_pro_id
                 !col:hcp_pro_id:HCP Pro:select name_display as result from pro where id = $hcp_pro_id limit 1=>/foo/bar/$hcp_pro_id
                 !col:ally_pro_id:Ally Pro:select name_display as result from pro where id = $ally_pro_id limit 1