From 2c5cf469b64df1102e343559dbf8d97f7ea77300 Mon Sep 17 00:00:00 2001 From: Heiko Kernbach Date: Thu, 22 Aug 2013 16:51:54 +0200 Subject: [PATCH] indexes are not editable through the webinterface --- html/admin/css/collectionView.css | 34 ++++- .../admin/js/collections/arangoCollections.js | 38 ++++- html/admin/js/templates/collectionView.ejs | 125 ++++++++++++++-- html/admin/js/views/collectionView.js | 136 ++++++++++++++++-- html/admin/js/views/dashboardView.js | 5 +- 5 files changed, 313 insertions(+), 25 deletions(-) diff --git a/html/admin/css/collectionView.css b/html/admin/css/collectionView.css index 52c3f3fba5..ff23c618f1 100644 --- a/html/admin/css/collectionView.css +++ b/html/admin/css/collectionView.css @@ -30,8 +30,26 @@ top: 59px; } -#change-collection .glyphicon-remove-circle { - color: red !important; +#newIndexView .glyphicon-remove-circle { + color: #DA4F49; +} + +#change-collection .glyphicon-minus-sign { + color: #DA4F49; + font-size: 20px; + margin-left: 10px; +} + +#change-collection .glyphicon-ban-circle { + color: black; + opacity: 0.6; + font-size: 20px; + margin-left: 10px; +} + +#change-collection .glyphicon-ban-circle:hover { + cursor: default; + float: right; } #change-collection #collectionEditIndexTable { @@ -41,3 +59,15 @@ #change-collection #newIndexView { margin-top: 20px; } + +#newIndexType { + margin-left: 5px; +} + +#createIndex { + margin-top: 15px !important; +} + +#tab-content-collection-edit { + max-height: 300px !important; +} diff --git a/html/admin/js/collections/arangoCollections.js b/html/admin/js/collections/arangoCollections.js index ce5ff0a16b..04dc3c4274 100644 --- a/html/admin/js/collections/arangoCollections.js +++ b/html/admin/js/collections/arangoCollections.js @@ -168,12 +168,48 @@ window.arangoCollections = Backbone.Collection.extend({ }); return data2; }, + createIndex: function (collection, postParameter) { + var returnVal = false; + + $.ajax({ + cache: false, + type: "POST", + url: "/_api/index?collection="+encodeURIComponent(collection), + data: JSON.stringify(postParameter), + contentType: "application/json", + processData: false, + async: false, + success: function(data) { + returnVal = true; + }, + error: function(data) { + } + }); + return returnVal; + }, + deleteIndex: function (collection, id) { + var returnval = false; + var self = this; + $.ajax({ + cache: false, + type: 'DELETE', + url: "/_api/index/"+encodeURIComponent(collection)+"/"+encodeURIComponent(id), + async: false, + success: function () { + returnval = true; + }, + error: function () { + returnval = false; + } + }); + return returnval; + }, getProperties: function (id) { var data2; $.ajax({ type: "GET", cache: false, - url: "/_api/collection/" + id + "/properties", + url: "/_api/collection/" + encodeURIComponent(id) + "/properties", contentType: "application/json", processData: false, async: false, diff --git a/html/admin/js/templates/collectionView.ejs b/html/admin/js/templates/collectionView.ejs index 8c487c8084..15c609139e 100644 --- a/html/admin/js/templates/collectionView.ejs +++ b/html/admin/js/templates/collectionView.ejs @@ -73,15 +73,124 @@ diff --git a/html/admin/js/views/collectionView.js b/html/admin/js/views/collectionView.js index 07928e7163..0e13f48905 100644 --- a/html/admin/js/views/collectionView.js +++ b/html/admin/js/views/collectionView.js @@ -9,6 +9,7 @@ var collectionView = Backbone.View.extend({ template: new EJS({url: 'js/templates/collectionView.ejs'}), render: function() { + var self = this; $(this.el).html(this.template.text); $('#change-collection').modal('show'); $('#change-collection').on('hidden', function () { @@ -18,14 +19,17 @@ var collectionView = Backbone.View.extend({ }); this.fillModal(); - $('.modalTooltips').tooltip({ - placement: "left" + $('.modalTooltips, .glyphicon-info-sign').tooltip({ + placement: "top" }); $('#collectionTab a').click(function (e) { e.preventDefault(); $(this).tab('show'); - }); + if ($(this).attr('href') === '#editIndex') { + self.resetIndexForms(); + } + }); return this; }, @@ -40,7 +44,10 @@ var collectionView = Backbone.View.extend({ "keydown #change-collection-name" : "listenKey", "keydown #change-collection-size" : "listenKey", "click #editIndex .glyphicon-plus-sign" : "toggleNewIndexView", - "click #editIndex .glyphicon-remove-circle" : "toggleNewIndexView" + "click #editIndex .glyphicon-remove-circle" : "toggleNewIndexView", + "change #newIndexType" : "selectIndexType", + "click #createIndex" : "createIndex", + "click .deleteIndex" : "deleteIndex" }, listenKey: function(e) { if (e.keyCode === 13) { @@ -51,12 +58,14 @@ var collectionView = Backbone.View.extend({ window.App.navigate("#", {trigger: true}); }, toggleNewIndexView: function () { - $('#indexEditView').toggle(); - $('#newIndexView').toggle(); - + $('#indexEditView').toggle("fast"); + $('#newIndexView').toggle("fast"); + this.resetIndexForms(); }, - hideNewIndexView: function () { - + selectIndexType: function () { + $('.newIndexClass').hide(); + var type = $('#newIndexType').val(); + $('#newIndexType'+type).show(); }, fillModal: function() { try { @@ -90,8 +99,110 @@ var collectionView = Backbone.View.extend({ this.fillLoadedModal(data); } }, + stringToArray: function (fieldString) { + var fields = []; + fieldString.split(',').forEach(function(field){ + field = field.replace(/(^\s+|\s+$)/g,''); + if (field !== '') { + fields.push(field); + } + }); + return fields; + }, + checkboxToValue: function (id) { + var checked = $(id).is('checked'); + return checked; + }, + createIndex: function (e) { + //e.preventDefault(); + var self = this; + var collection = this.myCollection.name; + var indexType = $('#newIndexType').val(); + var result; + var postParameter = {}; - appendIndex: function () { + switch(indexType) { + case 'Cap': + var size = parseInt($('#newCapSize').val(), 10) || 0; + var byteSize = parseInt($('#newCapByteSize').val(), 10) || 0; + postParameter = { + type: 'cap', + size: size, + byteSize: byteSize + }; + break; + case 'Geo': + //HANDLE ARRAY building + var fields = $('#newGeoFields').val(); + var geoJson = self.checkboxToValue('#newGeoJson'); + var constraint = self.checkboxToValue('#newGeoConstraint'); + var ignoreNull = self.checkboxToValue('#newGeoIgnoreNull'); + postParameter = { + type: 'geo', + fields: self.stringToArray(fields), + geoJson: geoJson, + constraint: constraint, + ignoreNull: ignoreNull + }; + break; + case 'Hash': + var fields = $('#newHashFields').val(); + var unique = self.checkboxToValue('#newHashUnique'); + postParameter = { + type: 'hash', + fields: self.stringToArray(fields), + unique: unique + }; + break; + case 'Fulltext': + var fields = ($('#newFulltextFields').val()); + var minLength = parseInt($('#newFulltextMinLength').val(), 10) || 0; + postParameter = { + type: 'fulltext', + fields: self.stringToArray(fields), + minLength: minLength + }; + break; + case 'Skiplist': + var fields = $('#newSkiplistFields').val(); + var unique = self.checkboxToValue('#newSkiplistUnique'); + postParameter = { + type: 'skiplist', + fields: self.stringToArray(fields), + unique: unique + }; + break; + } + result = window.arangoCollectionsStore.createIndex(collection, postParameter); + if (result === true) { + $('#collectionEditIndexTable tr').remove(); + self.getIndex(); + self.toggleNewIndexView(); + self.resetIndexForms(); + } + else { + //notification for user missing + } + }, + + resetIndexForms: function () { + $('#change-collection input').val('').prop("checked", false); + $('#newIndexType').val('Cap').prop('selected',true); + }, + + deleteIndex: function (e) { + var collection = this.myCollection.name; + var id = $(e.currentTarget).parent().parent().first().children().first().text();; + var result = window.arangoCollectionsStore.deleteIndex(collection, id); + if (result === true) { + $(e.currentTarget).parent().parent().remove(); + } + else { + alert("ERROR"); + } + }, + + getIndex: function () { this.index = window.arangoCollectionsStore.getIndex(this.options.colId, true); var cssClass = 'collectionInfoTh modal-text'; if (this.index) { @@ -100,13 +211,12 @@ var collectionView = Backbone.View.extend({ var actionString = ''; $.each(this.index.indexes, function(k,v) { - console.log(v); if (v.type === 'primary' || v.type === 'edge') { actionString = '' } else { - actionString = '' + actionString = '' } if (v.fields !== undefined) { @@ -134,7 +244,7 @@ var collectionView = Backbone.View.extend({ //show tabs & render figures tab-view $('#change-collection .nav-tabs').css("visibility","visible"); - this.appendIndex(); + this.getIndex(); $('#collectionSizeBox').show(); $('#collectionSyncBox').show(); diff --git a/html/admin/js/views/dashboardView.js b/html/admin/js/views/dashboardView.js index 29ac67f9a6..a1fcdae0d3 100644 --- a/html/admin/js/views/dashboardView.js +++ b/html/admin/js/views/dashboardView.js @@ -553,7 +553,10 @@ var dashboardView = Backbone.View.extend({ }, loadGraphState: function () { - localStorage.getItem("dbGraphState"); + var loadGraphState = localStorage.getItem("dbGraphState"); + if (loadGraphState === undefined) { + return; + } $.each(this.graphState, function(k,v) { if (v === true) { $("#"+k).show();