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

Changes made to the calcontroller.js file for sharing multiple tokens #765

Closed
wants to merge 7 commits into from
6 changes: 4 additions & 2 deletions js/app/controllers/calcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ app.controller('CalController', ['$scope', 'Calendar', 'CalendarService', 'VEven
$scope.$apply();
});
} else {
$scope.calendarsPromise = CalendarService.getPublicCalendar(constants.publicSharingToken).then(function(calendar) {
$scope.calendars = [calendar];
constants.publicSharingToken.split(".").forEach( (token) => {
$scope.calendarsPromise = CalendarService.getPublicCalendar(token).then(function(calendar) {
$scope.calendars.push(calendar);
});
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry, but the indentation is still wrong. This should be indented by one tab.

is.loading = false;
// TODO - scope.apply should not be necessary here
$scope.$apply();
Copy link
Member

Choose a reason for hiding this comment

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

These two lines are still called for each calendar. Please only call them once all calendars loaded.

To make sure they are called after all are done, you need to create an array with all CalendarService.getPublicCalendar(token) promises and do a Promise.all() on the array.

For more information about Promise functions see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all

Copy link
Member

Choose a reason for hiding this comment

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

Furthermore the catch is currently called on the forEach function. It has to be called on the Promise instead.

Copy link
Author

Choose a reason for hiding this comment

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

I will look into the same :)

Expand Down