Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCHR-2527: Make calendar show requests touching different months #2084

Conversation

igorpavlov-zz
Copy link
Contributor

@igorpavlov-zz igorpavlov-zz commented Aug 22, 2017

Overview

Currently the Leave Calendar does not reflect leave requests that have start and end dates in different months.

Before

1

After

2

Technical Details

Previously, only requests that had the both start and end dates from the specified month are shown.

from_date in January AND to_date in January

Now, all requests that have at least one day from the specified months are shown.

from_date in January OR to_date in January

Comments

  1. The additional check is needed since in this PR the Calendar Month component now gets requests that might touch days from other months. These days should not be considered since they are not going to be rendered.
while (pointerDate.isSameOrBefore(toDate)) {
  // Ensure that pointerDate is in same month/year that component represents
  if (pointerDate.month() === vm.month.index && pointerDate.year() === vm.month.year) {
    days.push(_.find(vm.month.days, function (day) {
      return day.date === pointerDate.format('YYYY-MM-DD');
    }));
  }

  pointerDate.add(1, 'day');
}
  1. Please see this PR CRM-20034 - CRM-20034 - Support OR grouping of api get params civicrm/civicrm-core#9844 for the reference to the OR operator support in CiviCRM.

⚠️ This PR can only be merged after #2085 is merged and synced.


  • Tests Pass

@igorpavlov-zz igorpavlov-zz changed the base branch from staging to la-milestone-3 August 22, 2017 13:25
@igorpavlov-zz igorpavlov-zz force-pushed the PCHR-2527-make-calendar-show-requests-from-diff-months branch from 75fb9dd to 6bd7437 Compare August 22, 2017 14:58
@@ -315,9 +314,13 @@ define([
* @return {Promise}
*/
function loadMonthLeaveRequests () {
var range = { from: vm.month.days[0].date,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation looks weird, please make it,

var range = { 
  from: vm.month.days[0].date,
  to: vm.month.days[vm.month.days.length - 1].date 
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

to_date: { to: vm.month.days[vm.month.days.length - 1].date },
from_date: range,
to_date: range,
options: { or: [['from_date', 'to_date']] },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we have double square brackets, please confirm if that is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is correct. cc @AkA84

to_date: { to: vm.month.days[vm.month.days.length - 1].date },
from_date: range,
to_date: range,
options: { or: [['from_date', 'to_date']] },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a comment in the code, it might get confusing in future.

var month = controller.month;
var range = { from: month.days[0].date,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation looks weird, please fix it as suggested above.

deferred.resolve();

return deferred.promise;
$q.resolve();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not it be return $q.resolve()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pardon.

return day.date === pointerDate.format('YYYY-MM-DD');
}));
// Ensure that pointerDate is in same month/year that component represents
if (pointerDate.month() === vm.month.index && pointerDate.year() === vm.month.year) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change is necessary? Please document it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deb1990 do you suggest to extend the comment or document it in the PR description?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment in the code makes sense, but I am not sure why it was necessary in the context of the ticket, so if you document it in the PR, it will be helpful.

@igorpavlov-zz igorpavlov-zz merged commit 88d5ba8 into la-milestone-3 Aug 22, 2017
@igorpavlov-zz igorpavlov-zz deleted the PCHR-2527-make-calendar-show-requests-from-diff-months branch August 23, 2017 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants