Browse Source

Generator views for all sub-actions

Vijayakrishnan Krishnan 5 năm trước cách đây
mục cha
commit
2c372c8db8

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

@@ -48,6 +48,7 @@ class GenerateTreeCommand extends Command
         $currentSubController = new GenController();
         $currentSubType = "";
         $currentView = "";
+        $currentMethod = null;
 
         foreach ($lines as $line) {
 
@@ -128,17 +129,30 @@ class GenerateTreeCommand extends Command
                     case 12: // subs and actions
 
                         if($currentSubType === 'ACTIONS') {
-                            $currentSubController->addMethod(
+                            $currentMethod = $currentSubController->addMethod(
                                 "ACTION_" . $line,
                                 "/ACTION_" . $line
                             );
+                            $currentMethod->type = 'action';
+                            $currentMethod->data = [];
                         }
                         else if($currentSubType === 'SUB') {
-                            $currentSubController->addMethod(
+                            $currentMethod = $currentSubController->addMethod(
                                 "SUB_" . $line,
                                 "/SUB_" . $line
                             );
+                            $currentMethod->type = 'sub';
+                            $currentMethod->data = [];
                         }
+
+                        break;
+
+                    case 16: // data for actions and subs
+
+                        if(!empty($currentMethod)) {
+                            $currentMethod->data[] = $line;
+                        }
+
                         break;
 
                 }
@@ -184,6 +198,8 @@ class GenController {
     public $hasView = false;
     public $sub = false;
     public $parentControllerName = '';
+    public $subLinksSaved = false;
+    public $actionLinksSaved = false;
     public function __construct($root = null, $name = null)
     {
         $this->root = $root;
@@ -203,7 +219,7 @@ class GenController {
             $this->saveController();
             $this->saveRoutes();
             $this->saved = true;
-//            $this->log();
+            $this->log();
         }
     }
     public function saveController() {
@@ -240,13 +256,18 @@ class GenController {
     }
     public function saveView(GenController $controller, GenControllerMethod $method) {
 
-        /*
-        $x = DB::getSchemaBuilder()->getColumnListing('client');
-        print_r($x);
-        */
-
         if($controller->sub) {
-            $this->saveSubView($controller, $method);
+            $controller->saveSubLinks($controller, $method);
+            $controller->saveActionLinks($controller, $method);
+            if($method->type === 'action') {
+                $this->saveSubActionView($controller, $method);
+            }
+            else if($method->type === 'sub' && count($method->data)) {
+                $this->saveSubSubView($controller, $method);
+            }
+            else {
+                $this->saveSubDefaultView($controller, $method);
+            }
         }
         else {
             if($method->name === 'view' && $controller->hasView) {
@@ -306,47 +327,72 @@ class GenController {
         $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";
     }
-    public function saveSubView(GenController $controller, GenControllerMethod $method)
+    public function saveSubLinks(GenController $controller, GenControllerMethod $method)
     {
-
-        // generate sub links if not existing
+        if ($controller->subLinksSaved) return;
         $subLinksView = resource_path("views/{$controller->root}/{$controller->parentControllerName}/subs.blade.php");
-        //if(!file_exists($subLinksView)) {
-            $subLinks = [];
-            foreach ($controller->methods as $meth) {
-                if(strpos($meth->name, "SUB_") !== 0) continue;
-                $display = $this->snakeToTitleCase(substr($meth->name, 4));
-                $subLinks[] = "<a " .
-                    "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
-                    "class='d-block p-3 py-2 border-bottom " .
-                    "{{ request()->route()->getActionMethod() === '{$meth->name}' ? 'bg-secondary text-white' : '' }}" .
-                    ($meth->name === 'SUB_dashboard' ? "{{ strpos(request()->route()->getActionMethod(), 'ACTION_') === 0 ? 'bg-secondary text-white' : '' }}" : "")
-                    . "'>$display</a>";
-            }
-            file_put_contents($subLinksView, implode("\n", $subLinks));
-//            echo "Generated " . $subLinksView . "\n";
-        //}
-
-        // generate action links if not existing
+        $subLinks = [];
+        foreach ($controller->methods as $meth) {
+            if (strpos($meth->name, "SUB_") !== 0) continue;
+            $display = $this->snakeToTitleCase(substr($meth->name, 4));
+            $subLinks[] = "<a " .
+                "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
+                "class='d-block p-3 py-2 border-bottom " .
+                "{{ request()->route()->getActionMethod() === '{$meth->name}' ? 'bg-secondary text-white' : '' }}" .
+                ($meth->name === 'SUB_dashboard' ? "{{ strpos(request()->route()->getActionMethod(), 'ACTION_') === 0 ? 'bg-secondary text-white' : '' }}" : "")
+                . "'>$display</a>";
+        }
+        file_put_contents($subLinksView, implode("\n", $subLinks));
+        echo "Generated " . $subLinksView . "\n";
+        $controller->subLinksSaved = true;
+    }
+    public function saveActionLinks(GenController $controller, GenControllerMethod $method)
+    {
+        if ($controller->actionLinksSaved) return;
         $actionLinksView = resource_path("views/{$controller->root}/{$controller->parentControllerName}/actions.blade.php");
-        //if(!file_exists($actionLinksView)) {
-            $actionLinks = [];
-            foreach ($controller->methods as $meth) {
-                if(strpos($meth->name, "ACTION_") !== 0) continue;
-                $display = $this->camelToTitleCase(substr($meth->name, 7));
-                $actionLinks[] = "<a " .
-                    "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
-                    "class='d-block btn btn-sm btn-default mb-3'>$display</a>";
-            }
-            file_put_contents($actionLinksView, implode("\n", $actionLinks));
-//            echo "Generated " . $actionLinksView . "\n";
-        //}
-
+        $actionLinks = [];
+        foreach ($controller->methods as $meth) {
+            if (strpos($meth->name, "ACTION_") !== 0) continue;
+            $display = $this->camelToTitleCase(substr($meth->name, 7));
+            $actionLinks[] = "<a " .
+                "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
+                "class='d-block btn btn-sm btn-default mb-3'>$display</a>";
+        }
+        file_put_contents($actionLinksView, implode("\n", $actionLinks));
+        echo "Generated " . $actionLinksView . "\n";
+        $controller->actionLinksSaved = true;
+    }
+    public function saveSubDefaultView(GenController $controller, GenControllerMethod $method)
+    {
         $text = file_get_contents(base_path('generatecv/tree-templates/sub.template.blade.php'));
         $text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
         $text = $this->generateSubContent($controller, $method, $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";
+    }
+    public function saveSubActionView(GenController $controller, GenControllerMethod $method) {
+        $text = file_get_contents(base_path('generatecv/tree-templates/sub-action.template.blade.php'));
+        $text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
+        $text = str_replace("_NAME_", $this->camelToTitleCase($this->snakeToTitleCase($method->name)), $text);
+        $text = str_replace("_BACK_ROUTE_", "{$controller->parentControllerName}-view", $text);
+        $text = str_replace("_API_", "/api/{$controller->dbTable}/" . substr($method->name, 7), $text);
+        $text = str_replace("_RETURN_ROUTE_", "{$controller->name}-{$method->name}", $text);
+        $fields = [];
+        if(count($method->data)) {
+            foreach ($method->data as $field) {
+                $fields[] =
+                    "<div class='form-group mb-3'>" .
+                    "<label class='control-label'>{$this->camelToTitleCase($this->snakeToTitleCase($field))}</label>" .
+                    "<input class='form-control' type='text' name='$field'>" .
+                    "</div>";
+            }
+        }
+        $text = str_replace("<!-- _SCAFFOLD_FIELDS_ -->", implode("\n", $fields), $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";
+    }
+    public function saveSubSubView(GenController $controller, GenControllerMethod $method) {
+
     }
     public function generateSubContent(GenController $controller, GenControllerMethod $method, $text) {
         if($method->name === 'SUB_dashboard') {
@@ -406,6 +452,7 @@ class GenController {
         foreach ($this->methods as $method) {
             $this->w('Rout: ' . $method->route, 1);
             $this->w('Meth: ' . $method->name . '($request' . ($method->hasUID ? ', $uid' : '') . ')', 1);
+            if(!empty($method->data)) $this->w('Data: ' . implode(", ", $method->data), 1);
             if(!$method->redirect) {
                 $this->w('View: ' . resource_path("views/{$this->root}/{$this->name}/{$method->name}.blade.php"), 1);
             }
@@ -425,7 +472,7 @@ class GenController {
     }
     public function camelToTitleCase($text) {
         $text = preg_replace("/^(SUB|ACTION)_/", "", $text);
-        $text = preg_replace("/([a-z])([A-Z])/", "$1 $2", $text);
+        $text = preg_replace("/([a-z])([A-Z0-9])/", "$1 $2", $text);
         return ucwords($text);
     }
     public function snakeToCamelCase($text) {
@@ -454,6 +501,8 @@ class GenControllerMethod {
     public $route;
     public $hasUID = false;
     public $redirect = false;
+    public $type = '';
+    public $data = [];
     public function __construct($name, $route)
     {
         $this->name = $name;

+ 5 - 0
generatecv/tree-lite.txt

@@ -4,6 +4,7 @@ PRO
     my_teams/view/{uid}
         ACTIONS
             updateTeamNumber
+                teamNumber
         SUB
             dashboard
             clients
@@ -14,10 +15,14 @@ PRO
         ACTIONS
             sendCellNumberConfirmationMessage
             confirmCellNumberWithConfirmationToken
+                token
             putNewCellNumber
+                newCellNumber
             sendEmailAddressConfirmationMessage
             confirmEmailAddressWithConfirmationToken
+                token
             putNewEmailAddress
+                newEmailAddress
         SUB
             dashboard
             med_profile

+ 21 - 0
generatecv/tree-templates/sub-action.template.blade.php

@@ -0,0 +1,21 @@
+@extends('_LAYOUT_')
+@section('content-inner')
+
+    <h4 class='py-3 mb-3 border-bottom'>
+        <div>_NAME_</div>
+    </h4>
+
+    <form action="/api-delegate-handler"
+          method="post" enctype="multipart/form-data"
+          class="bg-light rounded border px-3 pt-3 mr-3 mb-3">
+        <input type="hidden" name="uid" value="{{ $record->uid }}">
+        <input type="hidden" name="api" value="_API_">
+        <input type="hidden" name="return" value="{{route('_RETURN_ROUTE_', ['uid' => $record->uid])}}">
+        <!-- _SCAFFOLD_FIELDS_ -->
+        <div class="form-group mb-3">
+            <button class="btn btn-sm btn-primary mr-3 px-5">Submit</button>
+            <a href="{{route('_BACK_ROUTE_', ['uid' => $record->uid])}}" class="btn btn-sm btn-default px-5">Cancel</a>
+        </div>
+    </form>
+
+@endsection

+ 63 - 5
generatecv/tree.txt

@@ -6,6 +6,7 @@ PRO
     my_teams/view/{uid}
         ACTIONS
             updateTeamNumber
+                teamNumber
         SUB
             dashboard
             clients
@@ -16,42 +17,99 @@ PRO
         ACTIONS
             sendCellNumberConfirmationMessage
             confirmCellNumberWithConfirmationToken
+                token
             putNewCellNumber
+                newCellNumber
             sendEmailAddressConfirmationMessage
             confirmEmailAddressWithConfirmationToken
+                token
             putNewEmailAddress
+                newEmailAddress
             putTeam
-            removeTeam
+                teamUid
+#           removeTeam
             putMcp
-            removeMcp
+                mcpProUid
+#           removeMcp
             putAlly
-            removeAlly
+                allyProUid
+#           removeAlly
             putName
+                name
             putGender
+                gender
             putDateOfBirth
+                dateOfBirth
             putProfilePicture
-            removeProfilePicture
+                profilePictureBase64
+#           removeProfilePicture
             updatePhoneInfo
+                homePhoneNumber
+                workPhoneNumber
+                supporterPhoneNumber
+                supporterMemo
+                phoneNumbersMemo
             updateAddress
+                mailingAddressLine1
+                mailingAddressLine2
+                mailingAddressCity
+                mailingAddressState
+                mailingAddressCountry
+                mailingAddressZip
+                mailingAddressLat
+                mailingAddressLong
+                homeAddressLine1
+                homeAddressLine2
+                homeAddressCity
+                homeAddressState
+                homeAddressCountry
+                homeAddressZip
+                homeAddressLat
+                homeAddressLong
             updateMedicareNumber
+                medicareNumber
             manuallySetIsPartBPrimaryConfirmedToTrue
+                partBConfirmationMethod
+                partBConfirmationMemo
             manuallySetIsPartBPrimaryConfirmedToFalse
+                partBConfirmationMethod
+                partBConfirmationMemo
             setHasMcpDoneEmVisitToTrue
+                mcpEmVisitDate
+                mcpEmVisitNote
+                mcpEmVisitMemo
             updateMcpEmVisitInfo
+                mcpEmVisitDate
+                mcpEmVisitNote
+                mcpEmVisitMemo
             setHasMcpDoneEmVisitToFalse
             putCrmReasons
-            removeCrmReasons
+                cmReason1
+                cmReason2
+                rmReason1
+                rmReason2
+#           removeCrmReasons
             setIsClientEnrolledInCmToTrue
             setIsClientEnrolledInCmToFalse
             updateWhyNotEnrolledInCm
+                whyNotEnrolledInCmCategory
+                whyNotEnrolledInCmMemo
             setIsClientEnrolledInRmToTrue
             setIsClientEnrolledInRmToFalse
             updateWhyNotEnrolledInRm
+                whyNotEnrolledInRmCategory
+                whyNotEnrolledInRmMemo
             updateIntakeInfo
+                intakeText
+                intakeDetail
             deactivate
+                memo
             updateDeactivationMemo
+                memo
             reactivate
+                memo
             updateReactivationMemo
+                memo
         SUB
             dashboard
             med_profile