At the moment only the current month gets loaded. In the month view we can see aditional days of the previous and next month. We should load the events for those as well.

If we use a 14 days buffer, we are safe.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aspilicious’s picture

Status: Active » Postponed

This is postponed because we can't filter on a date range.

tim.plunkett’s picture

Status: Postponed » Active

Relevant bits of code:

Date module parses a single date into a range of itself to itself. So 2011-11 becomes 2011-11 to 2011-11.
http://drupalcode.org/project/date.git/blob/refs/heads/7.x-2.x:/date_api...

This is where we add our value:
http://drupalcode.org/project/fullcalendar.git/blob/refs/heads/7.x-2.x:/...

This is where we check for it:
http://drupalcode.org/project/fullcalendar.git/blob/refs/heads/7.x-2.x:/...

redndahead’s picture

Ok so here is what I found out

If in fullcalendar.fullcalendar.js around line 50 you replace

var date, month, year, date_argument, arguments, fetch_url;
date = $('.fullcalendar', calendar).fullCalendar('getDate');
month = $.fullCalendar.formatDate(date, 'MM');
year = $.fullCalendar.formatDate(date, 'yyyy');
date_argument = year + settings.separator + month;

with this

var prev_date, next_date, prev_month, prev_year, next_month, next_year, date_argument, arguments, fetch_url;
        
prev_date = $('.fullcalendar', calendar).fullCalendar('getDate');
next_date = $('.fullcalendar', calendar).fullCalendar('getDate');
        
prev_date.setMonth(prev_date.getMonth() - 1);
prev_month = $.fullCalendar.formatDate(prev_date, 'MM');
prev_year = $.fullCalendar.formatDate(prev_date, 'yyyy');
        
next_date.setMonth(next_date.getMonth() + 1);
next_month = $.fullCalendar.formatDate(next_date, 'MM');
next_year = $.fullCalendar.formatDate(next_date, 'yyyy');

date_argument = prev_year + settings.separator + prev_month + settings.separator + settings.separator + next_year + settings.separator + next_month;

It'll work when moving between months, but not when the calendar is loaded. I can't figure out where it sets the default date in the initial view. All we would need to do was pass it a range like 2011-10--2011-12 and it will get all the events for October, November and December. Technically we could pass it 2011-10-30--2011-12-03 and we would get the events for the showing month. But we would have to calculate what is the first date showing. This may take some work when having to consider what the user chose as the first day of the week.

Any ideas?

tim.plunkett’s picture

See #1353102: Custom initial date is broken for why initial dates are different/broken.

redndahead’s picture

Status: Active » Needs work
FileSize
3.52 KB

Here is a patch that is a proof of concept of getting this to work. There are some assumptions made that might need to be changed or removed.

1) I create a default fixed value of a range from the previous month to the next month. probably needs to be checked for ajax being enabled.
2) I then parse that argument to get me the starting date for fullcalendar.
3) For every update using ajax I create a range of the previous month to the next month and use that as the argument.

Hopefully it's in the right direction.

redndahead’s picture

FileSize
4.18 KB

Seems that with ajax turned off it still works fine. Only issue I've found so far is if you try to set a default date. This patch fixes that.

aspilicious’s picture

What happens on the end or the beginning of a year?

Does month: 13 year 2011 gets converted to january 2012?

redndahead’s picture

It will get converted to january 2012. The strtotime function takes care of that for php and setMonth() takes care of that for javascript. Just noticed I left a couple console.log's in there. Will have to remove that.

aspilicious’s picture

+++ b/js/fullcalendar.fullcalendar.jsundefined
@@ -47,11 +47,25 @@ Drupal.fullcalendar.processOptions = function(settings, dom_id) {
+        arguments = settings.args.replace('full_calendar_browse', date_argument);
+        fetch_url = Drupal.settings.basePath + 'fullcalendar/ajax/results/' + settings.view_name + '/' + settings.view_display + '/' + arguments;
+
         arguments = settings.args.replace('full_calendar_browse', date_argument);
         fetch_url = Drupal.settings.basePath + 'fullcalendar/ajax/results/' + settings.view_name + '/' + settings.view_display + '/' + arguments;
 

feels like duplication :p

aspilicious’s picture

+++ b/includes/views/fullcalendar.views.incundefined
@@ -89,8 +89,27 @@ function fullcalendar_views_pre_view(&$view, &$display_id, &$args) {
+        $start = date('Y-m', strtotime($style_options['times']['date']['year'] . '-' . $style_options['times']['date']['month'] . ' -1 month'));
+        $end = date('Y-m', strtotime($style_options['times']['date']['year'] . '-' . $style_options['times']['date']['month'] . ' +1 month'));

I think we should fetch the first part of strtotime before this line. Preventing duplication...

+++ b/js/fullcalendar.fullcalendar.jsundefined
@@ -47,11 +47,25 @@ Drupal.fullcalendar.processOptions = function(settings, dom_id) {
+        prev_date = $('.fullcalendar', calendar).fullCalendar('getDate');
+        next_date = $('.fullcalendar', calendar).fullCalendar('getDate');

I prefer next_date = prev_date; for performance reasons.

tim.plunkett’s picture

+++ b/js/fullcalendar.fullcalendar.jsundefined
@@ -47,11 +47,25 @@ Drupal.fullcalendar.processOptions = function(settings, dom_id) {
+        prev_date = $('.fullcalendar', calendar).fullCalendar('getDate');
+        next_date = $('.fullcalendar', calendar).fullCalendar('getDate');

Can we use something like next_date = $.extend({}, prev_date); to not run that twice?

That, plus the duplicated lines, plus the console.log(). Otherwise, this makes a lot of sense.

tim.plunkett’s picture

I think @aspilicious meant something like this:

// Instead of:

$start = date('Y-m', strtotime($style_options['times']['date']['year'] . '-' . $style_options['times']['date']['month'] . ' -1 month'));
$end = date('Y-m', strtotime($style_options['times']['date']['year'] . '-' . $style_options['times']['date']['month'] . ' +1 month'));

// Do:

$date_string = $style_options['times']['date']['year'] . '-' . $style_options['times']['date']['month'];
$start = date('Y-m', strtotime($date_string . ' -1 month'));
$end = date('Y-m', strtotime($date_string . ' +1 month'));
redndahead’s picture

Status: Needs work » Needs review
FileSize
3.83 KB

Here is an updated patch.

redndahead’s picture

FileSize
3.85 KB

Here is one without the $.extend() code that doesn't seem to be working.

redndahead’s picture

FileSize
3.82 KB

Here is the fixed date copy version.

tim.plunkett’s picture

With Ajax

  • with default date: WORKS
  • with date from url: ?month=3 shows April with no results
  • with no default or url: WORKS

Without Ajax

  • with default date: month set to May shows June
  • with date from url: ?month=3 shows April
  • with no default or url: WORKS
redndahead’s picture

FileSize
5.33 KB

This one removes the $separator variable. Also it fixes the other 3 broken issues reported above.

redndahead’s picture

FileSize
5.24 KB

This version limits the ajax queries to only the visible calendar dates.

redndahead’s picture

FileSize
4.9 KB

Some more cleanup with using formatDate()

tim.plunkett’s picture

+++ b/js/fullcalendar.fullcalendar.jsundefined
@@ -47,11 +47,13 @@ Drupal.fullcalendar.processOptions = function(settings, dom_id) {
+        prev_date = $.fullCalendar.formatDate(start, 'yyyy-MM-dd');
+        next_date = $.fullCalendar.formatDate(end, 'yyyy-MM-dd');

Brilliant.

+++ b/theme/theme.incundefined
@@ -166,12 +166,11 @@ function fullcalendar_check_arguments($view) {
+    $timestamp = strtotime($date_range[0] . " +1 month");

I'm not quite sure I understand this line, and don't we just do $settings['date']['month'] = $month - 1; a couple lines down? Maybe we should comment why we do this here.

I'll test all 6 cases again like in #16, but I think this looks really good.

tim.plunkett’s picture

With ajax, with a query string, nothing is loaded. Here is a patch that moves stuff around.

hook_fullcalendar_options_process is a terrible hook. It runs way too late for most things, and does too much.

tim.plunkett’s picture

Okay, this finally breaks up the insanity of hook_fullcalendar_options_process.

tim.plunkett’s picture

Okay, I hope we never again have to worry about zero-based vs one-based months.

This one works for me in all 6 cases.

tim.plunkett’s picture

Assigned: Unassigned » aspilicious

@redndahead said this worked in IRC, and I really want to commit this, but I should really let aspilicious double check.

redndahead’s picture

Assigned: aspilicious » Unassigned
FileSize
14.05 KB

This patch adds the fix from here since it's a small fix and we are already messing with that code. #1206518: Call a specific calendar view through the URL

tim.plunkett’s picture

Assigned: Unassigned » aspilicious

cross posted

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

Tested all the situations.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Fixed

http://drupalcode.org/project/fullcalendar.git/commit/e5a8bf7
Awesome.

Now we just need to figure out http://drupal.org/node/1206742 and we're really pretty much done.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.