Forum Discussion
Hi snaffle ,
fist of all, if there is no particular reason, we should always use "rest()' instead of 'restadmin()', as restadmin() may carry some private inforamtion which should not been seen by normal user.
for your query, is there any chances to convert /boards/id/${coreNode.id}/topics to /boards/id/${coreNode.id}/search/messages/count?q=is_root:true, which has the same effect to bring topic-only nodes. from that you will be able to use sort_by.
last but very minor, it is not necessary to add "restapi.response_style=view" to rest() or restadmin() calls, as both calls with automatically add "restapi.response_style=view" to your query string.
I hope that it helps.
Hi @Haidong.
I've taken over this component from another developer and to be honest I am still in the process of learning Freemarker and in particular what API calls work where, so I really appreciate your help.
The custom component in question is basically replacing the default topics list for each forum board. This was done to satisfy design requirements for the client. You can see what I mean at this link - http://saneforums.org/t5/Our-stories/bd-p/forum-001.
So I'm not 100% sure, but I believe "restadmin()" was used instead of just "rest()" because there are administrator/moderator only forum boards that need to be accessed. Access to these boards is managed through the use of Roles and if/else statements. Nonetheless, I will test on the staging server replacing the calls with just "rest()" and see if everything still functions.
Likewise, I'll remove the "restapi.response_style=view" part from the API call and make sure it all still works.
Now, in terms of the query itself, I've tried both your method and NicoB's method and they partly work.
The custom component also includes a call to generate the page navigation so I updated that call as well. So, using your example for the page navigation:
Old - <#assign resultSize = restadmin("/boards/id/${coreNode.id}/topics/count").value />
New - <#assign resultSize = restadmin("/boards/id/${coreNode.id}/search/messages/count?q=is_root:true").value />
And for the main API call:
Old - <#assign msgList = restadmin("/boards/id/${coreNode.id}/topics?restapi.format_detail=full_list_element&restapi.response_style=view&page_size=${page_size}&page=${page_number}").node_message_context />
New - <#assign msgList = restadmin("/boards/id/${coreNode.id}/search/messages/count?q=is_root:true&restapi.format_detail=full_list_element&restapi.response_style=view&page_size=${page_size}&page=${page_number}").node_message_context />
Changing the above correctly returns the page navigation, showing 3 pages and a link to each page.
The problem though is that it doesn't return any of the topic content itself, just a blank page. I've attached a screenshot which shows the result.
So it seems that the code which displays the topics doesn't work once I've changed the main API call:
<#list msgList.message as msg>
topics go here
</#list>
So I'm working my way through the API docs to figure out why it's not working but if you have any ideas on what needs to change here I'd be greatly appreciative.
Thanks
Nathan
Related Content
- 2 years ago
- 4 years ago