pocketquery dynamic template loading Query

Nathaniel Wright May 9, 2016

Hi,

I have a template that reads the options for a team from the database and also allows for fixed years (I haven't worked out how to perform 2 separate queries!). It uses these two parameters to update two queries on the page.

I'd like to re-use the same template and have it dynamically load the query based on an input that is defined at the time the page is edited - can you recommend a method that doesn't require me to duplicate the query/template?

 

Query: select TYPENAME as team FROM QA_OWNER.REL_TYPES

Template I want to re-use with query name(s) defined when the macro is added to the page (i.e. ReleaseCalendar and ReleaseStats are dynamically added)

 

<form id="my-pocketquery-form" class="aui">
<div class="field-group">
<label for="select-team">Choose Team:</label>
<select class="select" id="select-team" name="select-team">
<option value="%">All</option>
#foreach ($row in $result)
<option value="$row.team">$row.team</option>
#end

</select>
</div>
<div class="field-group">
<label for="select-year">Choose Year:</label>
<select class="select" id="select-year" name="select-year">
<option value="%">All</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select>
</div>
</form>

$PocketQuery.renderPocketQueryMacro("ReleaseCalendar", {
'page': $page,
'parameters': {'team':'%', 'year': '%'},
'dynamicload': true
})


<script>
jQuery('#my-pocketquery-form select').change(function() {
var container = jQuery('.pocketquery-dynamic-load[data-query="ReleaseCalendar"]');
var dataIndex = container.data('index');
var data = PocketQuery.getDynamicLoadData(dataIndex);
data.queryParameters = { team: jQuery('#select-team').val(), year: jQuery('#select-year').val() };
PocketQuery.load({
container: container,
data: data
});
var container = jQuery('.pocketquery-dynamic-load[data-query="ReleaseStats"]');
var dataIndex = container.data('index');
var data = PocketQuery.getDynamicLoadData(dataIndex);
data.queryParameters = { team: jQuery('#select-team').val(), year: jQuery('#select-year').val() };
PocketQuery.load({
container: container,
data: data
});

});
</script>

 

3 answers

0 votes
Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 22, 2016

Hi Nathaniel,

I suggest to create as many "dummy" SELECT parameters in your outer query as you need:

SELECT columnX, columnX, :additionalParam1, :additionalParam2
FROM tableX
...

These parameters will be configurable in the macro. In the template of your outer query, you will have all of your dummy params available in the $queryParameters object: $queryParameters.additionalParam1

With this you can then render your subquery like this:

$PocketQuery.renderPocketQueryMacro($queryParameters.additionalParam1, {
  'page': $page,
  'parameters': {'team':'%', 'year': '%'},
  'dynamicload': true
})

Please let me know if this works!

Regards, Felix (Scandio)

0 votes
Nathaniel Wright May 19, 2016

Yes indeed. I'd like to reuse a couple of queries that act as pickers for multiple inner queries to avoid having to duplicate those outer queries. The page wouldn't  always have the same inner queries, I.e they are defined at page creation time and not page load. 

0 votes
Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2016

Hi Nathaniel,

Do you mean that in your case you want to set the query dynamically for the renderPocketQueryMacro calls? So the solution would look somehow like this:

$PocketQuery.renderPocketQueryMacro($parameters.myTemplate, {
  'page': $page,
  'parameters': {'team':'%', 'year': '%'},
  'dynamicload': true
})

So the name of the "sub query" would actually be defined as parameter on the "parent query"? This would be a new idea to me, but very interesting. Please let me know if I understand you right.

Felix

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events