diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/arango/arango.js b/js/apps/system/_admin/aardvark/APP/frontend/js/arango/arango.js index 5d0baf9d96..6408ac419d 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/arango/arango.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/arango/arango.js @@ -255,6 +255,7 @@ ); if (!menu.disabled) { $('#subNavigationBar .bottom').children().last().bind('click', function () { + $('#subNavigationBar .breadcrumb').html(''); window.App.navigate(menu.route, {trigger: true}); }); } diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/collections/arangoQueries.js b/js/apps/system/_admin/aardvark/APP/frontend/js/collections/arangoQueries.js index 306a2ef522..737bc20a40 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/collections/arangoQueries.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/collections/arangoQueries.js @@ -44,9 +44,6 @@ }, saveCollectionQueries: function (callback) { - if (this.activeUser === false || this.activeUser === null) { - return false; - } if (this.activeUser === false || this.activeUser === null) { this.activeUser = 'root'; } diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/templates/queryView.ejs b/js/apps/system/_admin/aardvark/APP/frontend/js/templates/queryView.ejs index e00a23cf31..345f434b67 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/templates/queryView.ejs +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/templates/queryView.ejs @@ -6,7 +6,9 @@
- + + +
@@ -133,4 +135,4 @@
- + \ No newline at end of file diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/views/navigationView.js b/js/apps/system/_admin/aardvark/APP/frontend/js/views/navigationView.js index 92089e5a42..040254a34a 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/views/navigationView.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/views/navigationView.js @@ -262,6 +262,7 @@ ); if (!menu.disabled) { $(self.subEl + ' .bottom').children().last().bind('click', function (elem) { + $('#subNavigationBar .breadcrumb').html(''); self.activeSubMenu = menu; self.renderSubView(menu, elem); }); diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/views/queryView.js b/js/apps/system/_admin/aardvark/APP/frontend/js/views/queryView.js index 87b192164a..90b3c20b79 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/views/queryView.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/views/queryView.js @@ -17,6 +17,7 @@ outputCounter: 0, allowUpload: false, + renderComplete: false, customQueries: [], queries: [], @@ -72,7 +73,9 @@ 'click .outputEditorWrapper .fa-close': 'closeResult', 'click #toggleQueries1': 'toggleQueries', 'click #toggleQueries2': 'toggleQueries', + 'click #createNewQuery': 'createAQL', 'click #saveCurrentQuery': 'addAQL', + 'click #updateCurrentQuery': 'updateAQL', 'click #exportQuery': 'exportCustomQueries', 'click #importQuery': 'openImportDialog', 'click #removeResults': 'removeResults', @@ -219,11 +222,16 @@ this.queryPreview.setValue('No query selected.', 1); this.deselect(this.queryPreview); } else { + $('#updateCurrentQuery').hide(); if (this.settings.aqlWidth === undefined) { $('.aqlEditorWrapper').first().width($(window).width() * 0.33); } else { $('.aqlEditorWrapper').first().width(this.settings.aqlWidth); } + + if (localStorage.getItem('lastOpenQuery') !== 'undefined') { + $('#updateCurrentQuery').show(); + } } } else { if (this.settings.aqlWidth === undefined) { @@ -236,7 +244,7 @@ var divs = [ 'aqlEditor', 'queryTable', 'previewWrapper', 'querySpotlight', - 'bindParamEditor', 'toggleQueries1', 'toggleQueries2', + 'bindParamEditor', 'toggleQueries1', 'toggleQueries2', 'createNewQuery', 'saveCurrentQuery', 'querySize', 'executeQuery', 'switchTypes', 'explainQuery', 'importQuery', 'exportQuery' ]; @@ -318,17 +326,39 @@ this.fillBindParamTable(this.getCustomQueryParameterByName(name)); this.updateBindParams(); + this.currentQuery = this.collection.findWhere({name: name}); + + if (this.currentQuery) { + localStorage.setItem('lastOpenQuery', this.currentQuery.get('name')); + } + + $('#updateCurrentQuery').show(); + // render a button to revert back to last query $('#lastQuery').remove(); + $('#queryContent .arangoToolbarTop .pull-left') .append('Previous Query'); + this.breadcrumb(name); + $('#lastQuery').hide().fadeIn(500) .on('click', function () { + $('#updateCurrentQuery').hide(); self.aqlEditor.setValue(self.state.lastQuery.query, 1); self.fillBindParamTable(self.state.lastQuery.bindParam); self.updateBindParams(); + self.collection.each(function (model) { + model = model.toJSON(); + + if (model.value === self.state.lastQuery.query) { + self.breadcrumb(model.name); + } else { + self.breadcrumb(); + } + }); + $('#lastQuery').fadeOut(500, function () { $(this).remove(); }); @@ -515,31 +545,47 @@ }, getCachedQueryAfterRender: function () { - // get cached query if available - var queryObject = this.getCachedQuery(); - var self = this; + if (this.renderComplete === false) { + // get cached query if available + var queryObject = this.getCachedQuery(); + var self = this; - if (queryObject !== null && queryObject !== undefined && queryObject !== '') { - this.aqlEditor.setValue(queryObject.query, 1); + if (queryObject !== null && queryObject !== undefined && queryObject !== '') { + this.aqlEditor.setValue(queryObject.query, 1); - // reset undo history for initial text value - this.aqlEditor.getSession().setUndoManager(new ace.UndoManager()); + var queryName = localStorage.getItem('lastOpenQuery'); - if (queryObject.parameter !== '' || queryObject !== undefined) { - try { - // then fill values into input boxes - self.bindParamTableObj = JSON.parse(queryObject.parameter); + if (queryName !== undefined && queryName !== 'undefined') { + try { + var query = this.collection.findWhere({name: queryName}).toJSON(); + if (query.value === queryObject.query) { + self.breadcrumb(queryName); + $('#updateCurrentQuery').show(); + } + } catch (ignore) { + } + } - var key; - _.each($('#arangoBindParamTable input'), function (element) { - key = $(element).attr('name'); - $(element).val(self.bindParamTableObj[key]); - }); + // reset undo history for initial text value + this.aqlEditor.getSession().setUndoManager(new ace.UndoManager()); - // resave cached query - self.setCachedQuery(self.aqlEditor.getValue(), JSON.stringify(self.bindParamTableObj)); - } catch (ignore) {} + if (queryObject.parameter !== '' || queryObject !== undefined) { + try { + // then fill values into input boxes + self.bindParamTableObj = JSON.parse(queryObject.parameter); + + var key; + _.each($('#arangoBindParamTable input'), function (element) { + key = $(element).attr('name'); + $(element).val(self.bindParamTableObj[key]); + }); + + // resave cached query + self.setCachedQuery(self.aqlEditor.getValue(), JSON.stringify(self.bindParamTableObj)); + } catch (ignore) {} + } } + this.renderComplete = true; } }, @@ -612,7 +658,6 @@ this.fillSelectBoxes(); this.makeResizeable(); this.initQueryImport(); - this.getCachedQueryAfterRender(); // set height of editor wrapper $('.inputEditorWrapper').height($(window).height() / 10 * 5 + 25); @@ -1119,6 +1164,41 @@ }, 500); }, + updateAQL: function () { + var content = this.aqlEditor.getValue(); + var queryName = localStorage.getItem('lastOpenQuery'); + var query = this.collection.findWhere({name: queryName}); + if (query) { + query.set('value', content); + var callback = function (error) { + if (error) { + arangoHelper.arangoError('Query', 'Could not save query'); + } else { + var self = this; + arangoHelper.arangoNotification('Queries', 'Saved query ' + queryName); + this.collection.fetch({ + success: function () { + self.updateLocalQueries(); + } + }); + } + }.bind(this); + this.collection.saveCollectionQueries(callback); + } + + this.refreshAQL(true); + }, + + createAQL: function () { + localStorage.setItem('lastOpenQuery', undefined); + this.aqlEditor.setValue(''); + + this.refreshAQL(true); + + this.breadcrumb(); + $('#updateCurrentQuery').hide(); + }, + createCustomQueryModal: function () { var buttons = []; var tableContent = []; @@ -1231,6 +1311,9 @@ this.collection.fetch({ success: function () { self.updateLocalQueries(); + $('#updateCurrentQuery').show(); + + self.breadcrumb(saveName); } }); } @@ -1239,6 +1322,18 @@ window.modalView.hide(); }, + breadcrumb: function (name) { + window.setTimeout(function () { + if (name) { + $('#subNavigationBar .breadcrumb').html( + 'Query: ' + name + ); + } else { + $('#subNavigationBar .breadcrumb').html(''); + } + }, 50); + }, + verifyQueryAndParams: function () { var quit = false; @@ -1861,6 +1956,8 @@ this.collection.fetch({ success: function () { + self.getCachedQueryAfterRender(); + // old storage method var item = localStorage.getItem('customQueries'); if (item) { diff --git a/js/apps/system/_admin/aardvark/APP/frontend/scss/_toolbar.scss b/js/apps/system/_admin/aardvark/APP/frontend/scss/_toolbar.scss index 32018ea59a..3c5526d047 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/scss/_toolbar.scss +++ b/js/apps/system/_admin/aardvark/APP/frontend/scss/_toolbar.scss @@ -53,6 +53,10 @@ font-weight: 100; margin-left: 10px; + &.toolbarText { + top: 1px; + } + &.clickable { cursor: pointer; margin-left: 0;