Groovy paginate problem - groovy

I have an application written in groovy and I am having problems with the pagination of a resulting set.
I have a Controller called ReportingController. This controller has two methods called
listdoiTln and listdoiEv. Both methods are similar and at the end both have to render a list of reports. The last lines of both are as follows:
params.max = Math.min(params.max ? params.max.toInteger() : 15, 100)
render (view: 'list', model:[reportingInstanceList: reportingInstanceList, reportingInstanceTotal: i])
The list view is rendered as expected. At the footer of the list.gsp file I have:
<div class="paginateButtons">
<g:paginate controller="reporting" total="${reportingInstanceTotal}" max="25"/></div>
</div>
The list is working, the buttons for the pagination are there but it is always displayed the whole collection. Notice that I do not have files callled listdoiTln.gsp or listdoiEv.gsp. I am using list.gsp with different data models.
Surely I am doing something wrong.
Any hint?
Thanks in advance.
Luis

I had trouble with this, too, for quite a while. Try this:
Evaluate param.offset in the controller:
params.offset = params?.offset?.toInteger() ?: 0
Include the params in the model:
render (view: 'list',
model:[reportingInstanceList: reportingInstanceList,
reportingInstanceTotal: i,
params: params])
Check whether the value of reportingInstanceTotal is the value that you expect. That tripped me up for a while.
If it still doesn't work, let me know, or try looking at one of the list.gsp pages and its associated controller that are generated by the grails generate-all command.
The paginate buttons are quite cool, but there is little documentation and it takes longer than I expected to set them up.

Related

Magento 2 get custom Product Attribute from shipping

In the Carrier Model, pulling the products works via $request->getAllItems() and then getting the Product $item->getProduct().
I can't seem to figure out how to pull a custom product attribute.
$item->getProduct()->getAttribute('custom_attr'); // nothing
$item->getProduct()->getResource()->getAttribute('custom_attr'); // uses up 3GB memory and dies
$item->getProduct()->getCustomAttributes(); //empty array
$item->getProduct()->getExtensionAttributes(); //empty array
also tried creating the extension_attributes.xml
found it, finally :) Not sure if there is a better way as to load the whole product but works for now.
$_product = $objectManager->get('Magento\Catalog\Model\Product')->load($item->getProduct()->getId());
$attr = $_product->getData('attribute_name');

Excel VBA copy the value of a label from Internet Explorer

I'm trying to retrieve the value "CONGE STATUTAIRE" from the following html code
<span class="DescriptionLabel" id="lblProjectDescription">CONGE STATUTAIRE</span>
I've tried this
nom_proj = IE.Document.getElementsByClassName("DescriptionLabel")(0).innerText
The code pass this line without problem but the the value of nom_proj is " ", and I would have hope to get "CONGE STATUTAIRE" for result.
Could anyone tells me what's wrong with it? The rest of my code is working i.e. I can retrieve value by using the getelementbyID method.
Any help will be welcomed.
I would use the getElementById() method, to make sure it can return only one HTML element and not a collection of objects:
nom_proj = IE.Document.getElementById("lblProjectDescription").innerText
However, the reason why you get "" is most probably that the collection returned by getElementsByClassName() has more than one element (often, when retrieving object by class names).
Which means: in the Document of your browser there will be most probably more elements that are styled with the CSS class DescriptionLabel; for example, something like this:
<div name="emptyRow" class = "DescriptionLabel"></div>
You can test if there are more than one element by:
1) either, adding a watcher to IE.Document.getElementsByClassName("DescriptionLabel");
2) or, printing all the elements inside, I bet my hat you'll find inside more than one:
For Each obj In IE.Document.getElementsByClassName("DescriptionLabel")
Debug.Print obj.InnerText
Next obj
GENERAL SUGGESTION: if an HTML object has an id, use the getElementByID; that method returns a single object, not a collection, so even if you would be sure that the collection will contain a unique element, it would anyway be less clean and efficient in terms of coding.

undefined method `query_parameters' in Active Admin show/panel/table_for

I have something very similar working in another model, so there must be something minor that I'm overlooking.
I have a model Request that has_many RequestState(s), which in return has_one.
ActiveAdmin.register Request do
show do |ad|
...
panel "Request States" do
table_for ad.request_states do
column :id
column :actor_id
column :state
column :created_at
end
end
end
end
When I try to load the page, I get:
NoMethodError in Admin::Requests#show
undefined method `query_parameters' for #<Request:0x000001062040c0>
and it's complaining about each of the "column" lines.
The underlying data seems fine since the following and similar work correctly from the rails console:
Request.find(37).request_states.pluck(:id)
I had the same problem in ActiveAdmin 1.0, and solved it without renaming my Rails model. I just renamed the resource within ActiveAdmin:
ActiveAdmin.register Request, as: "BookRequest" do ...
This also forced me to rename my path helpers, e.g., admin_request_path became admin_book_request_path everywhere. Much less intrusive than renaming the Rails model though.
See https://activeadmin.info/2-resource-customization.html#rename-the-resource
Request is a reserved Class by Rails. I think you have to use something else class name.
http://api.rubyonrails.org/classes/ActionDispatch/Request.html
But not sure, because it's namespaced...
I was getting this issue and, for me at least, it turned out to be the assignment of #request in a before_filter called in my ApplicationController:
def newsletter
#request = NewsletterRequest.new
end
Changed the #request to #newsletter_request and avoided the collision.

Masking answer options in Confirmit (jscript)

I'm trying to mask the answer options that show up in a 3DGrid question item in Confirmit, using the value of a background variable.
E.g. when "background1" ==1, display answer category 1. If "background1" ==0, do not display answer category 1. If "background2" ==1, display category 3, otherwise do not. In any case, display answer category 2.
Hopefully this is easy for someone out there (I'm a psychologist, not a coder...so not so much so for me :/)
Thanks!
In order to access the data inside a question/variable we can use the f function of confirmit.
for instance:
f('my_question_id').get();
When masking a question, we need to pass in a Set object so Confirmit knows what Code's to show and not to show.
Often you will mask using a Set from a previous question. So you pass in the question_id and Confirmit does all the other magic.
Here we have the problem of not having a Set, so we will have to create our own.
For this, there are 2 approaches (can be found in the scripting manual under Working with Sets > Methods of the set Object > add and remove and Working with Sets > User defined functions...)
I'm going to stick to the first one because it is easier to use ;)
What we will do first is create a script node (it doesn't matter where you create it, just somewhere in the survey, I often have a folder Functions with all my script nodes in somewhere at the bottom of my survey)
In that script file we will have our function that crates our set:
function CreateMyAwesomeSet()
{
//create an empty Set
var mySet = new Set();
//if background1 equals 1, add 1 to our Set
if ( f('background1').get() == '1' )
{
mySet.add(1);
}
//return the Set of allowed Codes
return mySet;
}
Here we declare a function that we now can use wherever we want to.
So now, If we want to use this Set, we add a Code Mask to your grid:
CreateMyAwesomeSet()
You can ofcourse change the name of the function, and add extra if statements.
hope this helps

Searching by related model field

I know there are plenty of topics on this but I searched&tried so many and it is still not working.
I have tables: Team and Worker. Any worker can be assigned to a Team. So at the Workers Manager I want to search Workers also by Team name.
I got the column etc. but when I type part of team name - search starts but the written text dissappears and search doesn't care about the field. I checked the AJAX call with Firebug and there is a field called teamName (I added public field to my Worker model class). But when I print_r criteria in my search method - there is no condition.
How is that possible? How can I perform the searching by related field?
EDIT (my serach() method):
public function dsearch()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('idWorker',$this->idWorker);
$criteria->compare('idLeaderType',$this->idLeaderType);
$criteria->compare('t.idTeam',$this->idTeam);
$criteria->compare('idVoip',$this->idVoip);
$criteria->compare('workLogin',$this->workLogin,true);
$criteria->compare('workPass',$this->workPass,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('surname',$this->surname,true);
$criteria->compare('madeCalls',$this->madeCalls);
$criteria->compare('deleted',$this->deleted);
$criteria->compare('liveChanges',$this->liveChanges);
$criteria->compare('confirmer',$this->confirmer);
$criteria->compare('oldWorkerNum',$this->oldWorkerNum);
$criteria->compare('idDepart',$this->idDepart);
$criteria->compare('Team.name', $this->teamName, true);
$criteria->with=array('Team');
$criteria->together = true;
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
Use the mergeWith: Hope it works.
if($merge!==null){
$criteria->mergeWith($merge);
}
Reference:http://www.yiiframework.com/doc/api/1.1/CDbCriteria#mergeWith-detail
I found usefull extension to do that:
http://www.yiiframework.com/extension/relatedsearchbehavior/
I couldnt get it to work somehow. I downloaded new version and now its fine.
It works pretty well. Thanks for your time though.

Resources