Prechádzať zdrojové kódy

Generate inner (sub) tables with data

Vijayakrishnan Krishnan 5 rokov pred
rodič
commit
21d241a2f9

+ 41 - 4
app/Console/Commands/GenerateTreeCommand.php

@@ -244,11 +244,24 @@ class GenController {
             else {
                 if($method->hasUID) {
                     $code[] = "\t\t\$record = DB::table('{$this->dbTable}')->where('uid', \$uid)->first();";
-                    $code[] = "\t\treturn view('{$this->root}/{$this->name}/{$method->name}', compact('record'));";
+                    $input = ["'record'"];
+                    // if sub-index controller, load subRecords
+                    if($method->type === 'sub' && count($method->data)) {
+                        $dbParts = explode("=", $method->data[0]);
+                        $localField = $dbParts[0];
+                        $dbParts = explode(".", $dbParts[1]);
+                        $foreignTable = $dbParts[0];
+                        $foreignField = $dbParts[1];
+                        $code[] = "\t\t\$subRecords = DB::table('$foreignTable')->where('$foreignField', \$record->$localField)->get();";
+                        $input[] = "'subRecords'";
+                    }
+                    $code[] = "\t\treturn view('{$this->root}/{$this->name}/{$method->name}', " .
+                        "compact(" . implode(", ", $input) . "));";
                 }
                 else {
                     $code[] = "\t\t\$records = DB::table('{$this->dbTable}')->get();";
-                    $code[] = "\t\treturn view('{$this->root}/{$this->name}/{$method->name}', compact('records'));";
+                    $code[] = "\t\treturn view('{$this->root}/{$this->name}/{$method->name}', " .
+                        "compact('records'));";
                 }
             }
 
@@ -270,7 +283,7 @@ class GenController {
                 $this->saveSubActionView($controller, $method);
             }
             else if($method->type === 'sub' && count($method->data)) {
-                $this->saveSubSubView($controller, $method);
+                $this->saveSubIndexView($controller, $method);
             }
             else {
                 $this->saveSubDefaultView($controller, $method);
@@ -394,8 +407,32 @@ 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 saveSubSubView(GenController $controller, GenControllerMethod $method) {
+    public function saveSubIndexView(GenController $controller, GenControllerMethod $method) {
+        $text = file_get_contents(base_path('generatecv/tree-templates/sub-index.template.blade.php'));
+        $text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
+        $text = str_replace("_NAME_", $this->camelToTitleCase($this->snakeToTitleCase($method->name)), $text);
+
+        /*if($controller->hasAdd) {
+            $addLink = "<a class='btn btn-primary btn-sm' href='/{$controller->name}/add_new'>" .
+                "<i class='fa fa-plus-circle' aria-hidden='true'></i> Add New</a>";
+            $text = str_replace("<!-- _ADD_NEW_LINK_ -->", $addLink, $text);
+        }*/
 
+        $dbParts = explode("=", $method->data[0]);
+        $dbParts = explode(".", $dbParts[1]);
+        $table = $dbParts[0];
+        $columns = DB::getSchemaBuilder()->getColumnListing($table);
+
+        $ths = [];
+        $tds = [];
+        foreach ($columns as $column) {
+            $ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
+            $tds[] = "<td><?= \$subRecord->$column ?></td>";
+        }
+        $text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
+        $text = str_replace("<!-- __SCAFFOLD_TDS__ -->", implode("\n", $tds), $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 generateSubContent(GenController $controller, GenControllerMethod $method, $text) {
         if($method->name === 'SUB_dashboard') {

+ 2 - 1
app/Http/Controllers/my_teams_SINGLE_Controller.php

@@ -24,7 +24,8 @@ class my_teams_SINGLE_Controller extends Controller
 	// GET /my_teams/view/{uid}/SUB_clients
 	public function SUB_clients(Request $request, $uid) {
 		$record = DB::table('team')->where('uid', $uid)->first();
-		return view('pro/my_teams_SINGLE/SUB_clients', compact('record'));
+		$subRecords = DB::table('client')->where('team_id', $record->id)->get();
+		return view('pro/my_teams_SINGLE/SUB_clients', compact('record', 'subRecords'));
 	}
 
 	// GET /my_teams/view/{uid}/SUB_audit_log

+ 32 - 0
generatecv/tree-templates/sub-index.template.blade.php

@@ -0,0 +1,32 @@
+@extends('_LAYOUT_')
+@section('content-inner')
+
+    <div class="mr-3 pb-3">
+
+        <h4 class='my-3'>
+            <div>_NAME_</div>
+            <div class="ml-auto">
+                <!-- _ADD_NEW_LINK_ -->
+            </div>
+        </h4>
+
+        <div class="table-responsive p-0 bg-white border">
+            <table class="table table-hover text-nowrap">
+                <thead>
+                <tr>
+                    <!-- __SCAFFOLD_THS__ -->
+                </tr>
+                </thead>
+                <tbody>
+                @foreach($subRecords as $subRecord)
+                    <tr>
+                        <!-- __SCAFFOLD_TDS__ -->
+                    </tr>
+                @endforeach
+                </tbody>
+            </table>
+        </div>
+
+    </div>
+
+@endsection

+ 1 - 0
generatecv/tree.txt

@@ -13,6 +13,7 @@ PRO
         SUB
             dashboard
             clients
+                id=client.team_id
             audit_log
     my_clients|client|add|view
     my_clients/add_new

+ 185 - 1
resources/views/pro/my_teams_SINGLE/SUB_clients.blade.php

@@ -1,6 +1,190 @@
 @extends('pro.my_teams.view')
 @section('content-inner')
 
-    <h4 class='py-3 border-bottom'>Clients</h4>Controller: <b>my_teams_SINGLE</b><br>Action: <b>SUB_clients()</b><br>View: <b>pro/my_teams_SINGLE/SUB_clients.blade.php</b><br>
+    <div class="mr-3 pb-3">
+
+        <h4 class='my-3'>
+            <div>Clients</div>
+            <div class="ml-auto">
+                <!-- _ADD_NEW_LINK_ -->
+            </div>
+        </h4>
+
+        <div class="table-responsive p-0 bg-white border">
+            <table class="table table-hover text-nowrap">
+                <thead>
+                <tr>
+                    <th>Id</th>
+<th>Created At</th>
+<th>Type</th>
+<th>Uid</th>
+<th>Deactivated At</th>
+<th>Deactivation Memo</th>
+<th>Is Active</th>
+<th>Reactivated At</th>
+<th>Reactivation Memo</th>
+<th>Cell Number</th>
+<th>Cell Number Confirmation Token</th>
+<th>Cell Number Confirmed At</th>
+<th>Cm Reason1</th>
+<th>Cm Reason2</th>
+<th>Date Of Birth</th>
+<th>Email Address</th>
+<th>Email Address Confirmation Token</th>
+<th>Email Address Confirmed At</th>
+<th>Gender</th>
+<th>Has Mcp Done Em Visit</th>
+<th>Home Address City</th>
+<th>Home Address Country</th>
+<th>Home Address Lat</th>
+<th>Home Address Line1</th>
+<th>Home Address Line2</th>
+<th>Home Address Long</th>
+<th>Home Address State</th>
+<th>Home Address Zip</th>
+<th>Home Phone Number</th>
+<th>Intake Detail</th>
+<th>Intake Text</th>
+<th>Is Cell Number Confirmation Pending</th>
+<th>Is Cell Number Confirmed</th>
+<th>Is Client Enrolled In Cm</th>
+<th>Is Client Enrolled In Rm</th>
+<th>Is Email Address Confirmation Pending</th>
+<th>Is Email Address Confirmed</th>
+<th>Is Partbprimary Confirmed</th>
+<th>Is Password Temporary</th>
+<th>Mailing Address City</th>
+<th>Mailing Address Country</th>
+<th>Mailing Address Lat</th>
+<th>Mailing Address Line1</th>
+<th>Mailing Address Line2</th>
+<th>Mailing Address Long</th>
+<th>Mailing Address State</th>
+<th>Mailing Address Zip</th>
+<th>Mcp Em Visit Date</th>
+<th>Mcp Em Visit Memo</th>
+<th>Medicare Number</th>
+<th>Name Credential</th>
+<th>Name Display</th>
+<th>Name First</th>
+<th>Name Last</th>
+<th>Name Middle</th>
+<th>Name Prefix</th>
+<th>Name Suffix</th>
+<th>Partbconfirmation Memo</th>
+<th>Partbconfirmation Method</th>
+<th>Password</th>
+<th>Phone Numbers Memo</th>
+<th>Profile Picture Base64</th>
+<th>Rm Reason1</th>
+<th>Rm Reason2</th>
+<th>Supporter Memo</th>
+<th>Supporter Phone Number</th>
+<th>Username</th>
+<th>Why Not Enrolled In Cm Category</th>
+<th>Why Not Enrolled In Cm Memo</th>
+<th>Why Not Enrolled In Rm Category</th>
+<th>Why Not Enrolled In Rm Memo</th>
+<th>Work Phone Number</th>
+<th>Created By Session Id</th>
+<th>Deactivated By Session Id</th>
+<th>Reactivated By Session Id</th>
+<th>Ally Pro Id</th>
+<th>Mcp Em Visit Note Id</th>
+<th>Mcp Pro Id</th>
+<th>Team Id</th>
+<th>Cm Target</th>
+                </tr>
+                </thead>
+                <tbody>
+                @foreach($subRecords as $subRecord)
+                    <tr>
+                        <td><?= $subRecord->id ?></td>
+<td><?= $subRecord->created_at ?></td>
+<td><?= $subRecord->type ?></td>
+<td><?= $subRecord->uid ?></td>
+<td><?= $subRecord->deactivated_at ?></td>
+<td><?= $subRecord->deactivation_memo ?></td>
+<td><?= $subRecord->is_active ?></td>
+<td><?= $subRecord->reactivated_at ?></td>
+<td><?= $subRecord->reactivation_memo ?></td>
+<td><?= $subRecord->cell_number ?></td>
+<td><?= $subRecord->cell_number_confirmation_token ?></td>
+<td><?= $subRecord->cell_number_confirmed_at ?></td>
+<td><?= $subRecord->cm_reason1 ?></td>
+<td><?= $subRecord->cm_reason2 ?></td>
+<td><?= $subRecord->date_of_birth ?></td>
+<td><?= $subRecord->email_address ?></td>
+<td><?= $subRecord->email_address_confirmation_token ?></td>
+<td><?= $subRecord->email_address_confirmed_at ?></td>
+<td><?= $subRecord->gender ?></td>
+<td><?= $subRecord->has_mcp_done_em_visit ?></td>
+<td><?= $subRecord->home_address_city ?></td>
+<td><?= $subRecord->home_address_country ?></td>
+<td><?= $subRecord->home_address_lat ?></td>
+<td><?= $subRecord->home_address_line1 ?></td>
+<td><?= $subRecord->home_address_line2 ?></td>
+<td><?= $subRecord->home_address_long ?></td>
+<td><?= $subRecord->home_address_state ?></td>
+<td><?= $subRecord->home_address_zip ?></td>
+<td><?= $subRecord->home_phone_number ?></td>
+<td><?= $subRecord->intake_detail ?></td>
+<td><?= $subRecord->intake_text ?></td>
+<td><?= $subRecord->is_cell_number_confirmation_pending ?></td>
+<td><?= $subRecord->is_cell_number_confirmed ?></td>
+<td><?= $subRecord->is_client_enrolled_in_cm ?></td>
+<td><?= $subRecord->is_client_enrolled_in_rm ?></td>
+<td><?= $subRecord->is_email_address_confirmation_pending ?></td>
+<td><?= $subRecord->is_email_address_confirmed ?></td>
+<td><?= $subRecord->is_partbprimary_confirmed ?></td>
+<td><?= $subRecord->is_password_temporary ?></td>
+<td><?= $subRecord->mailing_address_city ?></td>
+<td><?= $subRecord->mailing_address_country ?></td>
+<td><?= $subRecord->mailing_address_lat ?></td>
+<td><?= $subRecord->mailing_address_line1 ?></td>
+<td><?= $subRecord->mailing_address_line2 ?></td>
+<td><?= $subRecord->mailing_address_long ?></td>
+<td><?= $subRecord->mailing_address_state ?></td>
+<td><?= $subRecord->mailing_address_zip ?></td>
+<td><?= $subRecord->mcp_em_visit_date ?></td>
+<td><?= $subRecord->mcp_em_visit_memo ?></td>
+<td><?= $subRecord->medicare_number ?></td>
+<td><?= $subRecord->name_credential ?></td>
+<td><?= $subRecord->name_display ?></td>
+<td><?= $subRecord->name_first ?></td>
+<td><?= $subRecord->name_last ?></td>
+<td><?= $subRecord->name_middle ?></td>
+<td><?= $subRecord->name_prefix ?></td>
+<td><?= $subRecord->name_suffix ?></td>
+<td><?= $subRecord->partbconfirmation_memo ?></td>
+<td><?= $subRecord->partbconfirmation_method ?></td>
+<td><?= $subRecord->password ?></td>
+<td><?= $subRecord->phone_numbers_memo ?></td>
+<td><?= $subRecord->profile_picture_base64 ?></td>
+<td><?= $subRecord->rm_reason1 ?></td>
+<td><?= $subRecord->rm_reason2 ?></td>
+<td><?= $subRecord->supporter_memo ?></td>
+<td><?= $subRecord->supporter_phone_number ?></td>
+<td><?= $subRecord->username ?></td>
+<td><?= $subRecord->why_not_enrolled_in_cm_category ?></td>
+<td><?= $subRecord->why_not_enrolled_in_cm_memo ?></td>
+<td><?= $subRecord->why_not_enrolled_in_rm_category ?></td>
+<td><?= $subRecord->why_not_enrolled_in_rm_memo ?></td>
+<td><?= $subRecord->work_phone_number ?></td>
+<td><?= $subRecord->created_by_session_id ?></td>
+<td><?= $subRecord->deactivated_by_session_id ?></td>
+<td><?= $subRecord->reactivated_by_session_id ?></td>
+<td><?= $subRecord->ally_pro_id ?></td>
+<td><?= $subRecord->mcp_em_visit_note_id ?></td>
+<td><?= $subRecord->mcp_pro_id ?></td>
+<td><?= $subRecord->team_id ?></td>
+<td><?= $subRecord->cm_target ?></td>
+                    </tr>
+                @endforeach
+                </tbody>
+            </table>
+        </div>
+        
+    </div>
 
 @endsection