airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata-django-portal] 12/28: AIRAVATA-2876 Reflect app input order in output, update order when saving
Date Tue, 11 Sep 2018 17:12:00 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 eaccc4a0f0ff4195a896ac9c48daca369b88a6b4
Author: Marcus Christie <machrist@iu.edu>
AuthorDate: Tue Sep 4 13:22:19 2018 -0400

    AIRAVATA-2876 Reflect app input order in output, update order when saving
---
 django_airavata/apps/api/serializers.py                  | 16 ++++++++++++++++
 .../js/models/ApplicationInterfaceDefinition.js          |  5 +++++
 2 files changed, 21 insertions(+)

diff --git a/django_airavata/apps/api/serializers.py b/django_airavata/apps/api/serializers.py
index 21b5cf7..bf16c3c 100644
--- a/django_airavata/apps/api/serializers.py
+++ b/django_airavata/apps/api/serializers.py
@@ -295,6 +295,22 @@ class ApplicationInterfaceDescriptionSerializer(
         lookup_field='applicationInterfaceId',
         lookup_url_kwarg='app_interface_id')
 
+    def to_representation(self, instance):
+        rep = super().to_representation(instance)
+        # Sort applicationInputs by 'inputOrder'
+        rep['applicationInputs'].sort(key=lambda input: input['inputOrder'])
+        return rep
+
+    def to_internal_value(self, data):
+        validated_data = super().to_internal_value(data)
+        # Update application input order based on order in array
+        app_inputs = validated_data.get('applicationInputs', [])
+        log.debug('app_inputs={}'.format(app_inputs))
+        for i in range(len(app_inputs)):
+            app_inputs[i]['inputOrder'] = i
+        log.debug('app_inputs={}'.format(app_inputs))
+        return validated_data
+
 
 class CommandObjectSerializer(CustomSerializer):
     command = serializers.CharField()
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/models/ApplicationInterfaceDefinition.js
b/django_airavata/apps/api/static/django_airavata_api/js/models/ApplicationInterfaceDefinition.js
index 0d98c9c..801ec52 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/models/ApplicationInterfaceDefinition.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/models/ApplicationInterfaceDefinition.js
@@ -12,6 +12,9 @@ const FIELDS = [
     type: 'string',
     list: true,
   },
+  // When saving/updating, the order of the inputs in the applicationInputs
+  // array determines the 'inputOrder' that will be applied to each input on the
+  // backend. Updating 'inputOrder' will have no effect.
   {
     name: 'applicationInputs',
     type: InputDataObjectType,
@@ -38,6 +41,8 @@ export default class ApplicationInterfaceDefinition extends BaseModel {
 
   constructor(data = {}) {
     super(FIELDS, data);
+    // Order application inputs
+    this.applicationInputs = this.getOrderedApplicationInputs();
   }
 
   getOrderedApplicationInputs() {


Mime
View raw message