From f7fe44dccc8c35f91b9685da16f6e83b9a61645c Mon Sep 17 00:00:00 2001 From: David Huynh Date: Tue, 15 Jun 2010 00:35:23 +0000 Subject: [PATCH] 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 --- .../jython/module/MOD-INF/controller.js | 2 +- main/.classpath | 2 +- .../gridworks/ClientSideResourceManager.java | 67 +++++++++ ...es.jar => butterfly-trunk-r21-sources.jar} | Bin 33850 -> 33857 bytes ...-trunk-r20.jar => butterfly-trunk-r21.jar} | Bin 62007 -> 62017 bytes main/webapp/WEB-INF/modules.properties | 1 - .../webapp/modules/core/MOD-INF/controller.js | 131 ++++++++++++++++++ .../modules/core/MOD-INF/module.properties | 3 +- main/webapp/modules/core/macros.vm | 0 main/webapp/modules/core/project.html | 100 ------------- main/webapp/modules/core/project.vt | 29 ++++ main/webapp/modules/core/scripts/index.js | 2 +- 12 files changed, 232 insertions(+), 105 deletions(-) create mode 100644 main/src/com/metaweb/gridworks/ClientSideResourceManager.java rename main/webapp/WEB-INF/lib-src/{butterfly-trunk-r20-sources.jar => butterfly-trunk-r21-sources.jar} (93%) rename main/webapp/WEB-INF/lib/{butterfly-trunk-r20.jar => butterfly-trunk-r21.jar} (95%) create mode 100644 main/webapp/modules/core/MOD-INF/controller.js create mode 100644 main/webapp/modules/core/macros.vm delete mode 100644 main/webapp/modules/core/project.html create mode 100644 main/webapp/modules/core/project.vt diff --git a/extensions/jython/module/MOD-INF/controller.js b/extensions/jython/module/MOD-INF/controller.js index ef26fbaa9..6c4c6de08 100644 --- a/extensions/jython/module/MOD-INF/controller.js +++ b/extensions/jython/module/MOD-INF/controller.js @@ -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", diff --git a/main/.classpath b/main/.classpath index ab04d6c81..067c64ff7 100644 --- a/main/.classpath +++ b/main/.classpath @@ -37,7 +37,7 @@ - + diff --git a/main/src/com/metaweb/gridworks/ClientSideResourceManager.java b/main/src/com/metaweb/gridworks/ClientSideResourceManager.java new file mode 100644 index 000000000..39001c316 --- /dev/null +++ b/main/src/com/metaweb/gridworks/ClientSideResourceManager.java @@ -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 _pathSet = new HashSet(); + final protected List _pathList = new ArrayList(); + } + + final static protected Map s_bundles + = new HashMap(); + + 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(); + } +} diff --git a/main/webapp/WEB-INF/lib-src/butterfly-trunk-r20-sources.jar b/main/webapp/WEB-INF/lib-src/butterfly-trunk-r21-sources.jar similarity index 93% rename from main/webapp/WEB-INF/lib-src/butterfly-trunk-r20-sources.jar rename to main/webapp/WEB-INF/lib-src/butterfly-trunk-r21-sources.jar index b027d44dcf679bfab946bbbbffb7c8f4b05bb498..ba34464a9b8f93a6e386355af94862944a14d547 100644 GIT binary patch delta 1485 zcmV;;1v2`&hyuZg0t`?~0|W{H00000JcyADDFQo)u{R%95p;*nJh%<5N$dmw0MiZt z04$S10UVRSe+iR}RtK`ryi=Bx{G|zu+e66I#Z+7y6*^OUC z{aNL=xJ2=i{k?y&sleA;{xW^Qq|3yJ+37=ktLAgmdl!CU31!8l?C9`t0Eh5-!3`vW z83P(~jRvJPU>68Olc*erpl0-wSs=SPU!nx7fI-6w5=x6!LZEhlOs4(|-06n?pOJ)hrGD{dUE|~zKyLsbYpP-n!p#8q@Iu|Uy5r;Z-4AV` zs!Loe8I^w_{7lV8?J1bcv>R7$*N~xIsI=^*-xgddSB@o5(bQl~1C#_VeYE`vjjE(g z>YZ&q8GFPq59NU`OuM=BzL3_w7HFKl zgH*OQ2=Wue?ytXr>A9hnf7(oTOhlav_+oZ^yo6|n?Woe1nA#@ziCpZv8@iT@v8U1+ zuU#%jy`nwZ#q$)|D(Q}?rFAEJnd5HoeASDJsfXMM9KE`r$@)((`NLV!-B407xz|kIUo1@ zUy)YkbavBRIUTrcVSQ*VM7yfs(zbm(!ut+nykw$q0HZP@&+PdEww!Gm&7m9PMXP^s z-J8Z0G+ovWqp|c+{D;vENo=1-jgN2-B3FBkqK>>pQ$-glW|~c;f0cNdQEggXqMr+s z6UkPnF)#PDE3{hBeH|hmld659%=VJM7abA;=cF`lO9SVg9VcqyvKzjPTGn;PrZ_F; z(J<^xL+s^zHCyY3?ReYIuvLM}R`Y-L?e@!N-}RPKx~K87MVgjp`o z9mUKIdbe9|x@-M1_>l`ZAc;Q>TMx}u`k+Iz)>pTo($Z=1PTBE00;oXhQqUnTLB>g zJcyHvd^rL;h_l9ghy)FEht52>4XsJ+1ONcjlUspn0)ktUK{_Op?14W5*`jWkbx6_rB+>U+cp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(EHO)r6&10Wq^fKZmE#A zj@#1m+ZyXYp9C;)EzTP_gb&a&1F@WScdU^rHsKax<#LgXU7RuSIBX3+HSjY$A#h-g zj2M5)=G_8OPPzGEYszxuHM0Ue8_8G$KgW{>p2E`xp25>B-^*(QO=RE~_@#kg;aP#u zc%Ah*Ja1qKtnTgo>ubdn8;C8f2AvmYx(vL4U(+cDeuFs;^9HV9fgUpOB3?4^Tf8jL z*=!IRcm=Q0w*m(@9xMi4!|w#PW~>QzgiL=dEd!zKjkB-~{2osj_yb;TFi|-u7%EjR zTQ#|KRpI^>3JbJ0T8WunldezIa}9qq@F)D4o^P_-tQ{lEwPb+SrLUE0W=TUOpyVqv zuz`r_EwK0hmvVu9>q^Cj$D}Lg+m_|+pAF6{m}#kA=PI>nMHiFF*uHLqkyMegzf^y+ z3mjgPXKB-^U#HjOmthUeEZP$W%M+5Vc_kecRERKJw@MU?wO}-D*qOlv)+I%ZTPA%=rjS`nzyIyT9 zOuq)0awIX%GuC*Cb)=1iL(88EJD2ChaWhR(`8o@cyqYQ zMgs4J!28tdAg+-eigQ2ruEk;QeGr^-9pr94J`eFcTH1Ww3-AjpAmGDG2;P6%GY@UF zcN_F82*rEn5RQvEM0_v9Ncwx?SFkDSpF`_w(362^pnDFRqk;Gww#3`E#-o9Gw8eXR zyXUb@LT_IJ{hX5OLmZQ6pfgZm8JgW29ua zE8C^zGWRy|oK)o-ZsQGQ&eJu{+sRp`{}k!(Aiag)f6<}gjD~1C-$d+f?9gCp80T`4 zjE07^hKvS2111zzyib`CovL zROmSZ!)3FN===o@(1^o4OlB)pV+Q~L)RUO*Yy$qIlkw^#lPd2$0zRyh@#-X#jqgAL ziLaCK>Kl{l??M8TvXk-Z8Kl_f;1rW9 M@(>0*=l}o!03CN0ApigX diff --git a/main/webapp/WEB-INF/modules.properties b/main/webapp/WEB-INF/modules.properties index 8b06ff19a..1b05a14bb 100644 --- a/main/webapp/WEB-INF/modules.properties +++ b/main/webapp/WEB-INF/modules.properties @@ -3,6 +3,5 @@ # core = / -core.scripting-jython = jython jython = /extensions/jython/ diff --git a/main/webapp/modules/core/MOD-INF/controller.js b/main/webapp/modules/core/MOD-INF/controller.js new file mode 100644 index 000000000..b6f876bfa --- /dev/null +++ b/main/webapp/modules/core/MOD-INF/controller.js @@ -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); +} diff --git a/main/webapp/modules/core/MOD-INF/module.properties b/main/webapp/modules/core/MOD-INF/module.properties index 9fe6eaa69..18cd4f845 100644 --- a/main/webapp/modules/core/MOD-INF/module.properties +++ b/main/webapp/modules/core/MOD-INF/module.properties @@ -1,3 +1,4 @@ description = Gridworks Core Module -templating = false +templating.macros = macros.vm + diff --git a/main/webapp/modules/core/macros.vm b/main/webapp/modules/core/macros.vm new file mode 100644 index 000000000..e69de29bb diff --git a/main/webapp/modules/core/project.html b/main/webapp/modules/core/project.html deleted file mode 100644 index 86aa86ca3..000000000 --- a/main/webapp/modules/core/project.html +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - Freebase Gridworks - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
starting up ...
-
- - diff --git a/main/webapp/modules/core/project.vt b/main/webapp/modules/core/project.vt new file mode 100644 index 000000000..9a83d2462 --- /dev/null +++ b/main/webapp/modules/core/project.vt @@ -0,0 +1,29 @@ + + + + + + Freebase Gridworks + + + + +#foreach($path in $styles) + +#end +#foreach($path in $scripts) + +#end + + + + + +
+
starting up ...
+
+ + diff --git a/main/webapp/modules/core/scripts/index.js b/main/webapp/modules/core/scripts/index.js index 9e134eec5..3c7dd9f33 100644 --- a/main/webapp/modules/core/scripts/index.js +++ b/main/webapp/modules/core/scripts/index.js @@ -112,7 +112,7 @@ function renderProjects(data) { var nameLink = $('') .text(project.name) - .attr("href", "/project.html?project=" + project.id) + .attr("href", "/project?project=" + project.id) .appendTo(tr.insertCell(tr.cells.length)); var renameLink = $('')