Browse Source

Support for multiple adders in sub listings

Vijayakrishnan Krishnan 4 years ago
parent
commit
1fa93e64cf
2 changed files with 112 additions and 64 deletions
  1. 56 27
      app/Console/Commands/GenerateTreeCommand.php
  2. 56 37
      generatecv/tree-lite.txt

+ 56 - 27
app/Console/Commands/GenerateTreeCommand.php

@@ -49,6 +49,7 @@ class GenerateTreeCommand extends Command
         $currentSubType = "";
         $currentView = "";
         $currentMethod = null;
+        $currentSubAdder = null;
 
         foreach ($lines as $line) {
 
@@ -264,6 +265,7 @@ class GenerateTreeCommand extends Command
                         break;
 
                     case 16: // data for actions and subs
+                        $currentSubAdder = null;
                         if(strpos($line, "!inc:") === 0) { // !inc:
                             if (!empty($currentMethod)) {
                                 $currentMethod->setIncFields('include', explode(",", substr($line, 5)));
@@ -306,6 +308,16 @@ class GenerateTreeCommand extends Command
                                 $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)) {
                             $currentMethod->data[] = $line;
                             if($exitURL) {
@@ -320,8 +332,8 @@ class GenerateTreeCommand extends Command
                         break;
 
                     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;
 
@@ -528,27 +540,25 @@ class GenController {
         // check if any method has a "sub add_new" in it, if yes, add action for the same
         $newMethods = [];
         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);
@@ -888,12 +898,16 @@ class GenController {
         $text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $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" ' .
-                    '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]);
@@ -1283,6 +1297,7 @@ class GenControllerMethod {
     public $dashboard = false;
     public $noActionLinks = false;
     public $queries = [];
+    public $subAdders = [];
     public function __construct($name, $route)
     {
         $this->name = $name;
@@ -1291,6 +1306,20 @@ class GenControllerMethod {
             $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) {
         $this->incType = $type;
         $this->incFields = $fields;

+ 56 - 37
generatecv/tree-lite.txt

@@ -1,43 +1,62 @@
 PRO
-    my_teams|team|add|view
-    my_teams/add_new
-        hcpProUid
-        allyProUid
-        teamNumber
-    my_teams/view/{uid}
-        ACTIONS
-            updateTeamNumber
-                teamNumber
-        SUB
-            dashboard
-            clients
-            audit_log
-    my_clients|client|add|view
-    my_clients/add_new
-        teamUid
-        mcpProUid
-        allyProUid
+ADMIN
+#   admin_dashboard
+    pros|pro|add|view|icon:user-md
+        !inc:@name_display,name_first,name_last
+        col:name_display
+        name_first
+        name_last
+    pros/add_new:create
+        cellNumber*:tel
+        emailAddress:email
         nameDisplay
-        name
-        gender
-        dateOfBirth
-        cellNumber
-        emailAddress
-        medicareNumber
-    my_clients/view/{uid}
+        namePrefix
+        nameFirst*
+        nameMiddle
+        nameLast*
+        nameSuffix
+        nameCredential
+        isHcp:bool
+        hcpNpi
+        previousProfessionCategory
+        currentProfessionCategory
+    pros/view/{uid}
         ACTIONS
-            sendCellNumberConfirmationMessage
-            confirmCellNumberWithConfirmationToken
-                token
-            putNewCellNumber
-                newCellNumber
-            sendEmailAddressConfirmationMessage
-            confirmEmailAddressWithConfirmationToken
-                token
-            putNewEmailAddress
-                newEmailAddress
         SUB
             dashboard
-            med_profile
-            med_profile_log
+            clients
             pro_access
+                id=client_pro_access.pro_id=>/pro_access/view/UID
+                add_new:client_pro_access=>/pro_access/view/UID
+                    proUid:hidden=uid
+                    clientUid:record:client:uid,name_first
+                    reasonCategory
+                    reasonMemo
+                    reasonDetail
+            mcp_updates
+            erx
+            action_items
+            care_months
+            care_month_entries
+            notes
+            bills
+            transactions
+                id=pro_transaction.pro_id=>/transactions/view/UID/SUB_dashboard
+                !inc:@created_at,pro_id,client_id,plus_or_minus,reason_type,amount,resulting_balance
+                !qry:clients:select id, concat(name_last, ', ', name_first) as name_display from client
+                !qry:pros:select id, concat(name_last, ', ', name_first) as name_display from pro
+                !col:pro_id:Pro:~pros:name_display:id,=,$$pro_id:all
+                !col:client_id:Client:~clients:name_display:id,=,$$client_id:all
+                add_new_credit:pro_transaction:createManualPlusForPro
+                    proUid:hidden=uid
+                    amount:number
+                    intendedResultingBalance:number
+                    customMemo
+                add_new_debit:pro_transaction:createManualMinusForPro
+                    proUid:hidden=uid
+                    amount:number
+                    intendedResultingBalance:number
+                    customMemo
+            sessions
+            audit_log
+