GenerateTreeCommand.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class GenerateTreeCommand extends Command
  6. {
  7. private $routesFile = null;
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'generatetree
  14. {path: /path/to/tree.txt}';
  15. /**
  16. * Execute the console command.
  17. *
  18. * @return mixed
  19. */
  20. public function handle()
  21. {
  22. $lines = ['<?php', '', 'use Illuminate\Support\Facades\Route;', '', ''];
  23. file_put_contents(base_path("routes/generated.php"), implode("\n", $lines));
  24. $sideLinks = [];
  25. global $argv;
  26. $file = fopen($argv[2], "r");
  27. $lines = [];
  28. while (!feof($file)) {
  29. $line = rtrim(fgets($file));
  30. if(trim($line) !== '') {
  31. $lines[] = str_replace("\t", " ", $line);
  32. }
  33. }
  34. fclose($file);
  35. $currentRoot = "";
  36. $currentController = new GenController();
  37. $currentSubController = new GenController();
  38. $currentSubType = "";
  39. $currentView = "";
  40. $currentMethod = null;
  41. foreach ($lines as $line) {
  42. // skip comments
  43. if(trim($line)[0] === '#') continue;
  44. $lineType = null;
  45. // no leading space - root specifier
  46. if($line[0] !== ' ') {
  47. $currentRoot = strtolower(trim($line));
  48. }
  49. else {
  50. $ls = $this->numLS($line);
  51. $line = trim($line);
  52. $exitURL = false;
  53. if(strpos($line, "=>") !== FALSE) {
  54. $parts = explode("=>", $line);
  55. $exitURL = str_replace("UID", "{{ \$subRecord->uid }}", $parts[1]);
  56. $line = $parts[0];
  57. }
  58. $tokens = explode("|", $line);
  59. $line = $tokens[0];
  60. $dbTable = null;
  61. $condition = null;
  62. if(count($tokens) >= 2) {
  63. $dbTable = $tokens[1];
  64. // check if table has loading conditions
  65. if(strpos($dbTable, ":")) {
  66. $parts = explode(":", $dbTable);
  67. $dbTable = $parts[0];
  68. $parts = explode("=", $parts[1]);
  69. $condition = [
  70. "field" => $parts[0],
  71. "value" => str_replace("OWN", "session('proId')" , $parts[1])
  72. ];
  73. }
  74. }
  75. $hasAdd = in_array("add", $tokens);
  76. $hasView = in_array("view", $tokens);
  77. $hasRemove = in_array("remove", $tokens);
  78. $icon = "user";
  79. if(strpos($tokens[count($tokens) - 1], "icon:") === 0) {
  80. $icon = substr($tokens[count($tokens) - 1], 5);
  81. }
  82. switch($ls) {
  83. case 4: // top level controller OR top level controller action
  84. // top level controller-action
  85. if(strpos($line, "/") !== FALSE) {
  86. if(!empty($currentController)) {
  87. $parts = explode(":", $line);
  88. $line = $parts[0];
  89. $method = explode("/", $line)[1];
  90. $newMethod = $currentController->addMethod($method, "/" . $line);
  91. if(count($parts) > 1) {
  92. $newMethod->api = $parts[count($parts) - 1];
  93. }
  94. // create _SINGLE_ controller if view
  95. if($method === "view") {
  96. $currentSubController = new GenController($currentRoot, $currentController->name . "_SINGLE");
  97. $currentSubController->dbTable = $currentController->dbTable;
  98. $currentSubController->parentRoute = "/" . $line;
  99. $currentSubController->parentControllerName = $currentController->name;
  100. $currentSubController->sub = true;
  101. $newMethod->redirect = "/" . $line . "/SUB_dashboard";
  102. }
  103. else if(strpos($method, "add_new") === 0) {
  104. $newMethod->type = 'add';
  105. }
  106. else if(strpos($method, "remove") === 0) {
  107. $newMethod->type = 'remove';
  108. }
  109. $currentMethod = $newMethod;
  110. }
  111. }
  112. // new top level controller
  113. else if(empty($currentController) || $line !== $currentController->name) {
  114. if(!empty($currentController)) {
  115. $currentController->save();
  116. }
  117. $currentController = new GenController($currentRoot, $line, $icon);
  118. $currentController->dbTable = $dbTable;
  119. $currentController->condition = $condition;
  120. $currentController->hasAdd = $hasAdd;
  121. $currentController->hasView = $hasView;
  122. $currentController->hasRemove = $hasRemove;
  123. $currentMethod = $currentController->addMethod("index", "/$line");
  124. if(!empty($currentSubController)) {
  125. $currentSubController->save();
  126. }
  127. $currentSubType = '';
  128. $currentSubController = new GenController();
  129. $sideLinks[] = "<li class='nav-item'><a href='/{$currentController->name}' " .
  130. "class='nav-link " .
  131. "{{ (isset(request()->route()->getController()->selfName) && strpos(request()->route()->getController()->selfName, '{$currentController->name}') === 0 ? 'active' : '') }}" . " '>" .
  132. "<i class='nav-icon fa fa-$icon'></i>" .
  133. "<p>" . $currentController->snakeToTitleCase($currentController->name) . "</p>" .
  134. "</a></li>";
  135. }
  136. break;
  137. case 8: // sub-type declaration | add_new fields | !inc/!exc
  138. if($line === 'ACTIONS' || $line === 'SUB') {
  139. $currentSubType = $line;
  140. }
  141. else if(strpos($line, "!inc:") === 0) { // !inc:
  142. if (!empty($currentMethod)) {
  143. $currentMethod->setIncFields('include', explode(",", substr($line, 5)));
  144. }
  145. }
  146. else if(strpos($line, "!exc:") === 0) { // !exc:
  147. if (!empty($currentMethod)) {
  148. $currentMethod->setIncFields('exclude', explode(",", substr($line, 5)));
  149. }
  150. }
  151. else if(strpos($line, "!lnk:") === 0) { // !lnk:
  152. if (!empty($currentMethod)) {
  153. $currentMethod->viewLinkField = substr($line, 5);
  154. }
  155. }
  156. else if(strpos($line, "!col:") === 0) { // !col:
  157. if (!empty($currentMethod)) {
  158. $currentMethod->setColumnSpec(substr($line, 5), $exitURL, 'record');
  159. }
  160. }
  161. else if (!empty($currentMethod) &&
  162. (strpos($currentMethod->name, 'add_new') === 0 ||
  163. $currentMethod->name === 'remove')) { // this is a field in add_new
  164. $currentMethod->data[] = $line;
  165. }
  166. break;
  167. case 12: // ACTIONS | SUB
  168. // check if this has show conditions
  169. $show = false;
  170. if(strpos($line, ":")) {
  171. $parts = explode(":", $line);
  172. $line = $parts[0];
  173. if($parts[1] === 'if') {
  174. $show = $parts[2];
  175. }
  176. }
  177. if($currentSubType === 'ACTIONS') {
  178. $currentMethod = $currentSubController->addMethod(
  179. "ACTION_" . $line,
  180. "/ACTION_" . $line
  181. );
  182. $currentMethod->type = 'action';
  183. $currentMethod->show = $show;
  184. $currentMethod->data = [];
  185. }
  186. else if($currentSubType === 'SUB') {
  187. $currentMethod = $currentSubController->addMethod(
  188. "SUB_" . $line,
  189. "/SUB_" . $line
  190. );
  191. $currentMethod->type = 'sub';
  192. $currentMethod->show = $show;
  193. $currentMethod->data = [];
  194. }
  195. break;
  196. case 16: // data for actions and subs
  197. if(strpos($line, "!inc:") === 0) { // !inc:
  198. if (!empty($currentMethod)) {
  199. $currentMethod->setIncFields('include', explode(",", substr($line, 5)));
  200. }
  201. }
  202. else if(strpos($line, "!exc:") === 0) { // !exc:
  203. if (!empty($currentMethod)) {
  204. $currentMethod->setIncFields('exclude', explode(",", substr($line, 5)));
  205. }
  206. }
  207. else if(strpos($line, "!lnk:") === 0) { // !lnk:
  208. if (!empty($currentMethod)) {
  209. $currentMethod->viewLinkField = substr($line, 5);
  210. }
  211. }
  212. else if(strpos($line, "!col:") === 0) { // !col:
  213. if (!empty($currentMethod)) {
  214. $currentMethod->setColumnSpec(substr($line, 5), $exitURL,
  215. $currentMethod->name === 'SUB_dashboard' ? 'record' : 'subRecord'
  216. );
  217. }
  218. }
  219. else if(strpos($line, "!grp:") === 0) { // !grp:
  220. if (!empty($currentMethod)) {
  221. $currentMethod->addGroup(substr($line, 5));
  222. }
  223. }
  224. else if(strpos($line, "!act:") === 0) { // !act:
  225. if (!empty($currentMethod)) {
  226. $currentMethod->addColumnAction(substr($line, 5), $exitURL);
  227. }
  228. }
  229. else if(!empty($currentMethod)) {
  230. $currentMethod->data[] = $line;
  231. if($exitURL) {
  232. if(strpos("=", $line) !== FALSE) {
  233. $currentMethod->viewURL = $exitURL;
  234. }
  235. else {
  236. $currentMethod->exitURL = $exitURL;
  237. }
  238. }
  239. }
  240. break;
  241. case 20: // SUB add_new fields
  242. if(!empty($currentMethod)) {
  243. $currentMethod->data[] = $line;
  244. }
  245. break;
  246. default:
  247. dump("ERROR: Cannot have $ls leading spaces!");
  248. dump("Line: $line");
  249. exit(1);
  250. }
  251. }
  252. }
  253. // do any pending saves
  254. if(!empty($currentSubController)) {
  255. $currentSubController->save();
  256. }
  257. if(!empty($currentController)) {
  258. $currentController->save();
  259. }
  260. echo "Saved " . base_path("routes/generated.php") . "\n";
  261. // save side links
  262. file_put_contents(resource_path("views/layouts/generated-links.blade.php"), implode("\n", $sideLinks));
  263. echo "Saved " . resource_path("views/layouts/generated-links.blade.php") . "\n";
  264. }
  265. private function numLS($line) {
  266. $count = 0;
  267. for ($i=0; $i<strlen($line); $i++) {
  268. if($line[$i] !== ' ') break;
  269. $count++;
  270. }
  271. return $count;
  272. }
  273. }
  274. class GenController {
  275. public $root;
  276. public $saved = false;
  277. public $name;
  278. public $methods;
  279. public $parentRoute = "";
  280. public $dbTable = null;
  281. public $condition = null;
  282. public $hasAdd = false;
  283. public $hasView = false;
  284. public $hasRemove = false;
  285. public $sub = false;
  286. public $parentControllerName = '';
  287. public $subLinksSaved = false;
  288. public $actionLinksSaved = false;
  289. public $icon = "user";
  290. public function __construct($root = null, $name = null, $icon = "user")
  291. {
  292. $this->root = $root;
  293. $this->name = $name;
  294. $this->icon = $icon;
  295. $this->methods = [];
  296. }
  297. public function addMethod($method, $route) {
  298. if($this->parentRoute) {
  299. $route = $this->parentRoute . $route;
  300. }
  301. $method = new GenControllerMethod($method, $route);
  302. $this->methods[] = $method;
  303. return $method;
  304. }
  305. public function save() {
  306. if(!$this->saved && !empty($this->root) && !empty($this->name)) {
  307. $this->saveController();
  308. $this->saveRoutes();
  309. $this->saved = true;
  310. // $this->log();
  311. }
  312. }
  313. public function saveController() {
  314. $text = file_get_contents(base_path('generatecv/tree-templates/controller.template.php'));
  315. $code = [];
  316. // check if any method has a "sub add_new" in it, if yes, add action for the same
  317. $newMethods = [];
  318. foreach ($this->methods as $method) {
  319. if($method->type === 'sub' && count($method->data) > 1 && strpos($method->data[1], 'add_new') === 0) {
  320. $methodName = preg_replace("/^SUB_/", "ACTION_", $method->name) . 'AddNew';
  321. $methodRoute = str_replace("/SUB_", "/ACTION_", $method->route) . 'AddNew';
  322. $newMethod = new GenControllerMethod($methodName, $methodRoute);
  323. $newMethod->hasUID = true;
  324. $newMethod->redirect = false;
  325. $newMethod->type = 'action';
  326. $newMethod->data = [];
  327. for($i = 2; $i<count($method->data); $i++) {
  328. $newMethod->data[] = $method->data[$i];
  329. }
  330. $newMethod->parentSub = $this->name . '-' . $method->name;
  331. $parts = explode(":", $method->data[1]);
  332. $newMethod->table = $parts[1];
  333. if(count($parts) === 3) {
  334. $newMethod->api = $parts[2];
  335. }
  336. $newMethod->exitURL = $method->exitURL;
  337. $newMethod->showLink = false;
  338. $newMethods[] = $newMethod;
  339. $method->childAddRoute = $this->name . '-' . $methodName;
  340. }
  341. }
  342. $this->methods = array_merge($this->methods, $newMethods);
  343. foreach ($this->methods as $method) {
  344. $code[] = "";
  345. $code[] = "\t// GET {$method->route}";
  346. $code[] = "\t" . 'public function ' . $method->name . '(Request $request' . ($method->hasUID ? ', $uid' : '') . ') {';
  347. if($method->redirect) {
  348. $target = str_replace('{uid}', '$uid', $method->redirect);
  349. $code[] = "\t\t" . 'return redirect("' . $target . '");';
  350. }
  351. else {
  352. if($method->hasUID) {
  353. $code[] = "\t\t\$record = DB::table('{$this->dbTable}')->where('uid', \$uid)->first();";
  354. $input = ["'record'"];
  355. // if sub-index controller, load subRecords
  356. if($method->type === 'sub' && count($method->data)) {
  357. $parts = explode(",", $method->data[0]);
  358. $loadingLine = [];
  359. // first 'where'
  360. $dbParts = explode("=", $parts[0]);
  361. $localField = $dbParts[0];
  362. $dbParts = explode(".", $dbParts[1]);
  363. $foreignTable = $dbParts[0];
  364. $foreignField = $dbParts[1];
  365. $loadingLine[] = "\t\t\$subRecords = DB::table('$foreignTable')";
  366. $loadingLine[] = "->where('$foreignField', \$record->$localField)";
  367. // other 'where's
  368. if(count($parts) > 1) {
  369. for ($i = 1; $i < count($parts); $i++) {
  370. $dbParts = explode("=", $parts[$i]);
  371. $field = $dbParts[0];
  372. $value = $dbParts[1];
  373. $loadingLine[] = "->where('$field', $value)";
  374. }
  375. }
  376. $loadingLine[] = "->get();";
  377. $code[] = implode("", $loadingLine);
  378. // $code[] = "\t\t\$subRecords = DB::table('$foreignTable')->where('$foreignField', \$record->$localField)->get();";
  379. $input[] = "'subRecords'";
  380. }
  381. // return response()->view('pro/my_teams/add_new', compact('records'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
  382. $code[] = "\t\treturn response()->view('{$this->root}/{$this->name}/{$method->name}', " .
  383. "compact(" . implode(", ", $input) . "), " .
  384. "session('message') ? 500 : 200)->header('Content-Type', 'text/html');";
  385. }
  386. else {
  387. $loadingLine = [];
  388. $loadingLine[] = "\t\t\$records = DB::table('{$this->dbTable}')";
  389. if($this->condition) {
  390. $loadingLine[] = "->where('{$this->condition['field']}', {$this->condition['value']})";
  391. }
  392. $loadingLine[] = "->get();";
  393. $code[] = implode("", $loadingLine);
  394. $code[] = "\t\treturn response()->view('{$this->root}/{$this->name}/{$method->name}', " .
  395. "compact('records'), " .
  396. "session('message') ? 500 : 200)->header('Content-Type', 'text/html');";
  397. }
  398. }
  399. $this->saveView($this, $method);
  400. $code[] = "\t}";
  401. }
  402. $text = str_replace("_NAME_", "{$this->name}_Controller", $text);
  403. $text = str_replace("// __METHODS__", implode("\n", $code), $text);
  404. file_put_contents(app_path("Http/Controllers/{$this->name}_Controller.php"), $text);
  405. echo "Generated " . app_path("Http/Controllers/{$this->name}_Controller.php") . "\n";
  406. }
  407. public function saveView(GenController $controller, GenControllerMethod $method) {
  408. if($controller->sub) {
  409. $controller->saveSubLinks($controller, $method);
  410. $controller->saveActionLinks($controller, $method);
  411. if($method->type === 'action') {
  412. $this->saveSubActionView($controller, $method);
  413. }
  414. else if($method->type === 'sub' && count($method->data)) {
  415. $this->saveSubIndexView($controller, $method);
  416. }
  417. else {
  418. $this->saveSubDefaultView($controller, $method);
  419. }
  420. }
  421. else {
  422. if($method->name === 'view' && $controller->hasView) {
  423. $this->saveShowView($controller, $method);
  424. }
  425. else if($method->name === 'index') {
  426. $this->saveIndexView($controller, $method);
  427. }
  428. else if(strpos($method->name, 'add_new') === 0 && $controller->hasAdd) {
  429. $this->saveAddNewView($controller, $method);
  430. }
  431. else if($method->name === 'remove' && $controller->hasRemove) {
  432. $this->saveAddNewView($controller, $method);
  433. }
  434. }
  435. }
  436. public function saveIndexView(GenController $controller, GenControllerMethod $method)
  437. {
  438. $text = file_get_contents(base_path('generatecv/tree-templates/index.template.blade.php'));
  439. $text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
  440. if($controller->hasAdd) {
  441. $addLinks = [];
  442. foreach ($controller->methods as $m) {
  443. if($m->type === 'add') {
  444. $addLinks[] = "<a class='btn btn-primary btn-sm ml-2' " .
  445. 'up-modal=".form-contents" up-width="800" up-history="false" ' .
  446. "href='/{$controller->name}/{$m->name}'>" .
  447. "<i class='fa fa-plus-circle' aria-hidden='true'></i> " .
  448. "{$this->snakeToTitleCase($m->name)}</a>";
  449. }
  450. }
  451. $text = str_replace("<!-- _ADD_NEW_LINK_ -->", implode("\n", $addLinks), $text);
  452. }
  453. $columns = DB::getSchemaBuilder()->getColumnListing($controller->dbTable);
  454. $ths = [];
  455. $tds = [];
  456. if($controller->hasRemove) {
  457. $ths[] = "<th></th>";
  458. $tds[] = "<td><a href='/{$controller->name}/remove/<?= \$record->uid ?>'>" .
  459. "<i class='fa fa-trash'></i>" .
  460. "</a></td>";
  461. }
  462. // !inc/!exc
  463. if($method->incType === "include") {
  464. $columns = $method->incFields;
  465. }
  466. else if($method->incType === "exclude") {
  467. $columns = array_filter($columns, function($item) use ($method) {
  468. return in_array($item, $method->incFields) === FALSE;
  469. });
  470. }
  471. foreach ($columns as $column) {
  472. $columnTitle = $this->snakeToTitleCase($column);
  473. $columnValue = "<?= \$record->$column ?>";
  474. $hasLink = $controller->hasView && $column === $method->viewLinkField;
  475. $linkTarget = "/{$controller->name}/view/<?= \$record->uid ?>";
  476. // check if this column has column spec
  477. if(isset($method->columns[$column])) {
  478. $columnTitle = $method->columns[$column]["label"];
  479. if(isset($method->columns[$column]["query"])) {
  480. $columnValue = "<?php \$_r = \Illuminate\Support\Facades\DB::" .
  481. "select(\"{$method->columns[$column]["query"]}\");\n" .
  482. "echo (\$_r && count(\$_r)) ? \$_r[0]->result : '-'; ?>";
  483. }
  484. if(isset($method->columns[$column]["link"])) {
  485. $hasLink = true;
  486. $linkTarget = $method->columns[$column]["link"];
  487. }
  488. }
  489. $ths[] = "<th>$columnTitle</th>";
  490. $tds[] = "<td>" .
  491. ($hasLink ? "<a href=\"{$linkTarget}\">" : "") .
  492. $columnValue .
  493. ($hasLink ? "</a>" : "") .
  494. "</td>";
  495. }
  496. $text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
  497. $text = str_replace("<!-- __SCAFFOLD_TDS__ -->", implode("\n", $tds), $text);
  498. $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $text);
  499. echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
  500. }
  501. public function saveShowView(GenController $controller, GenControllerMethod $method)
  502. {
  503. // delete sub links and action links
  504. if(file_exists(resource_path("views/{$controller->root}/{$controller->parentControllerName}/subs.blade.php"))) {
  505. unlink(resource_path("views/{$controller->root}/{$controller->parentControllerName}/subs.blade.php"));
  506. }
  507. if(file_exists(resource_path("views/{$controller->root}/{$controller->parentControllerName}/actions.blade.php"))) {
  508. unlink(resource_path("views/{$controller->root}/{$controller->parentControllerName}/actions.blade.php"));
  509. }
  510. // write info view
  511. $text = file_get_contents(base_path('generatecv/tree-templates/info.template.blade.php'));
  512. $text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
  513. $text = str_replace("_UID_", '<?= $record->uid ?>', $text);
  514. $text = str_replace("_INDEX_ROUTE_", $controller->name . '-index', $text);
  515. $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/info.blade.php"), $text);
  516. echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/info.blade.php") . "\n";
  517. // write main view
  518. $text = file_get_contents(base_path('generatecv/tree-templates/show.template.blade.php'));
  519. $text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
  520. $text = str_replace("_UID_", '<?= $record->uid ?>', $text);
  521. $text = str_replace("_INDEX_ROUTE_", $controller->name . '-index', $text);
  522. $text = str_replace("_SUB_LINKS_VIEW_", "{$controller->root}/{$controller->name}/subs", $text);
  523. $text = str_replace("_INFO_VIEW_", "{$controller->root}/{$controller->name}/info", $text);
  524. $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $text);
  525. echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
  526. }
  527. public function saveSubLinks(GenController $controller, GenControllerMethod $method)
  528. {
  529. if ($controller->subLinksSaved) return;
  530. $subLinksView = resource_path("views/{$controller->root}/{$controller->parentControllerName}/subs.blade.php");
  531. $subLinks = [];
  532. foreach ($controller->methods as $meth) {
  533. if (strpos($meth->name, "SUB_") !== 0 || $meth->showLink === false) continue;
  534. $display = $this->snakeToTitleCase(substr($meth->name, 4));
  535. $subLinks[] = ($meth->show ? "@if(\$record->{$meth->show}) " : "") .
  536. "<a " .
  537. "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
  538. "class='d-block px-3 py-2 border-bottom " .
  539. "{{ request()->route()->getActionMethod() === '{$meth->name}' ? 'bg-secondary text-white font-weight-bold' : '' }}" .
  540. (
  541. $meth->name === 'SUB_dashboard' ?
  542. "{{ strpos(request()->route()->getActionMethod(), 'ACTION_') === 0 ? 'bg-secondary text-white font-weight-bold' : '' }}" :
  543. ""
  544. )
  545. . "'>$display</a>" .
  546. ($meth->show ? " @endif" : "");
  547. }
  548. $this->file_force_contents($subLinksView, implode("\n", $subLinks));
  549. echo "Generated " . $subLinksView . "\n";
  550. $controller->subLinksSaved = true;
  551. }
  552. public function saveActionLinks(GenController $controller, GenControllerMethod $method)
  553. {
  554. if ($controller->actionLinksSaved) return;
  555. $actionLinksView = resource_path("views/{$controller->root}/{$controller->parentControllerName}/actions.blade.php");
  556. $actionLinks = [];
  557. foreach ($controller->methods as $meth) {
  558. if (strpos($meth->name, "ACTION_") !== 0 || $meth->showLink === false) continue;
  559. $display = $this->camelToTitleCase(substr($meth->name, 7));
  560. $actionLinks[] = ($meth->show ? "@if(\$record->{$meth->show}) " : "") .
  561. "<a " .
  562. 'up-modal=".form-contents" up-width="800" up-history="false" ' .
  563. "href='/{$controller->parentControllerName}/view/<?= \$record->uid ?>/{$meth->name}' " .
  564. "class='d-block btn btn-sm btn-default mb-3'>$display</a>" .
  565. ($meth->show ? " @endif" : "");
  566. }
  567. $this->file_force_contents($actionLinksView, implode("\n", $actionLinks));
  568. echo "Generated " . $actionLinksView . "\n";
  569. $controller->actionLinksSaved = true;
  570. }
  571. public function saveSubDefaultView(GenController $controller, GenControllerMethod $method)
  572. {
  573. $text = file_get_contents(base_path('generatecv/tree-templates/sub.template.blade.php'));
  574. $text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
  575. $text = $this->generateSubContent($controller, $method, $text);
  576. $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $text);
  577. echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
  578. }
  579. public function saveSubActionView(GenController $controller, GenControllerMethod $method) {
  580. $text = file_get_contents(base_path('generatecv/tree-templates/sub-action.template.blade.php'));
  581. $text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
  582. $text = str_replace("_NAME_", $this->camelToTitleCase($this->snakeToTitleCase($method->name)), $text);
  583. if(!$method->parentSub) {
  584. $text = str_replace("_BACK_ROUTE_", "{$controller->parentControllerName}-view", $text);
  585. }
  586. else {
  587. $text = str_replace("_BACK_ROUTE_", $method->parentSub, $text);
  588. }
  589. if(!$method->table) {
  590. $text = str_replace("_API_", "/api/{$this->snakeToCamelCase($controller->dbTable)}/" . substr($method->name, 7), $text);
  591. }
  592. else {
  593. $text = str_replace("_API_", "/api/{$this->snakeToCamelCase($method->table)}/{$method->api}", $text);
  594. }
  595. $text = str_replace("_RETURN_ROUTE_", "{$controller->name}-{$method->name}", $text);
  596. $fields = [];
  597. if(count($method->data)) {
  598. foreach ($method->data as $field) {
  599. $fields[] = $this->generateFormField($field);
  600. }
  601. }
  602. $text = str_replace("<!-- _SCAFFOLD_FIELDS_ -->", implode("\n", $fields), $text);
  603. $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $text);
  604. echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
  605. }
  606. public function saveSubIndexView(GenController $controller, GenControllerMethod $method) {
  607. $text = file_get_contents(base_path('generatecv/tree-templates/sub-index.template.blade.php'));
  608. $text = str_replace("_LAYOUT_", "{$controller->root}.{$controller->parentControllerName}.view", $text);
  609. $text = str_replace("_NAME_", $this->camelToTitleCase($this->snakeToTitleCase($method->name)), $text);
  610. if(count($method->data) > 1 && strpos($method->data[1], 'add_new') === 0) {
  611. $addLink = '<a class="btn btn-primary btn-sm" ' .
  612. 'up-modal=".form-contents" up-width="800" up-history="false" ' .
  613. 'href="{{route(\'' . $method->childAddRoute . '\', [\'uid\' => $record->uid])}}">' .
  614. "<i class='fa fa-plus-circle' aria-hidden='true'></i> Add New</a>";
  615. $text = str_replace("<!-- _ADD_NEW_LINK_ -->", $addLink, $text);
  616. }
  617. $dbParts = explode("=", $method->data[0]);
  618. $dbParts = explode(".", $dbParts[1]);
  619. $table = $dbParts[0];
  620. $columns = DB::getSchemaBuilder()->getColumnListing($table);
  621. $ths = [];
  622. $tds = [];
  623. // !inc/!exc
  624. if($method->incType === "include") {
  625. $columns = $method->incFields;
  626. }
  627. else if($method->incType === "exclude") {
  628. $columns = array_filter($columns, function($item) use ($method) {
  629. return in_array($item, $method->incFields) === FALSE;
  630. });
  631. }
  632. foreach ($columns as $column) {
  633. $columnTitle = $this->snakeToTitleCase($column);
  634. $columnValue = "<?= \$subRecord->$column ?>";
  635. $hasLink = $method->exitURL && $column === $method->viewLinkField;
  636. $linkTarget = $method->exitURL;
  637. // check if this column has column spec
  638. if(isset($method->columns[$column])) {
  639. $columnTitle = $method->columns[$column]["label"];
  640. if(isset($method->columns[$column]["query"])) {
  641. $columnValue = "<?php \$_r = \Illuminate\Support\Facades\DB::" .
  642. "select(\"{$method->columns[$column]["query"]}\");\n" .
  643. "echo (\$_r && count(\$_r)) ? \$_r[0]->result : '-'; ?>";
  644. }
  645. if(isset($method->columns[$column]["link"])) {
  646. $hasLink = true;
  647. $linkTarget = $method->columns[$column]["link"];
  648. }
  649. }
  650. $ths[] = "<th>$columnTitle</th>";
  651. $tds[] = "<td>" .
  652. ($hasLink ? "<a href=\"{$linkTarget}\">" : "") .
  653. $columnValue .
  654. ($hasLink ? "</a>" : "") .
  655. "</td>";
  656. }
  657. $text = str_replace("<!-- __SCAFFOLD_THS__ -->", implode("\n", $ths), $text);
  658. $text = str_replace("<!-- __SCAFFOLD_TDS__ -->", implode("\n", $tds), $text);
  659. $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $text);
  660. echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
  661. }
  662. public function generateSubContent(GenController $controller, GenControllerMethod $method, $text) {
  663. if($method->name === 'SUB_dashboard') {
  664. if(!isset($method->groups) || !count($method->groups)) {
  665. $html = file_get_contents(base_path('generatecv/tree-templates/dashboard.template.blade.php'));
  666. }
  667. else {
  668. $html = file_get_contents(base_path('generatecv/tree-templates/dashboard-grouped.template.blade.php'));
  669. $groupsHtml = [];
  670. $groupTemplate = file_get_contents(base_path('generatecv/tree-templates/dashboard-group.template.blade.php'));
  671. foreach ($method->groups as $group) {
  672. $groupHtml = $groupTemplate;
  673. $groupHtml = str_replace("<!-- __GROUP_NAME__ -->", $group["name"], $groupHtml);
  674. $fields = [];
  675. foreach ($group["fields"] as $field) {
  676. $columnTitle = $this->snakeToTitleCase($field);
  677. $columnValue = "<?= \$record->$field ?>";
  678. $hasLink = false;
  679. $linkTarget = null;
  680. $actions = [];
  681. // check if this column has column spec
  682. if(isset($method->columns[$field])) {
  683. $columnTitle = $method->columns[$field]["label"];
  684. if(isset($method->columns[$field]["query"])) {
  685. $columnValue = "<?php \$_r = \Illuminate\Support\Facades\DB::" .
  686. "select(\"{$method->columns[$field]["query"]}\");\n" .
  687. "echo (\$_r && count(\$_r)) ? \$_r[0]->result : '-'; ?>";
  688. }
  689. if(isset($method->columns[$field]["link"])) {
  690. $hasLink = true;
  691. $linkTarget = $method->columns[$field]["link"];
  692. }
  693. }
  694. /*
  695. "is_active" => array:1 [
  696. 0 => array:5 [
  697. "label" => "Deactivate"
  698. "icon" => "edit"
  699. "condition" => "if"
  700. "field" => "is_active"
  701. ]
  702. ]
  703. */
  704. if(isset($method->columnActions[$field])) {
  705. foreach($method->columnActions[$field] as $action) {
  706. $actionLine = [];
  707. if(isset($action["condition"])) {
  708. if($action["condition"] === "if") {
  709. $actionLine[] = "@if(";
  710. }
  711. else {
  712. $actionLine[] = "@if(!";
  713. }
  714. $actionLine[] = "\$record->{$action["field"]})";
  715. }
  716. $actionLine[] = "<a " .
  717. 'up-modal=".form-contents" up-width="800" up-history="false" ' .
  718. "href='{$action["link"]}' title='{$action["label"]}' class='ml-2 text-dark font-weight-normal'>" .
  719. "<i class='fa fa-{$action["icon"]} text-sm'></i>" .
  720. "</a>";
  721. if(isset($action["condition"])) {
  722. $actionLine[] = "@endif";
  723. }
  724. $actionLine = implode(" ", $actionLine);
  725. $actions[] = $actionLine;
  726. }
  727. }
  728. $actions = implode("\n", $actions);
  729. $fields[] = "<tr>" .
  730. "<td class=\"w-25 px-2 text-secondary border-right\">$columnTitle</td>" .
  731. "<td class=\"w-75 px-2 font-weight-bold\">" .
  732. ($hasLink ? "<a href=\"{$linkTarget}\">" : "") .
  733. $columnValue .
  734. ($hasLink ? "</a>" : "") .
  735. $actions .
  736. "</td>" .
  737. "</tr>";
  738. }
  739. $groupHtml = str_replace("<!-- __GROUP_FIELDS__ -->", implode("\n", $fields), $groupHtml);
  740. $groupsHtml[] = $groupHtml;
  741. }
  742. $groupsHtml = implode("\n", $groupsHtml);
  743. $html = str_replace("<!-- _GROUPS_ -->", $groupsHtml, $html);
  744. }
  745. $text = str_replace("_SUB_VIEW_", $html, $text);
  746. $text = str_replace("_ACTION_LINKS_VIEW_", "{$controller->root}/{$controller->parentControllerName}/actions", $text);
  747. }
  748. else {
  749. $text = str_replace("_SUB_VIEW_",
  750. "<h5 class='py-3 border-bottom'>" .
  751. $this->camelToTitleCase($this->snakeToTitleCase($method->name)) . "</h5>" .
  752. "Controller: <b>{$controller->name}</b><br>" .
  753. "Action: <b>{$method->name}()</b><br>" .
  754. "View: <b>{$controller->root}/{$controller->name}/{$method->name}.blade.php</b><br><br>",
  755. $text);
  756. }
  757. return $text;
  758. }
  759. public function saveAddNewView(GenController $controller, GenControllerMethod $method)
  760. {
  761. $text = file_get_contents(base_path('generatecv/tree-templates/add_new.template.blade.php'));
  762. $text = str_replace("_NAME_", $this->snakeToTitleCase($controller->name), $text);
  763. $text = str_replace("_ADD_TITLE_", $this->snakeToTitleCase($method->name), $text);
  764. $text = str_replace("_API_", "/api/{$this->snakeToCamelCase($controller->dbTable)}/{$method->api}", $text);
  765. $text = str_replace("_BACK_ROUTE_", "{$controller->name}-index", $text);
  766. $text = str_replace("_RETURN_ROUTE_", "{$controller->name}-{$method->name}", $text);
  767. $columns = $method->data;
  768. $fields = [];
  769. foreach ($columns as $column) {
  770. $fields[] = $this->generateFormField($column);
  771. }
  772. $text = str_replace("<!-- _SCAFFOLD_FIELDS_ -->", implode("\n", $fields), $text);
  773. $this->file_force_contents(resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php"), $text);
  774. echo "Generated " . resource_path("views/{$controller->root}/{$controller->name}/{$method->name}.blade.php") . "\n";
  775. }
  776. public function saveRoutes() {
  777. $lines = ["// --- {$this->root}: {$this->name} --- //"];
  778. foreach ($this->methods as $method) {
  779. // FORMAT:
  780. // Route::get('/foo/bar/{uid}', 'FooController@bar')->name('foo-action');
  781. $lines[] = "Route::get('{$method->route}', '{$this->name}_Controller@{$method->name}')->name('{$this->name}-{$method->name}');";
  782. }
  783. $lines[] = '';
  784. $lines[] = '';
  785. file_put_contents(base_path("routes/generated.php"), implode("\n", $lines), FILE_APPEND);
  786. }
  787. public function log() {
  788. $this->w('');
  789. $this->w("Controller: app/Http/Controllers/{$this->name}_Controller");
  790. $this->w("Table: {$this->dbTable}");
  791. $this->w('---------------------------------------------');
  792. foreach ($this->methods as $method) {
  793. $this->w('Rout: ' . $method->route, 1);
  794. $this->w('Meth: ' . $method->name . '($request' . ($method->hasUID ? ', $uid' : '') . ')', 1);
  795. if(!empty($method->data)) $this->w('Data: ' . implode(", ", $method->data), 1);
  796. $this->w('Exit: ' . $method->exitURL, 1);
  797. $this->w('View: ' . $method->viewURL, 1);
  798. if(!$method->redirect) {
  799. $this->w('View: ' . resource_path("views/{$this->root}/{$this->name}/{$method->name}.blade.php"), 1);
  800. }
  801. else {
  802. $this->w('Redi: ' . $method->redirect, 1);
  803. }
  804. $this->w('---------------------------------------------');
  805. }
  806. }
  807. public function w($line, $level = -1) {
  808. for($i=0; $i<$level; $i++) echo "\t";
  809. echo "$line\n";
  810. }
  811. public function snakeToTitleCase($text) {
  812. $text = preg_replace("/^(SUB|ACTION)_/", "", $text);
  813. return ucwords(str_replace("_", " ", $text));
  814. }
  815. public function camelToTitleCase($text) {
  816. $text = preg_replace("/^(SUB|ACTION)_/", "", $text);
  817. $text = preg_replace("/([a-z])([A-Z0-9])/", "$1 $2", $text);
  818. return ucwords($text);
  819. }
  820. public function snakeToCamelCase($text) {
  821. $text = ucwords(str_replace("_", " ", $text));
  822. $text = str_replace(" ", "", $text);
  823. $text[0] = strtolower($text[0]);
  824. return $text;
  825. }
  826. private function file_force_contents($dir, $contents){
  827. $dir = str_replace("\\", "/", $dir);
  828. $dir = str_replace( '//', '/', $dir);
  829. $parts = explode('/', $dir);
  830. $file = array_pop($parts);
  831. $dir = '';
  832. foreach($parts as $part) {
  833. if(strlen($part) === 0 || $part[strlen($part) - 1] !== ':') {
  834. if(!is_dir($dir .= "/$part")) mkdir($dir);
  835. }
  836. }
  837. file_put_contents("$dir/$file", $contents);
  838. }
  839. private function generateFormField($line) {
  840. $tokens = explode("=", $line);
  841. $default = false;
  842. if(count($tokens) > 1) {
  843. $default = $tokens[1];
  844. }
  845. $tokens = explode(":", $tokens[0]);
  846. $name = $tokens[0];
  847. $required = false;
  848. if($name[strlen($name) - 1] === '*') { // required field?
  849. $required = true;
  850. $name = substr($name, 0, strlen($name) - 1);
  851. }
  852. $display = $name;
  853. $dotPos = strpos($name, ".");
  854. if($dotPos !== FALSE) {
  855. $display = substr($name, $dotPos + 1);
  856. }
  857. $display = preg_replace('/uid$/i', "", $display);
  858. $type = "text";
  859. $options = [];
  860. if(count($tokens) > 1) {
  861. $type = $tokens[1];
  862. switch ($type) {
  863. case "select":
  864. $options = explode(",", $tokens[2]);
  865. break;
  866. case "record":
  867. $options['table'] = $tokens[2];
  868. $parts = explode(",", $tokens[3]);
  869. $options['valueField'] = $parts[0];
  870. $options['displayField'] = $parts[1];
  871. break;
  872. }
  873. }
  874. if($type !== 'hidden' && $type !== 'bool') {
  875. $code[] = "<div class='form-group mb-3'>";
  876. $code[] = "<label class='control-label'>{$this->camelToTitleCase($this->snakeToTitleCase($display))} " .
  877. ($required ? "*" : "") .
  878. "</label>";
  879. }
  880. $valueLine = "value='{{ old('$name') ? old('$name') : " . ($default ? "\$record->$default" : '\'\'') . " }}' ";
  881. switch ($type) {
  882. case "select":
  883. $code[] = "<select class='form-control' name='$name' " . $valueLine .
  884. ($required ? "required" : "") .
  885. ">";
  886. $code[] = "<option value=''>-- Select --</option>";
  887. foreach ($options as $o) {
  888. $code[] = "<option " .
  889. "<?= '$o' === (old('$name') ? old('$name') : " . ($default ? "\$record->$default" : "''") . ") ? 'selected' : '' ?> " .
  890. "value='$o'>$o</option>";
  891. }
  892. $code[] = "</select>";
  893. break;
  894. case "record":
  895. $code[] = "<select class='form-control' name='$name' " . $valueLine .
  896. ($required ? "required" : "") .
  897. ">";
  898. $code[] = "<option value=''>-- Select --</option>";
  899. $code[] = "<?php \$dbOptions = \Illuminate\Support\Facades\DB::table('{$options['table']}')->get(); ?>";
  900. $code[] = "<?php foreach(\$dbOptions as \$o): ?>";
  901. $code[] = "<option " .
  902. "<?= \$o->{$options['valueField']} === (old('$name') ? old('$name') : " . ($default ? "\$record->$default" : "''") . ") ? 'selected' : '' ?> " .
  903. "value='<?= \$o->{$options['valueField']} ?>'><?= \$o->{$options['displayField']} ?> (<?= \$o->{$options['valueField']} ?>)</option>";
  904. $code[] = "<?php endforeach; ?>";
  905. $code[] = "</select>";
  906. break;
  907. case "bool":
  908. $code[] = "<div class='form-group mb-3'>";
  909. $code[] = "<label class='control-label'>{$this->camelToTitleCase($this->snakeToTitleCase($display))} " .
  910. ($required ? "*" : "");
  911. $code[] = "<input class='ml-2' type='checkbox' name='$name' " .
  912. ($required ? "required" : "") .
  913. ">";
  914. $code[] = "</label>";
  915. break;
  916. default:
  917. $code[] = "<input class='form-control' type='$type' name='$name' " . $valueLine .
  918. ($required ? "required" : "") .
  919. ">";
  920. }
  921. if($type !== 'hidden') {
  922. $code[] = "</div>";
  923. }
  924. return implode("\n", $code);
  925. }
  926. }
  927. class GenControllerMethod {
  928. public $name;
  929. public $route;
  930. public $hasUID = false;
  931. public $redirect = false;
  932. public $type = '';
  933. public $data = [];
  934. public $parentSub = false;
  935. public $childAddRoute = false;
  936. public $table = false;
  937. public $api = 'create';
  938. public $show = null;
  939. public $viewURL = false;
  940. public $exitURL = false;
  941. public $showLink = true;
  942. public $incType = null;
  943. public $incFields = null;
  944. public $viewLinkField = 'uid';
  945. public $columns = [];
  946. public $columnActions = [];
  947. public $groups = [];
  948. public function __construct($name, $route)
  949. {
  950. $this->name = $name;
  951. $this->route = $route;
  952. if(strpos($this->route, "{uid}") !== FALSE) {
  953. $this->hasUID = true;
  954. }
  955. }
  956. public function setIncFields($type, $fields) {
  957. $this->incType = $type;
  958. $this->incFields = $fields;
  959. for ($i = 0; $i < count($this->incFields); $i++) {
  960. if($this->incFields[$i][0] === '@') {
  961. $this->incFields[$i] = substr($this->incFields[$i], 1);
  962. $this->viewLinkField = $this->incFields[$i];
  963. }
  964. }
  965. }
  966. public function setColumnSpec($line, $link, $recordVariable) {
  967. // ally_pro_id:Ally Pro:select name_display as 'result' from pro where id = $ally_pro_id limit 1
  968. $parts = explode(":", $line);
  969. $spec = [
  970. "label" => $parts[1]
  971. ];
  972. if(count($parts) > 2) {
  973. $query = $parts[2];
  974. $query = preg_replace("/\\$([a-zA-Z0-9_]+)/", "\" . ($$recordVariable->$1 ? $$recordVariable->$1 : -1) . \"", $query);
  975. $spec['query'] = $query;
  976. }
  977. if($link) {
  978. $spec['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "<?= \$$recordVariable->$1 ?>", $link);
  979. }
  980. $this->columns[$parts[0]] = $spec;
  981. }
  982. public function addGroup($line) {
  983. // Basic Details:id,uid,created_at,clients_count
  984. $parts = explode(":", $line);
  985. $this->groups[] = [
  986. "name" => $parts[0],
  987. "fields" => explode(",", $parts[1])
  988. ];
  989. }
  990. public function addColumnAction($line, $link) {
  991. // is_active:Deactivate:deactivate:edit:if:is_active
  992. $parts = explode(":", $line);
  993. $action = [
  994. "label" => $parts[1],
  995. "icon" => isset($parts[2]) ? $parts[2] : 'edit'
  996. ];
  997. if(count($parts) >= 5 ) {
  998. $action["condition"] = $parts[3];
  999. $action["field"] = $parts[4];
  1000. }
  1001. if($link) {
  1002. $action['link'] = preg_replace("/\\$([a-zA-Z0-9_]+)/", "<?= \$record->$1 ?>", $link);
  1003. }
  1004. if(!isset($this->columnActions[$parts[0]])) {
  1005. $this->columnActions[$parts[0]] = [];
  1006. }
  1007. $this->columnActions[$parts[0]][] = $action;
  1008. }
  1009. }