2010-01-26 06:17:14 +01:00
|
|
|
var theProject;
|
|
|
|
var ui = {};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
var Gridworks = {
|
2010-05-08 07:52:32 +02:00
|
|
|
gridworksHelperService: "http://1-0.gridworks-helper.dfhuynh.user.dev.freebaseapps.com/"
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Gridworks.reportException = function(e) {
|
|
|
|
if (window.console) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
function resize() {
|
|
|
|
var header = $("#header");
|
|
|
|
|
|
|
|
ui.menuBarContainer.css("top", header.outerHeight() + "px");
|
|
|
|
|
2010-04-13 01:48:48 +02:00
|
|
|
var leftPanelWidth = 300;
|
2010-04-13 06:49:28 +02:00
|
|
|
var leftPanelMargin = 7;
|
2010-04-09 03:48:50 +02:00
|
|
|
var width = $(window).width();
|
|
|
|
var top = ui.menuBarContainer.offset().top + ui.menuBarContainer.outerHeight();
|
2010-04-25 03:41:09 +02:00
|
|
|
var height = $(window).height() - top;
|
2010-04-09 03:48:50 +02:00
|
|
|
|
|
|
|
ui.viewPanel
|
|
|
|
.css("top", top + "px")
|
2010-04-13 01:48:48 +02:00
|
|
|
.css("left", leftPanelWidth + "px")
|
2010-04-09 03:48:50 +02:00
|
|
|
.css("height", height + "px")
|
2010-04-13 01:48:48 +02:00
|
|
|
.css("width", (width - leftPanelWidth) + "px");
|
|
|
|
|
|
|
|
ui.leftPanel
|
|
|
|
.css("top", (top + leftPanelMargin) + "px")
|
|
|
|
.css("left", leftPanelMargin + "px")
|
|
|
|
.css("height", (height - 2 * leftPanelMargin) + "px")
|
|
|
|
.css("width", (leftPanelWidth - 2 * leftPanelMargin) + "px");
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-04-13 01:48:48 +02:00
|
|
|
var leftPanelTabsPaddings = ui.leftPanelTabs.outerHeight(true) - ui.leftPanelTabs.innerHeight();
|
|
|
|
ui.leftPanelTabs
|
|
|
|
.height(ui.leftPanel.height() - leftPanelTabsPaddings);
|
2010-02-27 01:16:44 +01:00
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
var processPanelWidth = 400;
|
|
|
|
ui.processPanel
|
|
|
|
.css("width", processPanelWidth + "px")
|
|
|
|
.css("left", Math.floor((width - processPanelWidth) / 2) + "px");
|
|
|
|
}
|
|
|
|
|
2010-04-13 01:48:48 +02:00
|
|
|
function resizeTabs() {
|
2010-04-17 01:38:49 +02:00
|
|
|
var totalHeight = ui.leftPanel.height();
|
|
|
|
var headerHeight = ui.leftPanelTabs.find(".ui-tabs-nav").outerHeight(true);
|
|
|
|
|
|
|
|
var visibleTabPanels = ui.leftPanelTabs.find(".ui-tabs-panel:not(.ui-tabs-hide)");
|
|
|
|
var paddings = visibleTabPanels.innerHeight(true) - visibleTabPanels.height();
|
|
|
|
|
|
|
|
var allTabPanels = ui.leftPanelTabs.find(".ui-tabs-panel");
|
|
|
|
allTabPanels.height(totalHeight - headerHeight - paddings - 1);
|
2010-04-13 01:48:48 +02:00
|
|
|
}
|
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
function resizeAll() {
|
|
|
|
resize();
|
2010-04-13 01:48:48 +02:00
|
|
|
resizeTabs();
|
2010-04-09 03:48:50 +02:00
|
|
|
|
|
|
|
ui.menuBar.resize();
|
|
|
|
ui.browsingEngine.resize();
|
|
|
|
ui.processWidget.resize();
|
|
|
|
ui.historyWidget.resize();
|
|
|
|
ui.dataTableView.resize();
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
function initializeUI(uiState) {
|
|
|
|
var path = $("#path");
|
2010-05-17 21:22:58 +02:00
|
|
|
$('<span class="app-path-section" id="project-name-in-path"></span>').appendTo(path);
|
2010-04-24 08:29:30 +02:00
|
|
|
$('<a href="javascript:{}" class="permalink">permalink</a>')
|
2010-02-27 01:16:44 +01:00
|
|
|
.mouseenter(function() {
|
|
|
|
this.href = Gridworks.getPermanentLink();
|
2010-04-24 08:29:30 +02:00
|
|
|
}).appendTo(path);
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
Gridworks.setTitle();
|
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
var body = $("#body").empty().html(
|
|
|
|
'<div bind="viewPanel" class="view-panel"></div>' +
|
|
|
|
'<div bind="processPanel" class="process-panel"></div>' +
|
2010-04-13 01:48:48 +02:00
|
|
|
'<div bind="leftPanel" class="left-panel">' +
|
2010-04-19 01:05:56 +02:00
|
|
|
'<div bind="leftPanelTabs" class="gridworks-tabs">' +
|
2010-04-13 01:48:48 +02:00
|
|
|
'<ul>' +
|
|
|
|
'<li><a href="#gridworks-tabs-facets">Facet/Filter</a></li>' +
|
|
|
|
'<li><a href="#gridworks-tabs-history" bind="historyTabHeader">Undo/Redo</a></li>' +
|
|
|
|
'</ul>' +
|
|
|
|
'<div id="gridworks-tabs-facets" bind="facetPanel" class="facet-panel"></div>' +
|
|
|
|
'<div id="gridworks-tabs-history" bind="historyPanel" class="history-panel"></div>' +
|
|
|
|
'</div>' +
|
|
|
|
'</div>' +
|
2010-03-22 22:48:36 +01:00
|
|
|
'<div class="menu-bar-container" bind="menuBarContainer"><div bind="menuBarPanel" class="menu-bar"></div></div>'
|
|
|
|
);
|
|
|
|
ui = DOM.bind(body);
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
ui.menuBarContainer.css("top", $("#header").outerHeight() + "px");
|
|
|
|
ui.menuBar = new MenuBar(ui.menuBarPanel); // construct the menu first so we can resize everything else
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-04-13 09:08:23 +02:00
|
|
|
ui.leftPanelTabs.tabs({ selected: 0 });
|
2010-03-22 22:48:36 +01:00
|
|
|
resize();
|
2010-04-13 01:48:48 +02:00
|
|
|
resizeTabs();
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
ui.browsingEngine = new BrowsingEngine(ui.facetPanel, uiState.facets || []);
|
2010-02-01 04:22:35 +01:00
|
|
|
ui.processWidget = new ProcessWidget(ui.processPanel);
|
2010-04-13 01:48:48 +02:00
|
|
|
ui.historyWidget = new HistoryWidget(ui.historyPanel, ui.historyTabHeader);
|
2010-01-29 01:46:15 +01:00
|
|
|
ui.dataTableView = new DataTableView(ui.viewPanel);
|
2010-03-22 22:48:36 +01:00
|
|
|
|
2010-04-13 09:08:23 +02:00
|
|
|
ui.leftPanelTabs.bind('tabsshow', function(event, tabs) {
|
|
|
|
if (tabs.index === 0) {
|
|
|
|
ui.browsingEngine.resize();
|
|
|
|
} else if (tabs.index === 1) {
|
|
|
|
ui.historyWidget.resize();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
$(window).bind("resize", resizeAll);
|
2010-05-14 21:27:01 +02:00
|
|
|
|
|
|
|
if (uiState.facets) {
|
|
|
|
Gridworks.update({ engineChanged: true });
|
|
|
|
}
|
2010-03-22 22:48:36 +01:00
|
|
|
}
|
|
|
|
|
2010-05-01 00:49:59 +02:00
|
|
|
Gridworks.setTitle = function(status) {
|
|
|
|
var title = theProject.metadata.name + " - Gridworks";
|
|
|
|
if (status) {
|
|
|
|
title = status + " - " + title;
|
|
|
|
}
|
|
|
|
document.title = title;
|
2010-05-17 21:22:58 +02:00
|
|
|
|
|
|
|
var name = $("#project-name-in-path");
|
|
|
|
name.empty();
|
|
|
|
name.text('project: ');
|
|
|
|
$('<a href="#">' + theProject.metadata.name + '</a>').appendTo(name);
|
2010-05-01 00:49:59 +02:00
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
Gridworks.reinitializeProjectData = function(f) {
|
2010-02-05 00:38:40 +01:00
|
|
|
Ajax.chainGetJSON(
|
|
|
|
"/command/get-project-metadata?" + $.param({ project: theProject.id }), null,
|
|
|
|
function(data) {
|
|
|
|
theProject.metadata = data;
|
|
|
|
},
|
2010-02-11 07:44:48 +01:00
|
|
|
"/command/get-models?" + $.param({ project: theProject.id }), null,
|
2010-02-05 00:38:40 +01:00
|
|
|
function(data) {
|
2010-05-20 07:49:13 +02:00
|
|
|
for (var n in data) {
|
|
|
|
if (data.hasOwnProperty(n)) {
|
|
|
|
theProject[n] = data[n];
|
|
|
|
}
|
2010-02-05 00:38:40 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
f
|
|
|
|
);
|
2010-04-08 21:52:23 +02:00
|
|
|
};
|
2010-02-22 21:25:45 +01:00
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
/*
|
|
|
|
* Utility state functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
Gridworks.createUpdateFunction = function(options, onFinallyDone) {
|
|
|
|
var functions = [];
|
|
|
|
var pushFunction = function(f) {
|
|
|
|
var index = functions.length;
|
|
|
|
functions.push(function() {
|
|
|
|
f(functions[index + 1]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
pushFunction(function(onDone) {
|
|
|
|
ui.historyWidget.update(onDone);
|
|
|
|
});
|
2010-04-09 03:14:33 +02:00
|
|
|
if (options.everythingChanged || options.modelsChanged || options.columnStatsChanged) {
|
2010-02-26 22:56:41 +01:00
|
|
|
pushFunction(Gridworks.reinitializeProjectData);
|
|
|
|
}
|
2010-04-09 03:14:33 +02:00
|
|
|
if (options.everythingChanged || options.modelsChanged || options.rowsChanged || options.rowMetadataChanged || options.cellsChanged || options.engineChanged) {
|
2010-02-26 22:56:41 +01:00
|
|
|
pushFunction(function(onDone) {
|
|
|
|
ui.dataTableView.update(onDone);
|
|
|
|
});
|
|
|
|
pushFunction(function(onDone) {
|
|
|
|
ui.browsingEngine.update(onDone);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
functions.push(onFinallyDone || function() {});
|
|
|
|
|
|
|
|
return functions[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
Gridworks.update = function(options, onFinallyDone) {
|
|
|
|
var done = false;
|
|
|
|
var dismissBusy = null;
|
|
|
|
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.setAjaxInProgress();
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
Gridworks.createUpdateFunction(options, function() {
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.clearAjaxInProgress();
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
done = true;
|
|
|
|
if (dismissBusy) {
|
|
|
|
dismissBusy();
|
|
|
|
}
|
|
|
|
if (onFinallyDone) {
|
|
|
|
onFinallyDone();
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
if (!done) {
|
|
|
|
dismissBusy = DialogSystem.showBusy();
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
};
|
|
|
|
|
|
|
|
Gridworks.postProcess = function(command, params, body, updateOptions, callbacks) {
|
2010-04-09 00:16:12 +02:00
|
|
|
updateOptions = updateOptions || {};
|
|
|
|
callbacks = callbacks || {};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
params = params || {};
|
|
|
|
params.project = theProject.id;
|
|
|
|
|
|
|
|
body = body || {};
|
2010-04-09 00:16:12 +02:00
|
|
|
if (!("includeEngine" in updateOptions) || updateOptions.includeEngine) {
|
2010-04-29 02:54:48 +02:00
|
|
|
body.engine = JSON.stringify(
|
|
|
|
"engineConfig" in updateOptions ?
|
|
|
|
updateOptions.engineConfig :
|
|
|
|
ui.browsingEngine.getJSON()
|
|
|
|
);
|
2010-04-09 00:16:12 +02:00
|
|
|
}
|
2010-02-26 22:56:41 +01:00
|
|
|
|
|
|
|
var done = false;
|
|
|
|
var dismissBusy = null;
|
|
|
|
|
|
|
|
function onDone(o) {
|
|
|
|
done = true;
|
|
|
|
if (dismissBusy) {
|
|
|
|
dismissBusy();
|
|
|
|
}
|
|
|
|
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.clearAjaxInProgress();
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
if (o.code == "error") {
|
|
|
|
if ("onError" in callbacks) {
|
|
|
|
try {
|
2010-04-09 03:14:33 +02:00
|
|
|
callbacks.onError(o);
|
2010-02-26 22:56:41 +01:00
|
|
|
} catch (e) {
|
|
|
|
Gridworks.reportException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ("onDone" in callbacks) {
|
|
|
|
try {
|
2010-04-09 03:14:33 +02:00
|
|
|
callbacks.onDone(o);
|
2010-02-26 22:56:41 +01:00
|
|
|
} catch (e) {
|
|
|
|
Gridworks.reportException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (o.code == "ok") {
|
2010-04-09 03:14:33 +02:00
|
|
|
Gridworks.update(updateOptions, callbacks.onFinallyDone);
|
2010-03-23 01:26:28 +01:00
|
|
|
|
|
|
|
if ("historyEntry" in o) {
|
|
|
|
ui.processWidget.showUndo(o.historyEntry);
|
|
|
|
}
|
2010-02-26 22:56:41 +01:00
|
|
|
} else if (o.code == "pending") {
|
|
|
|
if ("onPending" in callbacks) {
|
|
|
|
try {
|
2010-04-09 03:14:33 +02:00
|
|
|
callbacks.onPending(o);
|
2010-02-26 22:56:41 +01:00
|
|
|
} catch (e) {
|
|
|
|
Gridworks.reportException(e);
|
|
|
|
}
|
|
|
|
}
|
2010-04-09 03:14:33 +02:00
|
|
|
ui.processWidget.update(updateOptions, callbacks.onFinallyDone);
|
2010-02-26 22:56:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.setAjaxInProgress();
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
$.post(
|
|
|
|
"/command/" + command + "?" + $.param(params),
|
|
|
|
body,
|
|
|
|
onDone,
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
if (!done) {
|
|
|
|
dismissBusy = DialogSystem.showBusy();
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
};
|
|
|
|
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.setAjaxInProgress = function() {
|
|
|
|
$(document.body).attr("ajax_in_progress", "true");
|
|
|
|
};
|
|
|
|
|
|
|
|
Gridworks.clearAjaxInProgress = function() {
|
|
|
|
$(document.body).attr("ajax_in_progress", "false");
|
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
/*
|
|
|
|
* Utility model functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
Gridworks.cellIndexToColumn = function(cellIndex) {
|
2010-02-22 21:25:45 +01:00
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
2010-02-26 22:56:41 +01:00
|
|
|
if (column.cellIndex == cellIndex) {
|
2010-02-22 21:25:45 +01:00
|
|
|
return column;
|
2010-04-24 03:19:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
Gridworks.columnNameToColumn = function(columnName) {
|
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
|
|
|
if (column.name == columnName) {
|
|
|
|
return column;
|
2010-02-22 21:25:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
|
|
|
|
2010-04-23 21:39:12 +02:00
|
|
|
Gridworks.preparePool = function(pool) {
|
|
|
|
for (var id in pool.recons) {
|
2010-05-05 02:26:26 +02:00
|
|
|
if (pool.recons.hasOwnProperty(id)) {
|
|
|
|
var recon = pool.recons[id];
|
|
|
|
if (recon.m) {
|
|
|
|
recon.m = pool.reconCandidates[recon.m];
|
|
|
|
}
|
|
|
|
if (recon.c) {
|
|
|
|
for (var j = 0; j < recon.c.length; j++) {
|
|
|
|
recon.c[j] = pool.reconCandidates[recon.c[j]];
|
|
|
|
}
|
2010-04-23 21:39:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-05-21 02:48:36 +02:00
|
|
|
Gridworks.fetchRows = function(start, limit, onDone, sorting) {
|
|
|
|
var body = {
|
|
|
|
engine: JSON.stringify(ui.browsingEngine.getJSON())
|
|
|
|
};
|
|
|
|
if (sorting) {
|
|
|
|
body.sorting = JSON.stringify(sorting)
|
|
|
|
}
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
$.post(
|
|
|
|
"/command/get-rows?" + $.param({ project: theProject.id, start: start, limit: limit }),
|
2010-05-21 02:48:36 +02:00
|
|
|
body,
|
2010-02-26 22:56:41 +01:00
|
|
|
function(data) {
|
|
|
|
theProject.rowModel = data;
|
2010-04-23 21:39:12 +02:00
|
|
|
|
|
|
|
// Un-pool objects
|
|
|
|
Gridworks.preparePool(data.pool);
|
|
|
|
for (var r = 0; r < data.rows.length; r++) {
|
|
|
|
var row = data.rows[r];
|
|
|
|
for (var c = 0; c < row.cells.length; c++) {
|
|
|
|
var cell = row.cells[c];
|
|
|
|
if ((cell) && ("r" in cell)) {
|
|
|
|
cell.r = data.pool.recons[cell.r];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
if (onDone) {
|
|
|
|
onDone();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
2010-02-27 01:16:44 +01:00
|
|
|
|
|
|
|
Gridworks.getPermanentLink = function() {
|
|
|
|
var params = [
|
|
|
|
"project=" + escape(theProject.id),
|
|
|
|
"ui=" + escape(JSON.stringify({
|
|
|
|
facets: ui.browsingEngine.getFacetUIStates()
|
|
|
|
}))
|
|
|
|
];
|
|
|
|
return "project.html?" + params.join("&");
|
|
|
|
};
|
2010-04-09 03:48:50 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loader
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onLoad() {
|
|
|
|
var params = URL.getParameters();
|
|
|
|
if ("project" in params) {
|
|
|
|
theProject = {
|
|
|
|
id: parseInt(params.project,10)
|
|
|
|
};
|
|
|
|
|
|
|
|
var uiState = {};
|
|
|
|
if ("ui" in params) {
|
|
|
|
try {
|
|
|
|
uiState = JSON.parse(params.ui);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Gridworks.reinitializeProjectData(function() {
|
|
|
|
initializeUI(uiState);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(onLoad);
|