Skip to content

Commit

Permalink
revise display, replace URL clipboard with popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Conal-Tuohy committed Feb 19, 2024
1 parent 3223912 commit f669740
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 42 deletions.
4 changes: 3 additions & 1 deletion src/xproc/trove-proxy-harvester.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<p:variable name="harvest-name" select="substring-after($path, '/harvester/harvest/')"/>
<t:view-harvest>
<p:with-option name="harvest-name" select="$harvest-name"/>
<p:with-option name="request-uri" select="/c:request/@href"/>
</t:view-harvest>
</p:when>
<p:otherwise>
Expand Down Expand Up @@ -155,6 +156,7 @@
<p:declare-step name="view-harvest" type="t:view-harvest">
<p:output port="result"/>
<p:option name="harvest-name" required="true"/>
<p:option name="request-uri" required="true"/>
<p:variable name="harvests-directory" select="p:system-property('init-parameters:harvester.harvest-directory')"/>
<p:variable name="harvest-directory" select="concat($harvests-directory, $harvest-name)"/>
<p:try>
Expand Down Expand Up @@ -183,7 +185,7 @@
</p:catch>
</p:try>
<p:xslt>
<p:input port="parameters"><p:empty/></p:input>
<p:with-param name="request-uri" select="$request-uri"/>
<p:input port="stylesheet"><p:document href="../xslt/harvester/view-harvest.xsl"/></p:input>
</p:xslt>
</p:declare-step>
Expand Down
115 changes: 74 additions & 41 deletions src/xslt/harvester/view-harvest.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
>
<xsl:param name="if-modified-since"/>
<xsl:param name="name"/>
<xsl:param name="request-uri"/>

<xsl:variable name="files" select="/c:directory/c:file"/>
<xsl:variable name="ro-crate-metadata" select="$files[@name='ro-crate-metadata.json']"/>
Expand Down Expand Up @@ -53,6 +54,11 @@
</xsl:if>
<title>{@name}</title>
<style xsl:expand-text="false">
h2 {
margin-top: 1.5em;
font-weight: normal;
font-size: large;
}
ul.files {
display: flex;
flex-wrap: wrap;
Expand All @@ -62,6 +68,39 @@
align-items: start;
justify-content: start;
}
details {
display: block;
}
details summary {
display: block;
list-style: none;
}
details summary span {
background-color: #FFFF00;
color: #000000;
margin: 0.5em;
font-size: 1em;
display: inline-block;
padding: 0.5em 1em;
border-radius: 0.5em;
text-decoration: none;
border-width: 0;
font-weight: bold;
cursor: pointer;
}
details summary span.hide {
display: none;
}
details[open] summary span.hide {
display: inline;
}
details[open] summary span.show {
display: none;
}
details textarea {
margin: 0.5em;
height:
}
ul.files li {
display: block;
padding: 0.5em;
Expand All @@ -88,13 +127,10 @@
border-width: 0;
font-weight: bold;
}
button#copy {
background-color: #FFFF00;
color: #000000;
}
button#delete {
background-color: #FF0000;
color: #FFFFFF;
cursor: pointer;
}
a.file {
font-weight: bold;
Expand Down Expand Up @@ -152,31 +188,14 @@
}
);
</script>
<xsl:if test="$data">
<button id="copy">Copy URLs of dataset data files</button>
<script xsl:expand-text="false">
async function copyDataURLsToClipboard() {
const type = "text/plain";
var text = Array.from(document.querySelectorAll("a.data.file")).join("\n");
const blob = new Blob([text], { type });
const data = [new ClipboardItem({ [type]: blob })];
await navigator.clipboard.write(data);
}
var copyButton = document.getElementById("copy");
copyButton.addEventListener(
"click",
copyDataURLsToClipboard
);
</script>
</xsl:if>
<xsl:if test="not($harvest/*) (: the harvest is finished as it contains no child elements which represent tasks still to do :)">
<button id="delete">Delete dataset</button>
<script xsl:expand-text="false">
var deleteButton = document.getElementById("delete");
deleteButton.addEventListener(
"click",
function(event) {
if (confirm("Delete dataset?")) {
if (confirm("Are you sure you want to delete the harvested dataset?")) {
fetch(
document.location,
{
Expand All @@ -202,20 +221,43 @@
</script>
</xsl:if>
</div>
<h2>Files</h2>
<!-- dataset package file, various metadata files -->
<!-- dataset package file -->
<xsl:for-each select="$zip">
<h2>ro-crate package of entire dataset</h2>
<p><a href="{@name}" class="file">{@name}</a></p>
</xsl:for-each>
<!-- various metadata files -->
<h2>metadata files</h2>
<ul class="files">
<xsl:for-each select="($zip, $error, $ro-crate-metadata, $status)">
<xsl:for-each select="($error, $ro-crate-metadata, $status)">
<li><a href="{@name}" class="file">{@name}</a></li>
</xsl:for-each>
</ul>
<!-- individual dataset files -->
<ul class="files">
<xsl:for-each select="$data">
<xsl:sort select="@name"/>
<li><a href="{@name}" class="data file">{@name}</a></li>
</xsl:for-each>
</ul>
<xsl:if test="$data">
<h2>harvested data files</h2>
<details>
<summary><span class="show">Show dataset URLs</span><span class="hide">Hide dataset URLs</span> </summary>
<div>
<xsl:variable name="rows" select="count($data)"/>
<xsl:variable name="cols" select="string-length($request-uri) + max($data/@name/string-length())"/>
<textarea id="urls" rows="{$rows}" cols="{$cols}" style="width: {$cols}em; height: {1 + $rows}em;"><xsl:for-each select="$data">
<xsl:sort select="@name"/>
<xsl:if test="position() != 1"><xsl:value-of select="codepoints-to-string(10)"/></xsl:if>
<xsl:value-of select="$request-uri || @name"/>
</xsl:for-each></textarea>
<script>
document.getElementById("urls").select();
</script>
</div>
</details>
<!-- individual dataset files -->
<ul class="files">
<xsl:for-each select="$data">
<xsl:sort select="@name"/>
<li><a href="{@name}" class="data file">{@name}</a></li>
</xsl:for-each>
</ul>
</xsl:if>
</body>
</html>
</c:body>
Expand All @@ -224,15 +266,6 @@
</xsl:choose>
</xsl:template>

<xsl:template match="c:file">
<li><a href="{@name}" class="data file" title="{
if (ends-with(@name, '.zip')) then 'entire dataset contained in a zip file' else
if (@name = 'ro-crate-metadata.json') then 'ro-crate metadata file' else
if (@name = 'status.xml') then 'XML file describing the harvest status' else
'harvested data file'
}">{@name}</a></li>
</xsl:template>

<xsl:template match="c:response">
<h2>Error</h2>
<p>{.}</p>
Expand Down

0 comments on commit f669740

Please sign in to comment.