]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 11 Apr 2016 23:52:52 +0000 (00:52 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 11 Apr 2016 23:52:52 +0000 (00:52 +0100)
etc/dbs/ui.php
lib/js/nb.js
lib/php/config.php
lib/php/db/table.php
lib/php/nb.php
lib/php/out.php

index f153a708f975353aa0c43acb124d9f01f3b6b795..45005f105db664b284c39864ebbd2376bc362877 100644 (file)
@@ -81,7 +81,11 @@ $CONF['ui'] = array(
     ),
 
     'node' => array(
+      'row_parse_post'=> function(&$r) {
+        $r['graph'] = '<a target="_blank" href="/graphite/?Hosts='.$r['id'].'"><img src="/images/graphite.png" /></a>';
+      },
       'extras'=> array(
+        'ip' => false,
         'ips' => false,
         'file' => false, # printed in meta
         # n => v
@@ -97,20 +101,32 @@ $CONF['ui'] = array(
         ))"),
         'fact' => "(SELECT count(*) FROM fact WHERE fact.idnode=node.id)",
         'keyevent' => "(SELECT count(*) FROM keyevent WHERE keyevent.idnode=node.id)",
-        'graph' => '\'<a target="_blank" href="/graphite/?Hosts=\' || id || \'"><img src="/images/graphite.png" /></a>\'',
+        #'graph' => '\'<a target="_blank" href="/graphite/?Hosts=\' || id || \'"><img src="/images/graphite.png" /></a>\'',
       ),
 
-      'view_backup' => array(
-        'Details' => '\'<a target="_blank" class="view_backup" href="?table=backup&idnode=\' || idnode || \'">Go</a>\'',
-      ),
+    ),
 
-      'view_pingdom_per_month' => array(
-        'Checks' => '\'<a target="_blank" class="pingdom_check_report" href="?table=pingdom_check_policy&idpingdom_policy=\' || idpingdom_policy || \'">\'||(SELECT count(*) FROM pingdom_check_policy pcp WHERE pcp.idpingdom_policy=view_pingdom_per_month.idpingdom_policy)||\'</a>\'',
-      ),
-      'pingdom_check' => array(
-        'View' => '\'<a target="_blank" class="pingdom_check_report" href="https://my.pingdom.com/reports/uptime#check=\' || id || \'"><img src="/images/graphite.png" /></a>\'',
+    'view_backup' => array(
+      'row_parse_post'=> function(&$r) {
+        $r['Detail'] = '<a target="_blank" class="view_backup" href="?table=backup&idnode='.$r['idnode'].'">View</a>';
+      },
+    ),
+
+    'view_pingdom_per_month' => array(
+      'row_parse_post'=> function(&$r) {
+        $r['Checks'] = '<a target="_blank" class="pingdom_check_report" href="?table=pingdom_check_policy&idpingdom_policy='.$r['idpingdom_policy'].'">'.$r['Checks'].'</a>';
+      },
+      'extras' => array(
+        'Checks' => '(SELECT count(*) FROM pingdom_check_policy pcp WHERE pcp.idpingdom_policy=view_pingdom_per_month.idpingdom_policy)',
       ),
     ),
+
+    'pingdom_check' => array(
+      'row_parse_post'=> function(&$r) {
+        $r['View'] = '<a target="_blank" class="pingdom_check_report" href="https://my.pingdom.com/reports/uptime#check='.$r['id'].'"><img src="/images/graphite.png" /></a>';
+      },
+    ),
+
   ),
 );
 ?>
index 94fcb76840946461bb0fb982b1499c2e215c8762..45ce77a8a17ef11f6fa80d3b7dc0d5803bfcd12f 100644 (file)
@@ -78,7 +78,10 @@ function NB() {
 
       // apply
       $(this).height(h); $(this).width(w);
-      $(this).css('overflow','auto');
+      $(this).css({
+        'overflow':'auto',
+      });
+      if (this.tagName == 'TABLE') $(this).css('display','block');
     });
   }
 
index 381e9f500947801f43f0722f7cb863af51885b15..10b9b73b4dfb691a34bdc2dc13dded9d8d5a464e 100644 (file)
@@ -9,9 +9,9 @@
 #define('NB_EOL','');
 #define('NB_PROD',true);
 require(dirname(__FILE__).'/nb.php');
-if (nb::php_cli()) argv2request();
+if (!empty($_SERVER['PROD'])) return;
 
-if (empty($_SERVER['DEV'])) return;
+if (nb::php_cli()) argv2request();
 
 // Should be done in php.ini for performance
 date_default_timezone_set('Europe/London');
index 8c3305cbb95d1bf7bc50234a8baaa9fc34f5302b..dd65fe5eab1de7c261cd7788871635f4871c5f46 100644 (file)
@@ -497,13 +497,16 @@ Class Table extends nb {
 
   public function add_extras($extras) {
     if ($this->p('extras') === '0') return false;
+    #return false;
 
     $this->fields();
 
     foreach ($extras as $k => $v) {
 
-      if ($v === null or $v === false) {
+      if ($v === false or $v === null) {
         if (isset($this->fields[$k])) unset($this->fields[$k]);
+        #if (isset($this->extras[$k])) unset($this->extras[$k]);
+        $this->_rows_fields = true;
         continue;
       }
 
@@ -535,11 +538,12 @@ Class Table extends nb {
     Html Output
   ******************************************************************/
   public function rows(&$opt=array(),$opt_by_val=null) {
+
     if (isset($this->orderby)) self::pdef('orderby',$this->orderby);
     if ($opt_by_val !== null) $opt = $opt_by_val;
 
     $format = $this->p('format');
-    if (!$format) bye("No param format");
+    if (!$format) bye("Invalid parameter!");
 
     //
     // Select
@@ -554,9 +558,17 @@ Class Table extends nb {
       $select_count = ( $where ? $this->db()->type('select_count') : null );
       if (empty($select_count)) $select_count = array('','');
 
-      $sql = "SELECT ".trim("$select_count[0] *"). $this->select_extras();
+      if (!empty($this->_rows_fields)) {
+        foreach ($this->fields() as $f) {
+          if (empty($f->extra)) $select_fields[] = $f->sql_name();
+        }
+      } else {
+        $select_fields = array('*');
+      }
+      $sql = "SELECT ".trim( $select_count[0].' '.join(',',$select_fields) ). $this->select_extras();
       $sql .= " FROM ".$this->sql_name();
       $sql .= $where;
+      #bye($sql);
 
       if ($this->p('orderby')) $sql .= ' ORDER BY '.$this->p('orderby');
 
@@ -616,16 +628,18 @@ Class Table extends nb {
 
     if ($opt['is_html']) out::$type = 'html';
     $count = 0;
+    $extras = self::p('extras') === '0' ? 0 : 1;
+    #bye($extras);
     while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
 
       $count++;
       $call = null;
 
-      if (!empty($this->db()->row_parse)) {
+      if ($extras and !empty($this->db()->row_parse)) {
         $call = $this->db()->row_parse; $call($row);
       }
 
-      if (!empty($this->row_parse_pre)) {
+      if ($extras and !empty($this->row_parse_pre)) {
         $call = $this->row_parse_pre; $call($row);
       }
 
@@ -635,7 +649,7 @@ Class Table extends nb {
         }
       }
 
-      if (!empty($this->row_parse_post)) {
+      if ($extras and !empty($this->row_parse_post)) {
         $call = $this->row_parse_post; $call($row);
       }
 
@@ -1199,14 +1213,8 @@ Class Table extends nb {
       $this->out2($e);
       return true;
 
-    } elseif ($r=self::class_action_out($this,$action)) {
-      return $r;
-# NB 10.04.16     } elseif (preg_match('/^table\.(\w+)/',$action,$m)) {
-# NB 10.04.16       if ($rows = $this->$m[1]() and !empty($rows)) {
-# NB 10.04.16         $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
-# NB 10.04.16       } else {
-# NB 10.04.16         $return = true;
-# NB 10.04.16       }
+    } elseif (self::class_action_out($this,$action)) {
+      return true;
 
     } elseif ($this->p('format') and !preg_match('/^(table|div)$/',$this->p('format'))) {
 
index a938b34a4d8942d22f8e9830204b36c2ff3d0e77..fcaf7f930dc6d6003f7e608da1b12b8fcf95b831 100644 (file)
@@ -488,10 +488,22 @@ class NB {
 
     $rows = array();
     if (in_array($name,get_class_methods($class))) $rows = $class->$name();
-    else $rows = $class->$name;
+    elseif (in_array($name,get_class_vars($class_name))) $rows = $class->$name;
+    else self::bye("Unknow action: `$action`");
+    #else $rows = $class->$name;
     if (!$rows) return false;
 
-    return out::rows(self::p('format',self::php_cli() ? 'csv' : 'table'),$rows,(is_scalar($rows) ? $name : array()));
+    #bye($rows);
+    if (is_scalar($rows)) {
+      #echo "$rows\n";
+      $rows = array($name => $rows);
+      #return true;
+    }
+    #debug($action.' '.$class_name.' '.$name);
+    out::rows(self::p('format',self::php_cli() ? 'csv' : 'table'),$rows,(is_scalar($rows) ? $name : array()));
+    return true;
+    $class->out2(self::object2array($rows),(is_scalar($rows) ? $name : array()));
+    return true;
     return self::object2array($rows);
     return $class->out2(self::object2array($rows),(is_scalar($rows) ? $name : array()));
   }
index e04890235944a89719b9e1442254eb2969df3c9f..451cdfe9c1db97659fed71c61821935786cdeacd 100644 (file)
@@ -141,13 +141,12 @@ Class Out extends Nb {
 
     # For sprintf
     unset($o['head_max_len']);
-# NB 01.04.16     if (!empty($head)) {
-# NB 01.04.16       $o['head_max_len'] = max(self::ar_map('strlen($a)',$head));
-# NB 01.04.16     }
+
     if (!empty($data)) {
       if (self::is_hash($data[0])) {
         $o['head_max_len'] = max(self::ar_map('strlen($a)',array_keys($data[0])));
       } elseif (is_array($data[0])) {
+        #debug($data);
         $o['head_max_len'] = max(self::ar_map('strlen($a)',$data[0]));
       }
       #bye($o);