From 6d0a677a727ffb4fb98dd8434c6a4fe5c9e373b6 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 23 Dec 2016 09:42:29 +0000 Subject: [PATCH] dbq --- lib/php/db.php | 14 ++------------ lib/php/db/table.php | 6 +++--- www/dbq/dbq.php | 27 ++++++++++----------------- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 2dc61595..94088410 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -120,12 +120,11 @@ class Db extends nb { public $sort; public $extras; public $format = 'json'; - public $formats = [ 'table','div','csv','xml','json','yaml','sh' ]; + public $formats = [ 'table','div','csv','xml','json','yaml','sh','sql' ]; public $limits = ['10','20','50','100','500','1000']; # Classes public $out; -# NB 21.09.16 public $_no_connect; function __construct($opt = '') { @@ -146,24 +145,15 @@ class Db extends nb { # Tables if (isset($opt['tables'])) { - #debug($opt['tables']); - #foreach ($opt['tables'] as $name=>$param) debug($name); foreach ($opt['tables'] as $name=>$param) $this->table($name,$param); unset($opt['tables']); } - # Encoding -# NB 22.09.16 if (isset($opt['encoding'])) { -# NB 22.09.16 self::$encoding = $opt['encoding']; -# NB 22.09.16 unset($opt['encoding']); -# NB 22.09.16 } - # Args into this foreach ($opt as $k=>$v) $this->$k = $v; #parent::__construct($opt); # Out Class - #if(!is_scalar($opt['type'])) debug($opt['type']); if (empty($this->out)) $this->out = new Out(['charset'=>$this->charset]); # Format @@ -176,7 +166,7 @@ class Db extends nb { } # Add formats from module out - foreach($this->out->types('_web_') as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t; +# NB 23.12.16 foreach($this->out->types('_web_') as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t; # Pdo $this->connect_init(); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index d3116fbf..3c153d15 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1793,7 +1793,7 @@ Class Table extends nb { 'html' => 'class="tables" name="table" id="table"', 'selected' => $this->name, 'prettyText' => true, - 'sort' => 'natcasesort', + 'sort' => 'natcasesort', ]); $r .= ''; @@ -1811,12 +1811,12 @@ Class Table extends nb { // Format $r .= ''; - + #debug($this->db()->formats); $r .= ''.html_select_array($this->db()->formats,[ 'html' => 'class="format" name="format" id="format"', 'selected' => $this->db()->format, 'prettyText' => true, - 'sort' => 'natcasesort', + 'sort' => 'natcasesort', ]); $r .= ''; diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index ede271a1..9227aef9 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -20,18 +20,12 @@ class DbQ extends nb { const VIEW = 1; public $title = 'Dbq'; - public $sep = ' / '; + public $sep_title = ' / '; const HTML_FORMAT = 'table'; const CLI_FORMAT = 'human'; public $human_ua_exp = '/^\S+\s+.Windows|iPhone|Android|Macintosh|Linux/'; - public $formats = [ - 'table', - 'csv', - 'json', - 'yaml', - 'sh', - ]; + public $formats = []; const PARAM_ARGS_SEP = '|'; @@ -44,9 +38,7 @@ class DbQ extends nb { 'action' => 'ls', 'args' => '', ]; - public $params_deep = []; - - public $run = false; # call run() when __contruct +# NB 23.12.16 public $params_deep = []; public $css = '/default.css'; public $js = '/default.js'; @@ -90,6 +82,9 @@ class DbQ extends nb { // // Init $this->uri_params(); + $run = isset($opt['run']) ? $opt['run'] : false; + unset($opt['run']); + parent::__construct($opt); if (!$this->params['db']) $this->not_implemented('Db missing'); @@ -99,10 +94,10 @@ class DbQ extends nb { $this->page = new Page([ 'css' => $this->css, - 'sep' => $this->sep, + 'sep' => $this->sep_title, ]); - if ($this->run) $this->run(); + if ($run) $this->run(); } public function page($obj,$meth=null,$head=[],$fct=null) { @@ -209,8 +204,6 @@ window._dbq = { $values = explode(self::PARAM_ARGS_SEP,$this->params['args']); - #if (!$keys) return; #$this->not_implemented('Table has no fields'); - #bye(array_combine($keys,$values)); $this->table->html_edit(array_combine($keys,$values),$this->table->base.($add ? 'insert/' : 'update/').$this->params['args'],$add); } @@ -355,7 +348,7 @@ window._dbq = { } $i++; - $this->params_deep[$p] = $i; +# NB 23.12.16 $this->params_deep[$p] = $i; } return $this->params; @@ -463,7 +456,7 @@ window._dbq = { if (empty($this->ext)) $this->ext = $format; list($title,$nav) = $this->title_nav(); - $this->page->title = join($this->sep,$title); + $this->page->title = join($this->sep_title,$title); $this->page->nav = $nav; if (!empty($this->formats)) $this->db->formats = $this->formats; -- 2.47.3