2010-02-27 01:16:44 +01:00
|
|
|
function BrowsingEngine(div, facetConfigs) {
|
2010-01-29 01:46:15 +01:00
|
|
|
this._div = div;
|
|
|
|
this._facets = [];
|
2010-01-30 02:05:30 +01:00
|
|
|
|
|
|
|
this._initializeUI();
|
2010-02-27 01:16:44 +01:00
|
|
|
|
|
|
|
if (facetConfigs.length > 0) {
|
|
|
|
for (var i = 0; i < facetConfigs.length; i++) {
|
|
|
|
var facetConfig = facetConfigs[i];
|
|
|
|
var type = facetConfig.c.type;
|
|
|
|
|
2010-03-02 23:32:52 +01:00
|
|
|
var elmt = this._createFacetContainer();
|
2010-02-27 01:16:44 +01:00
|
|
|
var facet;
|
|
|
|
switch (type) {
|
|
|
|
case "range":
|
2010-03-02 23:32:52 +01:00
|
|
|
facet = RangeFacet.reconstruct(elmt, facetConfig);
|
2010-02-27 01:16:44 +01:00
|
|
|
break;
|
2010-04-12 21:22:49 +02:00
|
|
|
case "scatterplot":
|
|
|
|
facet = ScatterplotFacet.reconstruct(elmt, facetConfig);
|
|
|
|
break;
|
2010-02-27 01:16:44 +01:00
|
|
|
case "text":
|
2010-03-02 23:32:52 +01:00
|
|
|
facet = TextSearchFacet.reconstruct(elmt, facetConfig);
|
2010-02-27 01:16:44 +01:00
|
|
|
break;
|
|
|
|
default:
|
2010-03-02 23:32:52 +01:00
|
|
|
facet = ListFacet.reconstruct(elmt, facetConfig);
|
2010-02-27 01:16:44 +01:00
|
|
|
}
|
|
|
|
|
2010-03-02 23:32:52 +01:00
|
|
|
this._facets.push({ elmt: elmt, facet: facet });
|
2010-02-27 01:16:44 +01:00
|
|
|
}
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
BrowsingEngine.prototype.resize = function() {
|
2010-04-24 02:44:33 +02:00
|
|
|
if (this._facets.length > 0) {
|
|
|
|
var header = this._div.find(".browsing-panel-header");
|
|
|
|
var body = this._div.find(".facets-container");
|
|
|
|
var bodyPaddings = body.outerHeight(true) - body.height();
|
|
|
|
|
|
|
|
body.css("height", (this._div.height() - header.outerHeight(true) - bodyPaddings) + "px");
|
|
|
|
|
|
|
|
this._elmts.facets.sortable("refresh");
|
|
|
|
}
|
2010-03-22 22:48:36 +01:00
|
|
|
};
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
BrowsingEngine.prototype.getFacetUIStates = function() {
|
|
|
|
var f = [];
|
|
|
|
for (var i = 0; i < this._facets.length; i++) {
|
|
|
|
var facet = this._facets[i];
|
|
|
|
f.push(facet.facet.getUIState());
|
|
|
|
}
|
|
|
|
return f;
|
2010-04-08 21:52:23 +02:00
|
|
|
};
|
2010-01-29 01:46:15 +01:00
|
|
|
|
2010-01-30 02:05:30 +01:00
|
|
|
BrowsingEngine.prototype._initializeUI = function() {
|
2010-01-29 01:46:15 +01:00
|
|
|
var self = this;
|
2010-03-02 23:32:52 +01:00
|
|
|
|
|
|
|
this._div.html(
|
2010-04-18 02:56:09 +02:00
|
|
|
'<div class="browsing-panel-help" bind="help">' +
|
|
|
|
'<h1>Explore data ...</h1>' +
|
|
|
|
'<p>by choosing a facet or filter method from the menus at the top of each column.</p>' +
|
2010-05-03 23:19:11 +02:00
|
|
|
'<p>Not sure how to get started? <a href="http://www.vimeo.com/groups/gridworks" target="_blank">Watch these screencasts</a>.</p>' +
|
2010-04-18 02:56:09 +02:00
|
|
|
'</div>' +
|
|
|
|
'<div class="browsing-panel-header" bind="header">' +
|
|
|
|
'<div class="browsing-panel-indicator" bind="indicator">' +
|
|
|
|
'<img src="images/small-spinner.gif" /> refreshing facets ...' +
|
2010-03-23 19:53:29 +01:00
|
|
|
'</div>' +
|
2010-04-18 02:56:09 +02:00
|
|
|
'<div class="browsing-panel-controls" bind="controls"><div class="grid-layout layout-tightest layout-full"><table>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td>' +
|
|
|
|
'<a href="javascript:{}" bind="refreshLink" class="action" title="Make sure all facets are up-to-date">Refresh</a>' +
|
|
|
|
'</td>' +
|
|
|
|
'<td width="1%">' +
|
|
|
|
'<a href="javascript:{}" bind="resetLink" class="action" title="Clear selection in all facets">Reset All</a>' +
|
|
|
|
'</td>' +
|
|
|
|
'<td width="1%">' +
|
|
|
|
'<a href="javascript:{}" bind="removeLink" class="action" title="Remove all facets">Remove All</a>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr bind="dependentRowControls">' +
|
|
|
|
'<td colspan="3"><input type="checkbox" class="inline" bind="includeDependentRowsCheck" /> show dependent rows</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'</table></div></div>' +
|
2010-03-12 02:06:23 +01:00
|
|
|
'</div>' +
|
2010-03-02 23:32:52 +01:00
|
|
|
'<ul bind="facets" class="facets-container"></ul>'
|
|
|
|
);
|
|
|
|
this._elmts = DOM.bind(this._div);
|
|
|
|
this._elmts.facets.sortable({
|
|
|
|
handle: '.facet-title',
|
|
|
|
update: function(event, ui) {
|
|
|
|
self._updateFacetOrder();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this._elmts.facets.disableSelection();
|
|
|
|
|
2010-03-12 02:06:23 +01:00
|
|
|
this._elmts.includeDependentRowsCheck.change(function() {
|
|
|
|
Gridworks.update({ engineChanged: true });
|
|
|
|
});
|
|
|
|
|
2010-03-02 23:32:52 +01:00
|
|
|
this._elmts.refreshLink.click(function() { self.update(); });
|
2010-03-23 19:53:29 +01:00
|
|
|
this._elmts.resetLink.click(function() { self.reset(); });
|
|
|
|
this._elmts.removeLink.click(function() { self.remove(); });
|
2010-03-02 23:32:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
BrowsingEngine.prototype._updateFacetOrder = function() {
|
|
|
|
var elmts = this._elmts.facets.children();
|
|
|
|
var newFacets = [];
|
|
|
|
for (var e = 0; e < elmts.length; e++) {
|
|
|
|
var elmt = elmts[e];
|
|
|
|
for (var f = 0; f < this._facets.length; f++) {
|
|
|
|
if (elmt === this._facets[f].elmt[0]) {
|
|
|
|
newFacets.push(this._facets[f]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._facets = newFacets;
|
2010-01-29 01:46:15 +01:00
|
|
|
};
|
|
|
|
|
2010-04-17 07:59:25 +02:00
|
|
|
BrowsingEngine.prototype.getJSON = function(keepUnrestrictedFacets, except) {
|
2010-03-12 02:06:23 +01:00
|
|
|
var a = {
|
|
|
|
facets: [],
|
|
|
|
includeDependent: this._elmts.includeDependentRowsCheck[0].checked
|
|
|
|
};
|
2010-01-29 01:46:15 +01:00
|
|
|
for (var i = 0; i < this._facets.length; i++) {
|
2010-02-22 21:25:45 +01:00
|
|
|
var facet = this._facets[i];
|
2010-04-17 08:19:47 +02:00
|
|
|
if ((keepUnrestrictedFacets || facet.facet.hasSelection()) && (facet.facet !== except)) {
|
|
|
|
a.facets.push(facet.facet.getJSON());
|
2010-02-22 21:25:45 +01:00
|
|
|
}
|
2010-01-29 01:46:15 +01:00
|
|
|
}
|
|
|
|
return a;
|
|
|
|
};
|
2010-01-30 02:05:30 +01:00
|
|
|
|
2010-02-02 02:36:02 +01:00
|
|
|
BrowsingEngine.prototype.addFacet = function(type, config, options) {
|
2010-03-02 23:32:52 +01:00
|
|
|
var elmt = this._createFacetContainer();
|
2010-01-30 02:05:30 +01:00
|
|
|
var facet;
|
|
|
|
switch (type) {
|
2010-02-02 02:36:02 +01:00
|
|
|
case "range":
|
2010-03-02 23:32:52 +01:00
|
|
|
facet = new RangeFacet(elmt, config, options);
|
2010-02-02 02:36:02 +01:00
|
|
|
break;
|
2010-04-12 21:22:49 +02:00
|
|
|
case "scatterplot":
|
|
|
|
facet = new ScatterplotFacet(elmt, config, options);
|
|
|
|
break;
|
2010-02-02 20:16:09 +01:00
|
|
|
case "text":
|
2010-03-02 23:32:52 +01:00
|
|
|
facet = new TextSearchFacet(elmt, config, options);
|
2010-02-02 20:16:09 +01:00
|
|
|
break;
|
2010-01-30 02:05:30 +01:00
|
|
|
default:
|
2010-03-02 23:32:52 +01:00
|
|
|
facet = new ListFacet(elmt, config, options);
|
2010-01-30 02:05:30 +01:00
|
|
|
}
|
|
|
|
|
2010-03-02 23:32:52 +01:00
|
|
|
this._facets.push({ elmt: elmt, facet: facet });
|
2010-01-30 02:05:30 +01:00
|
|
|
this.update();
|
|
|
|
};
|
|
|
|
|
2010-03-02 23:32:52 +01:00
|
|
|
BrowsingEngine.prototype._createFacetContainer = function() {
|
2010-04-18 08:47:27 +02:00
|
|
|
return $('<li></li>').addClass("facet-container").attr("id","facet-" + this._facets.length).hide().appendTo(this._elmts.facets);
|
2010-03-02 23:32:52 +01:00
|
|
|
};
|
|
|
|
|
2010-02-01 01:19:41 +01:00
|
|
|
BrowsingEngine.prototype.removeFacet = function(facet) {
|
|
|
|
var update = facet.hasSelection();
|
|
|
|
for (var i = this._facets.length - 1;i >= 0; i--) {
|
2010-04-17 08:58:30 +02:00
|
|
|
var facetRecord = this._facets[i];
|
|
|
|
if (facetRecord.facet === facet) {
|
2010-03-04 20:38:23 +01:00
|
|
|
this._facets.splice(i, 1);
|
2010-03-12 21:08:50 +01:00
|
|
|
|
2010-04-17 08:58:30 +02:00
|
|
|
facetRecord.facet.dispose();
|
|
|
|
|
2010-03-12 21:08:50 +01:00
|
|
|
// This makes really big facet disappear right away. If you just call remove()
|
|
|
|
// then it takes a while for all the event handlers to get unwired, and the UI
|
|
|
|
// appear frozen.
|
2010-04-17 08:58:30 +02:00
|
|
|
facetRecord.elmt.hide();
|
2010-03-12 21:08:50 +01:00
|
|
|
window.setTimeout(function() {
|
2010-04-17 08:58:30 +02:00
|
|
|
facetRecord.elmt.remove();
|
2010-03-12 21:08:50 +01:00
|
|
|
}, 300);
|
|
|
|
|
2010-02-01 01:19:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2010-04-24 08:29:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < this._facets.length; i++) {
|
|
|
|
if (typeof this._facets[i].facet.update == "function") {
|
|
|
|
this._facets[i].facet.update();
|
|
|
|
}
|
2010-02-01 01:19:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (update) {
|
2010-02-27 07:59:55 +01:00
|
|
|
Gridworks.update({ engineChanged: true });
|
2010-02-01 01:19:41 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
BrowsingEngine.prototype.update = function(onDone) {
|
2010-01-30 02:05:30 +01:00
|
|
|
var self = this;
|
|
|
|
|
2010-04-18 02:56:09 +02:00
|
|
|
this._elmts.help.hide();
|
|
|
|
|
|
|
|
this._elmts.header.show();
|
|
|
|
this._elmts.controls.css("visibility", "hidden");
|
|
|
|
this._elmts.indicator.css("visibility", "visible");
|
2010-03-02 23:32:52 +01:00
|
|
|
|
2010-01-30 02:05:30 +01:00
|
|
|
$.post(
|
|
|
|
"/command/compute-facets?" + $.param({ project: theProject.id }),
|
2010-02-27 01:16:44 +01:00
|
|
|
{ engine: JSON.stringify(this.getJSON(true)) },
|
2010-01-30 02:05:30 +01:00
|
|
|
function(data) {
|
|
|
|
var facetData = data.facets;
|
|
|
|
|
|
|
|
for (var i = 0; i < facetData.length; i++) {
|
|
|
|
self._facets[i].facet.updateState(facetData[i]);
|
|
|
|
}
|
2010-02-26 22:56:41 +01:00
|
|
|
|
2010-04-18 02:56:09 +02:00
|
|
|
self._elmts.indicator.css("visibility", "hidden");
|
2010-03-02 23:32:52 +01:00
|
|
|
if (self._facets.length > 0) {
|
2010-04-18 02:56:09 +02:00
|
|
|
self._elmts.header.show();
|
|
|
|
self._elmts.controls.css("visibility", "visible");
|
|
|
|
|
|
|
|
if (theProject.columnModel.hasDependentRows) {
|
|
|
|
self._elmts.dependentRowControls.show();
|
|
|
|
} else {
|
|
|
|
self._elmts.dependentRowControls.hide();
|
|
|
|
}
|
2010-04-24 09:17:12 +02:00
|
|
|
|
|
|
|
self.resize();
|
2010-04-13 09:52:01 +02:00
|
|
|
} else {
|
|
|
|
self._elmts.help.show();
|
2010-03-02 23:32:52 +01:00
|
|
|
}
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
if (onDone) {
|
|
|
|
onDone();
|
|
|
|
}
|
2010-01-30 02:05:30 +01:00
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
2010-03-23 19:53:29 +01:00
|
|
|
|
|
|
|
BrowsingEngine.prototype.reset = function() {
|
|
|
|
for (var i = 0; i < this._facets.length; i++) {
|
|
|
|
this._facets[i].facet.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
Gridworks.update({ engineChanged: true });
|
|
|
|
};
|
|
|
|
|
|
|
|
BrowsingEngine.prototype.remove = function() {
|
|
|
|
var oldFacets = this._facets;
|
|
|
|
|
|
|
|
this._facets = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < oldFacets.length; i++) {
|
2010-04-17 08:58:30 +02:00
|
|
|
var facet = oldFacets[i];
|
|
|
|
facet.facet.dispose();
|
|
|
|
facet.elmt.hide();
|
2010-03-23 19:53:29 +01:00
|
|
|
}
|
|
|
|
window.setTimeout(function() {
|
|
|
|
for (var i = 0; i < oldFacets.length; i++) {
|
|
|
|
oldFacets[i].elmt.remove();
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
Gridworks.update({ engineChanged: true });
|
|
|
|
};
|