Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #245 from GoogleCloudPlatform/dev-klausw-fixes
Browse files Browse the repository at this point in the history
Move query-rebuilding logic, apply when refreshing.
  • Loading branch information
klausw committed Jan 27, 2016
2 parents 793693c + b9cee79 commit c48149e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
23 changes: 23 additions & 0 deletions client/components/dashboard/dashboard-service.js
Expand Up @@ -585,6 +585,28 @@ DashboardService.prototype.rewriteQuery = function(widget, replaceParams) {
project_name, dataset_name, table_name, table_partition, params);
};

/**
* Rebuilds the current widget's query based on the config.
*
* If the query is a custom query, it will rewrite .query_exec to replace
* parameter tokens with values. If the query is a Query Builder query,
* it will rewrite .query tokens, and .query_exec with values.
*
* @param {!WidgetConfig} widget The widget to rewrite the query against.
*/
DashboardService.prototype.rebuildQuery = function(widget) {
if (widget.model.datasource.custom_query !== true) {
widget.model.datasource.query = (
this.rewriteQuery(widget, false));
widget.model.datasource.query_exec = (
this.rewriteQuery(widget, true));
} else {
widget.model.datasource.query_exec = (
this.queryBuilderService_.replaceTokens(widget.model.datasource.query,
this.params));
}
};


/**
* Updates the widget's query, if applicable, and changes the widget
Expand All @@ -594,6 +616,7 @@ DashboardService.prototype.rewriteQuery = function(widget, replaceParams) {
* @export
*/
DashboardService.prototype.refreshWidget = function(widget) {
this.rebuildQuery(widget);
if (widget.model.datasource.query) {
this.timeout_(function() {
widget.state().datasource.status = ResultsDataStatus.TOFETCH;
Expand Down
15 changes: 1 addition & 14 deletions client/components/widget/data_viz/gviz/gviz-directive.js
Expand Up @@ -304,23 +304,10 @@ explorer.components.widget.data_viz.gviz.gvizChart = function(
/**
* Applies the current parameters to the widget's query.
*
* If the query is a custom query, it will rewrite .query_exec to replace
* parameter tokens with values. If the query is a Query Builder query,
* it will rewrite .query tokens, and .query_exec with values.
* @export
*/
scope.applyParameters = function() {
let widget = scope.widgetConfig;
if (widget.model.datasource.custom_query !== true) {
widget.model.datasource.query = (
dashboardService.rewriteQuery(widget, false));
widget.model.datasource.query_exec = (
dashboardService.rewriteQuery(widget, true));
} else {
widget.model.datasource.query_exec = (
queryBuilderService.replaceTokens(widget.model.datasource.query,
dashboardService.params));
}
dashboardService.rebuildQuery(scope.widgetConfig);
};

// When the datasource status change
Expand Down

0 comments on commit c48149e

Please sign in to comment.