MOBILE-3109 lti: Add return types to lti

main
Dani Palou 2019-09-10 08:38:09 +02:00
parent 3647b7bfa0
commit a2fbe1c808
2 changed files with 76 additions and 13 deletions

View File

@ -15,7 +15,7 @@
import { Component, Optional, Injector } from '@angular/core';
import { Content } from 'ionic-angular';
import { CoreCourseModuleMainActivityComponent } from '@core/course/classes/main-activity-component';
import { AddonModLtiProvider } from '../../providers/lti';
import { AddonModLtiProvider, AddonModLtiLti } from '../../providers/lti';
/**
* Component that displays an LTI entry page.
@ -28,7 +28,7 @@ export class AddonModLtiIndexComponent extends CoreCourseModuleMainActivityCompo
component = AddonModLtiProvider.COMPONENT;
moduleName = 'lti';
lti: any; // The LTI object.
lti: AddonModLtiLti; // The LTI object.
protected fetchContentDefaultError = 'addon.mod_lti.errorgetlti';
@ -65,7 +65,7 @@ export class AddonModLtiIndexComponent extends CoreCourseModuleMainActivityCompo
protected fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<any> {
return this.ltiProvider.getLti(this.courseId, this.module.id).then((ltiData) => {
this.lti = ltiData;
this.description = this.lti.intro || this.description;
this.description = this.lti.intro;
this.dataRetrieved.emit(this.lti);
}).then(() => {
// All data obtained, now fill the context menu.

View File

@ -22,11 +22,7 @@ import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreUrlUtilsProvider } from '@providers/utils/url';
import { CoreCourseLogHelperProvider } from '@core/course/providers/log-helper';
import { CoreSite } from '@classes/site';
export interface AddonModLtiParam {
name: string;
value: string;
}
import { CoreWSExternalWarning, CoreWSExternalFile } from '@providers/ws';
/**
* Service that provides some features for LTI.
@ -104,7 +100,7 @@ export class AddonModLtiProvider {
* @param cmId Course module ID.
* @return Promise resolved when the LTI is retrieved.
*/
getLti(courseId: number, cmId: number): Promise<any> {
getLti(courseId: number, cmId: number): Promise<AddonModLtiLti> {
const params: any = {
courseids: [courseId]
};
@ -113,7 +109,9 @@ export class AddonModLtiProvider {
updateFrequency: CoreSite.FREQUENCY_RARELY
};
return this.sitesProvider.getCurrentSite().read('mod_lti_get_ltis_by_courses', params, preSets).then((response) => {
return this.sitesProvider.getCurrentSite().read('mod_lti_get_ltis_by_courses', params, preSets)
.then((response: AddonModLtiGetLtisByCoursesResult): any => {
if (response.ltis) {
const currentLti = response.ltis.find((lti) => lti.coursemodule == cmId);
if (currentLti) {
@ -141,8 +139,8 @@ export class AddonModLtiProvider {
* @param id LTI id.
* @return Promise resolved when the launch data is retrieved.
*/
getLtiLaunchData(id: number): Promise<any> {
const params: any = {
getLtiLaunchData(id: number): Promise<AddonModLtiGetToolLaunchDataResult> {
const params = {
toolid: id
};
@ -154,7 +152,9 @@ export class AddonModLtiProvider {
cacheKey: this.getLtiLaunchDataCacheKey(id)
};
return this.sitesProvider.getCurrentSite().read('mod_lti_get_tool_launch_data', params, preSets).then((response) => {
return this.sitesProvider.getCurrentSite().read('mod_lti_get_tool_launch_data', params, preSets)
.then((response: AddonModLtiGetToolLaunchDataResult): any => {
if (response.endpoint) {
return response;
}
@ -227,3 +227,66 @@ export class AddonModLtiProvider {
return this.logHelper.logSingle('mod_lti_view_lti', params, AddonModLtiProvider.COMPONENT, id, name, 'lti', {}, siteId);
}
}
/**
* LTI returned by mod_lti_get_ltis_by_courses.
*/
export type AddonModLtiLti = {
id: number; // External tool id.
coursemodule: number; // Course module id.
course: number; // Course id.
name: string; // LTI name.
intro?: string; // The LTI intro.
introformat?: number; // Intro format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN).
introfiles?: CoreWSExternalFile[]; // @since 3.2.
timecreated?: number; // Time of creation.
timemodified?: number; // Time of last modification.
typeid?: number; // Type id.
toolurl?: string; // Tool url.
securetoolurl?: string; // Secure tool url.
instructorchoicesendname?: string; // Instructor choice send name.
instructorchoicesendemailaddr?: number; // Instructor choice send mail address.
instructorchoiceallowroster?: number; // Instructor choice allow roster.
instructorchoiceallowsetting?: number; // Instructor choice allow setting.
instructorcustomparameters?: string; // Instructor custom parameters.
instructorchoiceacceptgrades?: number; // Instructor choice accept grades.
grade?: number; // Enable grades.
launchcontainer?: number; // Launch container mode.
resourcekey?: string; // Resource key.
password?: string; // Shared secret.
debuglaunch?: number; // Debug launch.
showtitlelaunch?: number; // Show title launch.
showdescriptionlaunch?: number; // Show description launch.
servicesalt?: string; // Service salt.
icon?: string; // Alternative icon URL.
secureicon?: string; // Secure icon URL.
section?: number; // Course section id.
visible?: number; // Visible.
groupmode?: number; // Group mode.
groupingid?: number; // Group id.
};
/**
* Param to send to the LTI.
*/
export type AddonModLtiParam = {
name: string; // Parameter name.
value: string; // Parameter value.
};
/**
* Result of WS mod_lti_get_ltis_by_courses.
*/
export type AddonModLtiGetLtisByCoursesResult = {
ltis: AddonModLtiLti[];
warnings?: CoreWSExternalWarning[];
};
/**
* Result of WS mod_lti_get_tool_launch_data.
*/
export type AddonModLtiGetToolLaunchDataResult = {
endpoint: string; // Endpoint URL.
parameters: AddonModLtiParam[];
warnings?: CoreWSExternalWarning[];
};