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 2022/06/03 20:11:55 UTC

[airavata-django-portal] 02/08: AIRAVATA-3564 Add new fields and save

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

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

commit ff79032b0730c8e6b7362b958d629eb6cc334301
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri Jun 3 09:42:12 2022 -0400

    AIRAVATA-3564 Add new fields and save
---
 .../users/ExtendedUserProfileContainer.vue         | 21 +++++++---------
 .../ExtendedUserProfileFieldEditor.vue             | 20 +++++++--------
 .../src/store/modules/extendedUserProfile.js       | 29 ++++++++++++++++++++--
 .../api/static/django_airavata_api/js/index.js     |  2 ++
 4 files changed, 48 insertions(+), 24 deletions(-)

diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/ExtendedUserProfileContainer.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/ExtendedUserProfileContainer.vue
index 2bd39ae6..118655c2 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/ExtendedUserProfileContainer.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/ExtendedUserProfileContainer.vue
@@ -12,7 +12,12 @@
     </div>
     <div class="row">
       <div class="col">
-        <b-button variant="primary" @click="addField"> Add Field </b-button>
+        <b-dropdown text="Add Field">
+          <b-dropdown-item @click="addField('text')">Text</b-dropdown-item>
+          <b-dropdown-item @click="addField('single_choice')">Single Choice</b-dropdown-item>
+          <b-dropdown-item @click="addField('multi_choice')">Multi Choice</b-dropdown-item>
+          <b-dropdown-item @click="addField('user_agreement')">User Agreement</b-dropdown-item>
+        </b-dropdown>
       </div>
     </div>
     <div class="row mt-4">
@@ -30,7 +35,6 @@ export default {
   components: { ExtendedUserProfileFieldEditor },
   data() {
     return {
-      fields: [],
     };
   },
   created() {
@@ -40,18 +44,11 @@ export default {
     ...mapActions("extendedUserProfile", [
       "loadExtendedUserProfileFields",
       "saveExtendedUserProfileFields",
+      "addExtendedUserProfileField",
     ]),
-    addField() {
+    addField(field_type) {
       // TODO: post an empty field to the API
-      this.fields.push({
-        id: null,
-        name: "",
-        description: "",
-        type: "text",
-        required: false,
-        options: null,
-        links: null,
-      });
+      this.addExtendedUserProfileField({field_type})
     },
     addOption(field) {
       if (!field.options) {
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/field-editors/ExtendedUserProfileFieldEditor.vue b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/field-editors/ExtendedUserProfileFieldEditor.vue
index 5b19426b..99ae9765 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/field-editors/ExtendedUserProfileFieldEditor.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/users/field-editors/ExtendedUserProfileFieldEditor.vue
@@ -1,5 +1,5 @@
 <template>
-  <b-card :title="'Field: ' + name">
+  <b-card :title="title">
     <b-form-group label="Name">
       <b-form-input v-model="name" />
     </b-form-group>
@@ -79,15 +79,15 @@ export default {
         this.setRequired({ value, field: this.extendedUserProfileField });
       },
     },
-    // TODO: probably don't need these
-    fieldTypeOptions() {
-      return [
-        { value: "text", text: "Text" },
-        { value: "single_choice", text: "Single Choice" },
-        { value: "multi_choice", text: "Multi Choice" },
-        { value: "user_agreement", text: "User Agreement" },
-      ];
-    },
+    title() {
+      const fieldTypes = {
+        text: "Text",
+        single_choice: "Single Choice",
+        multi_choice: "Multi Choice",
+        user_agreement: "User Agreement",
+      }
+      return `${fieldTypes[this.extendedUserProfileField.field_type]}: ${this.name}`;
+    }
   },
   methods: {
     ...mapMutations("extendedUserProfile", ["setName", "setHelpText", "setRequired"]),
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/store/modules/extendedUserProfile.js b/django_airavata/apps/admin/static/django_airavata_admin/src/store/modules/extendedUserProfile.js
index decd3d89..b3b7c4ec 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/store/modules/extendedUserProfile.js
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/store/modules/extendedUserProfile.js
@@ -1,4 +1,4 @@
-import { services } from "django-airavata-api";
+import { models, services } from "django-airavata-api";
 
 const state = () => ({
   extendedUserProfileFields: null,
@@ -13,8 +13,10 @@ const actions = {
     const extendedUserProfileFields = await services.ExtendedUserProfileFieldService.list();
     commit("setExtendedUserProfileFields", { extendedUserProfileFields });
   },
-  async saveExtendedUserProfileFields({ dispatch, state }) {
+  async saveExtendedUserProfileFields({ commit, dispatch, state }) {
+    let order = 1;
     for (const field of state.extendedUserProfileFields) {
+      commit("setOrder", {field, order: order++});
       // Create or update each field
       if (field.id) {
         await services.ExtendedUserProfileFieldService.update({
@@ -28,6 +30,20 @@ const actions = {
     // Reload the fields
     dispatch("loadExtendedUserProfileFields");
   },
+  async addExtendedUserProfileField({ state, commit }, { field_type }) {
+    const field = new models.ExtendedUserProfileField({
+      field_type,
+      name: `New Field ${state.extendedUserProfileFields.length + 1}`,
+      description: "",
+      help_text: "",
+      required: true,
+      links: [],
+      other: false,
+      choices: [],
+      checkbox_label: "",
+    });
+    commit("addExtendedUserProfileField", { field });
+  },
 };
 
 function getField(state, field) {
@@ -54,6 +70,15 @@ const mutations = {
   setRequired(state, { value, field }) {
     setFieldProp(state, field, "required", value);
   },
+  setOrder(state, {order, field}) {
+    setFieldProp(state, field, 'order', order);
+  },
+  addExtendedUserProfileField(state, { field }) {
+    if (!state.extendedUserProfileFields) {
+      state.extendedUserProfileFields = [];
+    }
+    state.extendedUserProfileFields.push(field);
+  },
 };
 
 export default {
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/index.js b/django_airavata/apps/api/static/django_airavata_api/js/index.js
index e177e42f..8aa2bfc3 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/index.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/index.js
@@ -18,6 +18,7 @@ import DataType from "./models/DataType";
 import Experiment from "./models/Experiment";
 import ExperimentSearchFields from "./models/ExperimentSearchFields";
 import ExperimentState from "./models/ExperimentState";
+import ExtendedUserProfileField from "./models/ExtendedUserProfileField";
 import FullExperiment from "./models/FullExperiment";
 import Group from "./models/Group";
 import GroupComputeResourcePreference from "./models/GroupComputeResourcePreference";
@@ -80,6 +81,7 @@ const models = {
   Experiment,
   ExperimentSearchFields,
   ExperimentState,
+  ExtendedUserProfileField,
   FullExperiment,
   Group,
   GroupComputeResourcePreference,