From 32395cbac293b985c09625ca88e4b1001f57f046 Mon Sep 17 00:00:00 2001 From: "Stephen V. Williams" Date: Wed, 15 May 2013 14:53:31 -0600 Subject: [PATCH] Fixed controller for CSV output, added button and coorsponding js and png --- .../controller/PagedSearchController.java | 7 ++- webapp/web/css/search.css | 17 ++++++- webapp/web/images/download-icon.png | Bin 0 -> 1404 bytes webapp/web/js/searchDownload.js | 44 ++++++++++++++++++ .../body/search/search-csvResults.ftl | 8 ++-- .../body/search/search-pagedResults.ftl | 23 ++++++--- 6 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 webapp/web/images/download-icon.png create mode 100644 webapp/web/js/searchDownload.js diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java index 510cb2532..b74979164 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java @@ -105,12 +105,13 @@ public class PagedSearchController extends FreemarkerHttpServlet { boolean wasCSVRequested = isRequestedFormatCSV(vreq); if( !wasXmlRequested && !wasCSVRequested){ super.doGet(vreq,response); - }else if (wasXMLRequested){ + }else if (wasXmlRequested){ try { ResponseValues rvalues = processRequest(vreq); response.setCharacterEncoding("UTF-8"); response.setContentType("text/xml;charset=UTF-8"); + response.setHeader("Content-Disposition", "attachment; filename=search.xml"); writeTemplate(rvalues.getTemplateName(), rvalues.getMap(), request, response); } catch (Exception e) { log.error(e, e); @@ -121,6 +122,7 @@ public class PagedSearchController extends FreemarkerHttpServlet { response.setCharacterEncoding("UTF-8"); response.setContentType("text/csv;charset=UTF-8"); + response.setHeader("Content-Disposition", "attachment; filename=search.csv"); writeTemplate(rvalues.getTemplateName(), rvalues.getMap(), request, response); } catch (Exception e) { log.error(e, e); @@ -134,8 +136,9 @@ public class PagedSearchController extends FreemarkerHttpServlet { //There may be other non-html formats in the future Format format = getFormat(vreq); boolean wasXmlRequested = Format.XML == format; + boolean wasCSVRequested = Format.CSV == format; log.debug("Requested format was " + (wasXmlRequested ? "xml" : "html")); - boolean wasHtmlRequested = ! wasXmlRequested; + boolean wasHtmlRequested = ! (wasXmlRequested || wasCSVRequested); try { diff --git a/webapp/web/css/search.css b/webapp/web/css/search.css index 35b6857eb..b3717888a 100644 --- a/webapp/web/css/search.css +++ b/webapp/web/css/search.css @@ -79,7 +79,22 @@ ul.searchTips li { } span#searchHelp { float:right; - margin-top:-45px; + margin-top:10px; font-size:.825em; padding-right:32px +} + +span#downloadResults { + float:left; + margin-top:10px; + font-size:.825em; + padding-left:10px +} + +img#downloadIcon { + cursor: pointer; +} + +.download-url { + padding: 5px 25px 5px; } \ No newline at end of file diff --git a/webapp/web/images/download-icon.png b/webapp/web/images/download-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..dd32132040b2d306b8b81ead5ef6f1ac2e68f0d7 GIT binary patch literal 1404 zcmV-?1%vvDP)WFU8GbZ8()Nlj27Z*CxAAWdOomE>Pr000EnNkl7$GgiSSYRkZ;nEBVrlx~ZHsLtb2y&S{SQskpU_1& zWmk@q<1|xRlRrSE6huNG+C|abl~{iH0}TRp_dTbJT^3egcP)Ev-g(b?-sgLs=X{?Z zudvoya)@gTf$#{yNR&`?g2?FIjQ!`2fcRBfGb4q^Z7+)vJ7HC6Q9*58M?DbL3Q8`rYej=HdxHey52St1Fp{#R2d* zn*Pu*Uw+q`)|r=sO${_`s>Y)=N@arUM*)qs96xu3ww~+Dhuw9F#bU(caS#H5C6REK z)ji&Fg-~>ycbgjUd7KPz{V3?yKeTb}Mr6e>3ItkfEXlib9F5j$Mg6P6Fw-+J4()Hm zD>Nz<_6+||w033%1rUNXX|j=Lu>>MfPPBC5x(1WF*)(w1K!gk319_2WF)i{)3IIC( zxW(0AIIS<|*?Z*VMgEQCgOQP}C!C8V^Kw2v;|Uib1lHOlptZzO zdy`W$d4)U>89@ib(X2}EHSOfV^bA4>V(|o(YfBMAq*F);!L!el&{SVXfycpE%hSb$ z96QsoqRn6=ijIuk%?e!Lad>r04aT@ArBF&?txe~nv6iyZ)x6cX9b*ha2(AqdWwkjp zb{|!md3xzsm^*Q4`dw)C$r%c+!b z4Nn#MIDO@Jej5m3j7ipAW58POJ)9ymJeG`5+|6mPx?(M|YF%kwCww?P3qWW8O@=4# zqf!&boyosAcD93#Kp2ms(@h|oRIMvP*7+;)ZVXyUf~J%myuByg0v`>zl9F4)<6P{yPG>Mgd;cu}re|YIm=5sKf!Fx_ z!vh(6b^Z#ZR+7E1Y)LQryagynqNTvv1p|u*KY-3ah@)pZ7`^v!+4ea9UR+d|kzV_D zZAB}YoIu{#v5BAC`_g59m9K#E($$PlPNgc8O{Gq9-&(M#HGxP)CixVpP)Q+hl%m*I zfNK^G)l^@%F#7ns9zJMpkT~HMp)#=dY3i zB?VGQloBYR5K>^QrD9D9KCk9dU-CK*H8kTmas{@=)<=EjWh{_npq`*v-m zslF~vq{jwc^3xWM5+1!vcw{1D-@m>LfB70}{T0-1SdUh@d(S^^z(cxK9hXu70000< KMNUMnLSTZ7){oZ! literal 0 HcmV?d00001 diff --git a/webapp/web/js/searchDownload.js b/webapp/web/js/searchDownload.js new file mode 100644 index 000000000..7d9da55a8 --- /dev/null +++ b/webapp/web/js/searchDownload.js @@ -0,0 +1,44 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +$(document).ready(function(){ + // This function creates and styles the "qTip" tooltip that displays the resource uri and the rdf link when the user clicks the uri/rdf icon. + $('span#downloadResults').children('img#downloadIcon').each(function() + { + $(this).qtip( + { + content: { + prerender: true, // We need this for the .click() event listener on 'a.close' + text: '
Download the results from this search
download results in XML format
download results in CSV format

close' + }, + position: { + corner: { + target: 'bottomLeft', + tooltip: 'topLeft' + } + }, + show: { + when: {event: 'click'} + }, + hide: { + fixed: true, // Make it fixed so it can be hovered over and interacted with + when: { + target: $('a.close'), + event: 'click' + } + }, + style: { + padding: '1em', + width: 350, + backgroundColor: '#f1f2ee' + } + }); + }); + + + + // Prevent close link for URI qTip from requesting bogus '#' href + $('a.close').click(function() { + $('#downloadIcon').qtip("hide"); + return false; + }); +}); \ No newline at end of file diff --git a/webapp/web/templates/freemarker/body/search/search-csvResults.ftl b/webapp/web/templates/freemarker/body/search/search-csvResults.ftl index 8cd910e05..0656e8e6a 100644 --- a/webapp/web/templates/freemarker/body/search/search-csvResults.ftl +++ b/webapp/web/templates/freemarker/body/search/search-csvResults.ftl @@ -1,5 +1,5 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> -URI,Name - <#list individuals as individual> - ${individual.uri?xml},${individual.name?xml} - +URI, Name +<#list individuals as individual> +"${individual.uri}","${individual.name}" + diff --git a/webapp/web/templates/freemarker/body/search/search-pagedResults.ftl b/webapp/web/templates/freemarker/body/search/search-pagedResults.ftl index e5e14dc95..5d96408bd 100644 --- a/webapp/web/templates/freemarker/body/search/search-pagedResults.ftl +++ b/webapp/web/templates/freemarker/body/search/search-pagedResults.ftl @@ -2,21 +2,27 @@ <#-- Template for displaying paged search results --> -

+ + +

<#escape x as x?html> Search results for '${querytext}' <#if classGroupName?has_content>limited to type '${classGroupName}' <#if typeName?has_content>limited to type '${typeName}' - - XML/RDF Results - - +

+ + Download Results + + Not the results you expected? -
+
<#-- Refinement links --> <#if classGroupLinks?has_content> @@ -100,3 +106,8 @@
${stylesheets.add('')} + +${headScripts.add('', + '')} + +${scripts.add('')}