From 572795c56d0d9bafb069e69d3c3884b7c7c9e9b6 Mon Sep 17 00:00:00 2001 From: Masadow Date: Tue, 14 May 2013 01:42:05 +0200 Subject: [PATCH 1/8] Add revision creation button --- DBV.php | 15 ++++++++++++++ templates/revisions.php | 43 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/DBV.php b/DBV.php index d2a9e1d..2b2fee1 100644 --- a/DBV.php +++ b/DBV.php @@ -176,6 +176,21 @@ public function revisionsAction() } } + public function addRevisionFolderAction() + { + $revision = $this->_getCurrentRevision(); + while (++$revision) + { + $dir = DBV_REVISIONS_PATH . DS . $revision; + if (!@file_exists($dir)) { + if (!@mkdir($dir)) + $this->_json(array('ok' => false, 'message' => __("Cannot create revision #{revision}!", array('revision' => "$revision")))); + break ; + } + } + + $this->_json(array('ok' => true, 'message' => __("Revision #{revision} successfully added!", array('revision' => "$revision")))); + } public function saveRevisionFileAction() { diff --git a/templates/revisions.php b/templates/revisions.php index bc89261..3146a43 100644 --- a/templates/revisions.php +++ b/templates/revisions.php @@ -55,7 +55,8 @@ - + +
@@ -128,6 +129,46 @@ } }); }); + + $$("#add_revision").invoke('observe', 'click', function(event) { + event.stop(); + + + var self = this; + + this.disable(); + + clear_messages('revisions'); + + new Ajax.Request('index.php?a=addRevisionFolder', { + parameters: { + + }, + onSuccess: function (transport) { + + self.enable(); + + var response = transport.responseText.evalJSON(); + + // if (typeof response.error != 'undefined') { + // return APP.growler.error('', response.error); + // } + + if (response.ok != true) { + render_messages('error', 'revisions', response.message, ''); + } + else { + render_messages('success', 'revisions', response.message, ''); + } + + var revision = parseInt(response.revision); + if (!isNaN(revision)) { + } + + Effect.ScrollTo('log', {duration: 0.2}); + } + }) + }); form.on('submit', function (event) { event.stop(); From 0823169364434d944a37e1109f6d34d5d70ce886 Mon Sep 17 00:00:00 2001 From: Masadow Date: Tue, 14 May 2013 01:47:18 +0200 Subject: [PATCH 2/8] Add default comments.sql file in newly created revisions --- DBV.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DBV.php b/DBV.php index 2b2fee1..7e569a1 100644 --- a/DBV.php +++ b/DBV.php @@ -184,7 +184,10 @@ public function addRevisionFolderAction() $dir = DBV_REVISIONS_PATH . DS . $revision; if (!@file_exists($dir)) { if (!@mkdir($dir)) - $this->_json(array('ok' => false, 'message' => __("Cannot create revision #{revision}!", array('revision' => "$revision")))); + $this->_json(array('ok' => false, 'message' => __("Cannot create folder for revision #{revision}!", array('revision' => "$revision")))); + $dir .= '/comments.sql'; + if (!@file_put_contents($dir, '')) + $this->_json(array('ok' => false, 'message' => __("Cannot create sql file for revision #{revision}!", array('revision' => "$revision")))); break ; } } From 3005d3b98fdcb4f4b0dbc2be9df6d46a0bfc7ff9 Mon Sep 17 00:00:00 2001 From: Masadow Date: Tue, 14 May 2013 03:09:51 +0200 Subject: [PATCH 3/8] Begin of refreshing view --- DBV.php | 4 ++-- templates/revisions.php | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/DBV.php b/DBV.php index 7e569a1..a1dbda4 100644 --- a/DBV.php +++ b/DBV.php @@ -186,13 +186,13 @@ public function addRevisionFolderAction() if (!@mkdir($dir)) $this->_json(array('ok' => false, 'message' => __("Cannot create folder for revision #{revision}!", array('revision' => "$revision")))); $dir .= '/comments.sql'; - if (!@file_put_contents($dir, '')) + if (!@file_put_contents($dir, ' ')) $this->_json(array('ok' => false, 'message' => __("Cannot create sql file for revision #{revision}!", array('revision' => "$revision")))); break ; } } - $this->_json(array('ok' => true, 'message' => __("Revision #{revision} successfully added!", array('revision' => "$revision")))); + $this->_json(array('ok' => true, 'rev' => $revision, 'message' => __("Revision #{revision} successfully added!", array('revision' => "$revision")))); } public function saveRevisionFileAction() diff --git a/templates/revisions.php b/templates/revisions.php index 3146a43..fcc97e4 100644 --- a/templates/revisions.php +++ b/templates/revisions.php @@ -10,7 +10,7 @@ - + revisions as $revision) { ?> revision >= $revision; @@ -150,21 +150,43 @@ var response = transport.responseText.evalJSON(); - // if (typeof response.error != 'undefined') { - // return APP.growler.error('', response.error); - // } - if (response.ok != true) { render_messages('error', 'revisions', response.message, ''); } else { render_messages('success', 'revisions', response.message, ''); - } - var revision = parseInt(response.revision); - if (!isNaN(revision)) { + var rev = parseInt(response.rev); + if (!isNaN(rev)) { + var tbody = document.getElementById('revision_body'); + var tr = tbody.insertRow(0); + + tr.setAttribute('data-revision', rev); + + var td = document.createElement('td'); + td.className = "center"; + td.innerHTML = ''; + var td2 = document.createElement('td'); + td2.innerHTML = '

'+rev+'

' + +''; + tr.appendChild(td); + tr.appendChild(td2); + // Following does not work in PrototypeJs + // alert(form.select('table > tbody')); + // form.select('table > tbody').insert({ + // top:'test' + // }); + + + } } + Effect.ScrollTo('log', {duration: 0.2}); } }) From ed04e3a6d65108fe7468ca2e44c4a56dc801c8ff Mon Sep 17 00:00:00 2001 From: Masadow Date: Tue, 14 May 2013 16:03:54 +0200 Subject: [PATCH 4/8] Dynamic refresh after adding new revision --- templates/revisions.php | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/templates/revisions.php b/templates/revisions.php index fcc97e4..3a8a48e 100644 --- a/templates/revisions.php +++ b/templates/revisions.php @@ -70,8 +70,7 @@ return; } - var textareas = form.select('textarea'); - textareas.each(function (textarea) { + function init_textarea(textarea) { textarea['data-editor'] = CodeMirror.fromTextArea(textarea, { mode: "text/x-mysql", tabMode: "indent", @@ -80,9 +79,13 @@ lineNumbers: true, theme: 'default' }); - }); + } - $$('.revision-handle').invoke('observe', 'click', function (event) { + var textareas = form.select('textarea'); + textareas.each(init_textarea); + + function revision_handle(event) { + var element = event.findElement('.revision-handle'); var container = element.up('td').down('.revision-files'); if (container) { @@ -98,9 +101,10 @@ }); } } - }); + } + $$('.revision-handle').invoke('observe', 'click', revision_handle); - $$('button[data-role="editor-save"]').invoke('observe', 'click', function (event) { + function editor_save(event) { var self = this; var editor = this.up('.heading').next('textarea')['data-editor']; @@ -128,7 +132,9 @@ render_messages('success', container, response.message); } }); - }); + } + + $$('button[data-role="editor-save"]').invoke('observe', 'click', editor_save); $$("#add_revision").invoke('observe', 'click', function(event) { event.stop(); @@ -170,19 +176,18 @@ td2.innerHTML = '

'+rev+'

' +''; tr.appendChild(td); tr.appendChild(td2); - // Following does not work in PrototypeJs - // alert(form.select('table > tbody')); - // form.select('table > tbody').insert({ - // top:'test' - // }); - - + $$('.revision-handle').invoke('observe', 'click', revision_handle); + $$('button[data-role="editor-save"]').invoke('observe', 'click', editor_save); + textareas = form.select('textarea'); + init_textarea(textareas[0]); } } From b30400130dbaf34059311fbb143e9b0737e9f37e Mon Sep 17 00:00:00 2001 From: Masadow Date: Tue, 21 May 2013 21:19:45 +0200 Subject: [PATCH 5/8] Multi config.php file support for multi db/project usage in a single install --- DBV.php | 24 ++++++++++++++++++- config.php.sample => config/config.php.sample | 0 config_list.php.sample | 8 +++++++ index.php | 6 ++++- public/scripts/bootstrap.js | 6 +++++ public/scripts/jquery.js | 5 ++++ templates/index.php | 19 +++++++++++++++ 7 files changed, 66 insertions(+), 2 deletions(-) rename config.php.sample => config/config.php.sample (100%) create mode 100644 config_list.php.sample create mode 100644 public/scripts/bootstrap.js create mode 100644 public/scripts/jquery.js diff --git a/DBV.php b/DBV.php index a1dbda4..a3dccd0 100644 --- a/DBV.php +++ b/DBV.php @@ -35,7 +35,6 @@ class DBV_Exception extends Exception class DBV { - protected $_action = "index"; protected $_adapter; protected $_log = array(); @@ -133,6 +132,27 @@ public function schemaAction() $this->_json($return); } } + + public function switchDatabaseAction() + { + $databaseID = isset($_GET['newdb']) ? $_GET['newdb'] : false; + if ($databaseID) + { + $lines = @file(DBV_ROOT_PATH . DS . "config_list.php"); + if ($lines) + { + $needlesize = @strlen('$current_id'); + foreach ($lines as &$line) + if (!@strncmp($line, '$current_id', $needlesize)) + { + $line = '$current_id = ' . $databaseID . ";" . PHP_EOL; + break ; + } + @file_put_contents(DBV_ROOT_PATH . DS . "config_list.php", @implode("", $lines)); + } + } + $this->indexAction(); + } public function revisionsAction() { @@ -292,6 +312,8 @@ protected function _getAction() protected function _view($view) { + global $conf_list; + global $current_id; $file = DBV_ROOT_PATH . DS . 'templates' . DS . "$view.php"; if (file_exists($file)) { include($file); diff --git a/config.php.sample b/config/config.php.sample similarity index 100% rename from config.php.sample rename to config/config.php.sample diff --git a/config_list.php.sample b/config_list.php.sample new file mode 100644 index 0000000..27bff3e --- /dev/null +++ b/config_list.php.sample @@ -0,0 +1,8 @@ +this.$items.length-1||t<0)return;return this.sliding?this.$element.one("slid",function(){r.to(t)}):n==t?this.pause().cycle():this.slide(t>n?"next":"prev",e(this.$items[t]))},pause:function(t){return t||(this.paused=!0),this.$element.find(".next, .prev").length&&e.support.transition.end&&(this.$element.trigger(e.support.transition.end),this.cycle(!0)),clearInterval(this.interval),this.interval=null,this},next:function(){if(this.sliding)return;return this.slide("next")},prev:function(){if(this.sliding)return;return this.slide("prev")},slide:function(t,n){var r=this.$element.find(".item.active"),i=n||r[t](),s=this.interval,o=t=="next"?"left":"right",u=t=="next"?"first":"last",a=this,f;this.sliding=!0,s&&this.pause(),i=i.length?i:this.$element.find(".item")[u](),f=e.Event("slide",{relatedTarget:i[0],direction:o});if(i.hasClass("active"))return;this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid",function(){var t=e(a.$indicators.children()[a.getActiveIndex()]);t&&t.addClass("active")}));if(e.support.transition&&this.$element.hasClass("slide")){this.$element.trigger(f);if(f.isDefaultPrevented())return;i.addClass(t),i[0].offsetWidth,r.addClass(o),i.addClass(o),this.$element.one(e.support.transition.end,function(){i.removeClass([t,o].join(" ")).addClass("active"),r.removeClass(["active",o].join(" ")),a.sliding=!1,setTimeout(function(){a.$element.trigger("slid")},0)})}else{this.$element.trigger(f);if(f.isDefaultPrevented())return;r.removeClass("active"),i.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return s&&this.cycle(),this}};var n=e.fn.carousel;e.fn.carousel=function(n){return this.each(function(){var r=e(this),i=r.data("carousel"),s=e.extend({},e.fn.carousel.defaults,typeof n=="object"&&n),o=typeof n=="string"?n:s.slide;i||r.data("carousel",i=new t(this,s)),typeof n=="number"?i.to(n):o?i[o]():s.interval&&i.pause().cycle()})},e.fn.carousel.defaults={interval:5e3,pause:"hover"},e.fn.carousel.Constructor=t,e.fn.carousel.noConflict=function(){return e.fn.carousel=n,this},e(document).on("click.carousel.data-api","[data-slide], [data-slide-to]",function(t){var n=e(this),r,i=e(n.attr("data-target")||(r=n.attr("href"))&&r.replace(/.*(?=#[^\s]+$j)/,"")),s=e.extend({},i.data(),n.data()),o;i.carousel(s),(o=n.attr("data-slide-to"))&&i.data("carousel").pause().to(o).cycle(),t.preventDefault()})}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.options=e.extend({},e.fn.collapse.defaults,n),this.options.parent&&(this.$parent=e(this.options.parent)),this.options.toggle&&this.toggle()};t.prototype={constructor:t,dimension:function(){var e=this.$element.hasClass("width");return e?"width":"height"},show:function(){var t,n,r,i;if(this.transitioning||this.$element.hasClass("in"))return;t=this.dimension(),n=e.camelCase(["scroll",t].join("-")),r=this.$parent&&this.$parent.find("> .accordion-group > .in");if(r&&r.length){i=r.data("collapse");if(i&&i.transitioning)return;r.collapse("hide"),i||r.data("collapse",null)}this.$element[t](0),this.transition("addClass",e.Event("show"),"shown"),e.support.transition&&this.$element[t](this.$element[0][n])},hide:function(){var t;if(this.transitioning||!this.$element.hasClass("in"))return;t=this.dimension(),this.reset(this.$element[t]()),this.transition("removeClass",e.Event("hide"),"hidden"),this.$element[t](0)},reset:function(e){var t=this.dimension();return this.$element.removeClass("collapse")[t](e||"auto")[0].offsetWidth,this.$element[e!==null?"addClass":"removeClass"]("collapse"),this},transition:function(t,n,r){var i=this,s=function(){n.type=="show"&&i.reset(),i.transitioning=0,i.$element.trigger(r)};this.$element.trigger(n);if(n.isDefaultPrevented())return;this.transitioning=1,this.$element[t]("in"),e.support.transition&&this.$element.hasClass("collapse")?this.$element.one(e.support.transition.end,s):s()},toggle:function(){this[this.$element.hasClass("in")?"hide":"show"]()}};var n=e.fn.collapse;e.fn.collapse=function(n){return this.each(function(){var r=e(this),i=r.data("collapse"),s=e.extend({},e.fn.collapse.defaults,r.data(),typeof n=="object"&&n);i||r.data("collapse",i=new t(this,s)),typeof n=="string"&&i[n]()})},e.fn.collapse.defaults={toggle:!0},e.fn.collapse.Constructor=t,e.fn.collapse.noConflict=function(){return e.fn.collapse=n,this},e(document).on("click.collapse.data-api","[data-toggle=collapse]",function(t){var n=e(this),r,i=n.attr("data-target")||t.preventDefault()||(r=n.attr("href"))&&r.replace(/.*(?=#[^\s]+$j)/,""),s=e(i).data("collapse")?"toggle":n.data();n[e(i).hasClass("in")?"addClass":"removeClass"]("collapsed"),e(i).collapse(s)})}(window.jQuery),!function(e){"use strict";function r(){e(".dropdown-backdrop").remove(),e(t).each(function(){i(e(this)).removeClass("open")})}function i(t){var n=t.attr("data-target"),r;n||(n=t.attr("href"),n=n&&/#/.test(n)&&n.replace(/.*(?=#[^\s]*$j)/,"")),r=n&&e(n);if(!r||!r.length)r=t.parent();return r}var t="[data-toggle=dropdown]",n=function(t){var n=e(t).on("click.dropdown.data-api",this.toggle);e("html").on("click.dropdown.data-api",function(){n.parent().removeClass("open")})};n.prototype={constructor:n,toggle:function(t){var n=e(this),s,o;if(n.is(".disabled, :disabled"))return;return s=i(n),o=s.hasClass("open"),r(),o||("ontouchstart"in document.documentElement&&e('