Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<xmlproperty file="edoc/expath-pkg.xml"/>

<target name="clean">
<delete dir="edoc/build/" />
<delete dir="build" />
</target>

<target name="compile" depends="clean">
<ant dir="edoc" antfile="build.xml" />
<move file="edoc/build" tofile="build" />
</target>

<target name="docker" depends="compile">
<copy file="build/${package(abbrev)}-${package(version)}.xar" tofile="docker/wdb.xar" />
<exec executable="docker" dir="docker">
<arg value="build" />
<arg value="--tag=wdbplus" />
<arg value="." />
</exec>
</target>
<xmlproperty file="edoc/expath-pkg.xml"/>
<property name="project.version" value="${package(version)}"/>
<property name="project.app" value="wdb"/>
<property name="build.dir" value="build"/>

<target name="clean">
<delete dir="build" />
</target>

<target name="compile" depends="clean">
<ant dir="edoc" antfile="build.xml" />
<move file="edoc/build" tofile="build" />
</target>

<target name="docker" depends="compile">
<copy file="build/${package(abbrev)}-${package(version)}.xar" tofile="docker/wdb.xar" />
<exec executable="docker" dir="docker">
<arg value="build" />
<arg value="--tag=wdbplus" />
<arg value="." />
</exec>
</target>
</project>
152 changes: 34 additions & 118 deletions edoc/admin/new.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -2,131 +2,47 @@ xquery version "3.1";

module namespace wdbPN = "https://github.com/dariok/wdbplus/ProjectNew";

import module namespace config = "https://github.com/dariok/wdbplus/config" at "../modules/wdb-config.xqm";
import module namespace wdbRc = "https://github.com/dariok/wdbplus/RestCollections" at "../rest/rest-coll.xql";
import module namespace sm = "http://exist-db.org/xquery/securitymanager";
import module namespace sm = "http://exist-db.org/xquery/securitymanager";

declare namespace http = "http://expath.org/ns/http-client";
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
declare namespace meta = "https://github.com/dariok/wdbplus/wdbmeta";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace http = "http://expath.org/ns/http-client";
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
declare namespace meta = "https://github.com/dariok/wdbplus/wdbmeta";
declare namespace tei = "http://www.tei-c.org/ns/1.0";

declare function wdbPN:body ( $node as node(), $model as map(*), $pName as xs:string*, $pShort as xs:string*,
$pID as xs:string*, $pColl as xs:string*, $pDate as xs:string*, $pDesc as xs:string*, $pLic as xs:string* ) {
let $user := sm:id()

return if (not($user//sm:group = 'dba'))
$pID as xs:string*, $collection as xs:string* )
(:), $pDate as xs:string*, $pDesc as xs:string*, $pLic as xs:string*, $data as xs:string* ) to be implemented later when a UI for project MD exists :)
as element() {
if ( not(sm:id()//sm:group = 'dba') )
then <p>Diese Seite ist nur für Administratoren zugänglich!</p>
else if (0 = (string-length($pName), string-length($pID), string-length($pColl)))
else if (0 = (string-length($pName), string-length($pID), string-length($collection)))
then
<form method="POST">
<label for="pName">Projekttitel: </label><input type="text" name="pName" /><br />
<label for="pShort">Kurztitel: </label><input type="text" name="pShort" /><br />
<label for="pID">ID (xs:NCName): </label><input type="text" name="pID" /><br />
<label for="pColl">Collection: </label><input type="text" name="pColl" /><br />
<label for="pDate">Zeitraum der Texte (ISO): </label><input type="text" name="pDate" /><br />
<form id="newProjectForm">
<label for="pName">Projekttitel: </label><input type="text" id="pName" /><br />
<label for="pShort">Kurztitel: </label><input type="text" id="pShort" /><br />
<label for="pID">ID (xs:NCName): </label><input type="text" id="pID" /><br />
<label for="pColl">Collection: </label><input type="text" id="pColl" /><br />
<!-- we do not use these for now;
TODO: add later, when a UI for project MD exists () -->
<!--<label for="pDate">Zeitraum der Texte (ISO): </label><input type="text" name="pDate" /><br />
<label for="pDesc">Beschreibung der (Haupt-)Inhalte: </label><input type="text" name="pDesc" /><br />
<label for="pLic">Lizenz der (Haupt-)Inhalte: </label><input type="text" name="pLic" /><br />
<label for="pLic">Lizenz der (Haupt-)Inhalte: </label><input type="text" name="pLic" /><br />-->
<input type="submit" name="erstellen" />
</form>
else
let $collectionData :=
<data>
<name>{$pName}</name>
<id>{$pID}</id>
<collectionName>{$pColl}</collectionName>
</data>

let $targetCollection := if ( $model?ed eq '' ) then 'data' else $model?ed
, $create := wdbRc:createSubcollectionXml ($collectionData, $targetCollection)

return if ( ($create)[1]//http:response/@status = '201')
then
(: TODO: this should be done in wdbRc:createSubcollection #424 :)
let $collection-uri := $create[2]

let $textCollection := xmldb:create-collection($collection-uri, "texts")
(: create collection resources and project.xqm only if this is a main project :)
let $resources := if ( $targetCollection = 'data' )
then
let $resourcesCollection := xmldb:create-collection($collection-uri, "resources")
return (
xmldb:create-collection($collection-uri || "/resources", "blobs"),
xmldb:create-collection($collection-uri || "/resources", "css"),
xmldb:create-collection($collection-uri || "/resources", "html"),
xmldb:create-collection($collection-uri || "/resources", "images"),
xmldb:create-collection($collection-uri || "/resources", "js"),
xmldb:create-collection($collection-uri || "/resources", "xq"),

xmldb:copy-collection($config:edocBaseDB || "/admin/project-template/resources/xsl", $resourcesCollection),

sm:chmod(xs:anyURI($resourcesCollection), 'rwxrwxr-x'),
sm:chown(xs:anyURI($resourcesCollection), "wdb:wdbusers"),
for $c in xmldb:get-child-collections($resourcesCollection)
return (
sm:chmod(xs:anyURI($resourcesCollection || '/' || $c), 'rwxrwxr-x'),
sm:chown(xs:anyURI($resourcesCollection || '/' || $c), "wdb:wdbusers")
),
for $f in xmldb:get-child-resources($resourcesCollection || "/xsl")
return (
sm:chmod(xs:anyURI($resourcesCollection || "/xsl/" || $f), "rwxrwxr-x"),
sm:chown(xs:anyURI($resourcesCollection || "/xsl/" || $f), "wdb:wdbusers")
),

xmldb:copy-resource($config:edocBaseDB || "/admin/project-template", "project.xqm", $collection-uri, "project.xqm"),
sm:chown(xs:anyURI($collection-uri || "/project.xqm"), "wdb:wdbusers"),
sm:chmod(xs:anyURI($collection-uri || "/project.xqm"), "rwxrwxr-x")
)
else ()

let $metaFile := $collection-uri || "/wdbmeta.xml"
, $MD := doc($metaFile)
(: $targetCollection != 'data': sub-project; here, we use process inheritance as standard behaviour :)
, $changeProcess := if ( $targetCollection != 'data' )
then update replace $MD//meta:process[@target = 'html']
with <process xmlns="https://github.com/dariok/wdbplus/wdbmeta" target="html" />
else ()

let $chmod := (
sm:chmod(xs:anyURI($collection-uri), 'rwxrwxr-x'),
sm:chmod(xs:anyURI($textCollection), 'rwxrwxr-x'),
sm:chmod(xs:anyURI($metaFile), 'rw-rw-r--'),
sm:chown(xs:anyURI($collection-uri), "wdb:wdbusers"),
sm:chown(xs:anyURI($textCollection), "wdb:wdbusers"),
sm:chown(xs:anyURI($metaFile), "wdb:wdbusers")
)

let $addMD := (
if ($pShort != "")
then
update insert <title type="sub" xmlns="https://github.com/dariok/wdbplus/wdbmeta"
>{$pShort}</title> into $MD//meta:titleData
else (),
if ($pDate != "")
then
update insert <date xmlns="https://github.com/dariok/wdbplus/wdbmeta"
>{$pDate}</date> into $MD//meta:titleData
else (),
if ($pLic != "")
then
update insert <licence xmlns="https://github.com/dariok/wdbplus/wdbmeta"
>{$pLic}</licence> into $MD//meta:legal
else ()
)

return
<dl>
<dd>Collection</dd>
<dt>{$create[2]}</dt>
<dd>wdbmeta.xml:</dd>
<dt>{$metaFile}</dt>
<dd>Admin</dd>
<dt>
<ul>
<li><a href="directoryForm.html?ed={$pID}">Upload</a></li>
<li><a href="new.html?ed={$pID}">Unterprojekt erstellen</a></li>
</ul>
</dt>
</dl>
else $create
<dl>
<dd>Collection</dd>
<dt>{ $collection }</dt>
<dd>Name</dd>
<dt>{ $pName }</dt>
<dd>Short title</dd>
<dt>{ $pShort }</dt>
<dd>Admin</dd>
<dt>
<ul>
<li><a href="directoryForm.html?ed={$pID}">Upload</a></li>
<li><a href="new.html?ed={$pID}">Unterprojekt erstellen</a></li>
</ul>
</dt>
</dl>
};
6 changes: 4 additions & 2 deletions edoc/admin/project-template/wdbmeta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<projectMD xmlns="https://github.com/dariok/wdbplus/wdbmeta">
<projectID></projectID>
<titleData>
<title></title>
<title type="main"></title>

<!-- add child elements to describe persons or organizations involved in the creation of a project -->
<!-- <involvement></involvement> -->
Expand Down Expand Up @@ -40,5 +40,7 @@
<command type="xsl">resources/xsl/tei-transcript.xsl</command>
</process>
</processes>
<struct></struct>
<struct>
<import path="../wdbmeta.xml" />
</struct>
</projectMD>
3 changes: 2 additions & 1 deletion edoc/modules/function.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function wdbfp:start ( $node as node(), $model as map(*), $id as xs:string?, $ed
util:log("error", "project not found: " || $err:value?ed || " from request " || $err:value?request),
wdbErr:error(map{
"code": $err:code,
"err:description": "project not found",
"description": "project not found",
"err:description": $err:description,
"err:additional": $err:additional
})
} catch * {
Expand Down
4 changes: 3 additions & 1 deletion edoc/post-install.xql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let $indexConfig := (
xmldb:store("/db/system/config/db/apps/edoc/annotations", "collection.xconf", doc($targetCollection || "/config/edoc/annotations/collection.xconf")),
xmldb:store("/db/system/config/db/apps/edoc/data", "collection.xconf", doc($targetCollection || "/config/edoc/data/collection.xconf")),
xmldb:store("/db/system/config/db/apps/edoc/rest", "collection.xconf", doc($targetCollection || "/config/edoc/rest/collection.xconf")),
xmldb:store("/db/system/config/db/apps/edoc/data7documentation", "collection.xconf", doc($targetCollection || "/config/edoc/data/documentation/collection.xconf"))
xmldb:store("/db/system/config/db/apps/edoc/data/documentation", "collection.xconf", doc($targetCollection || "/config/edoc/data/documentation/collection.xconf"))
)

let $collsr := (
Expand All @@ -38,6 +38,8 @@ let $chmod := (
return sm:chmod(xs:anyURI($targetCollection || '/modules/' || $xql), 'r-xr-xr-x'),
for $global in xmldb:get-child-resources($targetCollection || '/global')
return sm:chmod(xs:anyURI($targetCollection || '/global/' || $global), 'rw-rw-r--'),
for $global in xmldb:get-child-resources($targetCollection || '/logs')
return sm:chmod(xs:anyURI($targetCollection || '/logs/' || $global), 'rw-rw-rw-'),
sm:chmod(xs:anyURI($targetCollection || '/config.xml'), 'rw-rw-r--'),
sm:chmod(xs:anyURI($targetCollection || '/controller.xql'), 'r-xr-xr-x'),
sm:chmod(xs:anyURI($targetCollection || '/data/wdbmeta.xml'), 'rw-rw-r--'),
Expand Down
29 changes: 29 additions & 0 deletions edoc/resources/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,35 @@ $(document).on("change", "select[name=target]", () => {
wdbAdmin.setFiles($('#picker')[0].files);
});

$(document).on("submit", "#newProjectForm", ( event ) => {
event.preventDefault();
/* TODO adjust for RESTv2 meta */
let rest = window.location.pathname.substring(0, window.location.pathname.indexOf('admin')) + "api/v2/"
, baseUrl = rest + "projects/" + wdb.meta.ed + "/subprojects/"
, newCollectionData = { "title": $('#pName').val(), "short": $('#pShort').val(), "collection": $('#pColl').val() }
, method = $('#pID').val() == '' ? "post" : "put";

$.ajax({
method: method,
url: baseUrl + $('#pID').val(),
contentType: "application/json",
data: JSON.stringify(newCollectionData),
success: function ( data ) {
let url = new URL(window.location.href);
url.searchParams.delete("ed");
url.searchParams.append("pName", $('#pName').val()?.toString() ?? 'unknown');
url.searchParams.append("pShort", $('#pShort').val()?.toString() ?? 'unknown');
url.searchParams.append("pID", $('#pID').val()?.toString() ?? 'unknown');
url.searchParams.append("collection", data);
url.searchParams.append("ed", $('#pID').val()?.toString() ?? 'unknown');
window.location.href = url.toString();
},
error: function ( data ) {
$('#container').html("<p>" + data.responseText + "</p>");
}
});
});

// limit the number of concurrent PUT/POST requests to avoid lockups in eXist
let uploadManager = (function() {
const MAX_REQUESTS = 1; // local test: produces Jetty errors (“blocking message ...”) for 2 or more...
Expand Down
16 changes: 10 additions & 6 deletions edoc/resources/js/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,26 @@ const wdb = (function() {
};

/* Login and logout */
/* TODO: this needs to be reworked completely */
let login = function ( event, reload ) {
event.preventDefault();

let username = $('#user').val()
, password = $('#password').val();
wdb.report("info", "login request");
Cookies.remove('wdbplus');

let formdata = new FormData();
formdata.append("user", username);
formdata.append("password", password);

$.ajax({
url: 'login',
url: '../api/v2/login',
method: 'post',
data: {
user: username,
password: password,
edition: $('#edition').val()
},
data: formdata,
processData: false,
contentType: false,
cache: false,
success: function (data) {
try {
Cookies.set('wdbplus', btoa(username + ':' + password));
Expand Down
2 changes: 1 addition & 1 deletion edoc/resources/start.xsl → edoc/resources/xsl/start.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<p class="cite">
<xsl:text>Diese Seite zitieren: </xsl:text>
<a href="start.html?{.}">
<xsl:value-of select="doc('../config.xml')//config:server"/>
<xsl:value-of select="doc('../../config.xml')//config:server"/>
<xsl:text>/start.html?ed=</xsl:text>
<xsl:value-of select="."/>
</a>
Expand Down
2 changes: 0 additions & 2 deletions edoc/rest/rest-coll.xql
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ function wdbRc:createSubcollection ( $collectionData as map(*), $collectionID as
let $insID := update insert attribute xml:id { $collectionData?id } into $meta/meta:projectMD
let $insTitle := update replace $meta//meta:title[1] with <title xmlns="https://github.com/dariok/wdbplus/wdbmeta"
type="main">{ $collectionData?name }</title>
let $insParent := update insert <import xmlns="https://github.com/dariok/wdbplus/wdbmeta"
path="../wdbmeta.xml" /> into $meta/meta:projectMD/meta:struct

let $insPtr := update insert <ptr xmlns="https://github.com/dariok/wdbplus/wdbmeta"
path="{$collectionData?collectionName}/wdbmeta.xml" xml:id="{$collectionData?id}"
Expand Down
Loading