]> git.nbdom.net Git - nb.git/commitdiff
dbq
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 23 Dec 2016 09:42:29 +0000 (09:42 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 23 Dec 2016 09:42:29 +0000 (09:42 +0000)
lib/php/db.php
lib/php/db/table.php
www/dbq/dbq.php

index 2dc61595169c9192e7f9990ba4fd862b00bacaae..94088410bea8cc83d5afbf6a0a0fc16aafafe4fc 100644 (file)
@@ -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();
index d3116fbf6cea7915a59698c1045df5756b56bb03..3c153d15f629d917fba59921fa90d5f07de3e103 100644 (file)
@@ -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 .= '</span>';
 
@@ -1811,12 +1811,12 @@ Class Table extends nb {
 
       // Format
       $r .= '<span class="label">';
-
+      #debug($this->db()->formats);
       $r .= '<label for="format">Format</label>'.html_select_array($this->db()->formats,[
         'html'       => 'class="format" name="format" id="format"',
         'selected'   => $this->db()->format,
         'prettyText' => true,
-        'sort' => 'natcasesort',
+        'sort'       => 'natcasesort',
       ]);
       $r .= '</span>';
 
index ede271a1dd65c904ab2e85382b6ceddbd5ac928b..9227aef9898e490c83b12af1d84267cf909aff28 100644 (file)
@@ -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;