Skip to content

Commit

Permalink
Merge branch 'dev' to release WDC 2.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	Simulator/tests/unit/components.js
  • Loading branch information
lbrendanl committed Nov 3, 2016
2 parents ac5696b + 2554cb3 commit 6e2075a
Show file tree
Hide file tree
Showing 31 changed files with 1,624 additions and 445 deletions.
2 changes: 1 addition & 1 deletion Examples/html/IncrementalRefreshConnector.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.0.latest.js" type="text/javascript"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.1.1.js" type="text/javascript"></script>
<script src="../js/IncrementalRefreshConnector.js" type="text/javascript"></script>

</head>
Expand Down
2 changes: 1 addition & 1 deletion Examples/html/MadMoneyScraper.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.0.latest.js" type="text/javascript"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.1.1.js" type="text/javascript"></script>
<script src="../js/MadMoneyScraper.js" type="text/javascript"></script>

</head>
Expand Down
53 changes: 53 additions & 0 deletions Examples/html/StandardConnectionsExample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Standard Connections Placeholder Example</title>
<!-- In order to use promises, like this example, you will need to include this polyfill to add promises
functionality to the built in Tableau WDC browser (it does not have ES6 functionality by default) -->
<script src="https://www.promisejs.org/polyfills/promise-7.0.4.min.js"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.1.1.js" type="text/javascript"></script>
<script src="../js/StandardConnectionsExample.js"></script>
<style>
* {
padding: 0px;
margin: 0px;
font-family: Arial, sans-serif;
color: #1c1c1c;
}
body {
background-color: #f5f5f5;
text-align: center;
}
h1 {
margin-top: 30px;
font-weight: normal;
margin-bottom: 15px;
}
p {
margin-bottom: 15px;
line-height: 1.4;
}
button {
padding: 6px 12px;
background-color: #5cb85c;
border: 2px solid #4cae4c;
color: white;
border-radius: 4px;
margin: 0 auto;
font-size: 1.2em;
transition: background-color .4s, border-color .4s;
}
button:hover{
cursor: pointer;
background-color: #3c9e3c;
border-color: #3c9e3c;
}
</style>
</head>
<body>
<h1>JSON Placeholder Web Data Connector <br> Standard Connections</h1>
<p>Example Web Data Connector demonstrating the Standard Connections feature <br>using the <a href="http://jsonplaceholder.typicode.com/">JSON Placeholder REST service</a>.</p>
<button id="submitButton" onclick="send()">Get Data</button>
</body>
</html>
2 changes: 1 addition & 1 deletion Examples/html/StockQuoteConnector_promises.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.0.latest.js" type="text/javascript"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.1.1.js" type="text/javascript"></script>
<script src="../js/es6-promise.min.js" type="text/javascript"></script>
<script src="../js/StockQuoteConnector_promises.js" type="text/javascript"></script>

Expand Down
2 changes: 1 addition & 1 deletion Examples/html/earthquakeMultilingual.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

<script src="https://connectors.tableau.com/libs/tableauwdc-2.0.latest.js" type="text/javascript"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.1.1.js" type="text/javascript"></script>
<script src="../js/earthquakeMultilingual.js" type="text/javascript"></script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion Examples/html/earthquakeMultitable.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

<script src="https://connectors.tableau.com/libs/tableauwdc-2.0.latest.js" type="text/javascript"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.1.1.js" type="text/javascript"></script>
<script src="../js/earthquakeMultitable.js" type="text/javascript"></script>
</head>

Expand Down
2 changes: 1 addition & 1 deletion Examples/html/earthquakeUSGS.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

<script src="https://connectors.tableau.com/libs/tableauwdc-2.0.latest.js" type="text/javascript"></script>
<script src="https://connectors.tableau.com/libs/tableauwdc-2.1.1.js" type="text/javascript"></script>
<script src="../js/earthquakeUSGS.js" type="text/javascript"></script>
</head>

Expand Down
97 changes: 97 additions & 0 deletions Examples/js/StandardConnectionsExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Example of Standard Connections in Web Data Connectors using JSONPlaceholder JSON endpoints
// Tableau 10.1 - WDC API v2.1

// Define our Web Data Connector
(function(){
var myConnector = tableau.makeConnector();
myConnector.getSchema = function(schemaCallback) {
// Create a promise to get our Standard Connections List from a JSON file. This increases code readability since we
// no longer need to define the lengthy object within our javascript itself.
var standardConnections = new Promise(function(resolve, reject) {
loadJSON("StandardConnectionsData", function(json) {
var obj = JSON.parse(json);
var connectionList = [];
for (var connection in obj.connections) {
connectionList.push(obj.connections[connection]);
}
resolve(connectionList);
}, true);
});
// Create a promise to get our table schema info as well, just like above
var tables = new Promise(function(resolve, reject) {
loadJSON("StandardConnectionsTableInfoData", function(json) {
var obj = JSON.parse(json);
var tableList = [];
for (var table in obj.tables) {
tableList.push(obj.tables[table]);
}
resolve(tableList);
}, true);
});
// Once all our promises are resolved, we can call the schemaCallback to send this info to Tableau
Promise.all([tables, standardConnections]).then(function(data) {
schemaCallback(data[0], data[1]);
});
}

myConnector.getData = function(table, doneCallback) {
// Load our data from the API. Multiple tables for WDC work by calling getData multiple times with a different id
// so we want to make sure we are getting the correct table data per getData call
loadJSON(table.tableInfo.id, function(data) {
var obj = JSON.parse(data);
var tableData = [];
// Iterate through the data and build our table
for (var i = 0; i < obj.length; i++) {
tableEntry = {};
var ref = obj[i];
// We can use this handy shortcut because our JSON column names match our schema's column names perfectly
Object.getOwnPropertyNames(ref).forEach(function(val, idx, array){
// Handle specific cases by checking the name of the property
switch(val) {
case "address":
tableEntry.lat = ref[val].geo.lat;
tableEntry.lng = ref[val].geo.lng;
tableEntry.zipcode = ref[val].zipcode;
break;
case "company":
tableEntry.companyname = ref[val].name;
tableEntry.catchPhrase = ref[val].catchPhrase;
tableEntry.bs = ref[val].bs;
break;
default:
tableEntry[val] = ref[val];
}
});
tableData.push(tableEntry);
}
// Once we have all the data parsed, we send it to the Tableau table object
table.appendRows(tableData);
doneCallback();
});
}
tableau.registerConnector(myConnector);
})();


// Helper function that loads a json and a callback to call once that file is loaded

function loadJSON(path, cb, isLocal) {
var obj = new XMLHttpRequest();
obj.overrideMimeType("application/json");
if(isLocal) {
obj.open("GET", "../json/" + path + ".json", true);
}
else {
obj.open("GET", "https://crossorigin.me/http://jsonplaceholder.typicode.com/" + path, true);
}
obj.onreadystatechange = function() {
if (obj.readyState == 4 && obj.status == "200"){
cb(obj.responseText);
}
}
obj.send(null);
}

function send() {
tableau.submit();
}
140 changes: 140 additions & 0 deletions Examples/json/StandardConnectionsData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"connections" : [
{
"alias" : "User and Their Photos",
"tables" : [
{ "id" : "users",
"alias" : "Users" },
{ "id" : "albums",
"alias" : "Albums" },
{ "id" : "photos",
"alias" : "Photos" }
],
"joins" : [
{
"left" : {
"tableAlias" : "Users",
"columnId" : "id"
},
"right" : {
"tableAlias" : "Albums",
"columnId" : "userId"
},
"joinType" : "inner"
},{
"left" : {
"tableAlias" : "Albums",
"columnId" : "id"
},
"right" : {
"tableAlias" : "Photos",
"columnId" : "albumId"
},
"joinType" : "inner"
}
]
},{
"alias" : "Comments on User's Posts",
"tables" : [
{ "id" : "users",
"alias" : "Users" },
{ "id" : "posts",
"alias" : "Posts" },
{ "id" : "comments",
"alias" : "Comments" }
],
"joins" : [
{
"left" : {
"tableAlias" : "Users",
"columnId" : "id"
},
"right" : {
"tableAlias" : "Posts",
"columnId" : "userId"
},
"joinType" : "inner"
},{
"left" : {
"tableAlias" : "Posts",
"columnId" : "id"
},
"right" : {
"tableAlias" : "Comments",
"columnId" : "postId"
},
"joinType" : "inner"
}
]
},{
"alias" : "Complete Data Joins",
"tables" : [
{ "id" : "users",
"alias" : "Users" },
{ "id" : "albums",
"alias" : "Albums" },
{ "id" : "photos",
"alias" : "Photos" },
{ "id" : "posts",
"alias" : "Posts" },
{ "id" : "comments",
"alias" : "Comments" },
{ "id" : "todos",
"alias" : "Todos" }
],
"joins" : [
{
"left" : {
"tableAlias" : "Users",
"columnId" : "id"
},
"right" : {
"tableAlias" : "Albums",
"columnId" : "userId"
},
"joinType" : "inner"
},{
"left" : {
"tableAlias" : "Albums",
"columnId" : "id"
},
"right" : {
"tableAlias" : "Photos",
"columnId" : "albumId"
},
"joinType" : "inner"
},{
"left" : {
"tableAlias" : "Users",
"columnId" : "id"
},
"right" : {
"tableAlias" : "Posts",
"columnId" : "userId"
},
"joinType" : "inner"
},{
"left" : {
"tableAlias" : "Posts",
"columnId" : "id"
},
"right" : {
"tableAlias" : "Comments",
"columnId" : "postId"
},
"joinType" : "inner"
},{
"left" : {
"tableAlias" : "Users",
"columnId" : "id"
},
"right" : {
"tableAlias" : "Todos",
"columnId" : "userId"
},
"joinType" : "inner"
}
]
}
]
}
Loading

0 comments on commit 6e2075a

Please sign in to comment.