MOBILE-2591 calendar: Display button to go to activity in event
parent
63c1ff79d1
commit
faf5835708
|
@ -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",
|
||||
|
|
|
@ -22,10 +22,14 @@
|
|||
<h2>{{ 'addon.calendar.eventendtime' | translate}}</h2>
|
||||
<p>{{ (event.timestart + event.timeduration) | coreToLocaleString }}</p>
|
||||
</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>
|
||||
<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">
|
||||
<img *ngIf="event.moduleIcon" src="{{event.moduleIcon}}" item-start alt="" role="presentation" class="core-module-icon"> {{event.moduleName}}
|
||||
</ion-item>
|
||||
|
@ -34,6 +38,9 @@
|
|||
<core-format-text [text]="event.description"></core-format-text>
|
||||
</p>
|
||||
</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>
|
||||
|
||||
|
|
|
@ -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<any>} Promise resolved when done.
|
||||
*/
|
||||
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.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);
|
||||
});
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -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).
|
||||
|
|
Loading…
Reference in New Issue