diff --git a/Conjuro/Conjuro.php b/Conjuro/Conjuro.php index 637dd56..5ebaaaf 100644 --- a/Conjuro/Conjuro.php +++ b/Conjuro/Conjuro.php @@ -40,7 +40,16 @@ ///////////////////////////////////////////////////// DATABASE TOOLS //////////////////////////////////////////////////////////////////// - // Return data from database + /** + * Select a list from te database + */ + public function DBlist($type,$fields=null,$where='',$types = null,&...$data){ + return $this->db()->select($type,$fialds,$where,$types,...$data); + } + + /** + * Return single entity from DB + */ public function DBget($type,$key=""){ if ($key!="") $data=$this->db()->select($type,null,'where id=?','i',$key); @@ -227,14 +236,6 @@ } /** - * Load control libraries installed - */ - /*public function loadControls(){ - // TODO- glob directoty to fetch all libraries. - $this->loadControlLibrary("common"); - }*/ - - /** * Return a control */ public function control($name){ diff --git a/content/controls/common-admin.php b/content/controls/common-admin.php index 2e0e566..c6c1e7d 100644 --- a/content/controls/common-admin.php +++ b/content/controls/common-admin.php @@ -5,7 +5,12 @@ return [ new class("admin-title") extends Control{ protected function renderControl($meta,$data) { - echo $meta["title"]; + c()->rhtml('div',['class'=>'admin-title'],function() use($meta){ + echo $meta["title"]; + }); + c()->rhtml('div',['class'=>'admin-title-right'],function() use($meta){ + c()->control("icon")->render(['icon'=>'gear','class'=>'btn-ico'],$data); + }); } }, new class("admin-panel-buttons") extends Control{ @@ -22,6 +27,18 @@ echo ''.$meta["title"].''; echo ''; } - } + }, + new class("admin-tile") extends Control{ + protected function renderControl($meta,$data) { + ?> +
+
+
+ renderContent($child,$data); ?> +
+
+ \ No newline at end of file diff --git a/content/controls/common.php b/content/controls/common.php index 00f04b3..69595d7 100644 --- a/content/controls/common.php +++ b/content/controls/common.php @@ -33,7 +33,7 @@ function() use($meta,$data,$cols){ echo ''; $col=0; - foreach($meta['childs'] as $child){ + foreach($meta['content'] as $child){ c()->renderContent($child,$data); if(++$col>=$cols){ echo ''; @@ -82,6 +82,45 @@ $ctt=$meta["height"]; echo "
"; } - } + }, + new class("icon") extends Control{ + protected function renderControl($meta,$data) { + ?>
+ + +
  • + \ No newline at end of file diff --git a/content/fragment/layout-admin.php b/content/fragment/layout-admin.php index a8b04e9..447e2fe 100644 --- a/content/fragment/layout-admin.php +++ b/content/fragment/layout-admin.php @@ -5,7 +5,7 @@ <?=$this->conf("site-title")?> - +
    @@ -14,11 +14,11 @@
    showContent('panel');?>
    -
    showContent('header');?>
    -
    showContent('body');?>
    -
    - \ No newline at end of file diff --git a/content/fragment/layout.php b/content/fragment/layout.php index c233b14..c85e7ca 100644 --- a/content/fragment/layout.php +++ b/content/fragment/layout.php @@ -4,7 +4,7 @@ <?=$this->conf("site-title")?> - + diff --git a/content/modules/Admin.php b/content/modules/Admin.php index 0a390af..6e0e1dc 100644 --- a/content/modules/Admin.php +++ b/content/modules/Admin.php @@ -23,13 +23,45 @@ SOFTWARE. */ return new class($conf) extends Module{ + private function listPages(){ + $result=[]; + foreach($this->recursivedir('content/pages','*.json') as $page) + $result[]=['name'=>$page]; + return $result; + } + + private function listUsers(){ + return c()->DBlist('users','id,user,name,created_on,active'); + } + + private function recursivedir($dir,$pattern,$cut=-1){ + if ($cut<0) + $cut=strlen($dir)+1; + $result=[]; + foreach (glob("$dir/*",GLOB_ONLYDIR) as $ddir) { + foreach($this->recursivedir($ddir,$pattern,$cut) as $inner) + $result[]=$inner; + } + foreach (glob("$dir/$pattern") as $file) { + $result[]=substr($file,$cut); + } + return $result; + } + public function init(){ $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"=>"Test","link"=>"?page=admin/test","icon"=>"vial-virus"], ]; }); + $this->register("admin-pages-controller",function($page){ + $page->setData('pages',$this->listPages()); + }); + $this->register("admin-users-controller",function($page){ + $page->setData('users',$this->listUsers()); + }); } }?> \ No newline at end of file diff --git a/content/modules/Page.php b/content/modules/Page.php index f35261d..2bc6381 100644 --- a/content/modules/Page.php +++ b/content/modules/Page.php @@ -59,7 +59,7 @@ /** * Return the value defined for a page meta key */ - public function value($name){ + public function meta($name){ return $this->meta[$name]; } @@ -73,16 +73,23 @@ } /** + * Sets a data field + */ + public function setData($name,$value){ + $this->data[$name]=$value; + } + + /** * Sets the data dictionary of the page */ - public function setData($datablock){ + public function setAllData($datablock){ $this->data=$datablock; } /** * Gets the data dictionary of the page */ - public function getData(){ + public function getAllData(){ return $this->data; } @@ -99,18 +106,23 @@ * Prepare page (load dependencies if any) */ public function prepare(){ - if(isset($this->meta["control-libraries"])){ - foreach($this->meta["control-libraries"] as $clib){ + if(isset($this->meta['control-libraries'])){ + foreach($this->meta['control-libraries'] as $clib){ c()->loadControlLibrary($clib); } } + if(isset($this->meta['controller'])){ + foreach($this->meta['controller'] as $ctrl){ + c()->module($ctrl['module'])->do($ctrl['action'],$this); + } + } } - + /** * Page needs authorization of any kind */ public function needAuth(){ - return isset($this->meta["auth"]); + return isset($this->meta['auth']); } } @@ -142,12 +154,9 @@ if ($page->needAuth() && !$_SESSION['user']){ $page=$this->getPage($this->conf["login-page"]); } - $data=$_SESSION['data']; - $data['username']=$_SESSION['user']['name']; - $data['userid']=$_SESSION['user']['id']; - $page->setData($data); + $page->setData('username',$_SESSION['user']['name']); + $page->setData('userid',$_SESSION['user']['id']); $page->showPage(); - $_SESSION['data']=$page->getData(); } //Loads page meta from page name (id) diff --git a/content/pages/admin/dashboard.json b/content/pages/admin/dashboard.json index fbaab60..b5b235c 100644 --- a/content/pages/admin/dashboard.json +++ b/content/pages/admin/dashboard.json @@ -1,29 +1,28 @@ { "title": "Bienvenido a Conjuro", "layout": "layout-admin", - "control-libraries":["common","common-admin"], - "auth":["admin"], + "control-libraries": [ + "common", + "common-admin" + ], + "auth": [ + "admin" + ], "panel": [ { - "@": "admin-panel-buttons", - "meta": { - } + "@": "admin-panel-buttons" } ], - "header":[ + "header": [ { "@": "admin-title", - "meta": { - "title": "Dashboard" - } + "title": "Panel de control" } ], "body": [ { - "@": "html", - "meta": { - "html": "Welcome to Conjuro!!" - } + "@": "admin-tile", + "html": "Welcome to Conjuro!!" } ] } \ No newline at end of file diff --git a/content/pages/admin/pages.json b/content/pages/admin/pages.json new file mode 100644 index 0000000..04a6a99 --- /dev/null +++ b/content/pages/admin/pages.json @@ -0,0 +1,44 @@ +{ + "title": "Bienvenido a Conjuro", + "layout": "layout-admin", + "controller": [ + { + "module": "admin", + "action": "admin-pages-controller" + } + ], + "control-libraries": [ + "common", + "common-admin" + ], + "auth": [ + "admin" + ], + "panel": [ + { + "@": "admin-panel-buttons" + } + ], + "header": [ + { + "@": "admin-title", + "title": "Páginas" + } + ], + "body": [ + { + "@": "admin-tile", + "content": [ + { + "@": "list", + "data":"pages", + "item":{ + "@":"list-item", + "link":"?page=admin/edit", + "field-title":"name" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/content/pages/admin/users.json b/content/pages/admin/users.json new file mode 100644 index 0000000..34a98d5 --- /dev/null +++ b/content/pages/admin/users.json @@ -0,0 +1,44 @@ +{ + "title": "Bienvenido a Conjuro", + "layout": "layout-admin", + "controller": [ + { + "module": "admin", + "action": "admin-users-controller" + } + ], + "control-libraries": [ + "common", + "common-admin" + ], + "auth": [ + "admin" + ], + "panel": [ + { + "@": "admin-panel-buttons" + } + ], + "header": [ + { + "@": "admin-title", + "title": "Usuarios" + } + ], + "body": [ + { + "@": "admin-tile", + "content": [ + { + "@": "list", + "data":"users", + "item":{ + "@":"list-item", + "link":"?page=admin/user-edit", + "field-title":"name" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/content/pages/login.json b/content/pages/login.json index 4c7838b..ad22fe1 100644 --- a/content/pages/login.json +++ b/content/pages/login.json @@ -21,7 +21,7 @@ "method":"post", "action":"?page=admin/dashboard", "columns": 1, - "childs": [ + "content": [ { "@": "form-data", "id": "user", diff --git a/media/admin/style.css b/media/admin/style.css index 4971975..8f8303b 100644 --- a/media/admin/style.css +++ b/media/admin/style.css @@ -1,16 +1,22 @@ :root { --color-text: #333333; - --color-text-highlight: #5a5a5a; + --color-text-highlight: #838ea8; --color-text-logo: #838ea8; + --color-text-hover: white; + --scroll-bar-color: #909aad; + --scroll-bar-bg-color: transparent; + --color-control-bg:#b5c0da; + --color-control-dark:#838ea8; + --color-highlight:#9449d1; } /* Layout */ html, -body { +body{ margin: 0; font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; width: 100%; - height: 100%; + height: 100%; } html { @@ -26,6 +32,11 @@ overflow: hidden; } +html,body,td,input,select{ + font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; + color:var(--color-text); +} + #panel { position: fixed; background-color: #fafaff; @@ -36,6 +47,7 @@ height: 100%; box-shadow: 0 0 7px #00000055; padding: 0.5rem; + z-index: 10; } #panel>#panel-title { @@ -53,34 +65,60 @@ padding-bottom: 4rem; } -#footer { - position: absolute; - bottom: 0; - background-color: #8fa5b9; - text-align: right; - font-size: 16px; - font-weight: bold; - width: 100%; - line-height: 24px; - color: white; -} - #content { + position: relative; background-color: #dbe3e6; background-image: linear-gradient(#c3cfd3, #dbe3e6); background-repeat: no-repeat; - background-size: 100% 50%; - width: 100%; + background-size: 100% 130px; + width: calc(100% - 15rem); height: 100%; margin-left: 15rem; - margin-bottom: 84px; - border-bottom: 1px sold tomato; - padding: 0.5rem; + overflow-y: auto; + overflow-x: hidden; +} + +#content-main { + min-height: calc(100% - 2rem); +} + +#content-header { + background-color: #dbe3e6aa; + background-image: linear-gradient(#c3cfd3aa, #dbe3e6aa); + background-repeat: no-repeat; + background-size: 100% 200px; + + position: fixed; + top: 0; + left: 0; + right: 0; + height: 4rem; + z-index: 9; + padding: 0 1rem 0 16rem; + backdrop-filter: blur(5px); + line-height: 4rem; +} + +#content-body { + padding: 4.5rem 1rem 0 1rem; +} + +#footer { + position: relative; + bottom: 0; + left: 0; + text-align: right; + font-size: 0.7rem; + width: 100%; + height: 2rem; + ; + line-height: 2rem; } a, a:visited { color: var(--color-text); + text-decoration: none; } a:hover { @@ -90,7 +128,7 @@ /* Admin-Panel */ .admin-panel-button { padding: 0.5rem 0; - color:var(--color-text); + color: var(--color-text); } .admin-panel-button:hover { @@ -109,6 +147,73 @@ padding: 0 1rem 0 2rem; } +/* Admin common*/ + +.btn-ico { + padding: 0.3rem; + color: var(--color-text); + cursor: pointer; + border-radius: 3px; +} + +.btn-ico:hover { + color:var(--color-text-hover); + background-color: var(--color-control-bg); +} + +/* Admin title*/ + +.admin-title{ + display:inline-block; + width: 30%; +} +.admin-title-right{ + display:inline-block; + width: 70%; + text-align: right; +} + +/* Admin tile*/ + +.admin-tile{ + background-color: white; + border-radius: 0.3rem; + box-shadow: 0 0 7px #00000033; +} + +.admin-tile.small{ + display:inline-block; +} + +.admin-tile-header{ + font-size: 0.9rem; + padding: 0.5rem 1.5rem; +} +.admin-tile-body{ + padding:0.5rem 1.5rem 1.5rem 1.5rem; +} + +/* control::list */ + +ul.list{ + margin: 0; + padding-inline-start: 0; +} + +ul.list li{ + display:block; + padding:0.5rem 1rem; + cursor: pointer; + border-radius: 3px; +} + +ul.list li:hover{ + background-color: var(--color-control-bg); + background-image: linear-gradient(130deg,var(--color-control-bg) 80%, var(--color-highlight) 100%); + color:var(--color-text-hover); +} + + /* Sections */ div.section { @@ -137,4 +242,30 @@ padding: 2px 5px; border-bottom: 1px solid #f5f5f5; font-size: 16px; +} + +::-webkit-scrollbar-corner { + background: rgba(0, 0, 0, 0.5); +} + +* { + scrollbar-width: thin; + scrollbar-color: var(--scroll-bar-color) var(--scroll-bar-bg-color); +} + +/* Works on Chrome, Edge, and Safari */ +*::-webkit-scrollbar { + width: 6px; + height: 6px; + z-index: 20; +} + +*::-webkit-scrollbar-track { + background: var(--scroll-bar-bg-color); +} + +*::-webkit-scrollbar-thumb { + background-color: var(--scroll-bar-color); + border-radius: 20px; + border: 3px solid var(--scroll-bar-bg-color); } \ No newline at end of file