From 7fba814d18ee697750318aaec8fc8669a4c1b480 Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Thu, 20 Apr 2023 08:31:50 +0200
Subject: [PATCH] Refactor/change to cope with user reg form

---
 src/App.vue                         | 13 +++-------
 src/components/LoginSystem.vue      |  5 ++--
 src/components/Logout.vue           | 31 -----------------------
 src/components/MapPOI.vue           |  6 +++++
 src/components/Observation.vue      |  6 +++++
 src/components/ObservationList.vue  |  6 +++++
 src/components/PlacesList.vue       |  6 +++++
 src/components/RegisterUserForm.vue | 36 +++++++++++++++++++++++++++
 src/locales/en.json                 |  2 +-
 src/locales/nb.json                 |  2 +-
 src/main.js                         |  9 +++----
 src/router/index.js                 | 38 ++++++++++++++++++++++++++---
 static/css/vipsobsapp.css           |  5 ++++
 13 files changed, 112 insertions(+), 53 deletions(-)
 delete mode 100644 src/components/Logout.vue
 create mode 100644 src/components/RegisterUserForm.vue

diff --git a/src/App.vue b/src/App.vue
index f5f146c..236a66d 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -23,25 +23,18 @@
 -->
 <template>
     <main id="app" role="main" class="container">
-    <div v-if="$root.sharedState.uuid">
-      <router-view/>
-    </div>
-    <div v-else>
-      <Welcome></Welcome>
-    </div>
+      <router-view></router-view>
   </main>
 </template>
 
 <script>
-import Welcome from '@/components/Welcome'
 import CommonUtil from "@/components/CommonUtil";
 
-
 export default {
   name: 'App',
   components : {
-    Welcome
-  },
+    
+},
   methods: {
 	},
   beforeMount(){
diff --git a/src/components/LoginSystem.vue b/src/components/LoginSystem.vue
index ca72b13..028cd8a 100644
--- a/src/components/LoginSystem.vue
+++ b/src/components/LoginSystem.vue
@@ -27,7 +27,7 @@
 			<font-awesome-icon style="font-size: large; color: #3d8052; padding-left: 5px;" icon="fa-user" /> <span
 				v-text="userLoggedInName"></span>
 			<br />
-			<a class="vips-btn" v-on:click="handleLogout()">{{ $t("logout.button.label")}}</a>
+			<a class="btn btn-primary" v-on:click="handleLogout()">{{ $t("logout.button.label")}}</a>
 		</div>
 		<div v-else>
 			<form class="my-2 my-lg-0">
@@ -47,6 +47,7 @@
 					v-on:keyup.enter="handleLogin()">
 					{{ $t("login.button.label")}}
 				</button>
+				<router-link to="/RegisterUserForm" class="btn btn-warning" onclick="$('.offcanvas-collapse').toggleClass('open')">{{ $t("registeruser.button.label") }}</router-link>
 				<div v-show="errMsg" class="alert alert-warning alert-dismissible fade show">
 					{{errMsg}}
 					<button type="button" class="close" data-dismiss="alert" aria-label="Close">
@@ -236,7 +237,7 @@
 
 				this.$emit(CommonUtil.CONST_EVENT_LOGIN_USER_DETAIL, '');
 				$('.offcanvas-collapse').removeClass('open');
-				this.$router.push('/logout');
+				this.$router.push('/Logout');
 			},
 			/** Remove stored data on logout */
 			removeStoredData() {
diff --git a/src/components/Logout.vue b/src/components/Logout.vue
deleted file mode 100644
index 6aa2fe2..0000000
--- a/src/components/Logout.vue
+++ /dev/null
@@ -1,31 +0,0 @@
-<!--
-    
-  Copyright (c) 2022 NIBIO <http://www.nibio.no/>. 
-  
-  This file is part of VIPSObservationApp.
-  VIPSObservationApp is free software: you can redistribute it and/or modify
-  it under the terms of the NIBIO Open Source License as published by 
-  NIBIO, either version 1 of the License, or (at your option) any
-  later version.
-  
-  VIPSObservationApp is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  NIBIO Open Source License for more details.
-  
-  You should have received a copy of the NIBIO Open Source License
-  along with VIPSObservationApp.  If not, see <http://www.nibio.no/licenses/>.
-    
-  Author: Bhabesh Bhabani Mukhopadhyay
-  Author: Tor-Einar Skog <tor-einar.skog@nibio.no>
-  Dated : 19-Aug-2021
-    
--->
-<template>
-	<div>
-		<h1>{{$t("logout.header.text")}}</h1>
-		<div class="alert alert-warning" role="alert">
-			{{$t("logout.success.text")}}
-		</div>
-	</div>
-</template>
\ No newline at end of file
diff --git a/src/components/MapPOI.vue b/src/components/MapPOI.vue
index 58e84b6..d566279 100644
--- a/src/components/MapPOI.vue
+++ b/src/components/MapPOI.vue
@@ -545,6 +545,12 @@
 			appDiv.style.paddingRight = "15px";
 			appDiv.style.paddingLeft = "15px";
 		},
+		beforeRouteEnter(to,from,next){
+			next(vm=>{
+				if(vm.$root.sharedState.uuid == ""){ next("/Welcome"); }
+				else { next(); }
+			})
+		}
 	}
 </script>
 
diff --git a/src/components/Observation.vue b/src/components/Observation.vue
index fe4a898..057de53 100644
--- a/src/components/Observation.vue
+++ b/src/components/Observation.vue
@@ -784,6 +784,12 @@
 				this.observationForStore.locationIsPrivate = this.observation.locationIsPrivate;
 				this.observationForStore.polygonService = this.observation.polygonService;
 			}
+		},
+		beforeRouteEnter(to,from,next){
+			next(vm=>{
+				if(vm.$root.sharedState.uuid == ""){ next("/Welcome"); }
+				else { next(); }
+			})
 		}
 
 	}
diff --git a/src/components/ObservationList.vue b/src/components/ObservationList.vue
index 4037958..979e1d8 100644
--- a/src/components/ObservationList.vue
+++ b/src/components/ObservationList.vue
@@ -136,6 +136,12 @@
 			// Making it globally available, so that e.g. the Sync component can update the list
 			// calling e.g. this.$root.sharedState.observationListComponent.getObservationsFromStore();
 			this.$root.sharedState.observationListComponent = this;
+		},
+		beforeRouteEnter(to,from,next){
+			next(vm=>{
+				if(vm.$root.sharedState.uuid == ""){ next("/Welcome"); }
+				else { next(); }
+			})
 		}
 	}
 </script>
diff --git a/src/components/PlacesList.vue b/src/components/PlacesList.vue
index fbff8f7..6e7c382 100644
--- a/src/components/PlacesList.vue
+++ b/src/components/PlacesList.vue
@@ -173,6 +173,12 @@
 			// calling e.g. this.$root.sharedState.placesListComponent.fooBar();
 			this.$root.sharedState.placesListComponent = this;
 
+		},
+		beforeRouteEnter(to,from,next){
+			next(vm=>{
+				if(vm.$root.sharedState.uuid == ""){ next("/Welcome"); }
+				else { next(); }
+			})
 		}
 	}
 </script>
diff --git a/src/components/RegisterUserForm.vue b/src/components/RegisterUserForm.vue
new file mode 100644
index 0000000..1720e7f
--- /dev/null
+++ b/src/components/RegisterUserForm.vue
@@ -0,0 +1,36 @@
+<!--
+    
+  Copyright (c) 2023 NIBIO <http://www.nibio.no/>. 
+  
+  This file is part of VIPSObservationApp.
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU Affero General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU Affero General Public License for more details.
+
+  You should have received a copy of the GNU Affero General Public License
+  along with this program.  If not, see <https://www.gnu.org/licenses/>.
+    
+  Author: Tor-Einar Skog <tor-einar.skog@nibio.no>
+  Created : 2023-04-18
+    
+-->
+
+<template>
+	<div>
+        <h1>Register new user</h1>
+    </div>
+</template>
+
+<script>
+	import CommonUtil from '@/components/CommonUtil';
+
+  export default {
+    name: 'RegisterUserForm'
+  }
+</script>
\ No newline at end of file
diff --git a/src/locales/en.json b/src/locales/en.json
index ae35bdc..a1149f6 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -71,6 +71,6 @@
 	"about.header": "About",
 	"about.version": "Version",
 	"about.text": "<p>The app is developed by <a href='#' onclick=\"cordova.InAppBrowser.open('https://nibio.no/en', '_system')\">NIBIO</a>'s <a href='#' onclick=\"cordova.InAppBrowser.open('https://www.vips-landbruk.no/', '_system')\">VIPS</a> team.</p><p>VIPS project leader: <a href='#' onclick=\"cordova.InAppBrowser.open('https://www.nibio.no/ansatte/berit-nordskog', '_system')\">Berit Nordskog</a></p><p>&copy; 2022 <a href='#' onclick=\"cordova.InAppBrowser.open('https://nibio.no/en', '_system')\">NIBIO</a></p>",
-	
+	"registeruser.button.label": "Register new user",
 	"copy" : "Copy"
 }
\ No newline at end of file
diff --git a/src/locales/nb.json b/src/locales/nb.json
index 9b0e3d0..c70f7a4 100644
--- a/src/locales/nb.json
+++ b/src/locales/nb.json
@@ -71,6 +71,6 @@
 	"about.header": "Om appen",
 	"about.version": "Versjon",
 	"about.text": "<p>Appen er utviklet av <a href='#' onclick=\"cordova.InAppBrowser.open('https://nibio.no/', '_system')\">NIBIO</a>s <a href='#' onclick=\"cordova.InAppBrowser.open('https://www.vips-landbruk.no/', '_system')\">VIPS-team</a>.</p><p>Prosjektleder for VIPS: <a href='#' onclick=\"cordova.InAppBrowser.open('https://www.nibio.no/ansatte/berit-nordskog', '_system')\">Berit Nordskog</a></p><p>&copy; 2022 <a href='#' onclick=\"cordova.InAppBrowser.open('https://nibio.no/', '_system')\">NIBIO</a></p>",
-	
+	"registeruser.button.label": "Registrer ny bruker",
 	"copy" : "Kopi"
 }
\ No newline at end of file
diff --git a/src/main.js b/src/main.js
index 566a3e3..a11d407 100644
--- a/src/main.js
+++ b/src/main.js
@@ -72,12 +72,11 @@ const init = () => {
 	  },
 
       i18n,
-	  
       created() {
-		CommonUtil.setHeaderTitle(this.$i18n.t("index.header"));
-		CommonUtil.logInfo("Vue is ready");
-		CommonUtil.logInfo("User's preferred language is " + this.$i18n.locale);
-		// Are we logged in already?
+        CommonUtil.setHeaderTitle(this.$i18n.t("index.header"));
+        CommonUtil.logInfo("Vue is ready");
+        CommonUtil.logInfo("User's preferred language is " + this.$i18n.locale);
+        // Are we logged in already?
 		
 	  }
 
diff --git a/src/router/index.js b/src/router/index.js
index 3fd29a7..98a9088 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -9,11 +9,12 @@ import CropCategory from '@/components/CropCategory'
 import MapObservation from '@/components/MapObservation'
 import MapPOI from '@/components/MapPOI'
 import Quantification from '@/components/Quantification'
-import Logout from '@/components/Logout'
+import RegisterUserForm from '@/components/RegisterUserForm'
+
 
 Vue.use(Router)
 
-export default new Router({
+const router = new Router({
   routes: [
     {
       path: '/welcome',
@@ -61,11 +62,42 @@ export default new Router({
       name : 'Quantification',
       component : Quantification
     },
+    {
+      path : '/RegisterUserForm',
+      name : 'RegisterUserForm',
+      component : RegisterUserForm
+    },
     {
       path : '/logout',
       name : 'Logout',
-      component : Logout
+      component : Welcome
     },        
 
   ]
 })
+
+export default router;
+
+/*router.beforeEach((to,from,next) => {
+  //console.info(this.sharedState);
+
+  //console.info(router.app.$root.sharedState);
+  //console.info(router.app.$root.sharedState.uuid);
+  //console.info(from);
+
+  //console.info("uuid=" + router.app.$root.sharedState.uuid);
+  
+  console.info("to.name=" + to.name);
+  console.info(router.app.sharedState)
+  //var isLoggedIn = router.app.$root.sharedState.uuid != undefined && router.app.$root.sharedState.uuid != "";
+  
+  if(!isLoggedIn && ["RegisterUserForm","Welcome"].indexOf(to.name) < 0)
+  {
+    next({name:"Welcome"});
+  }
+  else {
+    next();
+  }
+});
+*/
+
diff --git a/static/css/vipsobsapp.css b/static/css/vipsobsapp.css
index d64309e..72b0378 100644
--- a/static/css/vipsobsapp.css
+++ b/static/css/vipsobsapp.css
@@ -23,6 +23,11 @@ a.nav-link{
 	border-color: #3d8052;
 }
 
+.btn-primary, .btn-primary:hover {
+	background-color: #3d8052;
+	border-color: #3d8052;
+}
+
 a.vips-btn {
 	background-color: #3d8052;
 	color: white;
-- 
GitLab