Converted project.html to project.vt and added a client side resource manager, where extensions can register scripts and styles to be included in .vt files

git-svn-id: http://google-refine.googlecode.com/svn/trunk@965 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-06-15 00:35:23 +00:00
parent b0389d8c6a
commit f7fe44dccc
12 changed files with 232 additions and 105 deletions

View File

@ -1,5 +1,5 @@
function init() {
Packages.java.lang.System.err.println("Initializing jython extension");
// Packages.java.lang.System.err.println("Initializing jython extension");
Packages.com.metaweb.gridworks.expr.MetaParser.registerLanguageParser(
"jython",

View File

@ -37,7 +37,7 @@
<classpathentry kind="lib" path="webapp/WEB-INF/lib/commons-io-1.4.jar"/>
<classpathentry kind="lib" path="webapp/WEB-INF/lib/rhino-1.7R2.jar"/>
<classpathentry kind="lib" path="webapp/WEB-INF/lib/velocity-1.5.jar"/>
<classpathentry kind="lib" path="webapp/WEB-INF/lib/butterfly-trunk-r20.jar"/>
<classpathentry kind="lib" path="webapp/WEB-INF/lib/lessen-trunk-r8.jar"/>
<classpathentry kind="lib" path="webapp/WEB-INF/lib/butterfly-trunk-r21.jar"/>
<classpathentry kind="output" path="webapp/WEB-INF/classes"/>
</classpath>

View File

@ -0,0 +1,67 @@
package com.metaweb.gridworks;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import edu.mit.simile.butterfly.ButterflyModule;
import edu.mit.simile.butterfly.MountPoint;
public class ClientSideResourceManager {
static public class ClientSideResourceBundle {
final protected Set<String> _pathSet = new HashSet<String>();
final protected List<String> _pathList = new ArrayList<String>();
}
final static protected Map<String, ClientSideResourceBundle> s_bundles
= new HashMap<String, ClientSideResourceBundle>();
static public void addPaths(
String bundleName,
ButterflyModule module,
String[] paths) {
ClientSideResourceBundle bundle = s_bundles.get(bundleName);
if (bundle == null) {
bundle = new ClientSideResourceBundle();
s_bundles.put(bundleName, bundle);
}
for (String path : paths) {
String fullPath = resolve(module, path);
if (!bundle._pathSet.contains(fullPath)) {
bundle._pathSet.add(fullPath);
bundle._pathList.add(fullPath);
}
}
}
static public String[] getPaths(String bundleName) {
ClientSideResourceBundle bundle = s_bundles.get(bundleName);
if (bundle == null) {
return new String[] {};
} else {
String[] paths = new String[bundle._pathList.size()];
bundle._pathList.toArray(paths);
return paths;
}
}
static protected String resolve(ButterflyModule module, String path) {
StringBuffer sb = new StringBuffer();
MountPoint mountPoint = module.getMountPoint();
boolean slashed = path.startsWith("/");
char[] mountPointChars = mountPoint.getMountPoint().toCharArray();
sb.append(mountPointChars, 0, slashed ? mountPointChars.length - 1 : mountPointChars.length);
sb.append(path);
return sb.toString();
}
}

View File

@ -3,6 +3,5 @@
#
core = /
core.scripting-jython = jython
jython = /extensions/jython/

View File

@ -0,0 +1,131 @@
var html = "text/html";
var encoding = "UTF-8";
var ClientSideResourceManager = Packages.com.metaweb.gridworks.ClientSideResourceManager;
var templatedFiles = {
// Requests with last path segments mentioned here
// will get served from .vt files with the same names
"project" : true
};
/*
* This optional function is invoked from the module's init() Java function.
*/
function init() {
// Packages.java.lang.System.err.println("Initializing by script " + module);
ClientSideResourceManager.addPaths(
"project/scripts",
module,
[
"externals/jquery-1.4.2.min.js",
"externals/jquery.cookie.js",
"externals/suggest/suggest-1.2.min.js",
"externals/jquery-ui/jquery-ui-1.8.custom.min.js",
"externals/imgareaselect/jquery.imgareaselect.js",
"externals/date.js",
"scripts/util/misc.js",
"scripts/util/url.js",
"scripts/util/string.js",
"scripts/util/ajax.js",
"scripts/util/menu.js",
"scripts/util/dialog.js",
"scripts/util/dom.js",
"scripts/util/sign.js",
"scripts/util/freebase.js",
"scripts/util/custom-suggest.js",
"scripts/widgets/history-widget.js",
"scripts/widgets/process-widget.js",
"scripts/widgets/histogram-widget.js",
"scripts/widgets/slider-widget.js",
"scripts/project.js",
"scripts/project/menu-bar.js",
"scripts/project/browsing-engine.js",
"scripts/project/scripting.js",
"scripts/facets/list-facet.js",
"scripts/facets/range-facet.js",
"scripts/facets/scatterplot-facet.js",
"scripts/facets/text-search-facet.js",
"scripts/views/data-table-view.js",
"scripts/views/data-table-cell-ui.js",
"scripts/views/data-table-column-header-ui.js",
"scripts/dialogs/recon-dialog.js",
"scripts/dialogs/expression-preview-dialog.js",
"scripts/dialogs/freebase-loading-dialog.js",
"scripts/dialogs/clustering-dialog.js",
"scripts/dialogs/scatterplot-dialog.js",
"scripts/dialogs/extend-data-preview-dialog.js",
"scripts/dialogs/templating-exporter-dialog.js",
"scripts/protograph/schema-alignment.js",
"scripts/protograph/schema-alignment-ui-node.js",
"scripts/protograph/schema-alignment-ui-link.js"
]
);
ClientSideResourceManager.addPaths(
"project/styles",
module,
[
"externals/suggest/css/suggest-1.2.min.css",
"externals/jquery-ui/css/ui-lightness/jquery-ui-1.8.custom.css",
"externals/imgareaselect/css/imgareaselect-default.css",
"styles/common.css",
"styles/jquery-ui-overrides.css",
"styles/util/menu.css",
"styles/util/dialog.css",
"styles/util/custom-suggest.css",
"styles/project.css",
"styles/project/browsing.css",
"styles/project/process.css",
"styles/project/menu-bar.css",
"styles/widgets/history.css",
"styles/widgets/histogram-widget.css",
"styles/widgets/slider-widget.css",
"styles/views/data-table-view.css",
"styles/dialogs/expression-preview-dialog.css",
"styles/dialogs/recon-dialog.css",
"styles/dialogs/clustering-dialog.css",
"styles/dialogs/scatterplot-dialog.css",
"styles/dialogs/freebase-loading-dialog.css",
"styles/dialogs/extend-data-preview-dialog.css",
"styles/protograph/schema-alignment-dialog.css"
]
);
}
/*
* This is the function that is invoked by Butterfly
*/
function process(path, request, response) {
if (path.endsWith("/")) {
path = path.substring(0, path.length - 1);
}
var slash = path.lastIndexOf("/");
var lastSegment = slash >= 0 ? path.substring(slash + 1) : path;
if (lastSegment in templatedFiles) {
var context = {};
context.scripts = ClientSideResourceManager.getPaths(lastSegment + "/scripts");
context.styles = ClientSideResourceManager.getPaths(lastSegment + "/styles");
send(request, response, path + ".vt", context);
}
}
function send(request, response, template, context) {
butterfly.sendTextFromTemplate(request, response, context, template, encoding, html);
}

View File

@ -1,3 +1,4 @@
description = Gridworks Core Module
templating = false
templating.macros = macros.vm

View File

View File

@ -1,100 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Freebase Gridworks</title>
<link rel="icon" type="image/png" href="images/favicon.png">
<link type="text/css" rel="stylesheet" href="externals/suggest/css/suggest-1.2.min.css" />
<link type="text/css" rel="stylesheet" href="externals/jquery-ui/css/ui-lightness/jquery-ui-1.8.custom.css" />
<link type="text/css" rel="stylesheet" href="externals/imgareaselect/css/imgareaselect-default.css" />
<link rel="stylesheet" href="/styles/common.css" />
<link rel="stylesheet" href="/styles/jquery-ui-overrides.css" />
<link rel="stylesheet" href="/styles/util/menu.css" />
<link rel="stylesheet" href="/styles/util/dialog.css" />
<link rel="stylesheet" href="/styles/util/custom-suggest.css" />
<link rel="stylesheet" href="/styles/project.css" />
<link rel="stylesheet" href="/styles/project/browsing.css" />
<link rel="stylesheet" href="/styles/project/process.css" />
<link rel="stylesheet" href="/styles/project/menu-bar.css" />
<link rel="stylesheet" href="/styles/widgets/history.css" />
<link rel="stylesheet" href="/styles/widgets/histogram-widget.css" />
<link rel="stylesheet" href="/styles/widgets/slider-widget.css" />
<link rel="stylesheet" href="/styles/views/data-table-view.css" />
<link rel="stylesheet" href="/styles/dialogs/expression-preview-dialog.css" />
<link rel="stylesheet" href="/styles/dialogs/recon-dialog.css" />
<link rel="stylesheet" href="/styles/dialogs/clustering-dialog.css" />
<link rel="stylesheet" href="/styles/dialogs/scatterplot-dialog.css" />
<link rel="stylesheet" href="/styles/dialogs/freebase-loading-dialog.css" />
<link rel="stylesheet" href="/styles/dialogs/extend-data-preview-dialog.css" />
<link rel="stylesheet" href="/styles/protograph/schema-alignment-dialog.css" />
<script type="text/javascript" src="externals/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="externals/jquery.cookie.js"></script>
<script type="text/javascript" src="externals/suggest/suggest-1.2.min.js"></script>
<script type="text/javascript" src="externals/jquery-ui/jquery-ui-1.8.custom.min.js"></script>
<script type="text/javascript" src="externals/imgareaselect/jquery.imgareaselect.js"></script>
<script type="text/javascript" src="externals/date.js"></script>
<script type="text/javascript" src="scripts/util/misc.js"></script>
<script type="text/javascript" src="scripts/util/url.js"></script>
<script type="text/javascript" src="scripts/util/string.js"></script>
<script type="text/javascript" src="scripts/util/ajax.js"></script>
<script type="text/javascript" src="scripts/util/menu.js"></script>
<script type="text/javascript" src="scripts/util/dialog.js"></script>
<script type="text/javascript" src="scripts/util/dom.js"></script>
<script type="text/javascript" src="scripts/util/sign.js"></script>
<script type="text/javascript" src="scripts/util/freebase.js"></script>
<script type="text/javascript" src="scripts/util/custom-suggest.js"></script>
<script type="text/javascript" src="scripts/widgets/history-widget.js"></script>
<script type="text/javascript" src="scripts/widgets/process-widget.js"></script>
<script type="text/javascript" src="scripts/widgets/histogram-widget.js"></script>
<script type="text/javascript" src="scripts/widgets/slider-widget.js"></script>
<script type="text/javascript" src="scripts/project.js"></script>
<script type="text/javascript" src="scripts/project/menu-bar.js"></script>
<script type="text/javascript" src="scripts/project/browsing-engine.js"></script>
<script type="text/javascript" src="scripts/project/scripting.js"></script>
<script type="text/javascript" src="scripts/facets/list-facet.js"></script>
<script type="text/javascript" src="scripts/facets/range-facet.js"></script>
<script type="text/javascript" src="scripts/facets/scatterplot-facet.js"></script>
<script type="text/javascript" src="scripts/facets/text-search-facet.js"></script>
<script type="text/javascript" src="scripts/views/data-table-view.js"></script>
<script type="text/javascript" src="scripts/views/data-table-cell-ui.js"></script>
<script type="text/javascript" src="scripts/views/data-table-column-header-ui.js"></script>
<script type="text/javascript" src="scripts/dialogs/recon-dialog.js"></script>
<script type="text/javascript" src="scripts/dialogs/expression-preview-dialog.js"></script>
<script type="text/javascript" src="scripts/dialogs/freebase-loading-dialog.js"></script>
<script type="text/javascript" src="scripts/dialogs/clustering-dialog.js"></script>
<script type="text/javascript" src="scripts/dialogs/scatterplot-dialog.js"></script>
<script type="text/javascript" src="scripts/dialogs/extend-data-preview-dialog.js"></script>
<script type="text/javascript" src="scripts/dialogs/templating-exporter-dialog.js"></script>
<script type="text/javascript" src="scripts/protograph/schema-alignment.js"></script>
<script type="text/javascript" src="scripts/protograph/schema-alignment-ui-node.js"></script>
<script type="text/javascript" src="scripts/protograph/schema-alignment-ui-link.js"></script>
</head>
<body>
<div id="header">
<a id="logo" href="http://www.freebase.com/" title="Freebase"><img alt="Freebase" src="images/freebase-headerlogo.png" /></a>
<div id="path"><span class="app-path-section"><a href="./index.html">Gridworks</a></span></div>
</div>
<div id="body">
<div id="loading-message"><img src="images/large-spinner.gif" /> starting up ...</div>
</div>
</body>
</html>

View File

@ -0,0 +1,29 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Freebase Gridworks</title>
<link rel="icon" type="image/png" href="images/favicon.png">
#foreach($path in $styles)
<link type="text/css" rel="stylesheet" href="$path" />
#end
#foreach($path in $scripts)
<script type="text/javascript" src="$path"></script>
#end
</head>
<body>
<div id="header">
<a id="logo" href="http://www.freebase.com/" title="Freebase"><img alt="Freebase" src="images/freebase-headerlogo.png" /></a>
<div id="path"><span class="app-path-section"><a href="./index.html">Gridworks</a></span></div>
</div>
<div id="body">
<div id="loading-message"><img src="images/large-spinner.gif" /> starting up ...</div>
</div>
</body>
</html>

View File

@ -112,7 +112,7 @@ function renderProjects(data) {
var nameLink = $('<a></a>')
.text(project.name)
.attr("href", "/project.html?project=" + project.id)
.attr("href", "/project?project=" + project.id)
.appendTo(tr.insertCell(tr.cells.length));
var renameLink = $('<a></a>')