|
@@ -50,6 +50,10 @@ class GenerateTreeCommand extends Command
|
|
$currentView = "";
|
|
$currentView = "";
|
|
|
|
|
|
foreach ($lines as $line) {
|
|
foreach ($lines as $line) {
|
|
|
|
+
|
|
|
|
+ // skip comments
|
|
|
|
+ if(trim($line)[0] === '#') continue;
|
|
|
|
+
|
|
$lineType = null;
|
|
$lineType = null;
|
|
|
|
|
|
// no leading space - root specifier
|
|
// no leading space - root specifier
|
|
@@ -64,10 +68,13 @@ class GenerateTreeCommand extends Command
|
|
$tokens = explode("|", $line);
|
|
$tokens = explode("|", $line);
|
|
$line = $tokens[0];
|
|
$line = $tokens[0];
|
|
$dbTable = null;
|
|
$dbTable = null;
|
|
- if(count($tokens) === 2) {
|
|
|
|
|
|
+ if(count($tokens) >= 2) {
|
|
$dbTable = $tokens[1];
|
|
$dbTable = $tokens[1];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ $hasAdd = in_array("add", $tokens);
|
|
|
|
+ $hasView = in_array("view", $tokens);
|
|
|
|
+
|
|
switch($ls) {
|
|
switch($ls) {
|
|
|
|
|
|
case 4: // top level controller OR top level controller action
|
|
case 4: // top level controller OR top level controller action
|
|
@@ -95,6 +102,8 @@ class GenerateTreeCommand extends Command
|
|
}
|
|
}
|
|
$currentController = new GenController($currentRoot, $line);
|
|
$currentController = new GenController($currentRoot, $line);
|
|
$currentController->dbTable = $dbTable;
|
|
$currentController->dbTable = $dbTable;
|
|
|
|
+ $currentController->hasAdd = $hasAdd;
|
|
|
|
+ $currentController->hasView = $hasView;
|
|
$currentController->addMethod("index", "/$line");
|
|
$currentController->addMethod("index", "/$line");
|
|
if(!empty($currentSubController)) {
|
|
if(!empty($currentSubController)) {
|
|
$currentSubController->save();
|
|
$currentSubController->save();
|
|
@@ -171,6 +180,8 @@ class GenController {
|
|
public $methods;
|
|
public $methods;
|
|
public $parentRoute = "";
|
|
public $parentRoute = "";
|
|
public $dbTable = null;
|
|
public $dbTable = null;
|
|
|
|
+ public $hasAdd = false;
|
|
|
|
+ public $hasView = false;
|
|
public $sub = false;
|
|
public $sub = false;
|
|
public $parentControllerName = '';
|
|
public $parentControllerName = '';
|
|
public function __construct($root = null, $name = null)
|
|
public function __construct($root = null, $name = null)
|
|
@@ -238,13 +249,13 @@ class GenController {
|
|
$this->saveSubView($controller, $method);
|
|
$this->saveSubView($controller, $method);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- if($method->name === 'view') {
|
|
|
|
|
|
+ if($method->name === 'view' && $controller->hasView) {
|
|
$this->saveShowView($controller, $method);
|
|
$this->saveShowView($controller, $method);
|
|
}
|
|
}
|
|
else if($method->name === 'index') {
|
|
else if($method->name === 'index') {
|
|
$this->saveIndexView($controller, $method);
|
|
$this->saveIndexView($controller, $method);
|
|
}
|
|
}
|
|
- else if($method->name === 'add_new') {
|
|
|
|
|
|
+ else if($method->name === 'add_new' && $controller->hasAdd) {
|
|
$this->saveAddNewView($controller, $method);
|
|
$this->saveAddNewView($controller, $method);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -254,16 +265,22 @@ class GenController {
|
|
{
|
|
{
|
|
$text = file_get_contents(base_path('generatecv/tree-templates/index.template.blade.php'));
|
|
$text = file_get_contents(base_path('generatecv/tree-templates/index.template.blade.php'));
|
|
$text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
|
|
$text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
|
|
- $text = str_replace("_ADD_NEW_ROUTE_", $controller->name . '-add_new', $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);
|
|
|
|
+ }
|
|
|
|
+
|
|
$columns = DB::getSchemaBuilder()->getColumnListing($controller->dbTable);
|
|
$columns = DB::getSchemaBuilder()->getColumnListing($controller->dbTable);
|
|
$ths = [];
|
|
$ths = [];
|
|
$tds = [];
|
|
$tds = [];
|
|
foreach ($columns as $column) {
|
|
foreach ($columns as $column) {
|
|
$ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
$ths[] = "<th>{$this->snakeToTitleCase($column)}</th>";
|
|
$tds[] = "<td>" .
|
|
$tds[] = "<td>" .
|
|
- ($column === 'uid' ? '<a href="/' . $controller->name . '/view/<?= $record->uid ?>">' : '') .
|
|
|
|
|
|
+ ($controller->hasView && $column === 'uid' ? '<a href="/' . $controller->name . '/view/<?= $record->uid ?>">' : '') .
|
|
"<?= \$record->$column ?>" .
|
|
"<?= \$record->$column ?>" .
|
|
- ($column === 'uid' ? '</a>' : '') .
|
|
|
|
|
|
+ ($controller->hasView && $column === 'uid' ? '</a>' : '') .
|
|
"</td>";
|
|
"</td>";
|
|
}
|
|
}
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|
|
$text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
|