diff --git a/js/apps/system/aardvark/aardvark.js b/js/apps/system/aardvark/aardvark.js index a4863cb222..5b50dd42b0 100644 --- a/js/apps/system/aardvark/aardvark.js +++ b/js/apps/system/aardvark/aardvark.js @@ -391,6 +391,23 @@ controller.get("/query/download/:user", function(req, res) { }).summary("Download all user queries") .notes("This function downloads all user queries from the given user"); +/** Download a query result + * + * Download and export all queries from the given username. + * + */ + +controller.get("/query/result/download/:query", function(req, res) { + var query = req.params("query"); + + var result = db._query(query).toArray(); + res.set("Content-Type", "application/json"); + res.set("Content-Disposition", "attachment; filename=results.json"); + res.json(result); + +}).summary("Download the result of a query") + .notes("This function downloads the result of a user query."); + // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE // ----------------------------------------------------------------------------- diff --git a/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js b/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js index c419910ea2..54eee33832 100644 --- a/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js +++ b/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js @@ -8,6 +8,10 @@ filters: [], + MAX_SORT: 12000, + + lastQuery: {}, + sortAttribute: "_key", url: '/_api/documents', @@ -157,7 +161,7 @@ query = "FOR x in @@collection"; query += this.setFiltersForQuery(bindVars); // Sort result, only useful for a small number of docs - if (this.getTotal() < 12000) { + if (this.getTotal() < this.MAX_SORT) { if (this.getSort() === '_key') { query += " SORT TO_NUMBER(x." + this.getSort() + ") == 0 ? x." + this.getSort() + " : TO_NUMBER(x." + this.getSort() + ")"; @@ -210,6 +214,7 @@ }); }); } + self.lastQuery = queryObj; callback(); window.progressView.hide(); }, @@ -224,6 +229,30 @@ this.reset(); }, + buildDownloadDocumentQuery: function() { + var self = this, query, queryObj, bindVars; + + bindVars = { + "@collection": this.collectionID + }; + + query = "FOR x in " + this.collectionID; + query += this.setFiltersForQuery(bindVars); + // Sort result, only useful for a small number of docs + if (this.getTotal() < this.MAX_SORT) { + query += " SORT x." + this.getSort(); + } + + query += " RETURN x"; + + queryObj = { + query: query, + bindVars: bindVars + }; + + return query; + }, + updloadDocuments : function (file) { var result; $.ajax({ diff --git a/js/apps/system/aardvark/frontend/js/templates/documentsView.ejs b/js/apps/system/aardvark/frontend/js/templates/documentsView.ejs index 5a6167fee1..acf9b0f962 100644 --- a/js/apps/system/aardvark/frontend/js/templates/documentsView.ejs +++ b/js/apps/system/aardvark/frontend/js/templates/documentsView.ejs @@ -25,6 +25,11 @@ +