Browse Source

feat: add extra row

Jérémy Lopes 3 years ago
parent
commit
3dc8bc8210

+ 14 - 0
src/background/workflow-engine/blocks-handler/handler-interaction-block.js

@@ -26,9 +26,23 @@ async function interactionHandler(block, { refData }) {
       if (Array.isArray(data) && currentColumnType !== 'array') {
         data.forEach((item) => {
           this.addData(block.data.dataColumn, item);
+          if (objectHasKey(block.data, 'extraRowDataColumn')) {
+            if (block.data.addExtraRow)
+              this.addData(
+                block.data.extraRowDataColumn,
+                block.data.extraRowValue
+              );
+          }
         });
       } else {
         this.addData(block.data.dataColumn, data);
+        if (objectHasKey(block.data, 'extraRowDataColumn')) {
+          if (block.data.addExtraRow)
+            this.addData(
+              block.data.extraRowDataColumn,
+              block.data.extraRowValue
+            );
+        }
       }
     } else if (block.name === 'javascript-code') {
       const arrData = Array.isArray(data) ? data : [data];

+ 40 - 0
src/components/newtab/workflow/edit/EditAttributeValue.vue

@@ -32,6 +32,46 @@
         <v-remixicon name="riKey2Line" />
       </ui-button>
     </div>
+    <ui-checkbox
+      :model-value="data.addExtraRow"
+      class="mt-3"
+      @change="updateData({ addExtraRow: $event })"
+    >
+      {{ t('workflow.blocks.attribute-value.forms.extraRow.checkbox') }}
+    </ui-checkbox>
+    <ui-input
+      v-if="data.addExtraRow"
+      :model-value="data.extraRowValue"
+      :title="t('workflow.blocks.attribute-value.forms.extraRow.title')"
+      :placeholder="
+        t('workflow.blocks.attribute-value.forms.extraRow.placeholder')
+      "
+      class="w-full mt-3 mb-2"
+      @change="updateData({ extraRowValue: $event })"
+    />
+    <div v-if="data.addExtraRow" class="flex items-center mt-1">
+      <ui-select
+        :model-value="data.extraRowDataColumn"
+        placeholder="Data column"
+        class="mr-2 flex-1"
+        @change="updateData({ extraRowDataColumn: $event })"
+      >
+        <option
+          v-for="column in workflow.data.value.dataColumns"
+          :key="column.name"
+          :value="column.name"
+        >
+          {{ column.name }}
+        </option>
+      </ui-select>
+      <ui-button
+        icon
+        title="Data columns"
+        @click="workflow.showDataColumnsModal(true)"
+      >
+        <v-remixicon name="riKey2Line" />
+      </ui-button>
+    </div>
   </edit-interaction-base>
 </template>
 <script setup>

+ 39 - 1
src/components/newtab/workflow/edit/EditGetText.vue

@@ -30,7 +30,7 @@
       class="mt-3"
       @change="updateData({ saveData: $event })"
     >
-      Save data
+      {{ t('workflow.blocks.get-text.checkbox') }}
     </ui-checkbox>
     <div v-if="data.saveData" class="flex items-center mt-1">
       <ui-select
@@ -69,6 +69,44 @@
       class="w-full"
       @change="updateData({ suffixText: $event })"
     />
+    <ui-checkbox
+      :model-value="data.addExtraRow"
+      class="mt-3"
+      @change="updateData({ addExtraRow: $event })"
+    >
+      {{ t('workflow.blocks.get-text.extraRow.checkbox') }}
+    </ui-checkbox>
+    <ui-input
+      v-if="data.addExtraRow"
+      :model-value="data.extraRowValue"
+      :title="t('workflow.blocks.get-text.extraRow.title')"
+      :placeholder="t('workflow.blocks.get-text.extraRow.placeholder')"
+      class="w-full mt-3 mb-2"
+      @change="updateData({ extraRowValue: $event })"
+    />
+    <div v-if="data.addExtraRow" class="flex items-center mt-1">
+      <ui-select
+        :model-value="data.extraRowDataColumn"
+        placeholder="Data column"
+        class="mr-2 flex-1"
+        @change="updateData({ extraRowDataColumn: $event })"
+      >
+        <option
+          v-for="column in workflow.data.value.dataColumns"
+          :key="column.name"
+          :value="column.name"
+        >
+          {{ column.name }}
+        </option>
+      </ui-select>
+      <ui-button
+        icon
+        title="Data columns"
+        @click="workflow.showDataColumnsModal(true)"
+      >
+        <v-remixicon name="riKey2Line" />
+      </ui-button>
+    </div>
   </edit-interaction-base>
 </template>
 <script setup>

+ 22 - 5
src/locales/en/blocks.json

@@ -129,6 +129,7 @@
       "get-text": {
         "name": "Get text",
         "description": "Get text from an element",
+        "checkbox": "Save data",
         "prefixText": {
           "placeholder": "Text prefix",
           "title": "Add prefix to the text"
@@ -136,6 +137,11 @@
         "suffixText": {
           "placeholder": "Text suffix",
           "title": "Add suffix to the text"
+        },
+        "extraRow": {
+          "checkbox": "Add extra row",
+          "placeholder": "Value",
+          "title": "Value of the extra row"
         }
       },
       "export-data": {
@@ -172,7 +178,12 @@
         "forms": {
           "name": "Attribute name",
           "checkbox": "Save data",
-          "column": "Select column"
+          "column": "Select column",
+          "extraRow": {
+            "checkbox": "Add extra row",
+            "placeholder": "Value",
+            "title": "Value of the extra row"
+          }
         }
       },
       "forms": {
@@ -190,9 +201,15 @@
             "label": "Typing delay (millisecond)(0 to disable)"
           }
         },
-        "select": { "name": "Select" },
-        "radio": { "name": "Radio" },
-        "checkbox": { "name": "Checkbox" }
+        "select": {
+          "name": "Select"
+        },
+        "radio": {
+          "name": "Radio"
+        },
+        "checkbox": {
+          "name": "Checkbox"
+        }
       },
       "repeat-task": {
         "name": "Repeat task",
@@ -316,4 +333,4 @@
       }
     }
   }
-}
+}

+ 13 - 2
src/locales/fr/blocks.json

@@ -129,6 +129,7 @@
       "get-text": {
         "name": "Obtenir le texte",
         "description": "Obtenir le texte d'un élément",
+        "checkbox": "Enregistrer les données",
         "prefixText": {
           "placeholder": "Préfixe du texte",
           "title": "Ajouter un préfixe au texte"
@@ -136,6 +137,11 @@
         "suffixText": {
           "placeholder": "Suffixe du texte",
           "title": "Ajouter un suffixe au texte"
+        },
+        "extraRow": {
+          "checkbox": "Ajouter une ligne supplémentaire",
+          "placeholder": "Valeur",
+          "title": "Valeur de la ligne supplémentaire"
         }
       },
       "export-data": {
@@ -172,7 +178,12 @@
         "forms": {
           "name": "Nom de l'attribut",
           "checkbox": "Enregistrer des données",
-          "column": "Sélectionnez la colonne"
+          "column": "Sélectionnez la colonne",
+          "extraRow": {
+            "checkbox": "Ajouter une ligne supplémentaire",
+            "placeholder": "Valeur",
+            "title": "Valeur de la ligne supplémentaire"
+          }
         }
       },
       "forms": {
@@ -321,4 +332,4 @@
       }
     }
   }
-}
+}

+ 1 - 0
src/utils/reference-data.js

@@ -50,6 +50,7 @@ export default function (block, data) {
     'selector',
     'prefixText',
     'suffixText',
+    'extraRowValue',
   ];
   let replacedBlock = block;
 

+ 6 - 0
src/utils/shared.js

@@ -226,6 +226,9 @@ export const tasks = {
       regexExp: ['g'],
       dataColumn: '',
       saveData: true,
+      addExtraRow: false,
+      extraRowValue: '',
+      extraRowDataColumn: '',
     },
   },
   'export-data': {
@@ -306,6 +309,9 @@ export const tasks = {
       attributeName: '',
       dataColumn: '',
       saveData: true,
+      addExtraRow: false,
+      extraRowValue: '',
+      extraRowDataColumn: '',
     },
   },
   forms: {