mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of https://github.com/arangodb/arangodb into devel
This commit is contained in:
commit
d44f280651
|
@ -44,12 +44,11 @@
|
||||||
return toReturn;
|
return toReturn;
|
||||||
},
|
},
|
||||||
|
|
||||||
saveCollectionQueries: function() {
|
saveCollectionQueries: function(callback) {
|
||||||
if (this.activeUser === 0) {
|
if (this.activeUser === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var returnValue = false;
|
|
||||||
var queries = [];
|
var queries = [];
|
||||||
|
|
||||||
this.each(function(query) {
|
this.each(function(query) {
|
||||||
|
@ -64,7 +63,6 @@
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
type: "PATCH",
|
type: "PATCH",
|
||||||
async: false,
|
|
||||||
url: "/_api/user/" + encodeURIComponent(this.activeUser),
|
url: "/_api/user/" + encodeURIComponent(this.activeUser),
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
extra: {
|
extra: {
|
||||||
|
@ -73,15 +71,13 @@
|
||||||
}),
|
}),
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
processData: false,
|
processData: false,
|
||||||
success: function() {
|
success: function(data) {
|
||||||
returnValue = true;
|
callback(false, data);
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
returnValue = false;
|
callback(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
saveImportQueries: function(file, callback) {
|
saveImportQueries: function(file, callback) {
|
||||||
|
@ -94,7 +90,6 @@
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
async: false,
|
|
||||||
url: "query/upload/" + encodeURIComponent(this.activeUser),
|
url: "query/upload/" + encodeURIComponent(this.activeUser),
|
||||||
data: file,
|
data: file,
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
|
|
|
@ -365,17 +365,23 @@
|
||||||
if (this.allowUpload === true) {
|
if (this.allowUpload === true) {
|
||||||
|
|
||||||
var callback = function() {
|
var callback = function() {
|
||||||
this.collection.fetch({async: false});
|
this.collection.fetch({
|
||||||
this.updateLocalQueries();
|
success: function() {
|
||||||
this.renderSelectboxes();
|
self.updateLocalQueries();
|
||||||
this.updateTable();
|
self.renderSelectboxes();
|
||||||
self.allowUpload = false;
|
self.updateTable();
|
||||||
$('#customs-switch').click();
|
self.allowUpload = false;
|
||||||
};
|
$('#customs-switch').click();
|
||||||
|
$('#confirmQueryImport').addClass('disabled');
|
||||||
|
$('#queryImportDialog').modal('hide');
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
arangoHelper.arangoError("Custom Queries", data.responseText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
self.collection.saveImportQueries(self.file, callback.bind(this));
|
self.collection.saveImportQueries(self.file, callback.bind(this));
|
||||||
$('#confirmQueryImport').addClass('disabled');
|
|
||||||
$('#queryImportDialog').modal('hide');
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -401,17 +407,16 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$.ajax("whoAmI?_=" + Date.now(), {async:false}).done(
|
$.ajax("whoAmI?_=" + Date.now()).success(
|
||||||
function(data) {
|
function(data) {
|
||||||
name = data.user;
|
name = data.user;
|
||||||
|
|
||||||
if (name === null || name === false) {
|
if (name === null || name === false) {
|
||||||
name = "root";
|
name = "root";
|
||||||
}
|
}
|
||||||
|
window.open("query/download/" + encodeURIComponent(name));
|
||||||
});
|
});
|
||||||
|
|
||||||
window.open("query/download/" + encodeURIComponent(name));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
deselect: function (editor) {
|
deselect: function (editor) {
|
||||||
|
@ -446,45 +451,63 @@
|
||||||
this.checkSaveName();
|
this.checkSaveName();
|
||||||
},
|
},
|
||||||
|
|
||||||
getAQL: function () {
|
getAQL: function (originCallback) {
|
||||||
var self = this, result;
|
var self = this, result;
|
||||||
|
|
||||||
this.collection.fetch({
|
this.collection.fetch({
|
||||||
async: false
|
success: function() {
|
||||||
});
|
//old storage method
|
||||||
|
var item = localStorage.getItem("customQueries");
|
||||||
|
if (item) {
|
||||||
|
var queries = JSON.parse(item);
|
||||||
|
//save queries in user collections extra attribute
|
||||||
|
_.each(queries, function(oldQuery) {
|
||||||
|
self.collection.add({
|
||||||
|
value: oldQuery.value,
|
||||||
|
name: oldQuery.name
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//old storage method
|
var callback = function(error, data) {
|
||||||
var item = localStorage.getItem("customQueries");
|
if (error) {
|
||||||
if (item) {
|
arangoHelper.arangoError(
|
||||||
var queries = JSON.parse(item);
|
"Custom Queries",
|
||||||
//save queries in user collections extra attribute
|
"Could not import old local storage queries"
|
||||||
_.each(queries, function(oldQuery) {
|
);
|
||||||
self.collection.add({
|
}
|
||||||
value: oldQuery.value,
|
else {
|
||||||
name: oldQuery.name
|
localStorage.removeItem("customQueries");
|
||||||
});
|
}
|
||||||
});
|
}.bind(self);
|
||||||
result = self.collection.saveCollectionQueries();
|
self.collection.saveCollectionQueries(callback);
|
||||||
|
}
|
||||||
|
self.updateLocalQueries();
|
||||||
|
|
||||||
if (result === true) {
|
if (originCallback) {
|
||||||
//and delete them from localStorage
|
originCallback();
|
||||||
localStorage.removeItem("customQueries");
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
this.updateLocalQueries();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteAQL: function (e) {
|
deleteAQL: function (e) {
|
||||||
|
var callbackSave = function(error) {
|
||||||
|
if (error) {
|
||||||
|
arangoHelper.arangoError("Query", "Could not delete query.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.updateLocalQueries();
|
||||||
|
this.renderSelectboxes();
|
||||||
|
this.updateTable();
|
||||||
|
}
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
var deleteName = $(e.target).parent().parent().parent().children().first().text();
|
var deleteName = $(e.target).parent().parent().parent().children().first().text();
|
||||||
|
|
||||||
var toDelete = this.collection.findWhere({name: deleteName});
|
var toDelete = this.collection.findWhere({name: deleteName});
|
||||||
this.collection.remove(toDelete);
|
|
||||||
this.collection.saveCollectionQueries();
|
|
||||||
|
|
||||||
this.updateLocalQueries();
|
this.collection.remove(toDelete);
|
||||||
this.renderSelectboxes();
|
this.collection.saveCollectionQueries(callbackSave);
|
||||||
this.updateTable();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateLocalQueries: function () {
|
updateLocalQueries: function () {
|
||||||
|
@ -556,16 +579,26 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.collection.saveCollectionQueries();
|
var callback = function(error) {
|
||||||
|
if (error) {
|
||||||
|
arangoHelper.arangoError("Query", "Could not save query");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var self = this;
|
||||||
|
this.collection.fetch({
|
||||||
|
success: function() {
|
||||||
|
self.updateLocalQueries();
|
||||||
|
self.renderSelectboxes();
|
||||||
|
$('#querySelect').val(saveName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}.bind(this);
|
||||||
|
this.collection.saveCollectionQueries(callback);
|
||||||
window.modalView.hide();
|
window.modalView.hide();
|
||||||
|
|
||||||
this.updateLocalQueries();
|
|
||||||
this.renderSelectboxes();
|
|
||||||
$('#querySelect').val(saveName);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getSystemQueries: function () {
|
getSystemQueries: function (callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
|
@ -573,11 +606,16 @@
|
||||||
url: "js/arango/aqltemplates.json",
|
url: "js/arango/aqltemplates.json",
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
processData: false,
|
processData: false,
|
||||||
async: false,
|
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
if (callback) {
|
||||||
|
callback(false);
|
||||||
|
}
|
||||||
self.queries = data;
|
self.queries = data;
|
||||||
},
|
},
|
||||||
error: function () {
|
error: function () {
|
||||||
|
if (callback) {
|
||||||
|
callback(true);
|
||||||
|
}
|
||||||
arangoHelper.arangoNotification("Query", "Error while loading system templates");
|
arangoHelper.arangoNotification("Query", "Error while loading system templates");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -592,15 +630,28 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshAQL: function(select) {
|
refreshAQL: function(select) {
|
||||||
this.getAQL();
|
|
||||||
this.getSystemQueries();
|
|
||||||
this.updateLocalQueries();
|
|
||||||
|
|
||||||
if (select) {
|
var self = this;
|
||||||
var previous = $("#querySelect" ).val();
|
|
||||||
this.renderSelectboxes();
|
var callback = function(error) {
|
||||||
$("#querySelect" ).val(previous);
|
if (error) {
|
||||||
}
|
arangoHelper.arangoError('Query', 'Could not reload Queries');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.updateLocalQueries();
|
||||||
|
if (select) {
|
||||||
|
var previous = $("#querySelect").val();
|
||||||
|
self.renderSelectboxes();
|
||||||
|
$("#querySelect").val(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.bind(self);
|
||||||
|
|
||||||
|
var originCallback = function() {
|
||||||
|
self.getSystemQueries(callback);
|
||||||
|
}.bind(self);
|
||||||
|
|
||||||
|
this.getAQL(originCallback);
|
||||||
},
|
},
|
||||||
|
|
||||||
importSelected: function (e) {
|
importSelected: function (e) {
|
||||||
|
|
Loading…
Reference in New Issue