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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ define([
* @return {Promise}
*/
function indexLeaveRequests (leaveRequestsList) {
var deferred = $q.defer();

leaveRequestsList.forEach(function (leaveRequest) {
var days = leaveRequestDays(leaveRequest);

Expand All @@ -175,9 +173,7 @@ define([
});
});

deferred.resolve();

return deferred.promise;
return $q.resolve();
}

/**
Expand Down Expand Up @@ -248,9 +244,12 @@ define([
var toDate = moment(leaveRequest.to_date);

while (pointerDate.isSameOrBefore(toDate)) {
days.push(_.find(vm.month.days, function (day) {
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.

days.push(_.find(vm.month.days, function (day) {
return day.date === pointerDate.format('YYYY-MM-DD');
}));
}

pointerDate.add(1, 'day');
}
Expand Down Expand Up @@ -315,9 +314,18 @@ define([
* @return {Promise}
*/
function loadMonthLeaveRequests () {
var range = {
from: vm.month.days[0].date,
to: vm.month.days[vm.month.days.length - 1].date
};

return LeaveRequest.all({
from_date: { from: vm.month.days[0].date },
to_date: { to: vm.month.days[vm.month.days.length - 1].date },
from_date: range,
to_date: range,
// The following syntax is a valid CRM API syntax for OR operator -
// Ex. [['field1', 'field2'], ['field3', 'field4']] is the syntax for:
// (field1 OR field2) AND (field3 OR field4)
options: { or: [['from_date', 'to_date']] },
status_id: {'IN': [
leaveRequestStatusValueFromName(sharedSettings.statusNames.approved),
leaveRequestStatusValueFromName(sharedSettings.statusNames.adminApproved),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,16 @@
}));
});

it("uses the selected months' first and last day as date delimiters", function () {
it('loads all requests touching the specified month', function () {
var month = controller.month;

expect(LeaveRequest.all.calls.mostRecent().args[0]).toEqual(jasmine.objectContaining({
from_date: { from: month.days[0].date },
to_date: { to: month.days[month.days.length - 1].date }
}));
var range = {
from: month.days[0].date,
to: month.days[month.days.length - 1].date
};

expect(LeaveRequest.all.calls.mostRecent().args[0]).toEqual(
jasmine.objectContaining({ from_date: range, to_date: range }
));
});
});

Expand Down