diff --git a/src/main/webapp/scripts/facets/list-facet.js b/src/main/webapp/scripts/facets/list-facet.js
index 8e7f8d072..6c82e3393 100644
--- a/src/main/webapp/scripts/facets/list-facet.js
+++ b/src/main/webapp/scripts/facets/list-facet.js
@@ -1,4 +1,4 @@
-function ListFacet(div, config, options) {
+function ListFacet(div, config, options, selection) {
this._div = div;
this._config = config;
@@ -7,12 +7,28 @@ function ListFacet(div, config, options) {
this._options.sort = "name";
}
- this._selection = [];
+ this._selection = selection || [];
this._data = null;
this.render();
}
+ListFacet.reconstruct = function(div, uiState) {
+ return new ListFacet(div, uiState.c, uiState.o, uiState.s);
+};
+
+ListFacet.prototype.getUIState = function() {
+ var json = {
+ c: this.getJSON(),
+ o: this._options
+ };
+
+ json.s = json.c.selection;
+ delete json.c.selection;
+
+ return json;
+}
+
ListFacet.prototype.getJSON = function() {
var o = {
type: "list",
diff --git a/src/main/webapp/scripts/facets/range-facet.js b/src/main/webapp/scripts/facets/range-facet.js
index 37357ed5a..c731bbe6b 100644
--- a/src/main/webapp/scripts/facets/range-facet.js
+++ b/src/main/webapp/scripts/facets/range-facet.js
@@ -26,6 +26,20 @@ RangeFacet.prototype._setDefaults = function() {
};
+RangeFacet.reconstruct = function(div, uiState) {
+ return new RangeFacet(div, uiState.c, uiState.o);
+};
+
+RangeFacet.prototype.getUIState = function() {
+ var json = {
+ c: this.getJSON(),
+ o: this._options
+ };
+
+ return json;
+}
+
+
RangeFacet.prototype.getJSON = function() {
var o = {
type: "range",
diff --git a/src/main/webapp/scripts/facets/text-search-facet.js b/src/main/webapp/scripts/facets/text-search-facet.js
index d2387151d..212aef664 100644
--- a/src/main/webapp/scripts/facets/text-search-facet.js
+++ b/src/main/webapp/scripts/facets/text-search-facet.js
@@ -3,16 +3,25 @@ function TextSearchFacet(div, config, options) {
this._config = config;
this._options = options;
- this._setDefaults();
+ this._query = config.query || null;
this._timerID = null;
this._initializeUI();
}
-TextSearchFacet.prototype._setDefaults = function() {
- this._query = null;
+TextSearchFacet.reconstruct = function(div, uiState) {
+ return new TextSearchFacet(div, uiState.c, uiState.o);
};
+TextSearchFacet.prototype.getUIState = function() {
+ var json = {
+ c: this.getJSON(),
+ o: this._options
+ };
+
+ return json;
+}
+
TextSearchFacet.prototype.getJSON = function() {
var o = {
type: "text",
@@ -58,7 +67,7 @@ TextSearchFacet.prototype.render = function() {
};
TextSearchFacet.prototype._reset = function() {
- this._setDefaults();
+ this._query = null;
this._updateRest();
};
diff --git a/src/main/webapp/scripts/project.js b/src/main/webapp/scripts/project.js
index bde4ec420..049ac904c 100644
--- a/src/main/webapp/scripts/project.js
+++ b/src/main/webapp/scripts/project.js
@@ -10,7 +10,6 @@ Gridworks.reportException = function(e) {
}
};
-
function onLoad() {
var params = URL.getParameters();
if ("project" in params) {
@@ -18,15 +17,36 @@ function onLoad() {
id: parseInt(params.project)
};
- Gridworks.reinitializeProjectData(initializeUI);
+ var uiState = {};
+ if ("ui" in params) {
+ try {
+ uiState = JSON.parse(params.ui);
+ } catch (e) {
+ }
+ }
+
+ Gridworks.reinitializeProjectData(function() {
+ initializeUI(uiState);
+ });
}
}
$(onLoad);
-function initializeUI() {
+function initializeUI(uiState) {
document.title = theProject.metadata.name + " - Gridworks";
- $('').text(theProject.metadata.name).addClass("app-path-section").appendTo($("#path"));
- $('').text(" project").appendTo($("#path"));
+
+ var path = $("#path");
+ $('').text(theProject.metadata.name).addClass("app-path-section").appendTo(path);
+ $('').text(" project").appendTo(path);
+
+ $('').html(" » ").appendTo(path);
+ $('')
+ .addClass("app-path-section")
+ .text("current view")
+ .mouseenter(function() {
+ this.href = Gridworks.getPermanentLink();
+ })
+ .appendTo(path);
var body = $("#body").empty();
@@ -47,7 +67,7 @@ function initializeUI() {
ui.processPanel = $('').addClass("process-panel").appendTo(document.body);
ui.menuBarPanel = $(''); $("#header").after(ui.menuBarPanel);
- ui.browsingEngine = new BrowsingEngine(ui.facetPanel);
+ ui.browsingEngine = new BrowsingEngine(ui.facetPanel, uiState.facets || []);
ui.processWidget = new ProcessWidget(ui.processPanel);
ui.historyWidget = new HistoryWidget(ui.historyPanel);
ui.dataTableView = new DataTableView(ui.viewPanel);
@@ -220,3 +240,13 @@ Gridworks.fetchRows = function(start, limit, onDone) {
"json"
);
};
+
+Gridworks.getPermanentLink = function() {
+ var params = [
+ "project=" + escape(theProject.id),
+ "ui=" + escape(JSON.stringify({
+ facets: ui.browsingEngine.getFacetUIStates()
+ }))
+ ];
+ return "project.html?" + params.join("&");
+};
diff --git a/src/main/webapp/scripts/project/browsing-engine.js b/src/main/webapp/scripts/project/browsing-engine.js
index 5fca33f0a..2082c4c2d 100644
--- a/src/main/webapp/scripts/project/browsing-engine.js
+++ b/src/main/webapp/scripts/project/browsing-engine.js
@@ -1,8 +1,40 @@
-function BrowsingEngine(div) {
+function BrowsingEngine(div, facetConfigs) {
this._div = div;
this._facets = [];
this._initializeUI();
+
+ if (facetConfigs.length > 0) {
+ for (var i = 0; i < facetConfigs.length; i++) {
+ var facetConfig = facetConfigs[i];
+ var type = facetConfig.c.type;
+
+ var div = $('').addClass("facet-container").appendTo(this._div);
+ var facet;
+ switch (type) {
+ case "range":
+ facet = RangeFacet.reconstruct(div, facetConfig);
+ break;
+ case "text":
+ facet = TextSearchFacet.reconstruct(div, facetConfig);
+ break;
+ default:
+ facet = ListFacet.reconstruct(div, facetConfig);
+ }
+
+ this._facets.push({ elmt: div, facet: facet });
+ }
+ this.update();
+ }
+}
+
+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;
}
BrowsingEngine.prototype._initializeUI = function() {
@@ -59,7 +91,7 @@ BrowsingEngine.prototype.update = function(onDone) {
$.post(
"/command/compute-facets?" + $.param({ project: theProject.id }),
- { engine: JSON.stringify(ui.browsingEngine.getJSON(true)) },
+ { engine: JSON.stringify(this.getJSON(true)) },
function(data) {
var facetData = data.facets;