mirror of https://gitee.com/bigwinds/arangodb
#1065 - added option to add a key for a new document or edge
This commit is contained in:
parent
bf076c8255
commit
09d14c1be4
|
@ -50,18 +50,29 @@ window.arangoDocument = Backbone.Collection.extend({
|
||||||
}
|
}
|
||||||
return returnval;
|
return returnval;
|
||||||
},
|
},
|
||||||
addDocument: function (collectionID) {
|
addDocument: function (collectionID, key) {
|
||||||
|
console.log("adding document");
|
||||||
var self = this;
|
var self = this;
|
||||||
self.createTypeDocument(collectionID);
|
self.createTypeDocument(collectionID, key);
|
||||||
},
|
},
|
||||||
createTypeEdge: function (collectionID, from, to) {
|
createTypeEdge: function (collectionID, from, to, key) {
|
||||||
var result = false;
|
var result = false, newEdge;
|
||||||
|
|
||||||
|
if (key) {
|
||||||
|
newEdge = JSON.stringify({
|
||||||
|
_key: key
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newEdge = JSON.stringify({});
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
async: false,
|
async: false,
|
||||||
url: "/_api/edge?collection=" + collectionID + "&from=" + from + "&to=" + to,
|
url: "/_api/edge?collection=" + collectionID + "&from=" + from + "&to=" + to,
|
||||||
data: JSON.stringify({}),
|
data: newEdge,
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
processData: false,
|
processData: false,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
@ -73,14 +84,24 @@ window.arangoDocument = Backbone.Collection.extend({
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
createTypeDocument: function (collectionID) {
|
createTypeDocument: function (collectionID, key) {
|
||||||
var result = false;
|
var result = false, newDocument;
|
||||||
|
|
||||||
|
if (key) {
|
||||||
|
newDocument = JSON.stringify({
|
||||||
|
_key: key
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newDocument = JSON.stringify({});
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
async: false,
|
async: false,
|
||||||
url: "/_api/document?collection=" + collectionID,
|
url: "/_api/document?collection=" + encodeURIComponent(collectionID),
|
||||||
data: JSON.stringify({}),
|
data: newDocument,
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
processData: false,
|
processData: false,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ var cutByResolution = function (str) {
|
||||||
<thead>
|
<thead>
|
||||||
<tr role="row">
|
<tr role="row">
|
||||||
<th class="sorting_disabled docsFirstCol" role="columnheader" rowspan="1" colspan="1">Content</th>
|
<th class="sorting_disabled docsFirstCol" role="columnheader" rowspan="1" colspan="1">Content</th>
|
||||||
<th class="sorting_disabled docsSecCol" role="columnheader" rowspan="1" colspan="1">_key</th>
|
<th class="sorting_disabled docsSecCol" role="columnheader" rowspan="1" colspan="1"></th>
|
||||||
<th class="sorting_disabled docsThirdCol" role="columnheader" rowspan="1" colspan="1">
|
<th class="sorting_disabled docsThirdCol" role="columnheader" rowspan="1" colspan="1">
|
||||||
<a id="addDocumentButton" class="pull-right addButton"><span class="arangoicon icon_arangodb_roundplus" title="Add a document"></span></a>
|
<a id="addDocumentButton" class="pull-right addButton"><span class="arangoicon icon_arangodb_roundplus" title="Add a document"></span></a>
|
||||||
</th>
|
</th>
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
"click .removeFilterItem" : "removeFilterItem",
|
"click .removeFilterItem" : "removeFilterItem",
|
||||||
"click #deleteSelected" : "deleteSelectedDocs",
|
"click #deleteSelected" : "deleteSelectedDocs",
|
||||||
"click #moveSelected" : "moveSelectedDocs",
|
"click #moveSelected" : "moveSelectedDocs",
|
||||||
"click #addDocumentButton" : "addDocument",
|
"click #addDocumentButton" : "addDocumentModal",
|
||||||
"click #documents_first" : "firstDocuments",
|
"click #documents_first" : "firstDocuments",
|
||||||
"click #documents_last" : "lastDocuments",
|
"click #documents_last" : "lastDocuments",
|
||||||
"click #documents_prev" : "prevDocuments",
|
"click #documents_prev" : "prevDocuments",
|
||||||
|
@ -94,10 +94,10 @@
|
||||||
"click .deleteIndex" : "prepDeleteIndex",
|
"click .deleteIndex" : "prepDeleteIndex",
|
||||||
"click #confirmDeleteIndexBtn" : "deleteIndex",
|
"click #confirmDeleteIndexBtn" : "deleteIndex",
|
||||||
"click #documentsToolbar ul" : "resetIndexForms",
|
"click #documentsToolbar ul" : "resetIndexForms",
|
||||||
"click #indexHeader #addIndex" : "toggleNewIndexView",
|
"click #indexHeader #addIndex" : "toggleNewIndexView",
|
||||||
"click #indexHeader #cancelIndex" : "toggleNewIndexView",
|
"click #indexHeader #cancelIndex" : "toggleNewIndexView",
|
||||||
"change #documentSize" : "setPagesize",
|
"change #documentSize" : "setPagesize",
|
||||||
"change #docsSort" : "setSorting"
|
"change #docsSort" : "setSorting"
|
||||||
},
|
},
|
||||||
|
|
||||||
showSpinner: function() {
|
showSpinner: function() {
|
||||||
|
@ -490,13 +490,11 @@
|
||||||
this.filterId = 0;
|
this.filterId = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
addDocument: function () {
|
addDocumentModal: function () {
|
||||||
var collid = window.location.hash.split("/")[1],
|
var collid = window.location.hash.split("/")[1],
|
||||||
// second parameter is "true" to disable caching of collection type
|
// second parameter is "true" to disable caching of collection type
|
||||||
doctype = arangoHelper.collectionApiType(collid, true);
|
doctype = arangoHelper.collectionApiType(collid, true);
|
||||||
if (doctype === 'edge') {
|
if (doctype === 'edge') {
|
||||||
//$('#edgeCreateModal').modal('show');
|
|
||||||
//arangoHelper.fixTooltips(".modalTooltips", "left");
|
|
||||||
|
|
||||||
var buttons = [], tableContent = [];
|
var buttons = [], tableContent = [];
|
||||||
|
|
||||||
|
@ -534,6 +532,20 @@
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
tableContent.push(
|
||||||
|
window.modalView.createTextEntry(
|
||||||
|
'new-edge-key-attr',
|
||||||
|
'_key',
|
||||||
|
undefined,
|
||||||
|
"the edges unique key(optional attribute, leave empty for autogenerated key",
|
||||||
|
'is optional: leave empty for autogenerated key',
|
||||||
|
false,
|
||||||
|
[
|
||||||
|
{/*optional validation rules for joi*/}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
buttons.push(
|
buttons.push(
|
||||||
window.modalView.createSuccessButton('Create', this.addEdge.bind(this))
|
window.modalView.createSuccessButton('Create', this.addEdge.bind(this))
|
||||||
);
|
);
|
||||||
|
@ -547,22 +559,49 @@
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var buttons = [], tableContent = [];
|
||||||
|
|
||||||
var result = this.documentStore.createTypeDocument(collid);
|
tableContent.push(
|
||||||
//Success
|
window.modalView.createTextEntry(
|
||||||
if (result !== false) {
|
'new-document-key-attr',
|
||||||
window.location.hash = "collection/" + result;
|
'_key',
|
||||||
return;
|
undefined,
|
||||||
|
"the documents unique key(optional attribute, leave empty for autogenerated key",
|
||||||
|
'is optional: leave empty for autogenerated key',
|
||||||
|
false,
|
||||||
|
[
|
||||||
|
{/*optional validation rules for joi*/}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
buttons.push(
|
||||||
|
window.modalView.createSuccessButton('Create', this.addDocument.bind(this))
|
||||||
|
);
|
||||||
|
|
||||||
|
window.modalView.show(
|
||||||
|
'modalTable.ejs',
|
||||||
|
'Create document',
|
||||||
|
buttons,
|
||||||
|
tableContent
|
||||||
|
);
|
||||||
}
|
}
|
||||||
//Error
|
|
||||||
arangoHelper.arangoError('Creating document failed');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
addEdge: function () {
|
addEdge: function () {
|
||||||
var collid = window.location.hash.split("/")[1];
|
var collid = window.location.hash.split("/")[1];
|
||||||
var from = $('.modal-body #new-edge-from-attr').last().val();
|
var from = $('.modal-body #new-edge-from-attr').last().val();
|
||||||
var to = $('.modal-body #new-edge-to').last().val();
|
var to = $('.modal-body #new-edge-to').last().val();
|
||||||
var result = this.documentStore.createTypeEdge(collid, from, to);
|
var key = $('.modal-body #new-edge-key-attr').last().val();
|
||||||
|
|
||||||
|
var result;
|
||||||
|
if (key !== '' || key !== undefined) {
|
||||||
|
result = this.documentStore.createTypeEdge(collid, from, to, key);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = this.documentStore.createTypeEdge(collid, from, to);
|
||||||
|
}
|
||||||
|
|
||||||
if (result !== false) {
|
if (result !== false) {
|
||||||
//$('#edgeCreateModal').modal('hide');
|
//$('#edgeCreateModal').modal('hide');
|
||||||
|
@ -575,6 +614,26 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addDocument: function() {
|
||||||
|
var collid = window.location.hash.split("/")[1];
|
||||||
|
var key = $('.modal-body #new-document-key-attr').last().val();
|
||||||
|
var result;
|
||||||
|
if (key !== '' || key !== undefined) {
|
||||||
|
result = this.documentStore.createTypeDocument(collid, key);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = this.documentStore.createTypeDocument(collid);
|
||||||
|
}
|
||||||
|
//Success
|
||||||
|
if (result !== false) {
|
||||||
|
window.modalView.hide();
|
||||||
|
window.location.hash = "collection/" + result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
arangoHelper.arangoError('Creating document failed');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
moveSelectedDocs: function() {
|
moveSelectedDocs: function() {
|
||||||
var buttons = [], tableContent = [];
|
var buttons = [], tableContent = [];
|
||||||
var toDelete = this.getSelectedDocs();
|
var toDelete = this.getSelectedDocs();
|
||||||
|
|
Loading…
Reference in New Issue