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/06/10 15:32:25 UTC

[airavata-django-portal] 03/08: AIRAVATA-3057 For URI_COLLECTION, only allow selecting file once

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

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

commit 1450a0db6f58dd5d1b5724d3f576dbf83fbc4bf4
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Jun 10 10:16:42 2019 -0400

    AIRAVATA-3057 For URI_COLLECTION, only allow selecting file once
---
 .../experiment/input-editors/FileInputEditor.vue   | 24 ++++++++++++++++++++--
 .../input-editors/MultiFileInputEditor.vue         |  1 +
 .../storage/UserStorageFileSelectionContainer.vue  | 10 ++++++++-
 .../components/storage/UserStoragePathViewer.vue   | 12 ++++++++++-
 4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/FileInputEditor.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/FileInputEditor.vue
index 7c9dc0f..6fa28ba 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/FileInputEditor.vue
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/FileInputEditor.vue
@@ -29,9 +29,16 @@
       </b-link>
     </div>
     <div v-if="isSelectingFile">
-      <user-storage-file-selection-container @file-selected="fileSelected" @cancel="cancelFileSelection"/>
+      <user-storage-file-selection-container
+        @file-selected="fileSelected"
+        @cancel="cancelFileSelection"
+        :selected-data-product-uris="selectedDataProductURIs"
+      />
     </div>
-    <div class="d-flex" v-if="!isSelectingFile && !isDataProductURI">
+    <div
+      class="d-flex"
+      v-if="!isSelectingFile && !isDataProductURI"
+    >
       <!-- TODO: fix layout -->
       <b-button @click="isSelectingFile=true">Select user file</b-button>
       <span class="text-muted">OR</span>
@@ -65,6 +72,19 @@ export default {
     isDataProductURI() {
       // Just assume that if the value is a string then it's a data product URL
       return this.value && typeof this.value === "string";
+    },
+    // When used in the MultiFileInputEditor, don't allow selecting the same
+    // file more than once. This computed property creates an array of already
+    // selected files.
+    selectedDataProductURIs() {
+      if (
+        this.experimentInput.type === models.DataType.URI_COLLECTION &&
+        this.experimentInput.value
+      ) {
+        return this.experimentInput.value.split(",");
+      } else {
+        return [];
+      }
     }
   },
   data() {
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/MultiFileInputEditor.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/MultiFileInputEditor.vue
index 75b8c5d..0d02ec4 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/MultiFileInputEditor.vue
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/MultiFileInputEditor.vue
@@ -58,6 +58,7 @@ export default {
         .filter(e => e.value) // exclude null entries
         .map(e => e.value)
         .join(",");
+      this.fileEntries = this.createFileEntries(this.data);
       this.valueChanged();
     },
     removeFile(fileEntry) {
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/UserStorageFileSelectionContainer.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/UserStorageFileSelectionContainer.vue
index 3f5696e..7dbd070 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/UserStorageFileSelectionContainer.vue
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/UserStorageFileSelectionContainer.vue
@@ -7,7 +7,9 @@
       :include-delete-action="false"
       :include-select-file-action="true"
       :download-in-new-window="true"
-    />
+      :selected-data-product-uris="selectedDataProductUris"
+    >
+    </user-storage-path-viewer>
     <!-- TODO: push this right? -->
     <b-link class="card-link" @click="$emit('cancel')">Cancel</b-link>
   </b-card>
@@ -19,6 +21,12 @@ import UserStoragePathViewer from "./UserStoragePathViewer";
 
 export default {
   name: "user-storage-file-selection-container",
+  props: {
+    selectedDataProductUris: {
+      type: Array,
+      default: () => []
+    }
+  },
   data() {
     return {
       userStoragePath: null
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 61cd61b..e8e86ff 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
@@ -37,6 +37,7 @@
         <b-button
           v-if="includeSelectFileAction && data.item.type === 'file'"
           @click="$emit('file-selected', data.item)"
+          :disabled="isAlreadySelected(data.item)"
           variant="primary"
         >
           Select
@@ -72,6 +73,10 @@ export default {
     downloadInNewWindow: {
       type: Boolean,
       default: false
+    },
+    selectedDataProductUris: {
+      type: Array,
+      default: () => []
     }
   },
   components: {
@@ -135,7 +140,7 @@ export default {
       }
     },
     downloadTarget() {
-      return this.downloadInNewWindow ? '_blank' : '_self';
+      return this.downloadInNewWindow ? "_blank" : "_self";
     }
   },
   methods: {
@@ -159,6 +164,11 @@ export default {
     },
     directorySelected(item) {
       this.$emit("directory-selected", item.path);
+    },
+    isAlreadySelected(item) {
+      return this.selectedDataProductUris.find(
+        uri => item.type === "file" && uri === item.dataProductURI
+      );
     }
   }
 };