diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f81b0cf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +content/data diff --git a/Conjuro/Conjuro.php b/Conjuro/Conjuro.php index df55c23..e9e00e7 100644 --- a/Conjuro/Conjuro.php +++ b/Conjuro/Conjuro.php @@ -125,8 +125,9 @@ if(!isset($this->db)){ switch($this->conf["db-engine"]){ case "dirDB": + $dir=getcwd().DIRECTORY_SEPARATOR.$this->conf["db-path"]; include_once "dirDB.php"; - $this->db=new dirDB($this->conf["db-path"]); + $this->db=new dirDB($dir); break; case "webDB": include_once "webDB.php"; @@ -363,13 +364,23 @@ $this->renderControl($meta,$data); } + public function getPlaceholders(){ + $this->getControlPlaceholders(); + } + abstract protected function renderControl($meta,$data); + + abstract protected function getControlPlaceholders(); } /** * Error control class */ class ErrorControl extends Control{ + protected function getControlPlaceholders(){ + return []; + } + protected function renderControl($meta,$data){ $name = $this->getName(); echo "[Control '$name' not found]"; diff --git a/Conjuro/dirDB.php b/Conjuro/dirDB.php index 93fde5a..7be06a0 100644 --- a/Conjuro/dirDB.php +++ b/Conjuro/dirDB.php @@ -21,15 +21,15 @@ } public function insert($table,$data,$many=false){ - $url=$this->url; + $base=$this->path; if ($many){ foreach($data as $v){ $id=$v["id"]=$this->guidv4(); - $this->write("$base/$table/$id.json",$v); + $this->write("$base/$table","$id.json",$v); } }else{ $id=$data["id"]=$this->guidv4(); - $this->write("$base/$table/$id.json",$data); + $this->write("$base/$table","$id.json",$data); } } @@ -44,22 +44,15 @@ } public function replace($table,$data){ - $this->call("${url}/action/replaceOne",[ - "dataSource"=>$this->dataSource, - "database"=>$this->db, - "collection"=>$table, - "filter"=>[ "_id"=>$id ], - "replacement"=>$data, - ]); + $base=$this->path; + $id=$data["id"]; + $this->write("$base/$table","$id.json",$data); } public function delete($table,$id){ - $this->call("${url}/action/deleteOne",[ - "dataSource"=>$this->dataSource, - "database"=>$this->db, - "collection"=>$table, - "filter"=>[ "_id"=>$id ], - ]); + $base=$this->path; + if (file_exists($path)) + unlink($path); } function read($path){ @@ -71,10 +64,11 @@ return json_decode($result,true); } - function write($path,$data){ - var_dump($path);die(); + function write($directory,$file,$data){ $data=json_encode($data); - file_put_contents($path,$data); + if (!is_dir($directory)) + mkdir($directory,0777,true); + file_put_contents("$directory/$file",$data); } function guidv4($data = null) { diff --git a/content/controls/builder.html b/content/controls/builder.html new file mode 100644 index 0000000..6fd6071 --- /dev/null +++ b/content/controls/builder.html @@ -0,0 +1,41 @@ +
+ +
+ +
+
+ +
+
+
+
Archivo base (layout):
+
Archivo base sobre la que se configura la página.
+ +
+
+
Controladores de página:
+
Modulos a ejecutar al inicio de la página, los módilos se ejecutaran en el orden indicado. +
+
+
+
+
+ +
+
+
+
+
Librerías de cotroles
+
Librerías de controles a cargar, los controles disponibles dependen de las librarias + cargadas.
+
+
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/content/controls/common-admin.php b/content/controls/common-admin.php index 2571d52..3026184 100644 --- a/content/controls/common-admin.php +++ b/content/controls/common-admin.php @@ -3,10 +3,13 @@ * Common control library 0.1 for Conjuro. */ return [ - new class("admin-title") extends Control{ + new class('admin-title') extends Control{ + protected function getControlPlaceholders(){ + return []; + } protected function renderControl($meta,$data) { ?> -
+
renderContent($child,$data); ?>
 
@@ -14,73 +17,56 @@ do("get-panel-links") as $lnk){ - c()->control("admin-panel-button")->render($lnk,$data); + foreach(m('Admin')->do('get-panel-links') as $lnk){ + c()->control('admin-panel-button')->render($lnk,$data); } } }, - new class("admin-panel-button") extends Control{ + new class('admin-panel-button') extends Control{ + protected function getControlPlaceholders(){ + return []; + } protected function renderControl($meta,$data) { echo '
'; echo ''; - echo ''.$meta["title"].''; + echo ''.$meta['title'].''; echo '
'; } }, - new class("admin-tile") extends Control{ + new class('admin-section') extends Control{ + protected function getControlPlaceholders(){ + return [ + 'class' =>['type'=>'s','description'=>'Clase opcional para el control de sección.'], + 'title' =>['type'=>'s','description'=>'Título'], + 'body-class'=>['type'=>'s','description'=>'Clase opcional para el cuerpo del control de sección.'], + 'content' =>['type'=>'a','description'=>'Contenido'], + ]; + } protected function renderControl($meta,$data) { ?>
-
+
> renderContent($child,$data); ?>
-
- -
-
-
-
Archivo base (layout):
-
Archivo base sobre la que se configura la página.
- -
-
-
Controladores de página:
-
Modulos a ejecutar al inicio de la página, los módilos se ejecutaran en el orden indicado.
-
-
-
-
- -
-
-
-
-
Librerías de cotroles
-
Librerías de controles a cargar, los controles disponibles dependen de las librarias cargadas.
-
-
-
- -
-
-
-
-
- @@ -11,11 +15,19 @@ } }, new class('html') extends Control{ + protected function getControlPlaceholders(){ + return []; + } + protected function renderControl($meta,$data) { echo $meta['html']; } }, new class('img') extends Control{ + protected function getControlPlaceholders(){ + return []; + } + protected function renderControl($meta,$data) { c()->rhtml( 'img', @@ -24,6 +36,10 @@ } }, new class('form') extends Control{ + protected function getControlPlaceholders(){ + return []; + } + protected function renderControl($meta,$data) { $cols=$meta['columns']; c()->rhtml( @@ -58,6 +74,10 @@ } }, new class('form-data') extends Control{ + protected function getControlPlaceholders(){ + return []; + } + protected function renderControl($meta,$data) { if ($meta['id']){ $lid=$meta["id"].'-label'; @@ -80,23 +100,39 @@ } }, new class('jump') extends Control{ + protected function getControlPlaceholders(){ + return []; + } + protected function renderControl($meta,$data) { $ctt=$meta["height"]; echo "
"; } }, new class('icon') extends Control{ + protected function getControlPlaceholders(){ + return []; + } + protected function renderControl($meta,$data) { ?>
data('username')?>
showContent('panel');?>
-
-
+
+
showContent('header');?>
-
showContent('body');?>
+
showContent('body');?>
diff --git a/content/modules/Admin.php b/content/modules/Admin.php index a4ab111..cb6a0a4 100644 --- a/content/modules/Admin.php +++ b/content/modules/Admin.php @@ -58,8 +58,8 @@ $this->register('get-panel-links',function(){ return [ ["title"=>"Dashboard","link"=>"?page=admin/dashboard","icon"=>"gauge"], - ["title"=>"Users","link"=>"?page=admin/users","icon"=>"user"], - ["title"=>"Pages","link"=>"?page=admin/pages","icon"=>"file"], + ["title"=>"Usuarios","link"=>"?page=admin/users","icon"=>"user"], + ["title"=>"Paginas","link"=>"?page=admin/pages","icon"=>"file"], ["title"=>"Test","link"=>"?page=admin/test","icon"=>"vial-virus"], ]; }); diff --git a/content/pages/admin/dashboard.json b/content/pages/admin/dashboard.json index d703b37..ebbdc0b 100644 --- a/content/pages/admin/dashboard.json +++ b/content/pages/admin/dashboard.json @@ -20,7 +20,7 @@ ], "body": [ { - "@": "admin-tile", + "@": "admin-section", "content": [ { "@": "html", diff --git a/content/pages/admin/page-edit.json b/content/pages/admin/page-edit.json index 2cb34ec..25cb336 100644 --- a/content/pages/admin/page-edit.json +++ b/content/pages/admin/page-edit.json @@ -26,7 +26,7 @@ ], "body": [ { - "@": "admin-tile", + "@": "admin-section", "title":"Editando {page-id}", "content": [ { diff --git a/content/pages/admin/pages.json b/content/pages/admin/pages.json index 1db6b56..767009e 100644 --- a/content/pages/admin/pages.json +++ b/content/pages/admin/pages.json @@ -26,7 +26,7 @@ ], "body": [ { - "@": "admin-tile", + "@": "admin-section", "content": [ { "@": "list", diff --git a/content/pages/admin/test.json b/content/pages/admin/test.json index cf61129..2906df6 100644 --- a/content/pages/admin/test.json +++ b/content/pages/admin/test.json @@ -20,7 +20,7 @@ ], "body": [ { - "@": "admin-tile", + "@": "admin-section", "html": "Welcome to Conjuro!!" }, { diff --git a/content/pages/admin/user-edit.json b/content/pages/admin/user-edit.json index 6bfd3e7..34a20e7 100644 --- a/content/pages/admin/user-edit.json +++ b/content/pages/admin/user-edit.json @@ -32,7 +32,7 @@ ], "body": [ { - "@": "admin-tile", + "@": "admin-section", "content": [ { "@": "list", diff --git a/content/pages/admin/users.json b/content/pages/admin/users.json index d49ec1f..08864dc 100644 --- a/content/pages/admin/users.json +++ b/content/pages/admin/users.json @@ -26,7 +26,7 @@ ], "body": [ { - "@": "admin-tile", + "@": "admin-section", "content": [ { "@": "list", diff --git a/media/admin/builder.js b/media/admin/builder.js index 1013902..cca12ac 100644 --- a/media/admin/builder.js +++ b/media/admin/builder.js @@ -18,6 +18,21 @@ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var builder = new (function () { +var builder = (function () { + var meta; + var root; + function init(pageMeta) { + meta = pageMeta; + root = document.body.querySelector("#page-builder"); + refresh(); + } + + function refresh(){ + µWeb.populate(root,meta); + } + + return { + init: init, + } })(); \ No newline at end of file diff --git a/media/admin/style.css b/media/admin/style.css index f497f6c..c42a1ce 100644 --- a/media/admin/style.css +++ b/media/admin/style.css @@ -77,6 +77,7 @@ background-size: 100% 130px; overflow-y: auto; overflow-x: hidden; + flex:1; } #content-header { @@ -228,11 +229,11 @@ } /* control::builder */ -.page-builder .caption{ +#page-builder .caption{ text-decoration: underline; } -.page-builder .info{ +#page-builder .info{ font-size: 0.7em; /*background-color: #fefff0;*/ margin:0.2rem 0; @@ -341,6 +342,8 @@ border: 3px solid var(--scroll-bar-bg-color); } +/**** Layouting ****/ + .layout { display: flex; } @@ -358,7 +361,7 @@ } .layout.big-gap { - gap: 1rem; + gap: 1.1rem; } .layout.horizontal.reverse { @@ -369,10 +372,33 @@ flex-direction: column-reverse; } -.main { +.layout>.main { flex: 1; } +.layout.horizontal>.main { + min-width: 0; +} +.layout.vertical>.main { + min-height: 0; +} + +.layout>.main.master { + flex: 0.7; +} + +.layout>.main.detail { + flex: 1.3; +} + +.layout>.main.c80-20:first-child { + flex: 0.8; +} + +.layout>.main.c80-20:last-child { + flex: 0.2; +} + .layout.horizontal.left { justify-content: flex-start; } @@ -419,4 +445,4 @@ .layout.vertical.bottom { justify-content: flex-end; -} \ No newline at end of file +} diff --git a/media/muWeb.js b/media/muWeb.js index 54c33e3..6e1a864 100644 --- a/media/muWeb.js +++ b/media/muWeb.js @@ -1,5 +1,5 @@ -/* µWeb 1.0 Web development micro-framework - * Copyright 2022 XWolfOverride +/* µWeb 1.1 Web development micro-framework + * Copyright 2022-2023 XWolfOverride * * Licensed under the MIT License * @@ -62,7 +62,7 @@ * Generates a repetition of elements from a source of data * @param {dom} template Template dom * @param {function} fncreated Element created callback - * @param {scting} idBase base id of repetition for each iteration (only for elements with id) + * @param {string} idBase base id of repetition for each iteration (only for elements with id) * @returns Repeater instance API */ function repeater(template, fncreated, idBase) { @@ -113,10 +113,18 @@ } } - function populate(dom, data, idBase, link) { + /** + * Popupate data into a page, actual page data is removed and new data is filled. + * @param {dom} dom Template dom to repeat + * @param {*} data Data source of repetition + * @param {string} idBase base id of repetition for each iteration (only for elements with id) + * @param {*} tag data to set on ._tag + */ + function populate(dom, data, idBase, tag) { if (dom.id && idBase) dom.id = idBase + dom.id; - dom._link = link; + dom._tag = tag; + dom._data=data; // process dataset: for (var k in dom.dataset) { var d = data[dom.dataset[k]]; @@ -128,7 +136,7 @@ } // go to childs for (var i in dom.children) - populate(dom.children[i], data, idBase, link); + populate(dom.children[i], data, idBase, tag); } return {