From 2d1c62903da1f9596db14aaa0c62d9e9af8499f8 Mon Sep 17 00:00:00 2001 From: Heiko Kernbach Date: Wed, 6 Aug 2014 09:35:45 +0200 Subject: [PATCH] prep for import and export of aql queries --- .../frontend/js/collections/arangoQueries.js | 28 +++++++++++++- .../aardvark/frontend/js/routers/router.js | 4 +- .../aardvark/frontend/js/views/queryView.js | 37 ++++++++++++++++--- .../aardvark/frontend/scss/_queryView.scss | 8 ++++ .../aardvark/frontend/scss/generated.css | 3 ++ 5 files changed, 72 insertions(+), 8 deletions(-) diff --git a/js/apps/system/aardvark/frontend/js/collections/arangoQueries.js b/js/apps/system/aardvark/frontend/js/collections/arangoQueries.js index f598c6cab3..bc976f0233 100644 --- a/js/apps/system/aardvark/frontend/js/collections/arangoQueries.js +++ b/js/apps/system/aardvark/frontend/js/collections/arangoQueries.js @@ -22,7 +22,7 @@ activeUser: 0, - parse: function(response) { + parse: function(response) { var self = this, toReturn; _.each(response.result, function(val) { @@ -37,6 +37,32 @@ } }); return toReturn; + }, + + saveQueries: function(data) { + var returnValue = false; + + $.ajax({ + cache: false, + type: "PATCH", + async: false, + url: "/_api/user/" + this.activeUser, + data: { + extra: { + queries: data + } + }, + contentType: "application/json", + processData: false, + success: function() { + returnValue = true; + }, + error: function() { + returnValue = false; + } + }); + + return returnValue; } }); diff --git a/js/apps/system/aardvark/frontend/js/routers/router.js b/js/apps/system/aardvark/frontend/js/routers/router.js index 58448f5174..d76812cfec 100644 --- a/js/apps/system/aardvark/frontend/js/routers/router.js +++ b/js/apps/system/aardvark/frontend/js/routers/router.js @@ -169,7 +169,9 @@ query: function () { if (!this.queryView) { - this.queryView = new window.queryView(); + this.queryView = new window.queryView({ + collection: this.queryCollection + }); } this.queryView.render(); this.naviView.selectMenuItem('query-menu'); diff --git a/js/apps/system/aardvark/frontend/js/views/queryView.js b/js/apps/system/aardvark/frontend/js/views/queryView.js index 6178eb79c9..4884ea58a0 100644 --- a/js/apps/system/aardvark/frontend/js/views/queryView.js +++ b/js/apps/system/aardvark/frontend/js/views/queryView.js @@ -40,7 +40,7 @@ 'click #arangoQueryTable .table-cell1': 'editCustomQuery', 'click #arangoQueryTable .table-cell2 a': 'deleteAQL', 'click #confirmQueryImport': 'importCustomQueries', - 'click #confirmQueryExport': 'exportCustomQueries' + 'click #confirmQueryExport': 'renderExportCustomQueries' }, createCustomQueryModal: function(){ @@ -177,6 +177,7 @@ if (typeof Storage) { if (localStorage.getItem("querySize") > 0) { querySize = parseInt(localStorage.getItem("querySize"), 10); + } } @@ -265,6 +266,7 @@ $("#queryDiv").show(); $("#customsDiv").show(); + this.renderExportCustomQueries(); this.initQueryImport(); this.switchTab('query-switch'); @@ -282,14 +284,29 @@ }, importCustomQueries: function () { - var result; + var result, fetched, self = this; if (this.allowUpload === true) { - result = true; + + this.collection.fetch({ + async: true, + success: function() { + result = self.collection.saveQueries(self.file); + } + }); + + console.log(result); } }, - exportCustomQueries: function () { + renderExportCustomQueries: function () { + var toExport = []; + _.each(this.customQueries, function(value, key) { + toExport.push({name: value.name, value: value.value}); + }); + var data = "text/json;charset=utf-8,"+ encodeURIComponent(JSON.stringify(toExport)); + $('#confirmQueryExport').html('Export'); }, deselect: function (editor) { @@ -342,11 +359,17 @@ }); this.customQueries = tempArray; - localStorage.setItem("customQueries", JSON.stringify(this.customQueries)); + + this.updateLocalQueries(); this.renderSelectboxes(); this.updateTable(); }, + updateLocalQueries: function () { + localStorage.setItem("customQueries", JSON.stringify(this.customQueries)); + this.renderExportCustomQueries(); + }, + saveAQL: function (e) { e.stopPropagation(); var inputEditor = ace.edit("aqlEditor"); @@ -389,11 +412,13 @@ window.modalView.hide(); - localStorage.setItem("customQueries", JSON.stringify(this.customQueries)); + this.updateLocalQueries(); this.renderSelectboxes(); $('#querySelect').val(saveName); }, + + getSystemQueries: function () { var self = this; $.ajax({ diff --git a/js/apps/system/aardvark/frontend/scss/_queryView.scss b/js/apps/system/aardvark/frontend/scss/_queryView.scss index 61d74ec566..232c8c12a9 100644 --- a/js/apps/system/aardvark/frontend/scss/_queryView.scss +++ b/js/apps/system/aardvark/frontend/scss/_queryView.scss @@ -42,6 +42,14 @@ } } +.queryMethods { + button { + a { + color: white; + } + } +} + .query-toolbar { @extend %toolbar; } diff --git a/js/apps/system/aardvark/frontend/scss/generated.css b/js/apps/system/aardvark/frontend/scss/generated.css index 3b1b29d32a..c86696a345 100644 --- a/js/apps/system/aardvark/frontend/scss/generated.css +++ b/js/apps/system/aardvark/frontend/scss/generated.css @@ -4961,6 +4961,9 @@ pre.gv-object-view { .editor-toolbar .arango-icon-disk { margin-top: 1px; } +.queryMethods button a { + color: white; } + .aql-editor { border-color: #a0a0a0; border-left: 0 !important;