Jelajahi Sumber

Can download artifacts via context menu in PT.

Joeri Exelmans 2 tahun lalu
induk
melakukan
002a81c267
1 mengubah file dengan 39 tambahan dan 3 penghapusan
  1. 39 3
      src/main/webapp/myPlugins/dtdesign.js

+ 39 - 3
src/main/webapp/myPlugins/dtdesign.js

@@ -29,6 +29,8 @@ WHERE {
     ?type rdfs:subClassOf object_diagram:Object .
   } UNION {
     ?type rdfs:subClassOf pt:Event .
+  } UNION {
+    ?type rdfs:subClassOf pt:Artifact .
   }
   FILTER(NOT EXISTS {
     ?more_concrete_type rdfs:subClassOf ?type .
@@ -84,9 +86,24 @@ WHERE {
   getAllGraphs: `
 SELECT ?g (COUNT(*) as ?count) {GRAPH ?g {?s ?p ?o}} GROUP BY ?g
 `,
+
+  getArtifactFilename: artifactIri => `\
+PREFIX pt: <http://ua.be/sdo2l/vocabulary/formalisms/processtraces#>
+PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>
+PREFIX base: <http://ua.be/sdo2l/vocabulary/base/base#>
+
+SELECT DISTINCT ?filename ?formalismName
+WHERE {
+  <${artifactIri}> pt:hasLocation ?filename .
+  <${artifactIri}> pt:relatesTo ?pmArtifact .
+  ?pmArtifact pm:hasType ?ftgFormalism .
+  ?ftgFormalism base:hasGUID ?formalismName .
+}`,
+
 };
 
 
+
 // When rebuilding OML, all graphs will be deleted from Fuseki, except for the following (which are not sourced from OML, but inserted directly as RDF triples into Fuseki)
 GRAPHS_NOT_TO_DELETE = [
   "http://ua.be/sdo2l/description/traces",
@@ -133,6 +150,12 @@ const typeToLinkType = new Map([
       description: (element, type) => `Has port ${type}`,
     },
   ]],
+  ["processtraces#Artifact", [
+    {
+      relation: "processtraces#hasLocation",
+      description: (element, type) => `Filename ${element}`,
+    },
+  ]],
   ["pm#element", [
     {
       relation: "processtraces#relatesTo",
@@ -187,7 +210,9 @@ function executeSPARQL(query) {
   })
   .then(res => res.json())
   .then(json => {
-    console.log({query, result: json.results.bindings});
+    // console.log({query, result: json.results.bindings});
+    console.log("Query:\n"+query);
+    console.log("Result:\n",json.results.bindings);
     return json.results.bindings;
   })
 }
@@ -253,6 +278,14 @@ fetch(BACKEND+"/version")
       } else {
         createdMenuItem = menu.addItem(menuItemText, null, null, parentMenuItem);
       }
+      if ((superclasses.get(type) || []).some(t => t.endsWith("processtraces#Artifact"))) {
+        executeSPARQL(QUERIES.getArtifactFilename(element))
+        .then(results => {
+          for (const {filename, formalismName} of results) {
+            menu.addItem(`File "${filename.value}"`, null, () => (createDownloadHandler(formalismName.value))(filename.value), createdMenuItem);
+          }
+        })
+      }
       alreadyVisited.add(entry(element, type));
       if (maxRecursion <= 0) {
         return;
@@ -347,7 +380,7 @@ fetch(BACKEND+"/version")
           .then(rejectIfStatusAbove400)
         ))
         .then(() => {
-          omlStatusDiv.innerText = "Emptied Fuseki, will now upload new triples...";
+          omlStatusDiv.innerText = "Emptied Fuseki, uploading new triples...";
           omlStatusDiv.style.color = "blue";
           errWndDiv.innerText = "No error.";
 
@@ -598,6 +631,8 @@ fetch(BACKEND+"/version")
     refreshList();
 
     containerDiv.appendChild(createUploadDiv(refreshList));
+
+    return refreshList;
   }
 
   function createPTrenderCallback(startTraceIri) {
@@ -605,6 +640,7 @@ fetch(BACKEND+"/version")
       return fetch(BACKEND+"/render_pt/"+encodeURIComponent(startTraceIri))
       .then(treatResponseAsPageXml)
       .then(() => {
+        refreshDrawioModelList();
         rebuildOML();
       });
     }
@@ -648,7 +684,7 @@ fetch(BACKEND+"/version")
   };
   const noExtraStuff = () => Promise.resolve(null);
 
-  createModelList("drawio", createSavePageDiv, "Open", modelName => loadPage(modelName), extraPMstuff);
+  const refreshDrawioModelList = createModelList("drawio", createSavePageDiv, "Open", modelName => loadPage(modelName), extraPMstuff);
   createModelList("xopp", createUploadDiv("xopp", "application/x-xopp,.xopp"), "Download", createDownloadHandler("xopp"), noExtraStuff);
   createModelList("csv", createUploadDiv("csv", "text/csv,.csv"), "Download", createDownloadHandler("csv"), noExtraStuff);
   createModelList("file", createUploadDiv("file", ""), "Download", createDownloadHandler("file"), noExtraStuff);