Class LABKEY.Exp.Data
Extends
LABKEY.Exp.ExpObject, LABKEY.Exp.RunItem.
The Experiment Data class describes the data input or output of a LABKEY.Exp.Run. This typically
corresponds to an assay results file uploaded to the LabKey server.
To create a LABKEY.Exp.Data object, upload a file using to the "assayFileUpload" action of the "assay" controller.
Additional Documentation:
Defined in: Experiment.js.
Constructor Attributes | Constructor Name and Description |
---|---|
LABKEY.Exp.Data(config)
The Data constructor is private.
|
Config Attributes | Config Name and Description |
---|---|
The DataClass the data belongs to.
|
|
The row id of the DataClass.
|
|
The name of the DataClass.
|
|
The local file url of the uploaded file.
|
Method Attributes | Method Name and Description |
---|---|
getContent(config)
Retrieves the contents of the data object from the server.
|
Class Detail
LABKEY.Exp.Data(config)
The Data constructor is private.
To create a LABKEY.Exp.Data object, upload a file using to the "assayFileUpload" action of
the "assay" controller.
// To perform a file upload over HTTP: <form id="upload-run-form" enctype="multipart/form-data" method="POST"> <div id="upload-run-button"></div> </form> <script type="text/javascript"> LABKEY.Utils.requiresScript("FileUploadField.js"); // Optional - specify a protocolId so that the Exp.Data object is assigned the related LSID namespace. var url = LABKEY.ActionURL.buildURL("assay", "assayFileUpload", LABKEY.ActionURL.getContainer(), { protocolId: 50 }); Ext.onReady(function() { var form = new Ext.form.BasicForm( Ext.get("upload-run-form"), { fileUpload: true, frame: false, url: url, listeners: { actioncomplete : function (form, action) { alert('Upload successful!'); var data = new LABKEY.Exp.Data(action.result); // now add the data as a dataInput to a LABKEY.Exp.Run var run = new LABKEY.Exp.Run(); run.name = data.name; run.dataInputs = [ data ]; // add the new run to a LABKEY.Exp.Batch object and // fetch the parsed file contents from the data object // using the LABKEY.Exp.Data#getContent() method. }, actionfailed: function (form, action) { alert('Upload failed!'); } } }); var uploadField = new Ext.form.FileUploadField({ id: "upload-run-field", renderTo: "upload-run-button", buttonText: "Upload Data...", buttonOnly: true, buttonCfg: { cls: "labkey-button" }, listeners: { "fileselected": function (fb, v) { form.submit(); } } }); }); </script> // Or, to upload the contents of a JavaScript string as a file: <script type="text/javascript"> Ext.onReady(function() { LABKEY.Ajax.request({ url: LABKEY.ActionURL.buildURL("assay", "assayFileUpload"), params: { fileName: 'test.txt', fileContent: 'Some text!' }, success: function(response, options) { var data = new LABKEY.Exp.Data(Ext.util.JSON.decode(response.responseText)); // now add the data as a dataInput to a LABKEY.Exp.Run var run = new LABKEY.Exp.Run(); run.name = data.name; run.dataInputs = [ data ]; // add the new run to a LABKEY.Exp.Batch object here } }); }); </script>
- Parameters:
- {Object} config Optional
- Private configuration object. Inherits the config properties of LABKEY.Exp.ExpObject.
Config Detail
{Object}
config.dataClass
The DataClass the data belongs to. With the following properties:
{Integer}
config.dataClass.id
The row id of the DataClass.
{String}
config.dataClass.name
The name of the DataClass.
{String}
config.dataFileURL
The local file url of the uploaded file.
Method Detail
getContent(config)
Retrieves the contents of the data object from the server.
- Parameters:
- config
- An object that contains the following configuration parameters
- {object} config.scope Optional
- A scoping object for the success and error callback functions (default to this).
- {function} config.success
- The function to call when the function finishes successfully.
This function will be called with the parameters:
- content The type of the content varies based on the format requested.
- format The format used in the request
- response The original response
- {function} config.failure Optional
- The function to call if this function encounters an error.
This function will be called with the following parameters:
- errorInfo: An object with a property called "exception," which contains the error message.
- format The format used in the request
- response The original response
- {String} config.format Optional
- How to format the content. Defaults to plaintext, supported for text/* MIME types,
including .html, .xml, .tsv, .txt, and .csv. Use 'jsonTSV' to get a JSON version of the .xls, .tsv, .or .csv
files, the structure of which matches the argument to convertToExcel in LABKEY.Utils.
- fileName: the name of the file
- sheets: an array of the sheets in the file. Text file types will have a single sheet named 'flat'.
- name: the name of the sheet
- values: two-dimensional array of all the cells in the worksheet. First array index is row, second is column
Use 'jsonTSVExtended' to get include metadata in the 2D array of cells. Text file types will not supply additional metadata but populate the 'value' attribute in the map. Excel files will include:- value: the string, boolean, date, or number in the cell
- timeOnly: whether the date part should be ignored for dates
- formatString: the Java format string to be used to render the value for dates and numbers
- formattedValue: the formatted string for that value for all value types
- error: true if this cell has an error
- formula: if the cell's value is specified by a formula, the text of the formula
Use 'jsonTSVIgnoreTypes' to always return string values for all cells, regardless of type.
An example of the results for a request for 'jsonTsv' format:{ "sheets": [ { "name": "Sheet1", "data": [ [ "StringColumn", "DateColumn" ], [ "Hello", "16 May 2009 17:00:00" ], [ "world", "12/21/2008 08:45AM" ] ] }, { "name": "Sheet2", "data": [ ["NumberColumn"], [55.44], [100.34], [-1] ] }, { "name": "Sheet3", "data": [] } ], "fileName": "SimpleExcelFile.xls" }
An example of the same file in the 'jsonTSVExtended' format:{ "sheets": [ { "name": "Sheet1", "data": [ [ { "value": "StringColumn", "formattedValue": "StringColumn" }, { "value": "DateColumn", "formattedValue": "DateColumn" } ], [ { "value": "Hello", "formattedValue": "Hello" }, { "formatString": "MMMM d, yyyy", "value": "16 May 2009 17:00:00", "timeOnly": false, "formattedValue": "May 17, 2009" } ], [ { "value": "world", "formattedValue": "world" }, { "formatString": "M/d/yy h:mm a", "value": "21 Dec 2008 19:31:00", "timeOnly": false, "formattedValue": "12/21/08 7:31 PM" } ] ] }, { "name": "Sheet2", "data": [ [{ "value": "NumberColumn", "formattedValue": "NumberColumn" }], [{ "formatString": "$#,##0.00", "value": 55.44, "formattedValue": "$55.44" }], [{ "value": 100.34, "formattedValue": "100.34" }], [{ "value": -1, "formattedValue": "-1" }] ] }, { "name": "Sheet3", "data": [] } ], "fileName": "SimpleExcelFile.xls" }