]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 7 Apr 2016 00:40:27 +0000 (01:40 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 7 Apr 2016 00:40:27 +0000 (01:40 +0100)
etc/dbs.yaml
lib/css/db.css
lib/php/db/table.php
lib/php/nb.php
lib/php/out.php
lib/php/page.php

index eae12cbfed3565b4e15b12554ce54abedc7a331f..da678f433525e92b8c1e246cc3449f66fdef411a 100644 (file)
@@ -97,9 +97,6 @@ _rent:
   title: 'Rent'
   notice: 'Micro foncier 4BE'
   default_table: 'rent'
-  map:
-    "SELECT addr FROM addr WHERE id='@id'": ".rows.place td.id, .rows.rent td.idplace"
-    "SELECT name FROM tenant WHERE id='@id'": ".rows.rent td.idtenant"
 
 # NEW- NB 10.01.16
   tables:
index bea3dbf184b64ea2e53aef1513c97325fe7b2abd..94ca2b2f8be9be762d711045721f081561f00b13 100644 (file)
@@ -63,7 +63,7 @@ table.rows tr { vertical-align: top; }
   vertical-align: top;
 }
 
-.db div.rows .row span {
+.db div.rows label {
   width: 70%;
   display: inline-block;
   white-space: normal;
index 698d3ac50936f01e113baedb2a04589c1d5d3116..d56fe26d0e15462804a2bcaedb2d1cbc87f6096f 100644 (file)
@@ -600,7 +600,15 @@ Class Table extends nb {
       : false
     ;
 
-    if ($opt['is_html'] and !$this->p('action')) echo $this->html_menu();
+    if ($opt['is_html'] and !$this->p('action') and !$this->p('inc')) {
+      echo $this->html_menu();
+
+    } elseif ($opt['is_html'] and !$this->p('inc')) {
+      echo $this->form_hidden();
+
+    }
+
+    if ($opt['is_html']) echo '<div class="results">'.NB_EOL;
 
     # Use the module out when format unknow
     $out_conf = null;
@@ -617,11 +625,18 @@ Class Table extends nb {
 
     }
 
+    if ($opt['is_html']) out::$type = 'html';
     $count = 0;
     while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
 
       $count++;
 
+      if ($opt['is_html'] and !$out_conf) {
+        foreach ($row as $k=>$v) {
+          if (!isset($this->extras[$k])) $row[$k] = out::format($v);
+        }
+      }
+
       #
       # Head
       #
@@ -718,6 +733,10 @@ Class Table extends nb {
 
     } # < out
 
+    if ($opt['is_html']) {
+      echo '</div>'.NB_EOL;
+    }
+
     $st->closeCursor();
 
     return $count;
@@ -946,6 +965,7 @@ Class Table extends nb {
   }
 
   public function rows_end_div($opt=array()) {
+    return '</div>'.NB_EOL;
   }
 
   public function sql_name($value=null) {
@@ -1269,21 +1289,21 @@ Class Table extends nb {
     ));
     $r .= '</span>';
 
-    // Dbs
+    // Dbs - see default.js if you change class
     if (!empty($this->db()->dbs) and count($this->db()->dbs)>1) {
       $r .= '<span class="label">';
       $r .= '<label for="db">Db</label>'.html_select_array($this->db()->dbs,array(
-        'html'       => 'class="dbs" name="db" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"',
+        'html'       => 'class="dbs" id="db" name="db" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"',
         'selected'   => self::p('db'),
         'prettyText' => true,
       ));
       $r .= '</span>';
     }
 
-    // Tables
+    // Tables - see default.js if you change class
     $r .= '<span class="label">';
     $r .= '<label for="table">Tables</label>'.html_select_array(array_keys($this->db()->tables()),array(
-      'html'       => 'class="tables" name="table" id="table"',
+      'html'       => 'class="tables" id="table" name="table" id="table"',
       'selected'   => $this->p('table'),
       'prettyText' => true,
     ));
index a0580a4cf8d176d9776bda12e8c24673e78f7de0..9dab24feb3848cff3c2b26ac3cf29d7dd42c81b7 100644 (file)
@@ -28,6 +28,12 @@ class NB {
 
   #public static function zaza() { return (is_object($this) ? 'TRUE' : 'FALSE'); }
   public static function test() { return 'TEST'; }
+  public function __construct($opt = array()) {
+    foreach ($opt as $k => $v) {
+      if ( ! array_key_exists($k,$this) ) self::bye("Unknow param $k = `$v`");
+      $this->$k = is_array($v) ? $v : trim($v);
+    }
+  }
 
   public function __sleep() { return array_keys((array)$this); }
   #public function __wakeup() { }
index 076389a40f607bc889c2894a43152d5114446967..fd0fc32155d6b35cab902510eaba15827b235b29 100644 (file)
@@ -167,10 +167,21 @@ Class Out extends Nb {
     }
 
     # yaml
-    if (!self::is_hash($row)) return out_yaml($row,$o);
+    if (!self::is_hash($row)) {
+    #bye($row);
+    }
+
+    if (!self::is_hash($row)) unset($o['head_max_len']);
+    if (is_array($row) and count($row)>1) $o['head_max_len'] = strlen(count($row));
+    #if (!self::is_hash($row)) return out_yaml($row,$o);
 
     # text
-    foreach ($row as $k => $v) { echo sprintf("%-".(!empty($o['head_max_len']) ? $o['head_max_len']+1 : 10)."s: %s\n",$k,self::escape($v)); }
+    foreach ($row as $k => $v) {
+      echo sprintf("%"
+        .(!empty($o['head_max_len']) ? '-'.($o['head_max_len']+1) : '')
+        ."s: %s\n",$k,self::escape($v)
+      );
+    }
     #foreach ($row as $k => $v) { echo "$k: ".self::escape($v)."\n"; }
 
     return true;
@@ -255,19 +266,28 @@ Class Out extends Nb {
     return;
   }
 
-  public static function escape($v,$type=null) {
-    static $replace_flags = null;
-
+  public static function format($v) {
     $is_scalar = is_scalar($v);
     $v = self::scalar($v);
     if ($v==='') $is_scalar = true;
 
-    if ($replace_flags === null) {
+    $v = self::escape($v);
+
+    if (!$is_scalar and strpos($type,'html') !== false) $v = '<pre>'.NB_EOL.$v.NB_EOL.'</pre>';
+    return $v;
+  }
+
+  public static function escape($v,$type=null,$charset=null) {
+    if ($charset === null) $type = self::$charset;
+
+    static $replace_flags = null;
+
+    if ($replace_flags === null and $charset=null and $type=null) {
 
       #$replace_flags = ENT_COMPAT | ENT_DISALLOWED;
       $replace_flags = ENT_COMPAT;
-
       if ($type === null) $type = self::$type;
+
       if (!$type) {
         return $v;
 
@@ -284,16 +304,14 @@ Class Out extends Nb {
         $replace_flags = $replace_flags | ENT_HTML5;
 
       } else { # text
-        return str_replace("\n",'|',$v);
-        return $v;
-        return preg_replace('/\n/','',$v);
+# NB 06.04.16         $v = str_replace("\n",'|',$v);
+# NB 06.04.16         $v = preg_replace('/\n/','',$v);
 
       }
 
     }
 
-    $v = htmlspecialchars($v,$replace_flags,strtoupper(self::$charset));
-    if (!$is_scalar and strpos($type,'html') !== false) $v = '<pre>'.NB_EOL.$v.NB_EOL.'</pre>';
+    $v = htmlspecialchars($v,$replace_flags,strtoupper($charset));
     return $v;
   }
 
@@ -415,5 +433,5 @@ $data = array(
 );
 #$data = array( array('a'=>'A'), array('b'=>'B'), array('c'=>'C') );
 $field = array();
-$o = new Out($argv[2] ? $argv[2] : 'yaml',$data,$field);
+$o = out::rows($argv[2] ? $argv[2] : 'yaml',$data,$field);
 ?>
index d0c02abb998195f12a42c8d50fb9eb45ba1a89e0..564d7ab420a4b94553499ffcb1567916eb659a03 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 require_once(dirname(__FILE__).'/nb.php');
+require_once(dirname(__FILE__).'/out.php');
 /*
 if (
   !@$_SERVER['DOCUMENT_ROOT'] and (realpath($argv[0]) == __FILE__)
@@ -42,7 +43,7 @@ class Page extends nb {
   /*
     Create
   */
-  function __construct($opt = array()) {
+  public function __construct($opt = array()) {
 
     //// opt
     foreach ($opt as $k => $v) {
@@ -75,11 +76,11 @@ class Page extends nb {
   /*
     Funtions
   */
-  function out($v) {
+  public static function out($v) {
     echo $v;
   }
 
-  function to_array($v) {
+  public static function to_array($v) {
     return (is_array($v) ? $v : array($v));
   }
 
@@ -101,11 +102,11 @@ class Page extends nb {
     return mb_strtoupper(mb_substr($str,0,1)).mb_strtolower(mb_substr($str,1,mb_strlen($str)));
   }
 
-  function js_quote($str) {
+  public static function js_quote($str) {
     return "'".str_replace("'","\'",$str)."'";
   }
 
-  function ansi2html($v) {
+  public static function ansi2html($v) {
     $html = array(
       sprintf('%c[1;',27) => sprintf('<bold>%c[0;',27),
 
@@ -134,7 +135,7 @@ class Page extends nb {
     );
   }
 
-  function str2txt($v) {
+  public static function str2txt($v) {
     static $replace_flags = null;
     static $charset = null;
     if ($replace_flags === null) {
@@ -214,7 +215,7 @@ class Page extends nb {
   /*
     Output
   */
-  function begin() {
+  public function begin() {
 
     $this->headers(); 
 
@@ -333,7 +334,7 @@ class Page extends nb {
     return $doctype;
   }
 
-  function head() {
+  public function head() {
     $head = '';
 
     #$head .= '</head>'.NB_EOL; return $head;
@@ -346,7 +347,7 @@ class Page extends nb {
 
       $head .= '<meta name="viewport" content="width=device-width, initial-scale=1" />'.NB_EOL;
 
-      foreach ($this->to_array($this->css) as $v) {
+      foreach (self::to_array($this->css) as $v) {
         $head .= '<link type="text/css" rel="stylesheet" href="' . $v . '" />'.NB_EOL;
       }