|
@@ -3,6 +3,7 @@
|
|
namespace App\Console\Commands;
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Console\Command;
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class GenerateTreeCommand extends Command
|
|
class GenerateTreeCommand extends Command
|
|
{
|
|
{
|
|
@@ -79,6 +80,7 @@ class GenerateTreeCommand extends Command
|
|
$currentSubController = new GenController($currentRoot, $currentController->name . "_SINGLE");
|
|
$currentSubController = new GenController($currentRoot, $currentController->name . "_SINGLE");
|
|
$currentSubController->dbTable = $currentController->dbTable;
|
|
$currentSubController->dbTable = $currentController->dbTable;
|
|
$currentSubController->parentRoute = "/" . $line;
|
|
$currentSubController->parentRoute = "/" . $line;
|
|
|
|
+ $currentSubController->sub = true;
|
|
$newMethod->redirect = "/" . $line . "/SUB_dashboard";
|
|
$newMethod->redirect = "/" . $line . "/SUB_dashboard";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -146,10 +148,6 @@ class GenerateTreeCommand extends Command
|
|
return $count;
|
|
return $count;
|
|
}
|
|
}
|
|
|
|
|
|
- private function initRoutesFile() {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
class GenController {
|
|
class GenController {
|
|
@@ -158,8 +156,8 @@ class GenController {
|
|
public $name;
|
|
public $name;
|
|
public $methods;
|
|
public $methods;
|
|
public $parentRoute = "";
|
|
public $parentRoute = "";
|
|
- public $single = false;
|
|
|
|
public $dbTable = null;
|
|
public $dbTable = null;
|
|
|
|
+ public $sub = false;
|
|
public function __construct($root = null, $name = null)
|
|
public function __construct($root = null, $name = null)
|
|
{
|
|
{
|
|
$this->root = $root;
|
|
$this->root = $root;
|
|
@@ -179,7 +177,7 @@ class GenController {
|
|
$this->saveController();
|
|
$this->saveController();
|
|
$this->saveRoutes();
|
|
$this->saveRoutes();
|
|
$this->saved = true;
|
|
$this->saved = true;
|
|
- $this->log();
|
|
|
|
|
|
+// $this->log();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public function saveController() {
|
|
public function saveController() {
|
|
@@ -202,6 +200,7 @@ class GenController {
|
|
$code[] = "\t\t\$records = DB::table('{$this->dbTable}')->get();";
|
|
$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'));";
|
|
}
|
|
}
|
|
|
|
+ $this->saveView($this, $method);
|
|
}
|
|
}
|
|
|
|
|
|
$code[] = "\t}";
|
|
$code[] = "\t}";
|
|
@@ -210,6 +209,58 @@ class GenController {
|
|
$text = str_replace("// __METHODS__", implode("\n", $code), $text);
|
|
$text = str_replace("// __METHODS__", implode("\n", $code), $text);
|
|
file_put_contents(app_path("Http/Controllers/{$this->name}_Controller.php"), $text);
|
|
file_put_contents(app_path("Http/Controllers/{$this->name}_Controller.php"), $text);
|
|
echo "Generated " . app_path("Http/Controllers/{$this->name}_Controller.php") . "\n";
|
|
echo "Generated " . app_path("Http/Controllers/{$this->name}_Controller.php") . "\n";
|
|
|
|
+ }
|
|
|
|
+ public function saveView(GenController $controller, GenControllerMethod $method) {
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ $x = DB::getSchemaBuilder()->getColumnListing('client');
|
|
|
|
+ print_r($x);
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ if($controller->sub) {
|
|
|
|
+ $this->saveSubView($controller, $method);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ if($method->name === 'view') {
|
|
|
|
+ $this->saveShowView($controller, $method);
|
|
|
|
+ }
|
|
|
|
+ else if($method->name === 'index') {
|
|
|
|
+ $this->saveIndexView($controller, $method);
|
|
|
|
+ }
|
|
|
|
+ else if($method->name === 'add_new') {
|
|
|
|
+ $this->saveAddNewView($controller, $method);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ public function saveIndexView(GenController $controller, GenControllerMethod $method)
|
|
|
|
+ {
|
|
|
|
+ $text = file_get_contents(base_path('generatecv/tree-templates/index.template.blade.php'));
|
|
|
|
+ $text = str_replace("_NAME_", $controller->name, $text);
|
|
|
|
+ $text = str_replace("_ADD_NEW_ROUTE_", $controller->name . '-add_new', $text);
|
|
|
|
+ $columns = DB::getSchemaBuilder()->getColumnListing($controller->dbTable);
|
|
|
|
+ $ths = [];
|
|
|
|
+ $tds = [];
|
|
|
|
+ foreach ($columns as $column) {
|
|
|
|
+ $ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
|
|
+ $tds[] = "<td><?= \$record->$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 saveShowView(GenController $controller, GenControllerMethod $method)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ public function saveSubView(GenController $controller, GenControllerMethod $method)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ public function saveAddNewView(GenController $controller, GenControllerMethod $method)
|
|
|
|
+ {
|
|
|
|
+
|
|
}
|
|
}
|
|
public function saveRoutes() {
|
|
public function saveRoutes() {
|
|
$lines = ["// --- {$this->root}: {$this->name} --- //"];
|
|
$lines = ["// --- {$this->root}: {$this->name} --- //"];
|
|
@@ -243,6 +294,22 @@ class GenController {
|
|
for($i=0; $i<$level; $i++) echo "\t";
|
|
for($i=0; $i<$level; $i++) echo "\t";
|
|
echo "$line\n";
|
|
echo "$line\n";
|
|
}
|
|
}
|
|
|
|
+ private function snakeToTitleCase($text) {
|
|
|
|
+ return ucwords(str_replace("_", " ", $text));
|
|
|
|
+ }
|
|
|
|
+ private function file_force_contents($dir, $contents){
|
|
|
|
+ $dir = str_replace("\\", "/", $dir);
|
|
|
|
+ $dir = str_replace( '//', '/', $dir);
|
|
|
|
+ $parts = explode('/', $dir);
|
|
|
|
+ $file = array_pop($parts);
|
|
|
|
+ $dir = '';
|
|
|
|
+ foreach($parts as $part) {
|
|
|
|
+ if($part[strlen($part) - 1] !== ':') {
|
|
|
|
+ if(!is_dir($dir .= "/$part")) mkdir($dir);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ file_put_contents("$dir/$file", $contents);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
class GenControllerMethod {
|
|
class GenControllerMethod {
|