Skip to content

Commit

Permalink
add dataset deletion functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Conal-Tuohy committed Feb 12, 2024
1 parent ce0fd9d commit 6a7b7c6
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/xproc/trove-proxy-harvester.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
<p:with-option name="harvest-name" select="$harvest-name"/>
</t:run-harvest>
</p:when>
<p:when test="$method = 'DELETE' ">
<!-- a request to delete a completed harvest -->
<p:variable name="harvest-name" select="$path => substring-after('/harvester/harvest/') => substring-before('/')"/>
<!--
<z:dump href="/tmp/run-harvest-request.xml"/>
-->
<t:delete-harvest>
<p:with-option name="harvest-name" select="$harvest-name"/>
</t:delete-harvest>
</p:when>
<p:otherwise>
<p:variable name="sub-path" select="substring-after($path, '/harvester/harvest/')"/>
<cx:message>
Expand Down Expand Up @@ -319,6 +329,37 @@
</p:group>
</p:declare-step>

<p:declare-step name="delete-harvest" type="t:delete-harvest">
<p:option name="harvest-name" required="true"/>
<p:documentation>
The input port provides the http request
</p:documentation>
<p:input port="source"/>
<p:documentation>
The output port produces a <c:response/> which redirects the client to the main "harvests" page
</p:documentation>
<p:output port="result" sequence="true"/>
<p:documentation>
Expected input:
<c:request xmlns:c="http://www.w3.org/ns/xproc-step" href="/harvester/harvest/test%20of%20harvest3/" method="DELETE"/>
</p:documentation>
<!-- find the harvest folder -->
<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)"/>
<file:delete recursive="true">
<p:with-option name="href" select="$harvest-directory"/>
</file:delete>
<p:identity>
<p:input port="source">
<p:inline>
<c:response status="303">
<c:header name="Location" value=".."/>
</c:response>
</p:inline>
</p:input>
</p:identity>
</p:declare-step>

<!-- Another pipeline, responding to an HTTP request, will launch this pipeline as a background task. -->
<!-- The output of this pipeline is not connected to a user's HTTP request; it will simply be discarded by the XProc-Z runtime. -->
<!-- The pipeline reads the harvest's "status.xml" file, executes the first command in it, and then recurses to -->
Expand Down
45 changes: 45 additions & 0 deletions src/xslt/harvester/view-harvest.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
padding: 1em;
margin-bottom: 1em;
}
button#delete {
display: inline-block;
background-color: #FF0000;
color: #FFFFFF;
padding: 0.5em 1em;
border-radius: 0.5em;
text-decoration: none;
}
a.file {
display: inline-block;
background-color: #1F9EDE;
Expand Down Expand Up @@ -126,6 +134,43 @@
);
</script>
</div>
<xsl:if test="not($harvest/*) (: the harvest is finished as it contains no child elements which represent tasks still to do :)">
<div>
<form id="deletion" action="" method="delete">
<button id="delete">Delete dataset</button>
</form>
<script xsl:expand-text="false">
var form = document.getElementById("deletion");
form.addEventListener(
"submit",
function(event) {
event.preventDefault();
if (confirm("Delete dataset?")) {
fetch(
new URL(event.currentTarget.action, document.location).href, // resolve URL relative to current page location
{
method: "DELETE",
mode: "cors", // no-cors, *cors, same-origin
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
/*headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},*/
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
//body: urlSearchParams
}
).then(
function(response) {
window.location.href= response.url;
}
);
}
}
);
</script>
</div>
</xsl:if>
<h2>Files</h2>
<!-- dataset package file, various metadata files -->
<ul class="files">
Expand Down

0 comments on commit 6a7b7c6

Please sign in to comment.