From: Nicolas Boisselier Date: Mon, 11 Apr 2016 23:52:52 +0000 (+0100) Subject: Bed X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=f6b557265022fd56225f72075436f51e1bde3eb4;p=nb.git Bed --- diff --git a/etc/dbs/ui.php b/etc/dbs/ui.php index f153a708..45005f10 100644 --- a/etc/dbs/ui.php +++ b/etc/dbs/ui.php @@ -81,7 +81,11 @@ $CONF['ui'] = array( ), 'node' => array( + 'row_parse_post'=> function(&$r) { + $r['graph'] = ''; + }, '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' => '\'\'', + #'graph' => '\'\'', ), - 'view_backup' => array( - 'Details' => '\'Go\'', - ), + ), - 'view_pingdom_per_month' => array( - 'Checks' => '\'\'||(SELECT count(*) FROM pingdom_check_policy pcp WHERE pcp.idpingdom_policy=view_pingdom_per_month.idpingdom_policy)||\'\'', - ), - 'pingdom_check' => array( - 'View' => '\'\'', + 'view_backup' => array( + 'row_parse_post'=> function(&$r) { + $r['Detail'] = 'View'; + }, + ), + + 'view_pingdom_per_month' => array( + 'row_parse_post'=> function(&$r) { + $r['Checks'] = ''.$r['Checks'].''; + }, + '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'] = ''; + }, + ), + ), ); ?> diff --git a/lib/js/nb.js b/lib/js/nb.js index 94fcb768..45ce77a8 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -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'); }); } diff --git a/lib/php/config.php b/lib/php/config.php index 381e9f50..10b9b73b 100644 --- a/lib/php/config.php +++ b/lib/php/config.php @@ -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'); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 8c3305cb..dd65fe5e 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -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'))) { diff --git a/lib/php/nb.php b/lib/php/nb.php index a938b34a..fcaf7f93 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -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())); } diff --git a/lib/php/out.php b/lib/php/out.php index e0489023..451cdfe9 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -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);