Zendesk: How to change zendesk default 100 per_page value - zendesk

Collections return a maximum of 100 records per page, and by default return 100 records per page. How can I change this default value?

You can set this on a per request basis by passing e.g. per_page=50 in the request parameters. You iterate the collection by incrementing the page attribute, e.g. page=3. Collections also include links in the response body for easier navigation, generally they are on this structure:
{
"users": [ ... ],
"count": 1234,
"next_page": "https://account.zendesk.com/api/v2/users.json?page=2&per_page=50",
"previous_page": null
}
Stop paging when the next_page attribute is null.

Related

How do I get a group count with multiple columns in the group with a virtual attribute

Keeping is simple assume I have a model "Loan" that has 2 attributes "Type" and "Status". Type as possible values of "Home", "Auto", "Building" and Status has possible values of "Open", "Pending", "Closed" and nil.
Without manually writing the SQL (using group and count?) how do I get the results of:
select type, status, count(*) from loans group by 1, 2;
I could do
Load.group(:type, :status).count()
But there are situations where status might be nil. In that case I want to replace the nil with "Unknown"
I tried adding a virtual attribute to the model:
def usable_status
status.nil? ? 'Unknown' : status
end
So I could then do
Load.group(:type, :usable_status).count()
But count didn't seem to recognize the virtual attribute since it is trying to pass it directly to the database.
Ideas?
Well, that's pretty easy to achieve by combining the rails styling with the SQL functionality:
Loan.group(:type, "COALESCE(status, 'Unknown')").count()

How to lookup a individual item in Falcor

I am having trouble figuring out how to structure routes for retrieving individual records. For example, lets say I have these routes:
itemsById[{integers:itemIds}]["id"]["name"]
userItems[{integers:itemIndices}]
So, the userItems route looks up the relevant item data in the itemsById route. This is fine for the list view of my app, however, I'm not sure how to define a route for the show view (which displays an individual item).
I suppose if I was on the list view I could store the index of the item that the user clicks on then lookup that index up in the itemsById route but the user might browse directly to the the show view route meaning I've no way to know the itemsById index.
I was thinking I could define a route to return the individual item:
userItem[{integers:itemId}]
This route takes the itemId as an argument then looks it up in the itemsById but this doesn't really seem right since Falcor suggests you shouldn't be working with IDs.
I'm likely missing something. Does anyone know what the correct approach is here?
I think you're close. As I understand, this would be your individual item lookup route:
itemsById[{keys:itemIds}][{keys:props}]
itemIds would be passed to your router as an array of item IDs. If the user is looking at a single-item detail view then the browser's URL might contain something like this: /items/7bca23. So on the client you'd do model.get('itemsById.7bca23.name') for example to grab the name of that item.
Meanwhile, for a list view you'd have a route like this:
itemsByIndex[{integers:indices}]
indices would be passed to your router as a series of numbers. On the client you'd do model.get('itemsByIndex[0..20].name'). Then from that route you'd return an array of objects like this:
{
path: [ 'itemsByIndex', 0 ],
value: { $type: 'ref', value: [ 'itemsById', '7bca23' ] }
}
Falcor will jump over to the itemsById route during that same request to provision the rest of the requested graph fragment.

Using outputcache in MVC

I have an action declared as following
[Route("{language}/Navigation/Test")]
[OutputCache(Duration = 3600, VaryByParam = "none")]
public ActionResult Test()
{
return View();
}
In order to check outputcache setting I added #DateTime.Now.Ticks.ToString() in view Test.cstml
What troubles me is that when i run http://localhost/EN/Navigation/Test first time, view gets cached and page refresh returns a same number of ticks. Now if i change language and set http://localhost/DE/Navigation/Test number of tick changes, ie. view is not served from cache.
I tried to remove VaryByParam = "none" but is always produces the same results.
What is wrong here, how to serve a cached view not matter what language is used.
VaryByParam varies by the parameters passed in a URL. I.e. The URL www.stackoverflow.com/page?param1=5. Because DE is a different URL to EN, the page won't be found in the cache so it requests a new one.
From MSDN
A semicolon-separated list of strings used to vary the output cache. By default, these strings correspond to a query string value sent with GET method attributes, or a parameter sent using the POST method. When this attribute is set to multiple parameters, the output cache contains a different version of the requested document for each specified parameter. Possible values include none, *, and any valid query string or POST parameter name.
Bottom line: It's based on URL, not routing. You are able to configure based on the query string but no more.

grails runtime calculation in gsp page

In my grails project I have an Invoice domain class. In this class I have amount value, discount, VAT etc. Discount and VAT are represented with two select.
In gsp I've added another field, called total, that shows the final value of the invoice. I would like that, when user changes value of discount, or of VAT, the total value changes.
For similar issue I've used a remoteFunction that, after passing parameters to a controller method, updates via javascript the value of the amount but in this case I don't know how to refer current values selected in gsp by user.
given the form with some fields in your GSP:
<g:textField name="discount" value="${discount}"/>
<g:textField name="vat" value="${vat}"/>
you can use a function like this (in jquery) to pass and receive the data to the controller:
function send(){
$.ajax({
url:'${createLink( controller:'your_controller', action:'someAction' )}',
data:{ discount:$( '#discount' ).val(), vat:$( '#vat' ).val() }
}).done( function( data ){
console.info( data );
} );

Grails g:paginate - Passing search parameters back to Controller

I have built an advanced search option that allows users to search a multitude of different fields - 38 possible fields in total.
Once the initial search has been submitted, 10 results are displayed with pagination options at the bottom (using grails' <g:paginate> tag).
I think I have a few problems here.
1) I need to somehow pass the fields back to the controller using the params attribute of the g:paginate tag, but I don't really want to create a params map of 40 something parameters.
2) I pass back to the page from the Controller a map of search parameters (so that they can have a dismissable list of parameters that perform the search again without the dismissed parameter). I can pass this back in the params attribute, but it's passed back to the controller as a String and not a map so I don't know how to iterate through it (I realised this after it iterated through each separate character!).
3) The URL of the links that the g:paginate tag creates could potentially be massive, depending on how much of the search fields the user enters. Could there be a danger of the URL exceeding it's maximum amount?
I'm contemplating changing from the built in grails paginate functionality, and creating a form which I can POST. I'm not sure if this is the best way though, and I may be missing some alternative way to do this that is much better.
Any help greatly received!
You can pass all your parameters to action using pageScope.variables like
<g:paginate params="${pageScope.variables}" total=.../>
index.gsp
<div class="pagination">
<g:paginate total="${personCount ?:0}" max="5" params="${params}" />
</div>
Controller.groovy
def index(Integer max)
{
def c=Person.createCriteria()
def results
int count
params.max = Math.min(max ?: 5, 100)
if(params.name != null)
{
params.max = 4
if(!params.offset)
{
params.offset = 0;
}
count = Person.countByNameLike("%"+params.name+"%")
results=c.list{
like("name","%"+params.name+"%")
maxResults(params.max)
firstResult(params.getInt("offset"))
}
}
else
{
results = Person.list(params)
count = Person.count()
}
respond results, model:[personCount: count]
}
I'd put your search params into session. Thus you can use the very basic grails g.paginate tag w/o polluting it. Each time the user changes his search, the parameters should get updated.
1 and 2) The best solution I found:
for the action:
def list() {
... //use params to filter you query and drop results to resultList of type PagedResultList
return [resultList: resultList, resultTotal: resultList.getTotalCount(), filterParams: params]
}
for the view:
<g:paginate total="${resultTotal}" action="list" params="${filterParams}"/>
See a complete example.
3) The url (and get parameters) limit size is 2000 (see why). If that is a problem to you, you'd better switch to an ajax solution or minimize the url size filtering only the filled params. You could accomplish that replacing this line:
return [resultList: resultList, resultTotal: resultList.getTotalCount(), filterParams: params.findAll{ it.value } ]

Resources