pocketquery dynamic template loading Query

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

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

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. 

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)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 24, 2018 in Confluence

Atlassian Research opportunity with Confluence templates

Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time!   We're looking for people to participate in a   remote 1-hr workshop...

1,037 views 15 13
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you