Skip to content

Commit

Permalink
Merge pull request #6 from aarenson/master
Browse files Browse the repository at this point in the history
Add exportfFieldFormat, allowing users to specify whether Tableau var…
  • Loading branch information
lsgs authored Oct 8, 2018
2 parents 03bb0ba + 839aa83 commit cd25f7e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
25 changes: 23 additions & 2 deletions TableauConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function printConnectorPageContent() {
$pageTitle = $this->getSystemSettingOrDefault('connector-page-title');
$instructionText = $this->getSystemSettingOrDefault('connector-page-instruction-text');
$formatLabelText = $this->getSystemSettingOrDefault('connector-page-format-label');
$fieldFormatLabelText = $this->getSystemSettingOrDefault('connector-page-fieldformat-label');
$dagLabelText = $this->getSystemSettingOrDefault('connector-page-dag-label');
$tokenLabelText = $this->getSystemSettingOrDefault('connector-page-token-label');
$fieldListLabelText = $this->getSystemSettingOrDefault('connector-page-fieldlist-label');
Expand Down Expand Up @@ -99,6 +100,13 @@ public function printConnectorPageContent() {
<label class="radio-inline"><input type="radio" name="raworlabel" value="label">label</label>
</span>
</div>
<div class="input-group">
<span class="input-group-addon" style=""><?php echo $fieldFormatLabelText;?></span>
<span class="form-control text-left">
<label class="radio-inline"><input type="radio" name="varorlabel" value="var" checked>variable</label>
<label class="radio-inline"><input type="radio" name="varorlabel" value="label">label</label>
</span>
</div>
<div class="input-group">
<span class="input-group-addon" style=""><?php echo $dagLabelText;?></span>
<span class="form-control text-left">
Expand Down Expand Up @@ -190,6 +198,7 @@ public function printConnectorPageContent() {
type: 'flat',
fields: fieldList,
rawOrLabel: connectionData.raworlabel,
varOrLabel: connectionData.varorlabel,
rawOrLabelHeaders: 'raw',
exportCheckboxLabel: false,
exportSurveyFields: connectionData.surveyfields,
Expand Down Expand Up @@ -248,7 +257,12 @@ function buildDataSource(connectionData, response){

var f = {};
f.id = rcExportVarname;
f.alias = rcExportVarname;

if (connectionData.varorlabel==='var') {
f.alias = rcExportVarname;
} else {
f.alias = varNode.find( 'TranslatedText' ).text();
}
f.description = varNode.find( 'TranslatedText' ).text();

var dataType = 'string';
Expand All @@ -258,7 +272,10 @@ function buildDataSource(connectionData, response){
}

if (rcFType==='checkbox') {
f.description = getCheckboxChoiceLabel($response, rcExportVarname)+' | '+f.description;
if (connectionData.varorlabel==='label') {
f.alias = f.description+' (choice='+getCheckboxChoiceLabel($response, rcExportVarname)+')';
}
f.description = getCheckboxChoiceLabel($response, rcExportVarname)+' | '+f.description;
}

f.dataType = odmTypeToTableauType(dataType);
Expand Down Expand Up @@ -343,6 +360,9 @@ function getCheckboxChoiceLabel($response, rcExportVarname) {
$("#submitButton").click(function() {
var exportFormat = $("input[name=\"raworlabel\"]:checked").val();
exportFormat = (exportFormat==='label') ? exportFormat : 'raw';

var exportFieldFormat = $("input[name=\"varorlabel\"]:checked").val();
exportFieldFormat = (exportFieldFormat==='label') ? exportFieldFormat : 'var';

var includeDag = ("1" == $("input[name=\"incldag\"]:checked").val());

Expand All @@ -356,6 +376,7 @@ function getCheckboxChoiceLabel($response, rcExportVarname) {
*/
var connectionData = {
raworlabel: exportFormat,
varorlabel: exportFieldFormat,
surveyfields: false, // can't yet tell from odm xml whiat instruments are surveys
dags: includeDag,
token: $("input#token").val(),
Expand Down
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@
"type": "text",
"default": "Raw data or labels?"
},
{
"key": "connector-page-fieldformat-label",
"name": "Connector page export field format field label",
"required": true,
"allow-project-overrides": false,
"type": "text",
"default": "Variable name or field label?"
},
{
"key": "connector-page-dag-label",
"name": "Connector page include DAG field label",
Expand Down

0 comments on commit cd25f7e

Please sign in to comment.