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 2021/10/05 19:47:28 UTC

[airavata-django-portal] 17/24: AIRAVATA-3477 Wrapped SliderInputEditor as web component

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

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

commit b7f21340af2f1b639e1d005af5d8c3033cbe506a
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Sep 15 11:59:40 2021 -0400

    AIRAVATA-3477 Wrapped SliderInputEditor as web component
---
 .../experiment/input-editors/SliderInputEditor.vue | 61 ++++++++++++++++-----
 .../input-editors/SliderInputEditor.vue            | 64 ++++++++++++++++++++++
 2 files changed, 112 insertions(+), 13 deletions(-)

diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/SliderInputEditor.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/SliderInputEditor.vue
index 0c2b0c9..fd1df8c 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/SliderInputEditor.vue
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/experiment/input-editors/SliderInputEditor.vue
@@ -4,9 +4,9 @@
     @change="onChange"
     :state="componentValidState"
     :disabled="readOnly"
-    :min="min"
-    :max="max"
-    :interval="step"
+    :min="sliderMin"
+    :max="sliderMax"
+    :interval="sliderStep"
     tooltip="always"
     :tooltip-formatter="tooltipFormatter"
   />
@@ -23,6 +23,21 @@ export default {
     value: {
       type: String,
     },
+    min: Number,
+    max: Number,
+    step: Number,
+    valueFormat: {
+      type: String,
+      validator(value) {
+        return ["percentage"].indexOf(value) !== -1;
+      },
+    },
+    displayFormat: {
+      type: String,
+      validator(value) {
+        return ["percentage"].indexOf(value) !== -1;
+      },
+    },
   },
   components: {
     VueSlider,
@@ -36,14 +51,26 @@ export default {
     this.initializeSliderValue();
   },
   computed: {
-    min: function () {
-      return "min" in this.editorConfig ? this.editorConfig.min : 0;
+    sliderMin: function () {
+      return typeof this.min !== "undefined"
+        ? this.min
+        : "min" in this.editorConfig
+        ? this.editorConfig.min
+        : 0;
     },
-    max: function () {
-      return "max" in this.editorConfig ? this.editorConfig.max : 100;
+    sliderMax: function () {
+      return typeof this.max !== "undefined"
+        ? this.max
+        : "max" in this.editorConfig
+        ? this.editorConfig.max
+        : 100;
     },
-    step: function () {
-      return "step" in this.editorConfig ? this.editorConfig.step : 1;
+    sliderStep: function () {
+      return typeof this.step !== "undefined"
+        ? this.step
+        : "step" in this.editorConfig
+        ? this.editorConfig.step
+        : 1;
     },
   },
   methods: {
@@ -57,15 +84,19 @@ export default {
     },
     parseValue(value) {
       // Just remove any percentage signs
-      const result = parseInt(value.replaceAll("%", ""));
-      return !isNaN(result) ? result : this.min;
+      const result = value ? parseInt(value.replaceAll("%", "")) : NaN;
+      return !isNaN(result) ? result : this.sliderMin;
     },
     onChange(value) {
       this.data = this.formatValue(value);
       this.valueChanged();
     },
     tooltipFormatter(value) {
-      if ("displayFormat" in this.editorConfig) {
+      if (this.displayFormat) {
+        if (this.displayFormat === "percentage") {
+          return `${value}%`;
+        }
+      } else if ("displayFormat" in this.editorConfig) {
         if (this.editorConfig.displayFormat.percentage) {
           return `${value}%`;
         }
@@ -73,7 +104,11 @@ export default {
       return value;
     },
     formatValue(value) {
-      if ("valueFormat" in this.editorConfig) {
+      if (this.valueFormat) {
+        if (this.valueFormat === "percentage") {
+          return `${value}%`;
+        }
+      } else if ("valueFormat" in this.editorConfig) {
         if (this.editorConfig.valueFormat.percentage) {
           return `${value}%`;
         }
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/input-editors/SliderInputEditor.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/input-editors/SliderInputEditor.vue
new file mode 100644
index 0000000..bec91e9
--- /dev/null
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/input-editors/SliderInputEditor.vue
@@ -0,0 +1,64 @@
+<template>
+  <slider-input-editor
+    v-if="experimentInput"
+    :id="id"
+    :value="data"
+    :experiment-input="experimentInput"
+    :read-only="readOnly"
+    :min="min"
+    :max="max"
+    :step="step"
+    :value-format="valueFormat"
+    :display-format="displayFormat"
+    @input="valueChanged"
+  />
+</template>
+
+<script>
+import SliderInputEditor from "../../components/experiment/input-editors/SliderInputEditor.vue";
+import WebComponentInputEditorMixin from "./WebComponentInputEditorMixin.js";
+
+export default {
+  mixins: [WebComponentInputEditorMixin],
+  props: {
+    // Explicit copy props from mixin, workaround for bug, see
+    // https://github.com/vuejs/vue-web-component-wrapper/issues/30#issuecomment-427350734
+    // for more details
+    ...WebComponentInputEditorMixin.props,
+    min: {
+      type: Number,
+    },
+    max: {
+      type: Number,
+    },
+    step: {
+      type: Number,
+    },
+    valueFormat: {
+      type: String,
+      validator(value) {
+        return ["percentage"].indexOf(value) !== -1;
+      },
+    },
+    displayFormat: {
+      type: String,
+      validator(value) {
+        return ["percentage"].indexOf(value) !== -1;
+      },
+    },
+  },
+  components: {
+    SliderInputEditor,
+  },
+};
+</script>
+
+<style lang="scss">
+@import "../styles";
+// Need to explicitly import VueSlider's CSS because importing component scss doesn't work
+// https://github.com/vuejs/vue-web-component-wrapper/issues/12
+@import "~vue-slider-component/dist-css/vue-slider-component.css";
+:host {
+  display: block;
+}
+</style>