From c9859ee89aac22e4ae1c090ea6c55691f0270d5a Mon Sep 17 00:00:00 2001
From: Sami Spets <savasp@utu.fi>
Date: Tue, 12 Nov 2019 09:55:13 +0200
Subject: [PATCH] Added loadConfigs method for client

---
 web-service/server/src/index.js            |  5 ++++-
 web-service/server/src/public/js/bundle.js | 16 ++++++++++++++--
 web-service/server/src/public/js/index.js  | 14 +++++++++++++-
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js
index ca6d16eb9..ebab412ab 100644
--- a/web-service/server/src/index.js
+++ b/web-service/server/src/index.js
@@ -231,8 +231,11 @@ app.post('/stream/config', async (req, res) => {
 
 app.get('/stream/config', async(req, res) => {
 	//example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi/stream/configurations/calibrations/default/board_size
-	
 	const wholeURI = encodeURIComponent(req.query.uri)
+	let dataURI = await Configs.find({URI: wholeURI});
+	if(dataURI[0].data.length){
+		return res.status(200).json(dataURI[0]);
+	}
 	const baseURI = "ftl%3A%2F%2Futu.fi%2Fstream%2Fconfigurations"
 	const uri = wholeURI.substring(47);
 	let depth = uri.split("%2F");
diff --git a/web-service/server/src/public/js/bundle.js b/web-service/server/src/public/js/bundle.js
index d59fd118b..8cf67432f 100644
--- a/web-service/server/src/public/js/bundle.js
+++ b/web-service/server/src/public/js/bundle.js
@@ -4720,17 +4720,29 @@ renderConfigOptions = () => {
     doc.innerHTML = input
 }
 
-changeConfigs = async () => {
+updateConfigs = async () => {
     const rawResp = await fetch('http://localhost:8080/stream/config', {
         method: 'POST',
         headers: {
             'Accept': 'application/json',
             'Content-Type': 'application/json'
         },
-        body: JSON.stringify({board_size: [0, 5], square_size: 1, frame_delay: 5, num_frames: 10, URI: current_data.uri})
+        body: JSON.stringify({board_size: [0, 5], square_size: 1, frame_delay: 5, num_frames: 10, URI: "current_data.uri"})
     });
     const content = await rawResp.json();
     console.log(content)
+}
+
+//current_data.configURI
+//configURI = 
+/**
+ * current_data.configURI is a dropdown menu
+ */
+
+loadConfigs = async () => {
+    const rawResp = await fetch(`http://localhost:8080/stream/config?uri=current_data.uri`)
+    const content = await rawResp.json();
+    console.log(content)
 }
 },{"../../peer":22}],24:[function(require,module,exports){
 (function (global){
diff --git a/web-service/server/src/public/js/index.js b/web-service/server/src/public/js/index.js
index 2f304dc02..becff6221 100644
--- a/web-service/server/src/public/js/index.js
+++ b/web-service/server/src/public/js/index.js
@@ -200,7 +200,7 @@ renderConfigOptions = () => {
     doc.innerHTML = input
 }
 
-changeConfigs = async () => {
+updateConfigs = async () => {
     const rawResp = await fetch('http://localhost:8080/stream/config', {
         method: 'POST',
         headers: {
@@ -211,4 +211,16 @@ changeConfigs = async () => {
     });
     const content = await rawResp.json();
     console.log(content)
+}
+
+//current_data.configURI
+//configURI = 
+/**
+ * current_data.configURI is a dropdown menu
+ */
+
+loadConfigs = async () => {
+    const rawResp = await fetch(`http://localhost:8080/stream/config?uri=current_data.uri`)
+    const content = await rawResp.json();
+    console.log(content)
 }
\ No newline at end of file
-- 
GitLab