From a2fbe1c808a01d7f9d2a953c55a5132ced37f295 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 10 Sep 2019 08:38:09 +0200 Subject: [PATCH] MOBILE-3109 lti: Add return types to lti --- src/addon/mod/lti/components/index/index.ts | 6 +- src/addon/mod/lti/providers/lti.ts | 83 ++++++++++++++++++--- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/src/addon/mod/lti/components/index/index.ts b/src/addon/mod/lti/components/index/index.ts index 53819e792..f454dec08 100644 --- a/src/addon/mod/lti/components/index/index.ts +++ b/src/addon/mod/lti/components/index/index.ts @@ -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 { 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. diff --git a/src/addon/mod/lti/providers/lti.ts b/src/addon/mod/lti/providers/lti.ts index 73eef5121..8ea9b09e9 100644 --- a/src/addon/mod/lti/providers/lti.ts +++ b/src/addon/mod/lti/providers/lti.ts @@ -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 { + getLti(courseId: number, cmId: number): Promise { 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 { - const params: any = { + getLtiLaunchData(id: number): Promise { + 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[]; +};