Prechádzať zdrojové kódy

Altering housekeeping modules

ahwelp 2 rokov pred
rodič
commit
d14dfaf508

+ 154 - 81
app/core/generator/GeneratorController.php

@@ -17,12 +17,15 @@ class GeneratorController {
             use Schema\Wrapper as Wrapper;
             use App\Core\Sanity\MigratorController as Migrator;
 
+            //https://book.cakephp.org/phinx/0/en/migrations.html#valid-column-types
             function {{PLUGIN_NAME}}_upgrade(\$pluginversion) {
                 if (\$pluginversion < "0.0.1") {
-                    \$table = Wrapper::get_table("{{PLUGIN_NAME}}");
-                    \$table->addColumn("name", "string", Array("null" => false));
-                    \$table->addColumn("time", "timestamp", Array("null" => true, "default"=>null));
-                    \$table->addColumn("areaid", "integer", Array("null" => false));
+                    \$table = Wrapper::get_table("{{PLUGIN_NAME}}s");
+                    \$table->addColumn("area_id",     "integer", Array("null" => false));
+                    \$table->addColumn("name",        "string", Array("null" => false));
+                    \$table->addColumn("description", "text",   Array("null" => true));
+                    //\$table->addColumn("time", "timestamp", Array("null" => true, "default"=>null));
+
                     \$table->addTimestamps();
                     \$table->addSoftDelete();
                     \$table->create();
@@ -31,16 +34,16 @@ class GeneratorController {
                     return;
                 }
 
-                //if (\$pluginversion < "0.0.2") {
-                    //\$table = Wrapper::get_table("{{PLUGIN_NAME}}");
-                    //Migrator::getInstance()->update_plugin_version("{{PLUGIN_NAME}}", "1.0.1");
-                    //return;
+                //if (\$pluginversion < "1.0.1") {
+                //    \$table = Wrapper::get_table("{{PLUGIN_NAME}}s");
+                //    Migrator::getInstance()->update_plugin_version("{{PLUGIN_NAME}}", "1.0.1");
+                //    return;
                 //}
             }
 
             function {{PLUGIN_NAME}}_rollback(\$pluginversion) {
                 if(\$pluginversion > "0.0.1"){
-                    \$table = Wrapper::get_table("{{PLUGIN_NAME}}");
+                    \$table = Wrapper::get_table("{{PLUGIN_NAME}}s");
                     \$table->drop();
                     return;
                 }
@@ -52,7 +55,7 @@ class GeneratorController {
             <?php
 
             \$plugin->name = "{{PLUGIN_NAME}}";
-            \$plugin->version = "0.0.1";
+            \$plugin->version = "0.0.0";
 
             //\$plugin->require = Array( ["name" => "plugin_name", "version" => "x.x.x"] );
             EOL;
@@ -66,14 +69,16 @@ class GeneratorController {
             use \App\Core\Template\Output as Output;
             use \{{NAMESPACE}}\Classes\{{OBJECT}} as {{OBJECT}};
 
-            class {{CONTROLLER}} {
+            class {{CONTROLLER}} extends \DefaultController{
+
+                protected \$_class   = {{OBJECT}}::class;
+                protected \$_baseUrl = '/{{PLUGIN_NAME}}';
 
                 /**
                 * Index
                 *   Show the main {{OBJECT}} list
                 */
                 function index(){
-                    Output::setView('index');
                     \$list = Array();
 
                     for(\$i = 0; \$i <= 10; \$i++){
@@ -83,8 +88,8 @@ class GeneratorController {
                         \$obj['description'] = sha1(\$i);
                         \$list[] = \$obj;
                     }
-                    Output::addValue('list', \$list );
-                    Output::render();
+
+                    Output::render('index', Array('list' => \$list));
                 }
 
                 /**
@@ -93,8 +98,7 @@ class GeneratorController {
                 * Render the main {{OBJECT}} formulary
                 */
                 function create(){
-                    Output::setView('form', ['id' => 0]);
-                    Output::render();
+                    Output::render('form', ['id' => 0]);
                 }
 
                 /**
@@ -107,6 +111,16 @@ class GeneratorController {
 
                 }
 
+                /**
+                * Search
+                *
+                * Store the param on the database
+                * @param {{OBJECT}} \${{OBJECT_LOWER}}
+                */
+                function search(){
+
+                }
+
                 /**
                 * Show
                 *
@@ -126,8 +140,7 @@ class GeneratorController {
                 * @param {{OBJECT}} \${{OBJECT_LOWER}}
                 */
                 function edit({{OBJECT}} \${{OBJECT_LOWER}}){
-                    Output::setView('form', \${{OBJECT_LOWER}});
-                    Output::render();
+                    Output::render('form', \${{OBJECT_LOWER}});
                 }
 
                 /**
@@ -175,8 +188,39 @@ class GeneratorController {
 
                 //const _idPolice = Array("type" => "", "min" => 0, "max" => 100000, "step" => 2);
 
-                const _tableName = "{{TABLE_NAME}}";
-                //const _properties = Array("id", "name");
+                const _tableName = "{{TABLE_NAME}}s";
+
+                /*const _properties = Array(
+                    "id"   => ['listable' => true,  'searcheble' => false, 'orderable' => false],
+                    "name" => ['listable' => true,  'searcheble' => true]);
+                */
+
+                const _properties = Array(
+                    'id',
+                    'name',
+                    'description'
+                );
+
+                /*protected \$_ignore = Array(
+
+                );*/
+
+                const _listable = Array(
+                    'id',
+                    'name'
+                );
+
+                const _searchable = Array(
+                    'name'
+                );
+
+                const _orderable = Array(
+
+                );
+
+                /*const _datatables = Array(
+
+                );*/
 
                 //const _timestamps = true;
                 //const _softdelete = true;
@@ -194,13 +238,14 @@ class GeneratorController {
 
             //Menu itens
             RouteCollection::get('*', function() {
-                Output::addMenu('/{{PLUGIN_NAME}}', '{{PLUGIN_NAME}}', "<i class='fa fa-fa-cubes'></i>", ['class' => 'nav-link']);
+                Output::addMenu('/{{PLUGIN_NAME}}', '{{PLUGIN_NAME}}', icon('cubes'), ['class' => 'nav-link']);
             }, -10)->doIgnore();
 
             RouteCollection::group("/{{PLUGIN_NAME}}", function(){
                 RouteCollection::get   ("/",            "\{{NAMESPACE}}\{{CONTROLLER}}@index");
                 RouteCollection::get   ("/form",        "\{{NAMESPACE}}\{{CONTROLLER}}@create");
                 RouteCollection::post  ("/",            "\{{NAMESPACE}}\{{CONTROLLER}}@store");
+                RouteCollection::post  ("/search",      "\{{NAMESPACE}}\{{CONTROLLER}}@search");
                 RouteCollection::get   ("/[i:id]",      "\{{NAMESPACE}}\{{CONTROLLER}}@show");
                 RouteCollection::get   ("/[i:id]/edit", "\{{NAMESPACE}}\{{CONTROLLER}}@edit");
                 RouteCollection::put   ("/[i:id]/edit", "\{{NAMESPACE}}\{{CONTROLLER}}@update");
@@ -210,67 +255,108 @@ class GeneratorController {
 
     private $indexTemplate =
             <<<EOL
-            <a href='/{{ENDPOINT}}/form' >Adicionar </a>
-            <div class="table-responsive">
-                <table class='table'>
-
-                    <thead>
-                       <tr>
-                          <th>Id</th>
-                          <th>Value</th>
-                          <th>Description</th>
-                          <th>Actions</th>
-                       </tr>
-                    </thead>
-
-                    {{#list}}
-                       <tr class="table-dark" data-id='{{id}}'>
-                          <td>{{id}}</td>
-                          <td>{{value}}</td>
-                          <td>{{description}}</td>
-                          <td>
-                             <a href="{{ENDPOINT}}/edit"> <i class="fa fa-pencil"></i></a>
-                             <a href="{{ENDPOINT}}/purge"> <i class="fa fa-fire"></i></a>
-                             <a href="{{ENDPOINT}}/"> <i class="fa fa-plus"></i></a>
-                             <a href="{{ENDPOINT}}/destroy"> <i class="fa fa-trash-o"></i></a>
-                          </td>
-                       </tr>
-                    {{/list}}
-                </table>
-            </div>
+            <a href='/{{ENDPOINT}}/form' > Adicionar </a>
             EOL;
 
     private $formTemplate =
             <<<EOL
-            {{@ if( {{id}} ): @}}
+            {{#id}}
             <form method="POST" action="/{{ENDPOINT}}/{{id}}/edit">
                <input type="hidden" name="id" value="{{id}}" />
                <input type="hidden" name="_method" value="put" />
-            {{@ else: @}}
+            {{/id}}
+            {{^id}}
             <form method="POST" action="/{{ENDPOINT}}">
                <input type="hidden" name="id" value="" />
-            {{@ endif; @}}
-
+            {{/id}}
+                <div class='row'>
+                    <div class="col-md-8 col-xs-12 g-3">
+                        <div class="card">
+                            <div class="card-header">Header</div>
+                            <div class="card-body">
+                                <div class="row g-3">
+                                    <div class="col-xs-12 col-3">
+                                        <label class="form-label">Código</label>
+                                        <input type="text" class="form-control" name='code' value="{{code}}">
+                                    </div>
+                                    <div class="col-xs-12 col-9">
+                                        <label class="form-label">Nome</label>
+                                        <input type="text" class="form-control" name='name' value="{{name}}">
+                                    </div>
+                                </div>
+
+                                <div class="row">
+                                    <div class="col-xs-12 g-3">
+                                        <label class="form-label">Descrição</label>
+                                        <textarea class="form-control" name="descricao">{{description}}</textarea>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="col-md-4 col-xs-12 g-3">
+                        <div class="card">
+                            <div class="card-header">Header</div>
+                            <div class="card-body">
+                                <div class="row g-3">
+                                    <div class="col-xs-12 col-3">
+                                        <label class="form-label">Código</label>
+                                        <input type="text" class="form-control" name='code' value="{{code}}">
+                                    </div>
+                                    <div class="col-xs-12 col-9">
+                                        <label class="form-label">Nome</label>
+                                        <input type="text" class="form-control" name='name' value="{{name}}">
+                                    </div>
+                                </div>
+
+                                <div class="row">
+                                    <div class="col-xs-12 g-3">
+                                        <label class="form-label">Descrição</label>
+                                        <textarea class="form-control" name="descricao">{{description}}</textarea>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                <div class='row'>
+                    <div class="col-md-8 col-xs-12 g-3">
+                        <div class="card">
+                            <div class="card-header">Header</div>
+                            <div class="card-body">
+                                <div class="row g-3">
+                                    <div class="col-xs-12 col-3">
+                                        <label class="form-label">Código</label>
+                                        <input type="text" class="form-control" name='code' value="{{code}}">
+                                    </div>
+                                    <div class="col-xs-12 col-9">
+                                        <label class="form-label">Nome</label>
+                                        <input type="text" class="form-control" name='name' value="{{name}}">
+                                    </div>
+                                </div>
+
+                                <div class="row">
+                                    <div class="col-xs-12 g-3">
+                                        <label class="form-label">Descrição</label>
+                                        <textarea class="form-control" name="descricao">{{description}}</textarea>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
             </form>
             EOL;
 
-
-    private $ctagsHeader =
+        private $todoList =
         <<<EOL
-        !_TAG_FILE_FORMAT	2	/extended format; --format=1 will not append ;" to lines/
-        !_TAG_FILE_SORTED	1	/0=unsorted, 1=sorted, 2=foldcase/
-        !_TAG_OUTPUT_FILESEP	slash	/slash or backslash/
-        !_TAG_OUTPUT_MODE	u-ctags	/u-ctags or e-ctags/
-        !_TAG_PROGRAM_AUTHOR	Universal Ctags Team	//
-        !_TAG_PROGRAM_NAME	Universal Ctags	/Derived from Exuberant Ctags/
-        !_TAG_PROGRAM_URL	https://ctags.io/	/official site/
-        !_TAG_PROGRAM_VERSION	0.0.0	/a3c87ab5/
+
         EOL;
 
     function createPluginFromTemplate($subname, $name){
 
         if (is_dir( DIR_APP.$subname . "/" . $name )){
-            echo "Treco ja existe";
+            echo "This module allready exist";
             return;
         }else{
             mkdir(DIR_APP.$subname . "/" . $name,              0755, true);
@@ -305,6 +391,7 @@ class GeneratorController {
         file_put_contents(DIR_APP.$subname . "/" . $name . "/classes/$object.php",  $this->objectBase);
 
         $this->controllerBase = str_replace("{{NAMESPACE}}",   $namespace,            $this->controllerBase);
+        $this->controllerBase = str_replace("{{PLUGIN_NAME}}", $plugin_name,          $this->controllerBase);
         $this->controllerBase = str_replace("{{OBJECT}}",      $object,               $this->controllerBase);
         $this->controllerBase = str_replace("{{OBJECT_LOWER}}",strtolower($object),   $this->controllerBase);
         $this->controllerBase = str_replace("{{CONTROLLER}}",  $controller,           $this->controllerBase);
@@ -319,6 +406,8 @@ class GeneratorController {
         $this->formTemplate = str_replace("{{ENDPOINT}}", $plugin_name, $this->formTemplate);
         file_put_contents(DIR_APP.$subname . "/" . $name . "/views/form.mustache", $this->formTemplate);
 
+        file_put_contents(DIR_APP.$subname . "/" . $name . "/todo.md", $this->todoList);
+
     }
 
     function listRoutes(){
@@ -327,6 +416,7 @@ class GeneratorController {
         echo str_pad("W",        5,  " ", STR_PAD_BOTH) .  "||";
         echo str_pad("FUNCTION", 60, " ", STR_PAD_BOTH) .  "\n";
         echo str_pad("", 120, "-") . "\n";
+
         foreach(\Routes\RouteCollection::returnRoutes() as $route){
             echo str_pad(implode($route->_verb , ", "), 10, " ", STR_PAD_BOTH) . "||";
             echo str_pad($route->_uri, 35, " ", STR_PAD_RIGHT) . "||";
@@ -340,22 +430,5 @@ class GeneratorController {
         }
     }
 
-    function createTags(){
-        $outputs = shell_exec("grep -Rnsi '@ctag' . | sed s/\ //g | sed s/*@ctag/\ /g");
-        $outputs = preg_split("/\R/", $outputs);
-        $return  = $this->ctagsHeader . "\n";
-        foreach($outputs as $output){
-            $line = explode(" ", str_replace("\\t", "", $output) );
-            @$line = $line[1] . "\t " . str_replace("./", "", explode(":", $line[0])[0]) . "\t ".$line[1] . "\n";
-            if( strpos($line, "app/core/generator/GeneratorController.php") ){
-                continue;
-            }
-            $return .= $line;
-            //echo "Generating: ".$line."\n";
-        }
-
-        file_put_contents(DIR_ROOT."tags", $return);
-    }
-
 }
 

+ 3 - 2
app/core/generator/Routes.php

@@ -4,6 +4,7 @@ use Routes\RouteCollection as RouteCollection;
 
 RouteCollection::cli('/', function(){
     echo "/create/[h:subname]/[h:name]\n";
+    echo "install\n";
 });
 
 RouteCollection::cli('/routes',                      '\App\Core\Generator\GeneratorController@listRoutes');
@@ -11,11 +12,11 @@ RouteCollection::cli('/create/tags',                 '\App\Core\Generator\Genera
 RouteCollection::cli('/create/[h:subname]/[h:name]', '\App\Core\Generator\GeneratorController@createPluginFromTemplate');
 
 RouteCollection::group('/core', function(){
-    
+
     RouteCollection::cli('/purge/[h:module]', function($module){
         echo "Purgin $module\n";
     });
-    
+
     RouteCollection::cli('/purge', function(){
         echo "Purging Everything\n";
     });