MOBILE-2591 calendar: Display button to go to activity in event

main
dpalou 2018-09-21 10:40:51 +02:00
parent 63c1ff79d1
commit faf5835708
4 changed files with 96 additions and 9 deletions

View File

@ -6,6 +6,7 @@
"errorloadevents": "Error loading events.", "errorloadevents": "Error loading events.",
"eventendtime": "End time", "eventendtime": "End time",
"eventstarttime": "Start time", "eventstarttime": "Start time",
"gotoactivity": "Go to activity",
"noevents": "There are no events", "noevents": "There are no events",
"notifications": "Notifications", "notifications": "Notifications",
"typeclose": "Close event", "typeclose": "Close event",

View File

@ -22,10 +22,14 @@
<h2>{{ 'addon.calendar.eventendtime' | translate}}</h2> <h2>{{ 'addon.calendar.eventendtime' | translate}}</h2>
<p>{{ (event.timestart + event.timeduration) |  coreToLocaleString }}</p> <p>{{ (event.timestart + event.timeduration) |  coreToLocaleString }}</p>
</ion-item> </ion-item>
<ion-item text-wrap *ngIf="courseName"> <a ion-item text-wrap *ngIf="courseName" [href]="courseUrl" core-link capture="true">
<h2>{{ 'core.course' | translate}}</h2> <h2>{{ 'core.course' | translate}}</h2>
<p><core-format-text [text]="courseName"></core-format-text></p> <p><core-format-text [text]="courseName"></core-format-text></p>
</ion-item> </a>
<a ion-item text-wrap *ngIf="categoryPath">
<h2>{{ 'core.category' | translate}}</h2>
<p><core-format-text [text]="categoryPath"></core-format-text></p>
</a>
<ion-item text-wrap *ngIf="event.moduleIcon"> <ion-item text-wrap *ngIf="event.moduleIcon">
<img *ngIf="event.moduleIcon" src="{{event.moduleIcon}}" item-start alt="" role="presentation" class="core-module-icon"> {{event.moduleName}} <img *ngIf="event.moduleIcon" src="{{event.moduleIcon}}" item-start alt="" role="presentation" class="core-module-icon"> {{event.moduleName}}
</ion-item> </ion-item>
@ -34,6 +38,9 @@
<core-format-text [text]="event.description"></core-format-text> <core-format-text [text]="event.description"></core-format-text>
</p> </p>
</ion-item> </ion-item>
<ion-item *ngIf="moduleUrl">
<a ion-button block color="primary" [href]="moduleUrl" core-link capture="true">{{ 'addon.calendar.gotoactivity' | translate }}</a>
</ion-item>
</ion-card-content> </ion-card-content>
</ion-card> </ion-card>

View File

@ -19,6 +19,7 @@ import { AddonCalendarProvider } from '../../providers/calendar';
import { AddonCalendarHelperProvider } from '../../providers/helper'; import { AddonCalendarHelperProvider } from '../../providers/helper';
import { CoreCoursesProvider } from '@core/courses/providers/courses'; import { CoreCoursesProvider } from '@core/courses/providers/courses';
import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreSitesProvider } from '@providers/sites'; import { CoreSitesProvider } from '@providers/sites';
import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseProvider } from '@core/course/providers/course';
@ -43,12 +44,16 @@ export class AddonCalendarEventPage {
event: any = {}; event: any = {};
title: string; title: string;
courseName: string; courseName: string;
courseUrl = '';
notificationsEnabled = false; notificationsEnabled = false;
moduleUrl = '';
categoryPath = '';
constructor(private translate: TranslateService, private calendarProvider: AddonCalendarProvider, navParams: NavParams, constructor(private translate: TranslateService, private calendarProvider: AddonCalendarProvider, navParams: NavParams,
private domUtils: CoreDomUtilsProvider, private coursesProvider: CoreCoursesProvider, timeUtils: CoreTimeUtilsProvider, private domUtils: CoreDomUtilsProvider, private coursesProvider: CoreCoursesProvider, timeUtils: CoreTimeUtilsProvider,
private calendarHelper: AddonCalendarHelperProvider, sitesProvider: CoreSitesProvider, private calendarHelper: AddonCalendarHelperProvider, private sitesProvider: CoreSitesProvider,
localNotificationsProvider: CoreLocalNotificationsProvider, private courseProvider: CoreCourseProvider) { localNotificationsProvider: CoreLocalNotificationsProvider, private courseProvider: CoreCourseProvider,
private textUtils: CoreTextUtilsProvider) {
this.eventId = navParams.get('id'); this.eventId = navParams.get('id');
this.notificationsEnabled = localNotificationsProvider.isAvailable(); this.notificationsEnabled = localNotificationsProvider.isAvailable();
@ -90,10 +95,28 @@ export class AddonCalendarEventPage {
* @return {Promise<any>} Promise resolved when done. * @return {Promise<any>} Promise resolved when done.
*/ */
fetchEvent(): Promise<any> { fetchEvent(): Promise<any> {
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.calendarHelper.formatEventData(event);
this.event = event; this.event = event;
// Reset some of the calculated data.
this.categoryPath = '';
this.courseName = '';
this.courseUrl = '';
this.moduleUrl = '';
// Guess event title. // Guess event title.
let title = this.translate.instant('addon.calendar.type' + event.eventtype); let title = this.translate.instant('addon.calendar.type' + event.eventtype);
if (event.moduleIcon) { if (event.moduleIcon) {
@ -102,6 +125,8 @@ export class AddonCalendarEventPage {
if (name.indexOf('core.mod_') === -1) { if (name.indexOf('core.mod_') === -1) {
event.moduleName = name; event.moduleName = name;
} }
// Calculate the title of the page;
if (title == 'addon.calendar.type' + event.eventtype) { if (title == 'addon.calendar.type' + event.eventtype) {
title = this.translate.instant('core.mod_' + event.modulename + '.' + event.eventtype); title = this.translate.instant('core.mod_' + event.modulename + '.' + event.eventtype);
@ -109,19 +134,39 @@ export class AddonCalendarEventPage {
title = name; title = name;
} }
} }
// Get the module URL.
if (canGetById) {
this.moduleUrl = event.url;
}
} else { } else {
if (title == 'addon.calendar.type' + event.eventtype) { if (title == 'addon.calendar.type' + event.eventtype) {
title = event.name; title = event.name;
} }
} }
this.title = title; this.title = title;
if (event.courseid && event.courseid != this.siteHomeId) { // If the event belongs to a course, get the course name and the URL to view it.
// It's a course event, retrieve the course name. if (canGetById && event.course) {
return this.coursesProvider.getUserCourse(event.courseid, true).then((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.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) => { }).catch((error) => {
this.domUtils.showErrorModalDefault(error, 'addon.calendar.errorloadevent', true); this.domUtils.showErrorModalDefault(error, 'addon.calendar.errorloadevent', true);
}); });

View File

@ -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<any>} Promise resolved when the event data is retrieved.
* @since 3.4
*/
getEventById(id: number, siteId?: string): Promise<any> {
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. * 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. * 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). * If an event notification time is 0, cancel its scheduled notification (if any).