pass the desired attribute down to the datasource
authorGil Moskowitz <gmoskowitz@xtuple.com>
Wed, 11 Jun 2014 15:37:57 +0000 (11:37 -0400)
committerGil Moskowitz <gmoskowitz@xtuple.com>
Wed, 11 Jun 2014 15:37:57 +0000 (11:37 -0400)
lib/enyo-x/source/views/workspace.js
node-datasource/routes/export.js

index 93a9684..463f4e9 100644 (file)
@@ -1059,12 +1059,12 @@ trailing:true, white:true, strict: false*/
       return true;
     },
 
-    // export the data for just one attr of the model displayed by the workspace
+    // export just one attribute of the model displayed by the workspace
     openExportTab: function (routeName, recordType, id, attr) {
       console.log('workspace exportAttr ' + recordType + '/' + attr + '(' + id + ')');
-      var query = { parameters: [{ attribute: "uuid", value: id }] };
-      // TODO: limit the data treated to just           attribute: attr
-
+      var query = { parameters: [{ attribute: "uuid", value: id }]
+                  , details: { attr: attr }
+      };
       // sending the locale information back over the wire saves a call to the db
       window.open(XT.getOrganizationPath() +
         '/%@?details={"nameSpace":"%@","type":"%@","query":%@,"culture":%@,"print":%@}'
index d0edc6f..80269c2 100644 (file)
@@ -161,8 +161,19 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
           // "export" will have to do.
         }
 
-        resultAsCsv = jsonToCsv(result.data.data);
-        res.attachment(filename + ".csv");
+        try {
+          var attr = requestDetails.query
+                   && requestDetails.query.details
+                   && requestDetails.query.details.attr;
+          if (attr) {
+            resultAsCsv = jsonToCsv(result.data.data[0][attr]);
+          } else {
+            resultAsCsv = jsonToCsv(result.data.data);
+          }
+          res.attachment(filename + ".csv");
+        } catch (error) {
+          resultAsCsv = jsonToCsv(error);
+        }
         res.send(resultAsCsv);
       }
     });