select number of items in drupal views - drupal

Is there a way i can have an exposed filter wherein the user can select the number of items displayed by the drupal view?

I am nearly positive that you can do this with hook_views_pre_build (&$view). I know for a fact that you can mess with $view->pager to update whether to use the pager or not and to alter the number of items per page.
This is a snippet from a custom module I did:
if (is_numeric($perpage) && (int) $perpage > 1) {
$view->pager["items_per_page"] = (int) $perpage;
} else if ($perpage == "all") {
$view->pager["use_pager"] = false;
$view->pager["items_per_page"] = 0;
}
I suspect you can turn the pager off and also set the items per page to limit the results.
EDIT:
OK, just saw the part about the exposed filter. The code snippet is actually from a bit of code that simulates an exposed filter for this case. The page has some links on it to select the number of items per page. The links refresh the page, and tack on a perpage=whatever parameter. The hook then sanitizes the input, and basically runs the code snippet above. I have also done something similar using HTML a select, and then wiring up the parameter w/ refresh using jQuery.

Based on this thread in the issue queue, that appears to be a long requested feature. It has apparently been added to the 6.x-3.x-dev branch, so it should be available in the 6.x-3.0-alpha3 release.
Or if you're using Drupal 7, it has been added to the 7.x-3.x-dev branch too, so it should be in the 7.x-3.0-alpha1 release.

Related

Can't Edit/Update Certain Items In Database (Table)

I have database that I have multiple orders entered into. Everything seems to be working fine except for a few old entries which will not accept updates/changes to their Fields.
Note: The majority of the Fields are Strings with Possible Values entered via a DropDown Box.
So if I open Order A I can make adjustments just fine and those changes persist even after closing the page and coming back or refreshing.
But if I open Order B, I can make changes via the dropdowns and it looks like they have adjusted, however if I leave the page or refresh all the changes have reverted back.
One piece of info that may be helpful is that each of these orders has at least one Field that contains an entry that is no longer a Possible Value (the original entries were removed/changed per request of the client).
Maybe they are "locked" because of this? Is there a way to look at an error log for a Published app?
I can delete the "corrupt" entries and recreate them (since there are currently only a few), but I would prefer to find a better solution in case this happens again in the future.
Any help would be greatly appreciated.
It's a bug. Such field level value updates should get through.
As workaround you can update prohibited(not possible anymore) values with allowed ones in OnSave Model's Event like:
switch (record.Field) {
case "old_value_1":
record.Field = "new_value_1";
break;
case "old_value_2":
record.Field = "new_value_2";
break;
...
}
Sorry for the inconvenience.
Each deployment has its own log. Have you tried "App Settings > DEPLOYMENTS > (click on the desployment) > VIEW LOGS"?

In SalesTable form, how to protect salesLine dimensions when items are already picked up?

In our Dynamics Ax 2009 configuration, we would like to avoid stock dimensions to be changed once the items are picked up or delivered.
Sometimes users change the facial stock dimensions (warehouse, location) on the sales lines while transactions have already been registered.
I'm not aware of a way to protect this by a change in Stock or Sales parameters.
I try to solve this, with a change in active() method in the Salesline datasource of the SalesTable form, which calls a specific method :
if (InventDim_Ds.allowEdit())
{
if (SalesLine.pickedInTotalSalesUnit() != 0 || SalesLine.DeliveredInTotal() != 0)
{
InventDim_Ds.allowEdit(false);
}
}
But it doesn't work, or works too well : now it is impossible to change the stock dimensions, even if nothing has been picked or delivered.
I assume this has to do with the link between sales lines and dimensions, but I don't know how to fix my code.
On first glance, it looks like your issue is with:
if (InventDim_Ds.allowEdit())
As it doesn't allow changes between lines. If one line is picked, it will disable the InventDim_Ds, then when you move to the next SalesLine triggering the active() method, it will see that it's disabled and not enter the if statement.
Try this:
InventDim_ds.allowEdit(!salesLine.pickedInTotalSalesUnit() && !salesLine.deliveredInTotal());

Discussion pagination in elgg 1.8 is not working properly

We have a website created using elgg, and we have discussion part of elgg where pagination is not working properly.
When listing all discussion list, pagination is working correctly, from latest to oldest
But pagination inside topic (one of the discussion) where replies are too many, and they separated by pagination (Previous, next), it is showing replies incorrectly:
In the first page we have:
As you can see it is ordered from latest to oldest: 17 days ago and then comes 21 days ago.
But when you go next page:
It is ordered inside the page from latest to oldest, but the the pages should be swapped.
How can I fix it?
Thanks forward
It works properly. Discussions are ordered by last action on the thread. You may have older thread first due to it having most recent response of all threads.
To change it, look at discussion_handle_list_page function in mod/groups/lib/discussion and how it uses order_by parameter. You need to override this page and just remove order_by to use default ordering, which is creation time of the entity (in his case thread). You could do it by tapping to the "route" plugin hook, or overriding whole discussions page handler.
And that's why not just change it inline: http://learn.elgg.org/en/1.9/guides/dont-modify-core.html
I have found finally going through all pagination libraries, and annotation views.
The problem is when listing replies for discussion on replies.php file which in /views/default/discussion there are two jquery functions on the bottom of the page that reverse the order.
function reverse(arr){
var newArr = [];
for(var iter = arr.length -1; iter >= 0; iter--){
newArr.push(arr[iter])
}
return newArr;
}
I have change the iter to start from 0 and go to arr.lenthg.
But it is not all yet, in order to get the latest replies first, I have added to
$options = array(
'guid' => $vars['entity']->getGUID(),
'annotation_name' => 'group_topic_post',
);
this line:
'order_by'=> 'time_created desc'
And then I got my replies ordered correctly: from latest to oldest.

Meteor client-side pagination

There's a collection Comments. Currently comments for the specfic Content are all published to the client.
Without pagination I can successfully render them in my template, insert new comments and enjoy the reactivity.
I'm fine at the moment with all comments sent to the client but I want to implement all-client-side pagination to visually simplify the page much like FB does.
Hare are the rules:
Comments are always sorted by the creation timestamp ASC (newer at the bottom of the list)
I need to show the total number of records in the collection (T)
I need to show the total number of comments currently displayed (C)
If there are more comments (C < T) I need to show a 'See more' link
Initially I show 5 newest comments (or all of them if there're less than 5)
New comments (pushed from the server) are instantly shown at the end of the list
When I click the 'See more' link up to 10 extra comments (the newest from the currently invisible -- and all of them are older that those already shown) are shown in the beginning of the list
So effectively it could be like:
have the minTime variable
initially set it to the timestamp of the 5th newest comment
when I click the link set it to the timestamp of the 10th newest comment older than the current value
template renders all the comments not older than this value
at some point calculate values C and T and save them
I tried to solve this with a bunch of Session variables but didn't succeed -- I think at some point getting and setting these vars from the template leads to recursion or what?
Additional problem is that I don't reliably know the 'initial' moment when I should calculate the minTime for the 1st time -- comments may still not be synched when the template is created or rendered for the first time.
So, the question: what is the proper way to fulfill my requirements?
Solution:
Meteor.startup(function(){
Session.set('number_of_visible_comments', 5);
});
Template.comments = function() {
return Comments.find({content: id_of_content}, {
sort: {timestamp: -1},
limit: Session.get('number_of_visible_comments')
});
};
Template.total_number_of_comments = function() {
return Comments.find({content: id_of_content}).count();
};
Template.number_of_visible_comments = function() {
return Session.get('number_of_visible_comments').count();
};
Template.comments.events({
'click': function() {
var count = Session.get('number_of_visible_comments') + 10;
Session.set('number_of_visible_comments', count);
}
});
In the meantime there are tow Meteor package for doing client-side pagination, one within a table. I admit I didn't go through all your requirements because of the comment exchange with ram1 above, but the package may help:
https://atmosphere.meteor.com/package/reactive-table
https://github.com/alethes/meteor-pages

add expiration date to a node in Drupal

i want to add an expiration date field to my custom content type in Drupal. it should specified by days (7-15-.... days after creating node) and after it reached the node should not display in site to visitors. but i need a renew option for it to allow creator renew it and activate it again.
is it too hard to impelmentation? how can i do it?
Have you already tried searching for modules?
Here's one that might do the trick http://drupal.org/project/auto_expire. There are others as well,but maybe you should check them out to see which one fits your needs (or can be altered easily if needed).
You can use Views to do that. Make a new View, specifically for a node or more nodes of that type, and put a filter on it with "Node:Updated". Then specify how many days you need.
You can create a View for the original poster and have him update the post, which will reset the counter.
A creative solution, but it should work.
Take a look at Node expire which sets up timers for nodes based on Rules. For a simpler approach, Scheduler can do it to. Both are linked from the Auto Expire module linked by wimvds, so there is some measure of duplication, though they do seem to have different approaches.
The following code may be of interest. It's a small snippet from a module i've had to create to auto expire adverts on an intranet site. The nodes simply unpublish after a number of days you specify in the code so could be hidden from your site and then the author of the content could simply just re -publish the nodes if they needed to.
/**
* Implementation of hook_cron().
*/
function auto_unpublish_pages_cron() {
//we only want to deal with all blog_post content type nodes
$c_type = 'blog_post';
//grab all nodes
$c_nodes = node_load_multiple(array(), array('type' => $c_type));
//setup time stamp for node expiry
$message_search_data = strtotime('- 7 days');
//now loop through nodes, & if they are old, expire them
foreach ($c_nodes as $m) {
$obj = entity_metadata_wrapper('node', $m);
//check when was last updated and if its still published
$last_update = $obj->changed->value();
$published = $obj->status->value();
//if it's still published & it's not recent, unpublish it
if (($message_search_date > $last_update) && $published<>0) {
$obj->status = 0;
$obj->save();
}
}
}

Resources