From 9d3b9acb642fdb4f6299a2348ed22c6e1d9ab3d2 Mon Sep 17 00:00:00 2001
From: vkovtun <viktor.kovtun@id.ethz.ch>
Date: Fri, 28 Jul 2023 19:15:19 +0200
Subject: [PATCH] SSDM-13839: Added file/directory creation to the JavaScript
 part.

---
 .../javascript/server-data-store-client.html  | 17 ++++++++++++++++-
 .../javascript/server-data-store-client.js    |  8 ++++++++
 .../javascript/server-data-store-facade.js    | 19 +++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/server-data-store/src/test/javascript/server-data-store-client.html b/server-data-store/src/test/javascript/server-data-store-client.html
index d6e3b4ef947..1c10ed71adc 100644
--- a/server-data-store/src/test/javascript/server-data-store-client.html
+++ b/server-data-store/src/test/javascript/server-data-store-client.html
@@ -100,7 +100,22 @@
         </div>
     </form>
 
-
+    <h2>Create</h2>
+    <form onsubmit="return false;">
+        <div id="create-area">
+            <table>
+                <tr>
+                    <td><label>Name:</label></td>
+                    <td><input type="text" id="create-path" required></td>
+                </tr>
+                <tr>
+                    <td><label>Is directory:</label></td>
+                    <td><input type="checkbox" id="create-directory"></td>
+                </tr>
+            </table>
+            <button id="create-submit">Create</button>
+        </div>
+    </form>
 </div>
 </body>
 </html>
\ No newline at end of file
diff --git a/server-data-store/src/test/javascript/server-data-store-client.js b/server-data-store/src/test/javascript/server-data-store-client.js
index a4b0c5c4ff6..855b15fe0f6 100644
--- a/server-data-store/src/test/javascript/server-data-store-client.js
+++ b/server-data-store/src/test/javascript/server-data-store-client.js
@@ -223,5 +223,13 @@ window.onload = function() {
 			}));
 		}
 	};
+
+	document.getElementById("create-submit").onclick = function() {
+		datastoreServer.create(owner, document.getElementById("create-path").value.trim(), document.getElementById("create-directory").value,
+			(_ => {
+				showEntries();
+			}));
+	};
+
 }
 
diff --git a/server-data-store/src/test/javascript/server-data-store-facade.js b/server-data-store/src/test/javascript/server-data-store-facade.js
index 25b21092030..d0eae812fdf 100644
--- a/server-data-store/src/test/javascript/server-data-store-facade.js
+++ b/server-data-store/src/test/javascript/server-data-store-facade.js
@@ -497,6 +497,25 @@ datastore.prototype.move = function(sourceOwner, source, targetOwner, target, ac
 	
 }
 
+/**
+ * Create a file/directory within DSS
+ */
+DataStoreServer.prototype.create = function(owner, source, directory, action){
+	const data =  this.fillCommonParameters({
+		"method": "create",
+		"owner" : owner,
+		"source": source,
+		"directory": directory
+	});
+	this._internal.sendHttpRequest(
+		"POST",
+		"text/plain",
+		this._internal.datastoreUrl,
+		encodeParams(data),
+		(response) => action(response)
+	);
+}
+
 
 /**
  * ==================================================================================
-- 
GitLab