From: Nicolas Boisselier Date: Wed, 18 Jan 2017 01:31:28 +0000 (+0000) Subject: dbq css X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=7c0ef183ffbc3160507c7819bc6165b425dceded;p=nb.git dbq css --- diff --git a/lib/php/db.php b/lib/php/db.php index ea6f62e4..0c184ec9 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -150,6 +150,13 @@ class Db extends nb { unset($opt['tables']); } + # connect + $connect = false; + if (isset($opt['connect'])) { + $connect = (bool) $opt['connect']; + unset($opt['connect']); + } + # Args into this foreach ($opt as $k=>$v) $this->$k = $v; #parent::__construct($opt); @@ -171,6 +178,7 @@ class Db extends nb { # Pdo $this->connect_init(); + if ($connect) $this->connect(); # Params /* @@ -208,9 +216,9 @@ class Db extends nb { if (empty($this->type)) $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$this->pdo)); if (!$this->type) return false; + if ($v = $this->p('db.host')) $this->host = $v; if ($this->conf_type('use_path')) { - if ($p = $this->p('db.host')) $this->host = $p; if (empty($this->host)) $this->host = preg_replace('/^\w+:/','',$this->pdo); # Add file @@ -232,8 +240,6 @@ class Db extends nb { # NB 26.10.16 } # NB 26.10.16 } - if ($p = $this->p('db.host')) $this->host = $p; - # Add args to pdo foreach ([ 'host' => 'host', @@ -252,8 +258,9 @@ class Db extends nb { } - # Title + # Defaults if (empty($this->title)) $this->title = prettyText($this->name); + if (empty($this->id) and !empty($this->name)) $this->id = preg_replace('/\W+/','',$this->name); # Row parser if (empty($this->row_parse_pre) and $this->conf_type('row_parse')) { @@ -396,7 +403,7 @@ class Db extends nb { */ public function table($name='',$params=[]) { if (!$name and !empty($this->default_table)) $name = $this->default_table; - if (!$name) bye('table name is empty'); + if (!$name) $this->bye('table(): Missing table'); if (empty($params) or empty($params['db'])) $params['db'] = $this; @@ -1084,7 +1091,6 @@ class Db extends nb { #debug(array_keys($this->tables())); $new = [] - #+( empty($this->id) ? [] : ['id' => $this->id]) +[ 'id' => (empty($this->id) ? '' : $this->id), 'name' => $this->name, diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 30a4b0a2..3a1a5f18 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -114,6 +114,7 @@ Class Table extends nb { public function create_temporary_rows() { // For static rows if(empty($this->rows)) return null; + if(!empty($this->rows) and empty($this->type)) $this->type = 'rows'; $fields = array_keys($this->rows[0]); $sql_names = $this->sql_names($fields); @@ -1398,7 +1399,7 @@ Class Table extends nb { $html = ''; - $html .= ''.NB_EOL; + $html .= '
'.NB_EOL; #if (!empty($opt)) $html .= '' .NB_EOL; $this->__rows_table_attr = []; @@ -1892,14 +1893,17 @@ Class Table extends nb { ; // Tables - see default.js if you change class - $r .= ''; - $r .= ''.html_select_array(array_keys($this->db()->tables()),[ - 'html' => 'class="tables" name="table" id="table"', - 'selected' => $this->name, - 'prettyText' => true, - 'sort' => 'natcasesort', - ]); - $r .= ''; + $tables = array_keys($this->db()->tables()); + if (count($tables)>1) { + $r .= ''; + $r .= ''.html_select_array($tables,[ + 'html' => 'class="tables" name="table" id="table"', + 'selected' => $this->name, + 'prettyText' => true, + 'sort' => 'natcasesort', + ]); + $r .= ''; + } // Dbs - see default.js if you change class if (!empty($this->db()->dbs) and count($this->db()->dbs)>1) { @@ -1925,7 +1929,7 @@ Class Table extends nb { $r .= ''; // Limit - if (!empty($this->db()->limits)) { + if (!empty($this->db()->limits) and count($this->db()->limits)>1) { $r .= ''; $r .= ''.html_select_array($this->db()->limits,[ 'html' => 'class="limit" name="limit" id="limit"', diff --git a/lib/php/nb.php b/lib/php/nb.php index 39ed3ab9..49ac0746 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -430,6 +430,7 @@ class NB { */ public static function debug_backtrace_info($call_info) { + // Error into string $errorType = array ( E_ERROR => 'ERROR', E_WARNING => 'WARNING', @@ -451,10 +452,12 @@ class NB { E_DEPRECATED => 'E_DEPRECATED ERROR', E_USER_DEPRECATED => 'E_USER_DEPRECATED ERROR', ); + if (isset($call_info['type']) and isset($errorType[$call_info['type']]) - ) $call_info['type'] = $errorType[$call_info['type']].'='.$call_info['type']; - #else ($call_info['type']) $call_info['type'] = $call_info['type']; + ) { + $call_info['type'] = $errorType[$call_info['type']].'='.$call_info['type']; + } // Default values if (isset($call_info['file']) and !empty($_SERVER['DOCUMENT_ROOT'])) diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index e446b19c..6924dae7 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -2,6 +2,7 @@ define('PRODUCTION',empty($_SERVER) or empty($_SERVER['PRODUCTION']) ? false : (bool)$_SERVER['PRODUCTION']); require_once(realpath(dirname(__FILE__).'/../../lib/php/nb.php')); +require_once(NB_ROOT.'/lib/php/config.php'); require_once(NB_ROOT.'/lib/php/http.php'); require_once(NB_ROOT.'/lib/php/mime.php'); @@ -36,7 +37,9 @@ class DbQ extends nb { public $params_deep = []; # contain index in case if we decide to use a regexp # Db - public $limits = []; + #public $limits = []; + public $default_limit = '30'; + public $limits = ['30','100','500','1000']; public $formats = [ 'html','csv','xml','json','yaml','sh','sql','php' ]; # Page @@ -94,6 +97,7 @@ class DbQ extends nb { $this->page = new Page([ 'css' => $this->css, 'sep' => $this->sep_title, + #'body_class' => 'fixed', ]); if ($run) $this->run(); @@ -119,6 +123,7 @@ class DbQ extends nb { public function page($obj,$meth=null,$head=[],$fct=null) { // Defaults + if (empty($head)) $head = []; if (empty($this->default_limit)) $this->default_limit = $this->db->limits[0]; // Write output @@ -137,6 +142,8 @@ class DbQ extends nb { 'param.action' => $this->params['action'], 'param.args' => $this->params['args'], 'param.deep' => $this->params_deep, + 'text.add' => 'Add', + 'text.clear' => 'Clear', ]; $this->page->js_code = 'window._dbq = '.json_encode($this->json); @@ -151,21 +158,27 @@ class DbQ extends nb { #if (is_scalar($obj)) { $conf = ['row_parse_post'=>$fct]; - if(is_array($obj)) { - $this->db->out($obj,$head,$conf); + $rows = ''; + if (is_array($obj)) { + $rows = $obj; } elseif (empty($meth)) { echo $obj; - } elseif(is_array($meth)) { - $this->db->out($meth,$head,$conf); + } elseif (is_array($meth)) { + $rows = $meth; - } else { # Objects Method - $out = $obj->$meth(); - if (!empty($out)) $this->db->out($out,$head,$conf); + } elseif(is_scalar($meth)) { # Objects Method + $rows = $obj->$meth(); + if (empty($this->params['table'])) $this->params['table'] = $meth; + + } else { + $this->error("Page error"); } + if (!empty($rows)) $this->db->out($rows,$head,$conf); + if (empty($this->_nopage)) $this->page->end(); exit; } @@ -178,17 +191,19 @@ class DbQ extends nb { if (!$this->params['db']) $this->not_implemented('Params db missing'); if (!isset($this->db)) $this->db = $this->db(); + # From conf if (!is_array($connect) and $connect === true and isset($this->db->conf[$this->params['db']]) ) { $connect = $this->db->conf[$this->params['db']]; + if (empty($connect['name'])) $this->not_found('Unknown database: '.$this->params['db']); } - if (empty($connect['name'])) $this->not_found('Unknown database: '.$this->params['db']); + $connect['id']= $this->params['db']; $this->db->__construct($connect); - $this->id = $this->params['db']; + #$this->id = $this->params['db']; $this->db->connect(); $this->db->base = '/'.$this->db->id; return $this->db; @@ -196,7 +211,6 @@ class DbQ extends nb { // Re use if (!empty($this->db)) return $this->db; - require_once(NB_ROOT.'/lib/php/config.php'); require_once(NB_ROOT.'/lib/php/db.php'); // New @@ -241,11 +255,12 @@ class DbQ extends nb { $opt = ($this->page->is('html') and ($this->perm >= self::VIEW) and $this->table->type() != 'sql' + and strpos(' table view',$this->table->type()) ) ? [ 'row_parse_pre' => function(&$r){ $GLOBALS['dbq_args'] = urlencode( join($this->param_args_sep,$this->table->fields_keys_values($r)) ); }, - 'row_parse_post' => function(&$r){ + 'row_parse_post' => $this->table->type() ? 0 : function(&$r){ $args = $GLOBALS['dbq_args']; @@ -279,7 +294,7 @@ class DbQ extends nb { } - public function table() { + public function table($param=[]) { if (!in_array($this->params['table'],array_keys($this->db->tables()))) { @@ -290,14 +305,14 @@ class DbQ extends nb { } - $this->table = $this->db->table($this->params['table'],[ + $this->table = $this->db->table($this->params['table'],array_merge([ 'db' => $this->db, 'show_hidden_params' => false, 'show_buttons' => false, 'show_header' => ($this->params['format'] == 'html'), #'params' => [], #'params' => [ 'limit' ], - ]); + ],$param)); $this->table->base = $this->db->base.'/'.$this->table->name; @@ -309,7 +324,7 @@ class DbQ extends nb { $title = array_filter(array_unique(array_slice(array_values($params),1)), function($v){ - return(in_array($v,self::ACTIONS_NO_TITLE) ? '' : $v); + return(in_array($v,self::ACTIONS_NO_TITLE) ? '' : trim($v)); } ); @@ -593,6 +608,29 @@ class DbQ extends nb { #return $this->page($rows); } + public function rows_table($name,$rows) { + $this->params['table'] = $name; + $this->params['db'] = ' '; + + $this->db->conf[ $this->params['db'] ] = [ + 'name' => $this->params['table'], + 'type' => 'sqlite', + 'host' => ':memory:', + 'type' => 'sqlite', + 'tables' => [ $this->params['table'] => [ + 'rows' => $rows + ] ], + ]; + $this->db->__construct($this->db->conf[ $this->params['db'] ]); + if (empty($this->db->conn)) $this->db(true); + + if (empty($this->table)) $this->table(); + $this->table->base = ''; + + $this->page($this,'table_rows'); + + } + public function run_root() { $action = $this->params['db']; if (!$action and self::PARAM_DB_DEFAULT) $action = self::PARAM_DB_DEFAULT; @@ -634,27 +672,9 @@ class DbQ extends nb { $this->page($this,'json'); } elseif ($action == 'phpinfo') { + $this->rows_table($action,$this->phpinfo_rows()); #$this->page(['phpinfo'=>$this->page->phpinfo(true)]); #$this->page($this->page->phpinfo()); - if (0) { - $this->params['table'] = 'phpinfo'; - /* - $this->params['db'] = 'mem'; - $this->db = new Db([ - 'name' => 'mem', - 'name' => 'id', - 'type' => 'sqlite', - 'host' => ':memory:', - ]); - */ - $this->params['db'] = 'sys'; - $this->db->table($this->params['table'],[ - 'rows' => $this->phpinfo_rows(), - 'type' => 'table', - ]); - return true; - #$this->page($this,'table_rows'); - } $this->page($this,'phpinfo_rows'); #$this->phpinfo_rows(); @@ -716,18 +736,6 @@ class DbQ extends nb { $action = $this->params['action']; if (!$action and self::PARAM_DB_DEFAULT) $action = self::PARAM_DB_DEFAULT; - if (0) { - $this->table->name = 'zaza'; - $this->table->rows = [ - [ - 'name' => 'Name 1', - ], - [ - 'name' => 'Name 2', - ], - ]; - } - #bye([$this->params,$action]); if ($action == 'help') { $this->page($this->table,[ diff --git a/www/dbq/html/default.css b/www/dbq/html/default.css index 6496cea2..f222ff38 100644 --- a/www/dbq/html/default.css +++ b/www/dbq/html/default.css @@ -114,10 +114,10 @@ table.rows { border-collapse: collapse; box-shadow: 0 0 0 1px #DDDDDD; table-layout: fixed; - /* - display: inline-block; +} + +table.rows.fixed { width: 100%; - */ } table.rows tr:nth-child(even) td { @@ -144,14 +144,12 @@ table.rows td .delete { white-space: nowrap; } -/* -table.rows td .code +table.rows.fixed td { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } -*/ table.rows th { text-align: left; diff --git a/www/dbq/html/default.js b/www/dbq/html/default.js index 15f9c5d4..667c1305 100644 --- a/www/dbq/html/default.js +++ b/www/dbq/html/default.js @@ -115,10 +115,26 @@ document.addEventListener("DOMContentLoaded", function() { }); */ + // No more than 100% width + document.querySelectorAll("table").forEach(function(e) { + if (parseInt(e.offsetWidth) > parseInt(window.innerWidth)) { + e.className = e.className.replace(/(^| +)fixed($| )/,'') + ' fixed' + e.className = e.className.trim(); + //console.log(e.offsetWidth +'>'+ window.innerWidth+' '+e.className); + } + }); + document.querySelectorAll("form.menu input[type=submit]").forEach(function(e) { e.insertAdjacentHTML("afterend",'' - +' ' - +(window._dbq['table.base'] ? ' ' : '') + +' ' + +( window._dbq['table.base'] + ? ' ' + : '' + ) ); }); diff --git a/www/dbq/html/default.min.css b/www/dbq/html/default.min.css index b34cefc6..1d2ada4a 100644 --- a/www/dbq/html/default.min.css +++ b/www/dbq/html/default.min.css @@ -1 +1 @@ -html{font:90% 'Trebuchet MS',sans-serif;background-color:#EEE}body{display:table;margin-left:auto;margin-right:auto;padding-left:1em;padding-right:1em;color:#444}h1{margin:0 0 0.2em 0;font-size:180%;padding-bottom:0.3em;margin-bottom:0.5em;border-bottom:dashed 1px #444}a{color:inherit}p a,div > a,li a,td a{color:#E59B24}a,a:visited{text-decoration:none}ul{padding:0;margin:0}li{list-style:none;padding:0 0 0 0.3em}table{border-collapse:collapse}td,th{padding:0.2em 0.7em}th a.sort{padding:0 0.3em}textarea,select,input:not([type]),input[type='text'],input[type='password'],input[type='date'],input[type='email'],input[type='url'],input[type='']{border-radius:3px;border:solid 1px #ddd;padding:0.3em 0.4em}input[size]{max-width:70%}div.row div label:after,form label:after{content:':'}form label,form input,form select{vertical-align:middle;margin:0.2em 0.4em 0.2em 0}table.rows,div.row,ul.row,form.edit,.menu,.block,object,iframe,pre{border-radius:4px;border-spacing:0;padding:0.5em 0.2em;margin-bottom:0.5em;border:solid 1px #DDD;background-color:#FAFAFA}.rows{padding:0}table.rows{border-style:hidden;border-collapse:collapse;box-shadow:0 0 0 1px #DDD;table-layout:fixed;width:99%}table.rows tr:nth-child(even) td{background-color:#FEFEFE}ul.row li,div.row div,table.rows th,table.rows td{border-bottom:solid 1px #DDD}ul.row li,div.row div,table.rows tr:last-child td{border-bottom:none}table.rows tr > *{border-right:solid 1px #FEFEFE}table.rows td{padding:0.3em 0.3em;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}table.rows th{text-align:left}div.row div{margin:0}ul.row li label,div.row div label{padding:0.1em 0.5em 0.1em 0;min-width:20%;display:inline-block}.menu,.nav,.rows,.buttons,td.button,.center{margin-left:auto;margin-right:auto;display:table}.button{font:inherit;display:inline-block;text-decoration:none;line-height:1.5em;cursor:pointer;border-radius:4px;white-space:nowrap;box-sizing:border-box;margin:0;padding:0 0.1em;cursor:pointer;color:#EEE;background-color:#666;padding:0.1em 0.3em;border:none}a:hover,.button:hover{opacity:0.8}form.menu{padding:0.5em;background-color:#FAFAFA}form.menu .button.add{float:right;margin-top:0.1em}form.menu .criterias{border-top:dashed 1px #DDD;margin-top:0.3em;padding-top:0.3em}form.menu .criterias span.label{border-right:solid 1px #fff;padding:0.2em 0.1em;margin:0.2em 0.2em 0 0;border-radius:3px}form.menu .criterias span.label:last-child{border-right:none}form.menu select:focus{max-width:auto}form.menu select{max-width:20%}form.menu .criterias input[type=text]:focus{width:auto}form.menu .criterias input[type=text]{width:4em}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left}form.edit .fields input,form.edit .fields textarea,form.edit .fields select{width:65%}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left} \ No newline at end of file +html{font:90% 'Trebuchet MS',sans-serif;background-color:#EEE}body{display:table;margin-left:auto;margin-right:auto;padding-left:1em;padding-right:1em;color:#444}h1{margin:0 0 0.2em 0;font-size:180%;padding-bottom:0.3em;margin-bottom:0.5em;border-bottom:dashed 1px #444}a{color:inherit}p a,div > a,li a,td a{color:#E59B24}a,a:visited{text-decoration:none}a:hover,.button:hover{opacity:0.8}ul{padding:0;margin:0}li{list-style:none;padding:0 0 0 0.3em}table{border-collapse:collapse}td,th{padding:0.2em 0.7em}th a.sort{padding:0 0.3em}textarea,select,input:not([type]),input[type='text'],input[type='password'],input[type='date'],input[type='email'],input[type='url'],input[type='']{border-radius:3px;border:solid 1px #DDD;padding:0.3em 0.4em;box-shadow:0 1px 1px #EEE}input[size]{max-width:70%}div.row div label:after,form label:after{content:':'}form label,form input,form select{vertical-align:middle;margin:0.2em 0.4em 0.2em 0}table.rows,div.row,ul.row,form.edit,.menu,.block,object,iframe,pre{border-radius:4px;border-spacing:0;padding:0.5em 0.2em;margin-bottom:0.5em;border:solid 1px #DDD;background-color:#FAFAFA;box-shadow:0 1px 2px #EEE}.rows{padding:0}table.rows{border-style:hidden;border-collapse:collapse;box-shadow:0 0 0 1px #DDD;table-layout:fixed}table.rows tr:nth-child(even) td{background-color:#FEFEFE}ul.row li,div.row div,table.rows th,table.rows td{border-bottom:solid 1px #DDD}ul.row li,div.row div,table.rows tr:last-child td{border-bottom:none}table.rows tr > *{border-right:solid 1px #FEFEFE}table.rows td{padding:0.3em 0.3em}table.rows td .view,table.rows td .delete{width:1%;white-space:nowrap}table.rows th{text-align:left}div.row div{margin:0}ul.row li label,div.row div label{padding:0.1em 0.5em 0.1em 0;min-width:20%;display:inline-block}.button{font:inherit;display:inline-block;text-decoration:none;line-height:1.5em;cursor:pointer;border-radius:4px;white-space:nowrap;box-sizing:border-box;margin:0;padding:0 0.1em;cursor:pointer;padding:0.1em 0.3em;border:none;color:#E59B24;background-color:#EEE;background:linear-gradient(to bottom right,#EEE,#DDD);margin-right:0.1em;box-shadow:0 1px 1px #BBB;font-weight:bold}.menu,.nav,.rows,.buttons,td.button,.center{margin-left:auto;margin-right:auto;display:table}form.menu{padding:0.5em;background-color:#FAFAFA}form.menu .button.add{float:right;margin-top:0.3ex;display:inline}form.menu .criterias{border-top:dashed 1px #DDD;margin-top:0.3em;padding-top:0.3em}form.menu .criterias span.label{border-right:solid 1px #fff;padding:0.2em 0.1em;margin:0.2em 0.2em 0 0;border-radius:3px}form.menu .criterias span.label:last-child{border-right:none}form.menu select:focus{max-width:auto}form.menu select{max-width:20%}form.menu .criterias input[type=text]:focus{width:auto}form.menu .criterias input[type=text]{width:4em}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left}form.edit .fields input,form.edit .fields textarea,form.edit .fields select{width:65%}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left} \ No newline at end of file
' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '