diff --git a/src/addon/calendar/lang/en.json b/src/addon/calendar/lang/en.json index 63e4b17ec..3342aaeeb 100644 --- a/src/addon/calendar/lang/en.json +++ b/src/addon/calendar/lang/en.json @@ -6,6 +6,7 @@ "errorloadevents": "Error loading events.", "eventendtime": "End time", "eventstarttime": "Start time", + "gotoactivity": "Go to activity", "noevents": "There are no events", "notifications": "Notifications", "typeclose": "Close event", diff --git a/src/addon/calendar/pages/event/event.html b/src/addon/calendar/pages/event/event.html index 8f68f8c46..dcef19bcc 100644 --- a/src/addon/calendar/pages/event/event.html +++ b/src/addon/calendar/pages/event/event.html @@ -22,10 +22,14 @@

{{ 'addon.calendar.eventendtime' | translate}}

{{ (event.timestart + event.timeduration) |  coreToLocaleString }}

- +

{{ 'core.course' | translate}}

-
+ + +

{{ 'core.category' | translate}}

+

+
{{event.moduleName}} @@ -34,6 +38,9 @@

+ + {{ 'addon.calendar.gotoactivity' | translate }} + diff --git a/src/addon/calendar/pages/event/event.ts b/src/addon/calendar/pages/event/event.ts index 274449cf7..1ddac25d8 100644 --- a/src/addon/calendar/pages/event/event.ts +++ b/src/addon/calendar/pages/event/event.ts @@ -19,6 +19,7 @@ import { AddonCalendarProvider } from '../../providers/calendar'; import { AddonCalendarHelperProvider } from '../../providers/helper'; import { CoreCoursesProvider } from '@core/courses/providers/courses'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreSitesProvider } from '@providers/sites'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreCourseProvider } from '@core/course/providers/course'; @@ -43,12 +44,16 @@ export class AddonCalendarEventPage { event: any = {}; title: string; courseName: string; + courseUrl = ''; notificationsEnabled = false; + moduleUrl = ''; + categoryPath = ''; constructor(private translate: TranslateService, private calendarProvider: AddonCalendarProvider, navParams: NavParams, private domUtils: CoreDomUtilsProvider, private coursesProvider: CoreCoursesProvider, timeUtils: CoreTimeUtilsProvider, - private calendarHelper: AddonCalendarHelperProvider, sitesProvider: CoreSitesProvider, - localNotificationsProvider: CoreLocalNotificationsProvider, private courseProvider: CoreCourseProvider) { + private calendarHelper: AddonCalendarHelperProvider, private sitesProvider: CoreSitesProvider, + localNotificationsProvider: CoreLocalNotificationsProvider, private courseProvider: CoreCourseProvider, + private textUtils: CoreTextUtilsProvider) { this.eventId = navParams.get('id'); this.notificationsEnabled = localNotificationsProvider.isAvailable(); @@ -90,10 +95,28 @@ export class AddonCalendarEventPage { * @return {Promise} Promise resolved when done. */ fetchEvent(): Promise { - return this.calendarProvider.getEvent(this.eventId).then((event) => { + const currentSite = this.sitesProvider.getCurrentSite(), + canGetById = this.calendarProvider.isGetEventByIdAvailable(); + let promise; + + if (canGetById) { + promise = this.calendarProvider.getEventById(this.eventId); + } else { + promise = this.calendarProvider.getEvent(this.eventId); + } + + return promise.then((event) => { + const promises = []; + this.calendarHelper.formatEventData(event); this.event = event; + // Reset some of the calculated data. + this.categoryPath = ''; + this.courseName = ''; + this.courseUrl = ''; + this.moduleUrl = ''; + // Guess event title. let title = this.translate.instant('addon.calendar.type' + event.eventtype); if (event.moduleIcon) { @@ -102,6 +125,8 @@ export class AddonCalendarEventPage { if (name.indexOf('core.mod_') === -1) { event.moduleName = name; } + + // Calculate the title of the page; if (title == 'addon.calendar.type' + event.eventtype) { title = this.translate.instant('core.mod_' + event.modulename + '.' + event.eventtype); @@ -109,19 +134,39 @@ export class AddonCalendarEventPage { title = name; } } + + // Get the module URL. + if (canGetById) { + this.moduleUrl = event.url; + } } else { if (title == 'addon.calendar.type' + event.eventtype) { title = event.name; } } + this.title = title; - if (event.courseid && event.courseid != this.siteHomeId) { - // It's a course event, retrieve the course name. - return this.coursesProvider.getUserCourse(event.courseid, true).then((course) => { + // If the event belongs to a course, get the course name and the URL to view it. + if (canGetById && event.course) { + this.courseName = event.course.fullname; + this.courseUrl = event.course.viewurl; + } else if (event.courseid && event.courseid != this.siteHomeId) { + // Retrieve the course. + promises.push(this.coursesProvider.getUserCourse(event.courseid, true).then((course) => { this.courseName = course.fullname; - }); + this.courseUrl = currentSite ? this.textUtils.concatenatePaths(currentSite.siteUrl, + '/course/view.php?id=' + event.courseid) : ''; + }).catch(() => { + // Error getting course, just don't show the course name. + })); } + + if (canGetById && event.iscategoryevent) { + this.categoryPath = event.category.nestedname; + } + + return Promise.all(promises); }).catch((error) => { this.domUtils.showErrorModalDefault(error, 'addon.calendar.errorloadevent', true); }); diff --git a/src/addon/calendar/providers/calendar.ts b/src/addon/calendar/providers/calendar.ts index 914726cb7..ef7151e02 100644 --- a/src/addon/calendar/providers/calendar.ts +++ b/src/addon/calendar/providers/calendar.ts @@ -200,6 +200,30 @@ export class AddonCalendarProvider { }); } + /** + * Get a calendar event by ID. This function returns more data than getEvent, but it isn't available in all Moodles. + * + * @param {number} id Event ID. + * @param {boolean} [refresh] True when we should update the event data. + * @param {string} [siteId] ID of the site. If not defined, use current site. + * @return {Promise} Promise resolved when the event data is retrieved. + * @since 3.4 + */ + getEventById(id: number, siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + const preSets = { + cacheKey: this.getEventCacheKey(id) + }, + data = { + eventid: id + }; + + return site.read('core_calendar_get_calendar_event_by_id', data, preSets).then((response) => { + return response.event; + }); + }); + } + /** * Get cache key for a single event WS call. * @@ -396,6 +420,16 @@ export class AddonCalendarProvider { }); } + /** + * Check if the get event by ID WS is available. + * + * @return {boolean} Whether it's available. + * @since 3.4 + */ + isGetEventByIdAvailable(): boolean { + return this.sitesProvider.wsAvailableInCurrentSite('core_calendar_get_calendar_event_by_id'); + } + /** * Get the next events for all the sites and schedules their notifications. * If an event notification time is 0, cancel its scheduled notification (if any).