]> git.nbdom.net Git - nb.git/commitdiff
docker dbq
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 21 Nov 2016 12:32:20 +0000 (12:32 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 21 Nov 2016 12:32:20 +0000 (12:32 +0000)
lib/php/db/page.php
src/Docker/Compose/dbq/default.css [new file with mode: 0644]
src/Docker/Compose/dbq/default.js [new file with mode: 0644]

index 8e0c0da92783848a46311f96bd2457f888c735c6..6f2056d27df5f3b7d4244594528bb87b472e7d06 100644 (file)
@@ -1,9 +1,39 @@
 <?php
 require_once(dirname(__FILE__).'/init.php');
 require_once(dirname(__FILE__).'/../page.php');
+$css = [];
+$js = [];
+if (!empty($_SERVER['DOCUMENT_ROOT'])) {
+  foreach (array_merge([]
+    ,glob($_SERVER['DOCUMENT_ROOT'].'/css/*.css')
+    ,glob($_SERVER['DOCUMENT_ROOT'].'/*.css')
+  ) as $c) {
+    $css[] = substr($c, strlen($_SERVER['DOCUMENT_ROOT']));
+  }
+  foreach (array_merge([]
+    ,[
+      $_SERVER['DOCUMENT_ROOT'].'/jquery/jquery.js',
+      $_SERVER['DOCUMENT_ROOT'].'/jquery/jquery-ui.js',
+    ]
+    ,glob($_SERVER['DOCUMENT_ROOT'].'/js/*.js')
+    ,glob($_SERVER['DOCUMENT_ROOT'].'/*.js')
+  )
+  as $j) {
+    if (file_exists($j)) $js[] = substr($j, strlen($_SERVER['DOCUMENT_ROOT']));
+  }
+  #debug([$js,$css]);
+}
+
 $Page = new Page([
   'title' => ($Db->title ? $Db->title : Db::prettyText($Db->name)),
+  'css' => $css,
+  'js' => $js,
   'content_type' => Page::content_type_and_set_format(),
+  'nav' => [
+    [ (!empty($Db) and !empty($Db->title)) ? $Db->title : 'Home', '/'],
+    ( (!empty($Table) and !empty($Table->name)) ? [Page::prettyText($Table->name),Page::path().'?table='.urlencode($Table->name)] : '' ),
+    ( Page::p('action') ? Page::prettyText(Page::p('action')) : '' ),
+  ],
   'call' => array(
     'begin',
     #['out', "Hello World !!!\n"],
@@ -38,3 +68,4 @@ $Page = new Page([
     'end',
   ),
 ]);
+unset($js,$css);
diff --git a/src/Docker/Compose/dbq/default.css b/src/Docker/Compose/dbq/default.css
new file mode 100644 (file)
index 0000000..0014e9b
--- /dev/null
@@ -0,0 +1,336 @@
+/*
+@import "/jquery/jquery-ui.css";
+::-moz-selection { background: #5babdf; color: #fff; text-shadow: none; }
+::selection { background: #5babdf; color: #fff; text-shadow: none; }
+*/
+
+/*
+See http://blog.javierusobiaga.com/stop-using-the-viewport-tag-until-you-know-ho
+@viewport{ zoom: 1.0; width: 320px; }
+@-ms-viewport{ width: 320px; zoom: 1.0; }
+border: solid 1px black;
+  width: auto;
+*/
+
+html {
+  background-color: #333;
+  font: 100% 'Trebuchet MS', sans-serif;
+}
+
+body {
+  color: #fff;
+  display: table;
+  margin-left: auto;
+  margin-right: auto;
+  padding-left: 1em;
+  padding-right: 1em;
+}
+
+#content {
+  width: 100%;
+}
+
+ul {
+  padding: 0;
+  margin: 0;
+}
+
+li {
+  list-style:none;
+  padding: 0 0 0 0.3em;
+}
+
+a[href] {
+  text-decoration: none;
+  color: #2A83BA;
+}
+
+hr {
+  clear: both;
+  margin: 0;
+  padding: 0.5px 0;
+  border: none;
+  background-color: #f4f4f4;
+}
+
+table { border-collapse: collapse; }
+td, th { padding: 0.2em 0.7em; }
+th { font-size: 0.8em; }
+select.Z,
+textarea,
+input:not([type]),
+input[type=''],
+input[type='text'] {
+  box-shadow: 0 0 5px 0 #eee;
+  border-radius: 4px;
+  border: solid 1px #eee;
+  padding: 0.4em;
+}
+
+.block,
+h1 a,
+.rows th a,
+.rad, .border, object, iframe, pre, .t2d tr {
+  background-color: #f8f8f8;
+  margin-bottom: 0.5em;
+  color: #444;
+}
+
+/*
+  Radius / Corners
+*/
+
+table.block,
+table.rad {
+  border-collapse: separate;
+  border-spacing: 0;
+}
+
+.block,
+.rad {
+  padding: 0.2em 0.1em;
+  border-radius: 4px;
+  -webkit-border-radius: 4px;
+  -moz-border-radius: 4px;
+}
+
+.block,
+.border {
+  border: solid 1px #ccc;
+}
+
+/*
+td.name,
+td.email,
+td.phone {
+  white-space: nowrap;
+}
+*/
+
+.rows div.list a {
+  list-style: disc inside none;
+  display: list-item;
+  /*
+  background:
+    url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7)
+    no-repeat
+    left center
+  ;
+  */
+}
+.rows div.list a.revision {
+  text-transform: capitalize;
+  list-style-type: circle;
+}
+/*
+.rows div.list a.revision:before {
+  content: ">";
+}
+*/
+.rows div.list {
+  white-space: nowrap;
+  margin: 0;
+  padding: 0 0.3em;
+  max-width: 10em;
+  height: 3.5em;
+  overflow: scroll;
+  border: solid 1px #ddd;
+  /*
+  opacity: 0.5;
+  */
+  border-radius: 4px;
+  -webkit-border-radius: 4px;
+  -moz-border-radius: 4px;
+}
+
+.small { font-size: 70%; }
+
+.db h1 {
+  display: inline-block;
+  padding: 0 0.2em;
+}
+
+/*
+table.border { border-bottom: none; }
+table.border td, table.border th { border-bottom: solid 1px #eee; }
+*/
+table.block th, table.block td,
+table.border th, table.border td {
+  border-bottom: solid 1px #eee;
+}
+
+table.block tr:last-child td, table.border tr:last-child td { border-bottom: none; }
+/*
+table.border tr.row:hover td:not([class~=action]) {
+*/
+table.block tr:hover td,
+table.border tr.row:hover td {
+  background-color: #f1f1f1;
+}
+
+div.rows .row li {
+  border-bottom: solid 0.1em #fafafa;
+}
+
+.options input[name="debug"] {
+  width: 2em;
+}
+
+/*
+  Markdown
+*/
+.db div.md {
+  /*
+  display: inline-block;
+  margin-left: 25%;
+  padding: 0.1em;
+  margin-top: -50px;
+  padding: 0;
+  padding: 0.3em;
+  float: right;
+  */
+  display: inline-block;
+}
+
+/*
+.db div.md p { margin: 0; padding: 0.2em 0.8em; }
+*/
+
+.inherit {
+  font-size: inherit;
+  font-family: inherit;
+  background-color: #fff;
+  border: none;
+}
+
+/*
+  Criterias
+  width: 16em;
+*/
+.menu {
+  font-size: 80%;
+  clear: both;
+}
+
+.menu select,
+.menu input:not([type=button]):not([type=password]):not([type=submit]) {
+  max-width: 8em;
+}
+
+.menu span {
+  border: solid 1px #f4f4f4;
+  /*
+  display: inline-block;
+  max-width: 28em;
+  */
+}
+
+.options {
+  border-bottom: solid 1px #f4f4f4;
+  margin-bottom: 0.1em;
+}
+
+@media (min-width: 400px) {
+  #_responsive {
+    content: none;
+  }
+  .t2d-th { display: none; }
+
+  .menu .buttons {
+    margin-left: auto;
+    margin-right: auto;
+    display: inline-block;
+  }
+
+  .menu .label {
+    display: inline-block;
+  }
+
+  .menu .label label {
+    display: inline-block;
+    text-align: right;
+    white-space: nowrap;
+  }
+
+  .db div.md { float: right; }
+
+
+}
+
+@media (max-width: 400px) {
+  #_responsive {
+    content: "400";
+  }
+  .menu .buttons {
+    display: block;
+  }
+  .label {
+    display: block;
+  }
+  .label label {
+    min-width: 25%;
+    display: inline-block;
+    vertical-align: middle;
+  }
+  
+  .t2d {
+    /*
+    */
+    border: none;
+    border-radius: 0;
+    -webkit-border-radius: 0;
+    -moz-border-radius: 0;
+    box-shadow: none;
+    -webkit-box-shadow: none;
+    -moz-box-shadow: none;
+    background-color: inherit;
+  }
+  .t2d thead { display: none; }
+  .t2d tbody tr, .t2d tbody td { display: block; }
+  .t2d tr {
+    margin-bottom: 0.4em;
+    border-radius: 4px;
+    -webkit-border-radius: 4px;
+    -moz-border-radius: 4px;
+    padding: 0.2em 0.1em;
+  }
+  .t2d-th { min-width: 25%; display: inline-block; }
+
+}
+/* <<< @media */
+
+.button {
+  background-color: #ddd;
+  border: none;
+  color: #444;
+}
+
+.menu, .nav, .rows,
+.center {
+  margin-left: auto;
+  margin-right: auto;
+  display: table;
+}
+
+/*
+table.rows {
+ overflow: auto; 
+}
+*/
+
+/*
+.debug {
+  max-width: 800px;
+  display: block;
+  overflow: scroll;
+}
+*/
+/*
+  See: http://www.ajaxload.info/
+*/
+.loading {
+  background: 
+  url(data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAAo=)
+  no-repeat
+  left center;
+}
diff --git a/src/Docker/Compose/dbq/default.js b/src/Docker/Compose/dbq/default.js
new file mode 100644 (file)
index 0000000..216ff1f
--- /dev/null
@@ -0,0 +1,186 @@
+$(document).ready(function(){
+
+var nb = new NB({
+  'ready': true,
+  'resize': {
+    'media_id': '_responsive',
+    'table2div': 'table.rows',
+    'maximize': '.embed',
+    'resize_width': 'table, div',
+  },
+  'debug': true,
+});
+
+var TABLE = $(':input[name="table"], #table, form select.tables').first().val();
+var DB = $(':input[name="db"], #db, form select.dbs').first().val();
+var PARAMS = $.param($(
+  ':input[value!=""][name="db"]:first'
+  +',:input[value!=""][name="table"]:first'
+  +',:input[value!=""][name="debug"]:first'
+));
+
+$('a.delete').href2delete('.nav',/(\d+)( \/ )(\d+)/);
+
+//var rb = document.getElementById('nav_bottom'); var rt = document.getElementById('nav_top'); if (rb && rt) rt.innerHTML = rb.innerHTML;
+$('.rows').each(function(){
+  var rows = $(this);
+  var nav = rows.next('.nav.bottom');
+  if (nav) {
+    //console.log ( nav.html() );
+    rows.before(nav.clone().attr('id','').removeClass('bottom').addClass('top'));
+  }
+});
+
+//$('<input type="button" onclick="nb.form_clear($(this).closest(\'form\')[0])" value="X"/>').prependTo('.criterias');
+var buttons = '<span class="buttons">'
+  //+'<input type="submit" class="button submit" value="GO"/>'
+  +'<input type="button" class="button table_add" value="Add" onclick="window.location = \'?action=edit&'+PARAMS+'\';"/>'
+// NB 03.04.16     +'<input type="button" class="button table_add" value="Add" onclick="window.location = \'?action=edit&amp;table=\'+$(\'#table\').val()"/>'
+  //+'<input type="button" onclick="nb.form_clear($(this).closest(\'form\')[0])" value="X"/>'
+  +'<a href="#" class="button" onclick="nb.form_clear($(this).closest(\'form\')[0])">X</a>'
++'</span>';
+//$('.options .buttons').append( $('<input type="button" onclick="nb.form_clear($(this).closest(\'form\')[0])" value="X"/>') );
+$('.db form.menu .options').append( $(buttons) );
+
+// Class
+$('.nav, table.rows, center.rows .row, div.rows .row, .db.edit .fields, .menu, div.md').addClass('border rad');
+//$('.rows .doc').addClass('rad');
+$(':submit, :button, :reset').addClass('button');
+$('body > h1, .err').addClass('rad');
+
+// Replace with queries
+var sql = {
+  "SELECT '@id (' || count(*) || ')' FROM @id": ".menu .tables li a, .menu .tables li span",
+};
+for (var k in sql) { sql2html(k,sql[k]); }
+/*
+console.log($('#db-table-replace').text().split(' '));
+*/
+if ($('#db-table-replace').length>0) $.each($('#db-table-replace').text().split(' '),function(i,v){
+  v = v.split('.');
+  var r = v[0];
+  var t = v[1];
+  var f = v[2];
+  //console.log('.rows td.'+f+', .rows span.'+f+' | '+'SELECT '+f+' FROM '+t+" WHERE id='@id'");
+  sql2html('SELECT '+f+' FROM '+t+" WHERE id='@id'",'.rows td.'+r+', .rows span.'+r);
+  //console.log('SELECT '+f+' FROM '+t+" WHERE id='@id'"+" | "+'.rows td.'+r+', .rows span.'+r);
+});
+/*
+$('td.revision a').addClass('button').css('margin','0.1em auto');
+$('td.revision').css('text-align','center');
+*/
+
+// Path truncate
+nb.e2links('.rows td.doc, .rows span.doc, .rows td.url, .rows span.url');
+
+// Truncate
+$('.rows .description').each(function(){
+  $(this).text( nb.str_trunc($(this).text(),30) );
+});
+
+// Auto submit
+$('.db form.menu select').on('change',function(e){
+  //if ($(this).attr('name') == 'tables') alert(this.parentElement);
+  if ($(this).attr('class') == 'dbs') return false;
+  if ($(this).attr('name') == 'tables') nb.form_clear(this.parentElement);
+  //if ($(this).attr('name') == 'format' && $(this).val().match(/table/)) alert('zaza');
+  //if ($(this).attr('name') == 'format') alert($(this).val());
+  //console.log ($(this).attr('name'));
+  return $(this).closest('form').submit();
+});
+
+/*
+  <<< End
+  Functions >>>
+*/
+
+function zaza(sql) {
+console.log(db);
+  $.ajax({
+    type: 'GET',
+    url: 'index.php',
+    data: {
+      format: "json",
+      header: "0",
+      table: sql,
+      //table: encodeURI(sql),
+    },
+    contentType: 'application/json; charset=utf-8',
+    dataType: 'json',
+    success: function(data) {
+      console.log(data);
+    },
+    error: function() {
+      alert('Error loading '+url);
+    }
+  });
+return;
+  var url = 'index.php?format=json&header=0&table='+encodeURI(sql);
+  //alert(url);
+  var jqxhr = $.getJSON(url,function() {
+    //console.log( "success" );
+  })
+  .done(function(data) {
+    //console.log(data);
+    $.each( data, function(i,rec) {
+      console.log(rec['idtenant']);
+    });
+    console.log( "second success" );
+  })
+  .fail(function() {
+    //console.log( "error" );
+  })
+  .always(function() {
+    //console.log( "complete" );
+  });
+}
+
+function sql2url(sql) {
+  var db = DB;
+  return 'index.php?format=csv&header=0'
+    +(typeof db != 'undefined' ? '&db='+encodeURI(db) : '')
+    +'&table='+encodeURI(sql)
+  ;
+}
+
+function sql2html(sql,dom) {
+  //console.log('BUGGGGGGGGG !!!'); return;
+// TODO - NB 09.04.16  if (!this.cache) this.cache = {};
+
+  $(dom).each(function(){
+
+    item = $(this)
+    id = $(this).text(); if ((typeof id == 'undefined') || id == '' ) return;
+    url = sql2url(sql.replace(/@id/g,id.trim().replace("'","\\'")));
+    //console.log('dom='+dom+' id='+id+' url='+url);
+    //$(this).addClass('loading');
+    $(this).load(url,function(){$(this).removeClass('loading')});
+    return;
+
+  });
+  return $(dom);
+  /*
+  id = $(dom); if (id.length == 0) return;
+  id = id.html(); if (typeof id == 'undefined') return;
+
+  sql = sql.replace(/@id/,id.replace("'","\\'"));
+
+  console.log('dom='+dom+' id='+id+' sql='+sql);
+  $.ajax({
+
+    type: "GET",
+    url: sql2url(sql),
+    // data: "table=" + sql, // appears as $_GET['id'] @ ur backend side
+    success: function(data) {
+      // data is ur summary
+      if (data == '') return;
+      //data = data.replace('@id',id);
+      console.log('  '+dom+'=<'+data.trim()+'>');
+      //$(dom).html(data);
+    }
+
+  });
+  */
+}
+
+}); // $(document).ready(function(){