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 2020/05/12 22:45:33 UTC

[airavata-django-portal] 04/04: AIRAVATA-3324 Handle loading exact value and 404 error case

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

machristie pushed a commit to branch AIRAVATA-3324-custom-input-editor-autocomplete-input-editor
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit f1ef162905f8f1c2fafc8a06b445c6b99f16bfb9
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue May 5 10:20:54 2020 -0400

    AIRAVATA-3324 Handle loading exact value and 404 error case
---
 .../input-editors/AutocompleteInputEditor.vue      | 29 +++++++++++++++++++---
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/AutocompleteInputEditor.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/AutocompleteInputEditor.vue
index b107471..6efd81e 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/AutocompleteInputEditor.vue
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/AutocompleteInputEditor.vue
@@ -84,9 +84,30 @@ export default {
   methods: {
     loadTextForValue(value) {
       if (this.autocompleteUrl) {
-        return utils.FetchUtils.get(this.autocompleteUrl, {
-          id: value
-        }).then(resp => resp.text);
+        return utils.FetchUtils.get(
+          this.autocompleteUrl,
+          {
+            exact: value
+          },
+          {
+            ignoreErrors: true // don't automatically report errors to user - code will handle 404s
+          }
+        )
+          .then(resp => {
+            if (resp.results && resp.results.length > 0) {
+              return resp.results[0].text;
+            } else {
+              return `value: ${value}`;
+            }
+          })
+          .catch(error => {
+            if (error.details.status === 404) {
+              // if we can't fine an exact match, just return the value as the text
+              return `value: ${value}`;
+            } else {
+              throw error;
+            }
+          });
       } else {
         return Promise.resolve(null);
       }
@@ -119,7 +140,7 @@ export default {
           }
         });
       }
-    }, 200),
+    }, 200)
   },
   created() {
     if (this.value) {