From 672d0de58dd523ef35d053b5946052048e0951a5 Mon Sep 17 00:00:00 2001
From: Nicola Fulvio Calabria <nicola.calabria@inaf.it>
Date: Wed, 23 Nov 2022 10:21:48 +0100
Subject: [PATCH] Partial implementation of node collections controller

---
 vospace-ui-frontend/src/api/server/index.js   | 11 ++++
 .../src/components/Collections.vue            | 62 +++++++++++++++++++
 .../src/components/CollectionsMenuItem.vue    | 13 ++++
 .../src/components/TopMenu.vue                |  3 +
 vospace-ui-frontend/src/router.js             | 26 ++++----
 5 files changed, 104 insertions(+), 11 deletions(-)
 create mode 100644 vospace-ui-frontend/src/components/Collections.vue
 create mode 100644 vospace-ui-frontend/src/components/CollectionsMenuItem.vue

diff --git a/vospace-ui-frontend/src/api/server/index.js b/vospace-ui-frontend/src/api/server/index.js
index 1d63162..063b889 100644
--- a/vospace-ui-frontend/src/api/server/index.js
+++ b/vospace-ui-frontend/src/api/server/index.js
@@ -79,6 +79,17 @@ export default {
       }
     }, false, true);
   },
+  loadNodeCollections() {
+    let url = BASE_API_URL + 'collections';
+    return apiRequest({
+      method: 'GET',
+      url: url,
+      withCredentials: true,
+      headers: {
+        'Cache-Control': 'no-cache'
+      }
+    }, false, true);
+  },  
   getUserInfo() {
     let url = BASE_API_URL + 'user';
     return apiRequest({
diff --git a/vospace-ui-frontend/src/components/Collections.vue b/vospace-ui-frontend/src/components/Collections.vue
new file mode 100644
index 0000000..6489d97
--- /dev/null
+++ b/vospace-ui-frontend/src/components/Collections.vue
@@ -0,0 +1,62 @@
+<!--
+  This file is part of vospace-ui
+  Copyright (C) 2021 Istituto Nazionale di Astrofisica
+  SPDX-License-Identifier: GPL-3.0-or-later
+-->
+<template>
+<div>
+  <b-button variant="primary" class="float-right" @click="loadCollections">Reload</b-button>
+  <h3>Collections</h3>
+  <div v-if="jobs.length > 0" class="mb-3">
+    <table class="table b-table table-striped table-hover">
+      <thead>
+        <tr>
+          <th>Id</th>
+          <th>Title</th>
+        </tr>
+      </thead>
+      <tbody>
+        <tr v-for="job in jobs" :key="job.id">
+          <td>{{job.type}}</td>
+          <td>{{job.creationTime}}</td>
+          <td>{{job.id}}</td>
+          <td><a :href="'download?jobId=' + job.id" v-if="job.phase === 'COMPLETED' && job.type === 'ARCHIVE'">Download archive</a></td>
+          <td>{{job.phase}}</td>
+        </tr>
+      </tbody>
+    </table>
+  </div>
+  <div v-if="jobs.length === 0">
+    No jobs
+  </div>
+  <div id="jobs-loading" v-if="jobsLoading" class="loading">
+    <div class="spinner-wrapper">
+      <b-spinner variant="primary" style="width: 3rem; height: 3rem;" label="Loading"></b-spinner>
+    </div>
+  </div>
+  <FAQModal/>
+</div>
+</template>
+
+<script>
+import FAQModal from './modal/FAQModal.vue'
+
+export default {
+  components: {
+    FAQModal
+  },
+  computed: {
+    jobs() { return this.$store.state.jobs },
+    jobsLoading() { return this.$store.state.jobsLoading }
+  },
+  mounted() {
+    this.loadJobs();
+    this.$store.commit('setLoading', false);
+  },
+  methods: {
+    loadJobs() {
+      this.$store.dispatch('loadJobs');
+    }
+  }
+}
+</script>
diff --git a/vospace-ui-frontend/src/components/CollectionsMenuItem.vue b/vospace-ui-frontend/src/components/CollectionsMenuItem.vue
new file mode 100644
index 0000000..20df043
--- /dev/null
+++ b/vospace-ui-frontend/src/components/CollectionsMenuItem.vue
@@ -0,0 +1,13 @@
+<!--
+  This file is part of vospace-ui
+  Copyright (C) 2021 Istituto Nazionale di Astrofisica
+  SPDX-License-Identifier: GPL-3.0-or-later
+-->
+<template>
+<b-navbar-nav v-if="this.$store.state.user !== 'anonymous'">
+  <b-nav-item href="#/collections">
+    <strong>Collections</strong>&nbsp;    
+  </b-nav-item>
+</b-navbar-nav>
+</template>
+}
\ No newline at end of file
diff --git a/vospace-ui-frontend/src/components/TopMenu.vue b/vospace-ui-frontend/src/components/TopMenu.vue
index a3e8f1f..147614e 100644
--- a/vospace-ui-frontend/src/components/TopMenu.vue
+++ b/vospace-ui-frontend/src/components/TopMenu.vue
@@ -8,6 +8,7 @@
   <b-navbar toggleable="lg" type="dark" id="top-menu">
     <b-navbar-brand href="#/" class="d-none d-md-block">VOSpace<sup><b>v1.0</b></sup></b-navbar-brand>
     <JobsMenuItem />
+    <CollectionsMenuItem /> 
     <b-navbar-nav class="ml-auto">
       <!--<b-nav-item right v-b-modal.modal-faq href="#">FAQ</b-nav-item>-->
       <FAQMenuItem />
@@ -22,11 +23,13 @@
 
 <script>
 import JobsMenuItem from './JobsMenuItem.vue';
+import CollectionsMenuItem from './CollectionsMenuItem.vue';
 import FAQMenuItem from './FAQMenuItem.vue';
 
 export default {
   components: {
     JobsMenuItem,
+    CollectionsMenuItem,
     FAQMenuItem
   },
   computed: {
diff --git a/vospace-ui-frontend/src/router.js b/vospace-ui-frontend/src/router.js
index d88906e..34bfdda 100644
--- a/vospace-ui-frontend/src/router.js
+++ b/vospace-ui-frontend/src/router.js
@@ -7,17 +7,21 @@ import VueRouter from 'vue-router';
 
 import Main from './components/Main.vue';
 import Jobs from './components/Jobs.vue';
+import Collections from './components/Collections.vue'
 
 export default new VueRouter({
-  routes: [{
-    path: '/',
-    redirect: '/nodes/'
-  }, {
-    name: 'nodes',
-    path: '/nodes/:path(.*)',
-    component: Main
-  }, {
-    path: '/jobs',
-    component: Jobs
-  }]
+    routes: [{
+            path: '/',
+            redirect: '/nodes/'
+        }, {
+            name: 'nodes',
+            path: '/nodes/:path(.*)',
+            component: Main
+        }, {
+            path: '/jobs',
+            component: Jobs
+        }, {
+            path: '/collections',
+            component: Collections
+        }]
 })
-- 
GitLab