Implemented permanent link, at least for facets' states.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@147 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-02-27 00:16:44 +00:00
parent f5ff9044cf
commit f0b8268809
5 changed files with 115 additions and 14 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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();
};

View File

@ -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";
$('<span></span>').text(theProject.metadata.name).addClass("app-path-section").appendTo($("#path"));
$('<span></span>').text(" project").appendTo($("#path"));
var path = $("#path");
$('<span></span>').text(theProject.metadata.name).addClass("app-path-section").appendTo(path);
$('<span></span>').text(" project").appendTo(path);
$('<span>').html(" &raquo; ").appendTo(path);
$('<a href="javascript:{}"></a>')
.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 = $('<div></div>').addClass("process-panel").appendTo(document.body);
ui.menuBarPanel = $('<div></div>'); $("#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("&");
};

View File

@ -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 = $('<div></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;