Guest User

Untitled

a guest
Nov 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. $(document).ready(function (datasource) {
  2.  
  3. var indicator = $('#CSV').val();
  4. var datasource = indicator;
  5. var myConnector = tableau.makeConnector();
  6.  
  7. $('#CSV').on('change keyup paste click', function() {
  8. indicator = $('#CSV').val();
  9. datasource = indicator;
  10. tableau.connectionData = datasource;
  11. });
  12.  
  13. myConnector.getSchema = function (schemaCallback) {
  14.  
  15. var source = tableau.connectionData;
  16.  
  17. $.ajax({
  18. url: source,
  19. dataType: "text"
  20. }).done(successFunction);
  21.  
  22. function successFunction(data) {
  23. var data = data.replace(/\"/g, "");
  24. var data = data.replace(/ /g, '');
  25. var allRows = data.split(/\r?\n|\r/);
  26. var cols = [];
  27. for (var singleRow = 0; singleRow < allRows.length; singleRow++) {
  28. var rowCells = allRows[singleRow].split(',');
  29. for (var rowCell = 0; rowCell < rowCells.length; rowCell++) {
  30. if (singleRow === 0) {
  31. x = rowCells[rowCell];
  32.  
  33. y = {
  34. id: x,
  35. alias: x,
  36. dataType: tableau.dataTypeEnum.string
  37. };
  38. cols.push(y);
  39. }
  40. }
  41. }
  42. console.log(cols);
  43. var tableInfo = {
  44. id: "WDCcsv",
  45. alias: "WDCcsv",
  46. columns: cols
  47. };
  48.  
  49. schemaCallback([tableInfo]);
  50. }
  51. };
  52.  
  53. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  54. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56.  
  57. myConnector.getData = function (table, doneCallback) {
  58.  
  59.  
  60. var source = tableau.connectionData;
  61.  
  62. $.ajax({
  63. url: source,
  64. dataType: "text",
  65. }).done(successFunction);
  66.  
  67. function successFunction(data) {
  68. var data = data.replace(/\"/g, "");
  69. var allRows = data.split(/\r?\n|\r/);
  70. var tableData = [];
  71. var cols = [];
  72. for (var singleRow = 0; singleRow < allRows.length; singleRow++) {
  73. var rowCells = allRows[singleRow].split(',');
  74. for (var rowCell = 0; rowCell < rowCells.length; rowCell++) {
  75. if (singleRow === 0) {
  76. x = rowCells[rowCell];
  77. y = {
  78. id: x,
  79. alias: x,
  80. dataType: tableau.dataTypeEnum.string
  81. };
  82. cols.push(y);
  83. }
  84. }
  85. if (singleRow != 0) {
  86. x = rowCells;
  87.  
  88. tableData.push(x);
  89. }
  90. }
  91.  
  92. table.appendRows(tableData);
  93. doneCallback();
  94. }
  95. };
  96.  
  97. tableau.registerConnector(myConnector);
  98.  
  99. $(document).ready(function () {
  100. $("#submitButton").click(function () {
  101. indicator = $('#CSV').val();
  102. datasource = indicator;
  103. tableau.connectionName = "WDCcsv";
  104. tableau.connectionData = datasource;
  105. tableau.submit();
  106. });
  107. });
  108.  
  109.  
  110.  
  111. });
Add Comment
Please, Sign In to add comment