浏览代码

DTDesign plugin: Show ongoing/finished enactments of PMs

Joeri Exelmans 2 年之前
父节点
当前提交
9b411fef8b
共有 2 个文件被更改,包括 75 次插入16 次删除
  1. 20 4
      flake.nix
  2. 55 12
      src/main/webapp/myPlugins/dtdesign.js

+ 20 - 4
flake.nix

@@ -20,9 +20,7 @@
           '';
         };
         # Absolute minimal web server serving 'webRoot'
-        staticServer = pkgs.stdenv.mkDerivation rec {
-          name = "drawio-msdl-staticserver";
-          src = ./src/main/webapp;
+        staticServer = let
           lighttpConfig = pkgs.writeTextFile {
             name = "lighttpd.conf";
             text = ''
@@ -43,8 +41,13 @@
               )
             '';
           };
-          script = pkgs.writeShellScript "drawio-msdl-staticserver.sh" ''            exec ${pkgs.lighttpd}/bin/lighttpd -f ${lighttpConfig} -D
+          script = pkgs.writeShellScript "drawio-msdl-staticserver.sh" ''
+            exec ${pkgs.lighttpd}/bin/lighttpd -f ${lighttpConfig} -D
           '';
+        in pkgs.stdenv.mkDerivation {
+          name = "drawio-msdl-staticserver";
+          src = ./src/main/webapp;
+          buildInputs = [ pkgs.lighttpd ];
           installPhase = ''
             mkdir -p $out/bin
             ln -s ${script} $out/bin/drawio-msdl-staticserver
@@ -52,5 +55,18 @@
         };
       };
       defaultPackage = packages.webRoot;
+
+      apps = rec {
+        # App that starts when invoking `nix run .#serviceMonitor`
+        staticServer = {
+          type = "app";
+          program = "${self.packages.${system}.staticServer}/bin/drawio-msdl-staticserver";
+        };
+
+        # App that starts when invoking `nix run .`
+        default = staticServer;
+      };
     });
+
+  nixConfig.bash-prompt-prefix = "\\e\[94;1m[drawio]\\e\[m ";
 }

+ 55 - 12
src/main/webapp/myPlugins/dtdesign.js

@@ -1,11 +1,17 @@
+Draw.loadPlugin(function(ui) {
+
+const WEE = "http://localhost:8081";
+
 const BACKEND = "http://localhost:5000";
 const EXPECTED_BACKEND_VERSION = 3; // expected backend version
+
 const SPARQL_SERVER   = "http://localhost:3030"
 const SPARQL_ENDPOINT = "/SystemDesignOntology2Layers/sparql"
 
 const dropVocabularyPrefix = str => str.substring(41);
 const dropDescriptionPrefix = str => str.substring(30);
 const dropArtifactPrefix = str => str.substring(41);
+const addArtifactPrefix = str => "http://ua.be/sdo2l/description/artifacts/" + str;
 
 const QUERIES = {
   // Query that navigates the given link from the given source element, and returns the IRI and most-concrete-type of the target element.
@@ -83,10 +89,10 @@ const typeToLinkType = new Map([
       description: (element, type) => `Is rendered as ${type}`,
     },
     // Outcommented, because it's not an interesting relation:
-    // {
-    //   relation: "object_diagram#inModel",
-    //   description: (element, type) => `Is part of model ${type}`,
-    // },
+    {
+      relation: "object_diagram#inModel",
+      description: (element, type) => `Is part of model ${type}`,
+    },
     {
       relation: "traceability_model#traceLinkTo",
       description: (element, type) => `Trace-link (outgoing) ${element}`,
@@ -178,8 +184,6 @@ const defaultSettings = {
   dialogHeight: 400,
 };
 
-Draw.loadPlugin(function(ui) {
-
 fetch(BACKEND+"/version")
 .then(response => response.json())
 .catch(() => 0) // parsing failed - probably backend doesn't even have a version
@@ -329,6 +333,7 @@ fetch(BACKEND+"/version")
           // If the plugin was loaded while Fuseki was empty, superclasses will be empty as well.
           // After a successful OML build, Fuseki won't be empty and we can load the superclass relations.
           // A better way to handle this, would be to guarantee that even if the backend is empty (no models, and hence, no OML descriptions), the vocabularies are always built, and the resulting triples loaded into Fuseki.
+          // For now, however, the following is workable:
           if (superclasses.size === 0) {
             loadSuperclasses();
           }
@@ -481,7 +486,7 @@ fetch(BACKEND+"/version")
       document.body.removeChild(a);
     };
   }
-  function createModelList(modelType, createUploadDiv, downloadButtonLabel, onDownloadClick) {
+  function createModelList(modelType, createUploadDiv, downloadButtonLabel, onDownloadClick, extraStuff) {
     const containerDiv = document.createElement('div');
       containerDiv.classList.add('geFormatSection')
       containerDiv.style.padding = '12px 14px 8px 14px';
@@ -508,6 +513,8 @@ fetch(BACKEND+"/version")
               loadButton.style.marginLeft = "12px";
             div.appendChild(document.createTextNode(modelName));
             div.appendChild(loadButton);
+            extraStuff(modelName)
+            .then(stuff => stuff.forEach(el => div.appendChild(el)));
             return div;
           }));
         }
@@ -522,13 +529,49 @@ fetch(BACKEND+"/version")
     refreshList();
 
     containerDiv.appendChild(createUploadDiv(refreshList));
-
   }
 
-  createModelList("drawio", createSavePageDiv, "Open", modelName => loadPage(modelName));
-  createModelList("xopp", createUploadDiv("xopp", "application/x-xopp,.xopp"), "Download", createDownloadHandler("xopp"));
-  createModelList("csv", createUploadDiv("csv", "text/csv,.csv"), "Download", createDownloadHandler("csv"));
-  createModelList("file", createUploadDiv("file", ""), "Download", createDownloadHandler("file"));
+  const extraButtonsIfPM = modelName => {
+    if (modelName.endsWith(":pm")) {
+      const enactButton = mxUtils.button("Start New", ()=>{});
+      const pmModel = addArtifactPrefix(modelName.substr(0, modelName.length-3)+"_pm#model");
+      const urlEncoded = encodeURIComponent(pmModel);
+      return Promise.all([
+        fetch(WEE+"/traces/active/"+urlEncoded)
+        .then(response => response.json())
+        .then(enactments => {
+          return enactments.map((enactment, i) => mxUtils.button(`Continue ${i}`, ()=>{}))
+        }),
+        fetch(WEE+"/traces/finished/"+urlEncoded)
+        .then(response => response.json())
+        .then(enactments => {
+          return enactments.map((enactment, i) => mxUtils.button(`Finished ${i}`, ()=>{}))
+        }),
+      ])
+      .then(([ongoing, finished]) => {
+        const pmDiv = document.createElement('div');
+        pmDiv.style.marginLeft = '8px';
+        pmDiv.style.borderWidth = '1px';
+        pmDiv.style.borderStyle = 'solid';
+        pmDiv.appendChild(document.createTextNode("PM Enactment: "));
+        pmDiv.appendChild(enactButton);
+        if (ongoing.length > 0) {
+          ongoing.forEach(o => pmDiv.appendChild(o));
+        }
+        if (finished.length > 0) {
+          finished.forEach(f => pmDiv.appendChild(f));
+        }
+        return [pmDiv];
+      });
+    }
+    return Promise.resolve([]);
+  };
+  const noExtraButtons = () => Promise.resolve([]);
+
+  createModelList("drawio", createSavePageDiv, "Open", modelName => loadPage(modelName), extraButtonsIfPM);
+  createModelList("xopp", createUploadDiv("xopp", "application/x-xopp,.xopp"), "Download", createDownloadHandler("xopp"), noExtraButtons);
+  createModelList("csv", createUploadDiv("csv", "text/csv,.csv"), "Download", createDownloadHandler("csv"), noExtraButtons);
+  createModelList("file", createUploadDiv("file", ""), "Download", createDownloadHandler("file"), noExtraButtons);
 
   // Load a model and add it as a new page to the editor
   function loadPage(pageName) {