/*jslint indent: 2, stupid: true, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */
/*global require, window, exports, Backbone, EJS, $, arangoHelper, nv, d3*/
var collectionInfoView = Backbone.View.extend({
el: '#modalPlaceholder',
chart: null,
initialize: function () {
},
template: new EJS({url: 'js/templates/collectionInfoView.ejs'}),
render: function() {
$(this.el).html(this.template.text);
$('#show-collection').modal('show');
this.fillModal();
$('.modalInfoTooltips').tooltip({
placement: "left"
});
$('#infoTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
return this;
},
events: {
"hidden #show-collection" : "hidden"
},
listenKey: function(e) {
if (e.keyCode === 13) {
this.saveModifiedCollection();
}
},
hidden: function () {
window.App.navigate("#", {trigger: true});
},
fillModal: function() {
try {
this.myCollection = window.arangoCollectionsStore.get(this.options.colId).attributes;
}
catch (e) {
// in case the collection cannot be found or something is not present (e.g. after a reload)
window.App.navigate("#");
return;
}
$('#show-collection-name').text("Collection: "+this.myCollection.name);
$('#show-collection-id').text(this.myCollection.id);
$('#show-collection-type').text(this.myCollection.type);
$('#show-collection-status').text(this.myCollection.status);
if (this.myCollection.status === 'loaded') {
this.data = window.arangoCollectionsStore.getFigures(this.options.colId, true);
this.revision = window.arangoCollectionsStore.getRevision(this.options.colId, true);
this.properties = window.arangoCollectionsStore.getProperties(this.options.colId, true);
this.index = window.arangoCollectionsStore.getIndex(this.options.colId, true);
this.fillLoadedModal(this.data);
//this.convertFigures(this.data);
//this.renderFigures();
}
},
renderFigures: function () {
var self = this;
// prevent some d3-internal races with a timeout
window.setTimeout(function () {
var chart = nv.models.pieChart()
.x(function(d) { return d.label; })
.y(function(d) { return d.value; })
.showLabels(true);
nv.addGraph(function() {
d3.select(".modal-body-right svg")
.datum(self.convertFigures())
.transition().duration(1200)
.call(chart);
return chart;
});
return chart;
}, 500);
},
convertFigures: function () {
var self = this;
var collValues = [];
if (self.data && self.data.figures) {
$.each(self.data.figures, function(k,v) {
collValues.push({
"label" : k,
"value" : v.count
});
});
}
return [{
key: "Collections Status",
values: collValues
}];
},
roundNumber: function(number, n) {
var faktor;
faktor = Math.pow(10,n);
var returnVal = (Math.round(number * faktor) / faktor);
return returnVal;
},
appendFigures: function () {
var cssClass = 'modal-text';
if (this.data) {
$('#figures').append(
'
'+
''+
''
);
}
},
appendIndex: function () {
var cssClass = 'collectionInfoTh modal-text';
if (this.index) {
var fieldString = '';
var indexId = '';
$.each(this.index.indexes, function(k,v) {
if (v.fields !== undefined) {
fieldString = v.fields.join(", ");
}
//cut index id
var position = v.id.indexOf('/');
var indexId = v.id.substr(position+1, v.id.length);
$('#collectionIndexTable').append(
''+
'' + indexId + ' | '+
'' + v.type + ' | '+
'' + v.unique + ' | '+
'' + fieldString + ' | '+
'
'
);
});
}
},
fillLoadedModal: function (data) {
$('#collectionSizeBox').show();
$('#collectionSyncBox').show();
$('#collectionRevBox').show();
if (data.waitForSync === false) {
$('#show-collection-sync').text('false');
}
else {
$('#show-collection-sync').text('true');
}
var calculatedSize = data.journalSize / 1024 / 1024;
$('#show-collection-size').text(this.roundNumber(calculatedSize,2));
$('#show-collection-rev').text(this.revision.revision);
this.appendIndex();
this.appendFigures();
$('#show-collection').modal('show');
},
getCollectionId: function () {
return this.myCollection.id;
},
getCollectionStatus: function () {
return this.myCollection.status;
},
hideModal: function () {
$('#show-collection').modal('hide');
}
});