-
Notifications
You must be signed in to change notification settings - Fork 261
Parameters sample no REACT. #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lbrendanl
merged 6 commits into
tableau:V1Samples
from
graysonarts:parameters-sample-vanilla-js
Oct 5, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a756aa7
removing old images and updating Flex
benlower a455a6d
Fetching is complete
fa38717
Fix style issues
8b69de1
parity with original demo, but uglier
2d39c51
Address code review feedback
756bca1
moving to wrapping everything into an anonymous function
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,100 @@ | ||
| //TODO | ||
| 'use strict'; | ||
|
|
||
| (function () { | ||
| $(document).ready(function () { | ||
| const table = $('#parameterTable'); | ||
| const tableBody = table.children('tbody'); | ||
|
|
||
| // This is the entry point into the extension. It initializes the Tableau Extensions Api, and then | ||
| // grabs all of the parameters in the workbook, processing each one individually. | ||
| tableau.extensions.initializeAsync().then(function () { | ||
| tableau.extensions.dashboardContent.dashboard.getParametersAsync().then(function (parameters) { | ||
| parameters.forEach(function (p) { | ||
| p.addEventListener(tableau.TableauEventType.ParameterChanged, onParameterChange); | ||
| parameterRow(p).appendTo(tableBody); | ||
| }); | ||
|
|
||
| // This is used to manipulate what part of the UI is visible. If there are no parameters | ||
| // found, we want to give you a message to tell you that you need to add one, otherwise, we | ||
| // show the table we created. | ||
| $('#loading').addClass('hidden'); | ||
| if (parameters.length === 0) { | ||
| $('#addParameterWarning').removeClass('hidden').addClass('show'); | ||
| } else { | ||
| $('#parameterTable').removeClass('hidden').addClass('show'); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| // When the parameter is changed, we recreate the row with the updated values. This keeps the code | ||
| // clean, and emulates the approach that something like React does where it "rerenders" the UI with | ||
| // the updated data. | ||
| // | ||
| // To avoid multiple layout processing in the browser, we build the new row unattached to the DOM, | ||
| // and then attach it at the very end. This helps avoid jank. | ||
| function onParameterChange (parameterChangeEvent) { | ||
| parameterChangeEvent.getParameterAsync().then(function (param) { | ||
| const newRow = parameterRow(param); | ||
| const oldRow = $("tr[data-fieldname='" + param.id + "'"); | ||
| oldRow.replaceWith(newRow); | ||
| }); | ||
| } | ||
|
|
||
| // | ||
| // DOM creation methods | ||
| // | ||
|
|
||
| // A cell in the table | ||
| function cell (value) { | ||
| const row = $('<td>'); | ||
| row.append(value); | ||
| return row; | ||
| } | ||
|
|
||
| // A simple cell that contains a text value | ||
| function textCell (value) { | ||
| const cellElement = $('<td>'); | ||
| cellElement.text(value); | ||
| return cellElement; | ||
| } | ||
|
|
||
| // The allowable values column has a complex structure, so to make things easier/cleaner, | ||
| // this function creates the subtree for the value of the allowable values column. | ||
| function allowableValues (value) { | ||
| function termKey (key) { | ||
| return $('<dt>').attr('id', key).text(key); | ||
| } | ||
|
|
||
| function termValue (value, default_) { | ||
| return $('<dd>').text(value || default_); | ||
| } | ||
|
|
||
| const allowable = $('<dl class="dl-horizontal">'); | ||
|
|
||
| if (value.type === 'all') { | ||
| allowable.append(termKey('Restrictions')); | ||
| allowable.append(termValue('None')); | ||
| } else { | ||
| allowable.append(termKey('Min Value')); | ||
| allowable.append(termValue(value.minValue._value, 'No Min')); | ||
| allowable.append(termKey('Max Value')); | ||
| allowable.append(termValue(value.maxValue._value, 'No Max')); | ||
| allowable.append(termKey('Step Size')); | ||
| allowable.append(termValue(value.maxValue.stepSize, 'default')); | ||
| } | ||
|
|
||
| return allowable; | ||
| } | ||
|
|
||
| // This function creates a subtree of a row for a specific parameter. | ||
| function parameterRow (p) { | ||
| let row = $('<tr>').attr('data-fieldname', p.id); | ||
| row.append(textCell(p.name)); | ||
| row.append(textCell(p.dataType)); | ||
| row.append(textCell(p.currentValue.formattedValue)); | ||
| row.append(cell(allowableValues(p.allowableValues))); | ||
|
|
||
| return row; | ||
| } | ||
| })(); |
Binary file not shown.
File renamed without changes
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is good :)