Эх сурвалжийг харах

Generator for add-new pages

Vijayakrishnan Krishnan 5 жил өмнө
parent
commit
a9cae65f2a

+ 26 - 2
app/Console/Commands/GenerateTreeCommand.php

@@ -268,7 +268,7 @@ class GenController {
 
         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>";
+                "<i class='fa fa-plus-circle' aria-hidden='true'></i> Add New</a>";
             $text = str_replace("<!-- _ADD_NEW_LINK_ -->", $addLink, $text);
         }
 
@@ -367,7 +367,25 @@ class GenController {
     }
     public function saveAddNewView(GenController $controller, GenControllerMethod $method)
     {
-
+        $text = file_get_contents(base_path('generatecv/tree-templates/add_new.template.blade.php'));
+        $text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
+        $text = str_replace("_BACK_ROUTE_", "{$controller->name}-index", $text);
+        $columns = DB::getSchemaBuilder()->getColumnListing($controller->dbTable);
+        $fields = [];
+        foreach ($columns as $column) {
+            if(in_array($column,
+                    ['id', 'uid', 'created_at',
+                        'deactivated_at', 'deactivation_memo',
+                        'reactivated_at', 'reactivation_memo']) === true) continue;
+            $fields[] =
+                "<div class='form-group mb-3'>" .
+                    "<label class='control-label'>{$this->snakeToTitleCase($column)}</label>" .
+                    "<input class='form-control' type='text' name='{$this->snakeToCamelCase($column)}'>" .
+                "</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 saveRoutes() {
         $lines = ["// --- {$this->root}: {$this->name} --- //"];
@@ -410,6 +428,12 @@ class GenController {
         $text = preg_replace("/([a-z])([A-Z])/", "$1 $2", $text);
         return ucwords($text);
     }
+    public function snakeToCamelCase($text) {
+        $text = ucwords(str_replace("_", " ", $text));
+        $text = str_replace(" ", "", $text);
+        $text[0] = strtolower($text[0]);
+        return $text;
+    }
     private function file_force_contents($dir, $contents){
         $dir = str_replace("\\", "/", $dir);
         $dir = str_replace( '//', '/', $dir);

+ 23 - 0
generatecv/tree-templates/add_new.template.blade.php

@@ -0,0 +1,23 @@
+@extends('layouts.pro-logged-in')
+@section('content')
+
+    <h2 class="d-flex mb-3 border-bottom pb-3">
+        <div>_NAME_: Add New</div>
+        <div class="ml-auto">
+            <a class="btn btn-primary btn-sm" href="{{route('_BACK_ROUTE_')}}">
+                <i class="fa fa-chevron-left" aria-hidden="true"></i>
+                Back
+            </a>
+        </div>
+    </h2>
+
+
+    <form action="_ACTION_" enctype="multipart/form-data">
+        <!-- _SCAFFOLD_FIELDS_ -->
+        <div class="form-group mb-3">
+            <button class="btn btn-sm btn-primary mr-3 px-5">Save</button>
+            <a href="{{route('_BACK_ROUTE_')}}" class="btn btn-sm btn-default px-5">Cancel</a>
+        </div>
+    </form>
+
+@endsection

+ 4 - 4
generatecv/tree.txt

@@ -58,16 +58,16 @@ PRO
             med_profile_log
             pro_access
             notes
-            notes/add_new
+#           notes/add_new
             care_months
-            care_months/add_new
+#           care_months/add_new
             care_month_entries
             bills
             related_transactions
             action_items
-            action_items/add_new
+#           action_items/add_new
             erx
-            erx/add_new
+#           erx/add_new
             mcp_updates
             ally_updates
             audit_log