You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/05/24 13:08:08 UTC

[airavata-django-portal] 02/03: AIRAVATA-3034 Handle initial route, 404s

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch airavata-3016
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit 56cf641f66ec0cdc22cde794e37420606e3ba7aa
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu May 23 12:48:55 2019 -0400

    AIRAVATA-3034 Handle initial route, 404s
---
 django_airavata/apps/api/exceptions.py             |  7 +++
 .../components/storage/UserStoragePathViewer.vue   | 60 +++++++++-------------
 .../js/containers/UserStorageContainer.vue         | 51 ++++++++++++++++--
 .../common/js/components/NotificationsDisplay.vue  |  2 +
 4 files changed, 81 insertions(+), 39 deletions(-)

diff --git a/django_airavata/apps/api/exceptions.py b/django_airavata/apps/api/exceptions.py
index c90a7e2..ce284a1 100644
--- a/django_airavata/apps/api/exceptions.py
+++ b/django_airavata/apps/api/exceptions.py
@@ -1,5 +1,6 @@
 import logging
 
+from django.core.exceptions import ObjectDoesNotExist
 from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import exception_handler
@@ -29,6 +30,12 @@ def custom_exception_handler(exc, context):
             {'detail': str(exc)},
             status=status.HTTP_500_INTERNAL_SERVER_ERROR)
 
+    if isinstance(exc, ObjectDoesNotExist):
+        log.error("ObjectDoesNotExist", exc_info=exc)
+        return Response(
+            {'detail': str(exc)},
+            status=status.HTTP_404_NOT_FOUND)
+
     # Generic handler
     if response is None:
         log.error("API exception", exc_info=exc)
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/UserStoragePathViewer.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/UserStoragePathViewer.vue
index 7b3e168..350ce99 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/UserStoragePathViewer.vue
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/UserStoragePathViewer.vue
@@ -1,71 +1,61 @@
 <template>
-  <b-table :fields="fields" :items="items">
-    <template slot="name" slot-scope="data">
-      <router-link v-if="data.item.type === 'dir'" :to="'/~/' + data.item.path">{{ data.item.name }}</router-link>
-      <b-link v-else :href="data.item.downloadURL">{{ data.item.name }}</b-link>
+  <b-table
+    :fields="fields"
+    :items="items"
+  >
+    <template
+      slot="name"
+      slot-scope="data"
+    >
+      <router-link
+        v-if="data.item.type === 'dir'"
+        :to="'/~/' + data.item.path"
+      >{{ data.item.name }}</router-link>
+      <b-link
+        v-else
+        :href="data.item.downloadURL"
+      >{{ data.item.name }}</b-link>
     </template>
   </b-table>
 </template>
 <script>
-import { services } from "django-airavata-api";
-
 export default {
   name: "user-storage-path-viewer",
   props: {
-    path: {
-      type: String,
+    userStoragePath: {
       required: true
     }
   },
-  data() {
-    return {
-      userStoragePath: null,
-      fields: [
+  computed: {
+    fields() {
+      return [
         {
           label: "Name",
           key: "name"
         }
-      ]
-    };
-  },
-  computed: {
+      ];
+    },
     items() {
       if (this.userStoragePath) {
-
         const dirs = this.userStoragePath.directories.map(d => {
           return {
             name: d.name,
             path: d.path,
             type: "dir"
-          }
+          };
         });
         const files = this.userStoragePath.files.map(f => {
           return {
             name: f.name,
             type: "file",
             downloadURL: f.downloadURL
-          }
-        })
+          };
+        });
         return dirs.concat(files);
       } else {
         return [];
       }
     }
-  },
-  methods: {
-    loadUserStoragePath(path) {
-      return services.UserStoragePathService.get({ path }).then(result => {
-        this.userStoragePath = result;
-      });
-    }
-  },
-  created() {
-    this.loadUserStoragePath(this.path);
-  },
-  watch: {
-    path(newValue) {
-      this.loadUserStoragePath(newValue);
-    }
   }
 };
 </script>
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/UserStorageContainer.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/UserStorageContainer.vue
index 13a553a..68fae77 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/UserStorageContainer.vue
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/UserStorageContainer.vue
@@ -1,8 +1,11 @@
 <template>
-  <router-view :path="storagePath"></router-view>
+  <router-view :user-storage-path="userStoragePath"></router-view>
 </template>
 
 <script>
+import { services, utils } from "django-airavata-api";
+import { notifications } from "django-airavata-common-ui";
+
 export default {
   name: "user-storage-container",
   computed: {
@@ -14,10 +17,50 @@ export default {
       }
     }
   },
+  data() {
+    return {
+      userStoragePath: null
+    };
+  },
+  methods: {
+    loadUserStoragePath(path) {
+      return services.UserStoragePathService.get(
+        { path },
+        { ignoreErrors: true }
+      )
+        .then(result => {
+          this.userStoragePath = result;
+        })
+        .catch(err => {
+          if (err.details.status === 404) {
+            this.handleMissingPath(path);
+          } else {
+            utils.FetchUtils.reportError(err);
+          }
+        });
+    },
+    handleMissingPath(path) {
+      this.$router.replace("/~/");
+      // Display a transient error about the path not existing
+      notifications.NotificationList.add(
+        new notifications.Notification({
+          type: "WARNING",
+          message: "Path does not exist: " + path,
+          duration: 2
+        })
+      );
+    }
+  },
+  created() {
+    if (this.$route.path === "/") {
+      this.$router.replace("/~/");
+    }
+    this.loadUserStoragePath(this.storagePath);
+  },
   watch: {
-    // '$route' (to, from) {
-
-    // }
+    $route(to, from) {
+      this.loadUserStoragePath(this.storagePath);
+    }
   }
 };
 </script>
diff --git a/django_airavata/static/common/js/components/NotificationsDisplay.vue b/django_airavata/static/common/js/components/NotificationsDisplay.vue
index 70a5aae..defbdf6 100644
--- a/django_airavata/static/common/js/components/NotificationsDisplay.vue
+++ b/django_airavata/static/common/js/components/NotificationsDisplay.vue
@@ -36,6 +36,8 @@ export default {
         return "success";
       } else if (notification.type === "ERROR") {
         return "danger";
+      } else if (notification.type === "WARNING") {
+        return "warning";
       } else {
         return "secondary";
       }