-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' to release WDC 2.1
# Conflicts: # README.md # Simulator/tests/unit/components.js
- Loading branch information
Showing
31 changed files
with
1,624 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.