airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata-django-portal] 10/13: AIRAVATA-2727 Routes for new GroupResourceProfile, ComputePrefs
Date Tue, 14 Aug 2018 19:51:52 GMT
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 182d9e74024cf5085e1db3415fcbca3236a48c1b
Author: Marcus Christie <machrist@iu.edu>
AuthorDate: Tue Aug 14 11:07:07 2018 -0400

    AIRAVATA-2727 Routes for new GroupResourceProfile, ComputePrefs
---
 .../ComputePreference.vue                          | 22 +++++++--
 .../ComputePreferences.vue                         | 55 ----------------------
 .../GroupComputeResourcePreference.vue             | 43 ++++++++---------
 .../ComputeResourcePreferenceDashboard.vue         |  6 +--
 .../static/django_airavata_admin/src/router.js     |  8 ++++
 .../js/models/GroupResourceProfile.js              | 25 ++--------
 6 files changed, 51 insertions(+), 108 deletions(-)

diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/ComputePreference.vue
b/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/ComputePreference.vue
index d3a1491..5d8edda 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/ComputePreference.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/ComputePreference.vue
@@ -165,14 +165,14 @@
         let groupResourceProfile = this.groupResourceProfile.clone();
         groupResourceProfile.mergeComputeResourcePreference(this.data, this.localComputeResourcePolicy,
this.localBatchQueueResourcePolicies);
         // TODO: success and error handling are the same so we can just combine those
-        if (groupResourceProfile.groupResourceProfileId) {
-          DjangoAiravataAPI.services.ServiceFactory.service("GroupResourceProfiles").update({data:
groupResourceProfile, lookup: groupResourceProfile.groupResourceProfileId})
+        if (this.id) {
+          DjangoAiravataAPI.services.ServiceFactory.service("GroupResourceProfiles").update({data:
groupResourceProfile, lookup: this.id})
             .then(groupResourceProfile => {
               // Navigate back to GroupResourceProfile with success message
               this.$router.push({
                 name: 'group_resource_preference', params: {
                   value: groupResourceProfile,
-                  id: groupResourceProfile.groupResourceProfileId
+                  id: this.id
                 }
               });
             })
@@ -198,8 +198,22 @@
         }
       },
       cancel: function() {
-        this.$router.push({ name: 'group_resource_preference', params: {id: this.id}});
+        if (this.id) {
+          this.$router.push({ name: 'group_resource_preference', params: {id: this.id}});
+        } else {
+          this.$router.push({ name: 'new_group_resource_preference', params: {value: this.groupResourceProfile}});
+        }
       }
     },
+    beforeRouteEnter: function(to, from, next) {
+      // If we don't have the Group Resource Profile id or instance, then the
+      // Group Resource Profile wasn't created and we need to just go back to
+      // the dashboard
+      if (!to.params.id && !to.params.groupResourceProfile) {
+        next({name: 'group_resource_preference_dashboard'});
+      } else {
+        next();
+      }
+    }
   }
 </script>
\ No newline at end of file
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/ComputePreferences.vue
b/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/ComputePreferences.vue
deleted file mode 100644
index f18e5bf..0000000
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/ComputePreferences.vue
+++ /dev/null
@@ -1,55 +0,0 @@
-<template>
-  <array-component-view v-bind:homeAction="createHomeAction()" v-bind:maxIndex="data.computePreferences.length-1"
-                        v-model="currentIndex">
-      <compute-preference v-model="data.computePreferences[currentIndex]" v-bind:key="currentIndex"
v-bind:newCreation="data.computePreferences[currentIndex].groupResourceProfileId == null"></compute-preference>
-  </array-component-view>
-</template>
-
-<script>
-  import ArrayComponentView from '../../commons/ArrayComponentView'
-  import ComputePreference from './ComputePreference';
-  import VModelMixin from '../../commons/vmodel_mixin'
-
-  export default {
-    name: "compute-preferences",
-    components: {
-      ArrayComponentView,
-      ComputePreference
-    },
-    mixins: [VModelMixin],
-    props: {
-      index: {
-        type: Number,
-        default: 0
-      },
-      newCreation:{
-        type:Boolean,
-        default:false
-      }
-    },
-    data: function () {
-      return {
-        currentIndex: this.index
-      }
-    },
-    methods: {
-      createMovableAction: function () {
-        return (index) => {
-          this.currentIndex = index
-        }
-      },
-      createHomeAction: function () {
-        return () => this.$router.push({
-          name: 'group_resource_preference', params: {
-            value: this.data,
-            transform:false
-          }
-        })
-      }
-    },
-  }
-</script>
-
-<style scoped>
-
-</style>
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/GroupComputeResourcePreference.vue
b/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/GroupComputeResourcePreference.vue
index 46b3cd3..e62dc28 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/GroupComputeResourcePreference.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/admin/group_resource_preferences/GroupComputeResourcePreference.vue
@@ -70,12 +70,11 @@
       },
     },
     mounted: function () {
-      if (this.value.groupResourceProfileId) {
-        services.ServiceFactory.service("SharedEntities").retrieve({lookup: this.value.groupResourceProfileId})
-          .then(sharedEntity => this.sharedEntity = sharedEntity);
-      } else if (this.id) {
-        services.ServiceFactory.service("GroupResourceProfiles").retrieve({lookup: this.id})
-          .then(grp => this.data = grp);
+      if (this.id) {
+        if (!this.value.groupResourceProfileId) {
+          services.ServiceFactory.service("GroupResourceProfiles").retrieve({lookup: this.id})
+            .then(grp => this.data = grp);
+        }
         services.ServiceFactory.service("SharedEntities").retrieve({lookup: this.id})
           .then(sharedEntity => this.sharedEntity = sharedEntity);
       }
@@ -130,13 +129,14 @@
     methods: {
       saveGroupResourceProfile: function () {
         var persist = null;
-        if (this.data.groupResourceProfileId) {
-          persist = this.service.update({data: this.data, lookup: this.data.groupResourceProfileId});
+        if (this.id) {
+          persist = this.service.update({data: this.data, lookup: this.id});
         } else {
           persist = this.service.create({data: this.data})
             .then((data) => {
               // Save sharing settings too
-              return this.$refs.shareButton.mergeAndSave(data.groupResourceProfileId);
+              const groupResourceProfileId = data.groupResourceProfileId;
+              return this.$refs.shareButton.mergeAndSave(groupResourceProfileId);
             });
         }
         // TODO: handle errors
@@ -148,16 +148,7 @@
         let computeResourcePreference = this.data.computePreferences.find(pref => pref.computeResourceId
=== computeResourceId);
         const computeResourcePolicy = this.data.getComputeResourcePolicy(computeResourceId);
         const batchQueueResourcePolicies = this.data.getBatchQueueResourcePolicies(computeResourceId);
-        this.$router.push({
-          name: 'compute_preference', params: {
-            value: computeResourcePreference,
-            id: this.data.groupResourceProfileId,
-            host_id: computeResourceId,
-            groupResourceProfile: this.data,
-            computeResourcePolicy: computeResourcePolicy,
-            batchQueueResourcePolicies: batchQueueResourcePolicies,
-          }
-        });
+        this.navigateToComputeResourcePreference(computeResourcePreference, computeResourcePolicy,
batchQueueResourcePolicies);
       },
       getComputeResourceName: function (computeResourceId) {
         // TODO: load compute resources to get the real name
@@ -173,14 +164,18 @@
         const computeResourcePreference = new models.GroupComputeResourcePreference();
         const computeResourceId = this.selectedComputeResource;
         computeResourcePreference.computeResourceId = computeResourceId;
+        this.navigateToComputeResourcePreference(computeResourcePreference);
+      },
+      navigateToComputeResourcePreference: function(computeResourcePreference, computeResourcePolicy=null,
batchQueueResourcePolicies=null) {
+        const routeName = (this.id) ? 'compute_preference' : 'compute_preference_for_new_group_resource_profile';
         this.$router.push({
-          name: 'compute_preference', params: {
+          name: routeName, params: {
             value: computeResourcePreference,
-            id: this.data.groupResourceProfileId,
-            host_id: computeResourceId,
+            id: this.id,
+            host_id: computeResourcePreference.computeResourceId,
             groupResourceProfile: this.data,
-            computeResourcePolicy: null,
-            batchQueueResourcePolicies: null,
+            computeResourcePolicy: computeResourcePolicy,
+            batchQueueResourcePolicies: batchQueueResourcePolicies,
           }
         });
       }
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/components/dashboards/ComputeResourcePreferenceDashboard.vue
b/django_airavata/apps/admin/static/django_airavata_admin/src/components/dashboards/ComputeResourcePreferenceDashboard.vue
index 87896c8..8fc5470 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/components/dashboards/ComputeResourcePreferenceDashboard.vue
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/components/dashboards/ComputeResourcePreferenceDashboard.vue
@@ -56,10 +56,8 @@
       },
       newGroupResourcePreference: function () {
         this.$router.push({
-          name: 'group_resource_preference', params: {
-            newCreation: true
-          }
-        })
+          name: 'new_group_resource_preference'
+        });
       },
       loadGroupResourceProfiles: function () {
         services.GroupResourceProfileService.list()
diff --git a/django_airavata/apps/admin/static/django_airavata_admin/src/router.js b/django_airavata/apps/admin/static/django_airavata_admin/src/router.js
index 6d54012..4f883d5 100644
--- a/django_airavata/apps/admin/static/django_airavata_admin/src/router.js
+++ b/django_airavata/apps/admin/static/django_airavata_admin/src/router.js
@@ -34,10 +34,18 @@ const routes = [
   {path: '/admin', component: AdminDashboard, name: "admin_dashboard"},
   {path: '/experiments', component: ExperimentsDashboard, name: 'experiments_dashboard'},
   {
+    path: '/group-resource-profiles/new', component: GroupComputeResourcePreference, name:
'new_group_resource_preference',
+    props: true
+  },
+  {
     path: '/group-resource-profiles/:id', component: GroupComputeResourcePreference, name:
'group_resource_preference',
     props: true
   },
   {
+    path: '/group-resource-profiles/new/compute-preferences/:host_id', component: ComputePreference,
name: 'compute_preference_for_new_group_resource_profile',
+    props: true
+  },
+  {
     path: '/group-resource-profiles/:id/compute-preferences/:host_id', component: ComputePreference,
name: 'compute_preference',
     props: true
   },
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/models/GroupResourceProfile.js
b/django_airavata/apps/api/static/django_airavata_api/js/models/GroupResourceProfile.js
index 259cfcf..34d664e 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/models/GroupResourceProfile.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/models/GroupResourceProfile.js
@@ -11,16 +11,19 @@ const FIELDS = [
          name: 'computePreferences',
          type: GroupComputeResourcePreference,
          list: true,
+         default: BaseModel.defaultNewInstance(Array),
      },
      {
          name: 'computeResourcePolicies',
          type: ComputeResourcePolicy,
          list: true,
+         default: BaseModel.defaultNewInstance(Array),
      },
      {
          name: 'batchQueueResourcePolicies',
          type: BatchQueueResourcePolicy,
-         list: true
+         list: true,
+         default: BaseModel.defaultNewInstance(Array),
      },
      {
          name: 'creationTime',
@@ -43,30 +46,10 @@ export default class GroupResourceProfile extends BaseModel {
         return this.computeResourcePolicies.find(pol => pol.computeResourceId === computeResourceId);
     }
 
-    setComputeResourcePolicy(computeResourcePolicy) {
-        const currentPolicy = this.getComputeResourcePolicy(computeResourcePolicy.computeResourceId);
-        if (currentPolicy) {
-            Object.assign(currentPolicy, computeResourcePolicy);
-        } else {
-            this.computeResourcePolicies.push(computeResourcePolicy);
-        }
-    }
-
     getBatchQueueResourcePolicies(computeResourceId) {
         return this.batchQueueResourcePolicies.filter(pol => pol.computeResourceId ===
computeResourceId);
     }
 
-    setComputeResourcePolicy(batchQueueResourcePolicies) {
-        for (let newPolicy of batchQueueResourcePolicies) {
-            const currentPolicy = this.batchQueueResourcePolicies.find(pol => pol.resourcePolicyId
=== newPolicy.resourcePolicyId);
-            if (currentPolicy) {
-                Object.assign(currentPolicy, newPolicy);
-            } else {
-                this.batchQueueResourcePolicies.push(newPolicy);
-            }
-        }
-    }
-
     mergeComputeResourcePreference(computeResourcePreference, computeResourcePolicy, batchQueueResourcePolicies)
{
         // merge/add computeResourcePreference and computeResourcePolicy
         const existingComputeResourcePreference = this.computePreferences.find(pref =>
pref.computeResourceId === computeResourcePreference.computeResourceId);


Mime
View raw message