MOBILE-2334 assign: Implement feedback and submission delegates
This commit is contained in:
		
							parent
							
								
									8400bf7452
								
							
						
					
					
						commit
						e9f7bd0bc5
					
				
							
								
								
									
										31
									
								
								src/addon/mod/assign/assign.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/addon/mod/assign/assign.module.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | |||||||
|  | // (C) Copyright 2015 Martin Dougiamas
 | ||||||
|  | //
 | ||||||
|  | // Licensed under the Apache License, Version 2.0 (the "License");
 | ||||||
|  | // you may not use this file except in compliance with the License.
 | ||||||
|  | // You may obtain a copy of the License at
 | ||||||
|  | //
 | ||||||
|  | //     http://www.apache.org/licenses/LICENSE-2.0
 | ||||||
|  | //
 | ||||||
|  | // Unless required by applicable law or agreed to in writing, software
 | ||||||
|  | // distributed under the License is distributed on an "AS IS" BASIS,
 | ||||||
|  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | ||||||
|  | // See the License for the specific language governing permissions and
 | ||||||
|  | // limitations under the License.
 | ||||||
|  | 
 | ||||||
|  | import { NgModule } from '@angular/core'; | ||||||
|  | import { AddonModAssignFeedbackDelegate } from './providers/feedback-delegate'; | ||||||
|  | import { AddonModAssignSubmissionDelegate } from './providers/submission-delegate'; | ||||||
|  | import { AddonModAssignDefaultFeedbackHandler } from './providers/default-feedback-handler'; | ||||||
|  | import { AddonModAssignDefaultSubmissionHandler } from './providers/default-submission-handler'; | ||||||
|  | 
 | ||||||
|  | @NgModule({ | ||||||
|  |     declarations: [ | ||||||
|  |     ], | ||||||
|  |     providers: [ | ||||||
|  |         AddonModAssignFeedbackDelegate, | ||||||
|  |         AddonModAssignSubmissionDelegate, | ||||||
|  |         AddonModAssignDefaultFeedbackHandler, | ||||||
|  |         AddonModAssignDefaultSubmissionHandler | ||||||
|  |     ] | ||||||
|  | }) | ||||||
|  | export class AddonModAssignModule { } | ||||||
							
								
								
									
										106
									
								
								src/addon/mod/assign/providers/default-feedback-handler.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								src/addon/mod/assign/providers/default-feedback-handler.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,106 @@ | |||||||
|  | // (C) Copyright 2015 Martin Dougiamas
 | ||||||
|  | //
 | ||||||
|  | // Licensed under the Apache License, Version 2.0 (the "License");
 | ||||||
|  | // you may not use this file except in compliance with the License.
 | ||||||
|  | // You may obtain a copy of the License at
 | ||||||
|  | //
 | ||||||
|  | //     http://www.apache.org/licenses/LICENSE-2.0
 | ||||||
|  | //
 | ||||||
|  | // Unless required by applicable law or agreed to in writing, software
 | ||||||
|  | // distributed under the License is distributed on an "AS IS" BASIS,
 | ||||||
|  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | ||||||
|  | // See the License for the specific language governing permissions and
 | ||||||
|  | // limitations under the License.
 | ||||||
|  | 
 | ||||||
|  | import { Injectable } from '@angular/core'; | ||||||
|  | import { TranslateService } from '@ngx-translate/core'; | ||||||
|  | import { AddonModAssignFeedbackHandler } from './feedback-delegate'; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Default handler used when a feedback plugin doesn't have a specific implementation. | ||||||
|  |  */ | ||||||
|  | @Injectable() | ||||||
|  | export class AddonModAssignDefaultFeedbackHandler implements AddonModAssignFeedbackHandler { | ||||||
|  |     name = 'AddonModAssignDefaultFeedbackHandler'; | ||||||
|  |     type = 'default'; | ||||||
|  | 
 | ||||||
|  |     constructor(private translate: TranslateService) { } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get files used by this plugin. | ||||||
|  |      * The files returned by this function will be prefetched when the user prefetches the assign. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {any[]|Promise<any[]>} The files (or promise resolved with the files). | ||||||
|  |      */ | ||||||
|  |     getPluginFiles(assign: any, submission: any, plugin: any, siteId?: string): any[] | Promise<any[]> { | ||||||
|  |         return []; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get a readable name to use for the plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {string} The plugin name. | ||||||
|  |      */ | ||||||
|  |     getPluginName(plugin: any): string { | ||||||
|  |         // Check if there's a translated string for the plugin.
 | ||||||
|  |         const translationId = 'addon.mod_assign_feedback_' + plugin.type + '.pluginname', | ||||||
|  |             translation = this.translate.instant(translationId); | ||||||
|  | 
 | ||||||
|  |         if (translationId != translation) { | ||||||
|  |             // Translation found, use it.
 | ||||||
|  |             return translation; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // Fallback to WS string.
 | ||||||
|  |         if (plugin.name) { | ||||||
|  |             return plugin.name; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if the feedback data has changed for this plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the feedback. | ||||||
|  |      * @return {boolean|Promise<boolean>} Boolean (or promise resolved with boolean): whether the data has changed. | ||||||
|  |      */ | ||||||
|  |     hasDataChanged(assign: any, submission: any, plugin: any, inputData: any): boolean | Promise<boolean> { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check whether the plugin has draft data stored. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {boolean|Promise<boolean>} Boolean or promise resolved with boolean: whether the plugin has draft data. | ||||||
|  |      */ | ||||||
|  |     hasDraftData(assignId: number, userId: number, siteId?: string): boolean | Promise<boolean> { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether or not the handler is enabled on a site level. | ||||||
|  |      * | ||||||
|  |      * @return {boolean|Promise<boolean>} True or promise resolved with true if enabled. | ||||||
|  |      */ | ||||||
|  |     isEnabled(): boolean | Promise<boolean> { | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether or not the handler is enabled for edit on a site level. | ||||||
|  |      * @return {boolean|Promise<boolean>} Whether or not the handler is enabled for edit on a site level. | ||||||
|  |      */ | ||||||
|  |     isEnabledForEdit(): boolean | Promise<boolean> { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										130
									
								
								src/addon/mod/assign/providers/default-submission-handler.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								src/addon/mod/assign/providers/default-submission-handler.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,130 @@ | |||||||
|  | // (C) Copyright 2015 Martin Dougiamas
 | ||||||
|  | //
 | ||||||
|  | // Licensed under the Apache License, Version 2.0 (the "License");
 | ||||||
|  | // you may not use this file except in compliance with the License.
 | ||||||
|  | // You may obtain a copy of the License at
 | ||||||
|  | //
 | ||||||
|  | //     http://www.apache.org/licenses/LICENSE-2.0
 | ||||||
|  | //
 | ||||||
|  | // Unless required by applicable law or agreed to in writing, software
 | ||||||
|  | // distributed under the License is distributed on an "AS IS" BASIS,
 | ||||||
|  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | ||||||
|  | // See the License for the specific language governing permissions and
 | ||||||
|  | // limitations under the License.
 | ||||||
|  | 
 | ||||||
|  | import { Injectable } from '@angular/core'; | ||||||
|  | import { TranslateService } from '@ngx-translate/core'; | ||||||
|  | import { AddonModAssignSubmissionHandler } from './submission-delegate'; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Default handler used when a submission plugin doesn't have a specific implementation. | ||||||
|  |  */ | ||||||
|  | @Injectable() | ||||||
|  | export class AddonModAssignDefaultSubmissionHandler implements AddonModAssignSubmissionHandler { | ||||||
|  |     name = 'AddonModAssignDefaultSubmissionHandler'; | ||||||
|  |     type = 'default'; | ||||||
|  | 
 | ||||||
|  |     constructor(private translate: TranslateService) { } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether the plugin can be edited in offline for existing submissions. In general, this should return false if the | ||||||
|  |      * plugin uses Moodle filters. The reason is that the app only prefetches filtered data, and the user should edit | ||||||
|  |      * unfiltered data. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {boolean|Promise<boolean>} Boolean or promise resolved with boolean: whether it can be edited in offline. | ||||||
|  |      */ | ||||||
|  |     canEditOffline(assign: any, submission: any, plugin: any): boolean | Promise<boolean> { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get files used by this plugin. | ||||||
|  |      * The files returned by this function will be prefetched when the user prefetches the assign. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {any[]|Promise<any[]>} The files (or promise resolved with the files). | ||||||
|  |      */ | ||||||
|  |     getPluginFiles(assign: any, submission: any, plugin: any, siteId?: string): any[] | Promise<any[]> { | ||||||
|  |         return []; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get a readable name to use for the plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {string} The plugin name. | ||||||
|  |      */ | ||||||
|  |     getPluginName(plugin: any): string { | ||||||
|  |         // Check if there's a translated string for the plugin.
 | ||||||
|  |         const translationId = 'addon.mod_assign_submission_' + plugin.type + '.pluginname', | ||||||
|  |             translation = this.translate.instant(translationId); | ||||||
|  | 
 | ||||||
|  |         if (translationId != translation) { | ||||||
|  |             // Translation found, use it.
 | ||||||
|  |             return translation; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // Fallback to WS string.
 | ||||||
|  |         if (plugin.name) { | ||||||
|  |             return plugin.name; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the size of data (in bytes) this plugin will send to copy a previous submission. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {number|Promise<number>} The size (or promise resolved with size). | ||||||
|  |      */ | ||||||
|  |     getSizeForCopy(assign: any, plugin: any): number | Promise<number> { | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the size of data (in bytes) this plugin will send to add or edit a submission. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {number|Promise<number>} The size (or promise resolved with size). | ||||||
|  |      */ | ||||||
|  |     getSizeForEdit(assign: any, plugin: any): number | Promise<number> { | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if the submission data has changed for this plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the submission. | ||||||
|  |      * @return {boolean|Promise<boolean>} Boolean (or promise resolved with boolean): whether the data has changed. | ||||||
|  |      */ | ||||||
|  |     hasDataChanged(assign: any, submission: any, plugin: any, inputData: any): boolean | Promise<boolean> { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether or not the handler is enabled on a site level. | ||||||
|  |      * | ||||||
|  |      * @return {boolean|Promise<boolean>} True or promise resolved with true if enabled. | ||||||
|  |      */ | ||||||
|  |     isEnabled(): boolean | Promise<boolean> { | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether or not the handler is enabled for edit on a site level. | ||||||
|  |      * @return {boolean|Promise<boolean>} Whether or not the handler is enabled for edit on a site level. | ||||||
|  |      */ | ||||||
|  |     isEnabledForEdit(): boolean | Promise<boolean> { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										314
									
								
								src/addon/mod/assign/providers/feedback-delegate.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										314
									
								
								src/addon/mod/assign/providers/feedback-delegate.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,314 @@ | |||||||
|  | // (C) Copyright 2015 Martin Dougiamas
 | ||||||
|  | //
 | ||||||
|  | // Licensed under the Apache License, Version 2.0 (the "License");
 | ||||||
|  | // you may not use this file except in compliance with the License.
 | ||||||
|  | // You may obtain a copy of the License at
 | ||||||
|  | //
 | ||||||
|  | //     http://www.apache.org/licenses/LICENSE-2.0
 | ||||||
|  | //
 | ||||||
|  | // Unless required by applicable law or agreed to in writing, software
 | ||||||
|  | // distributed under the License is distributed on an "AS IS" BASIS,
 | ||||||
|  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | ||||||
|  | // See the License for the specific language governing permissions and
 | ||||||
|  | // limitations under the License.
 | ||||||
|  | 
 | ||||||
|  | import { Injectable, Injector } from '@angular/core'; | ||||||
|  | import { CoreLoggerProvider } from '@providers/logger'; | ||||||
|  | import { CoreEventsProvider } from '@providers/events'; | ||||||
|  | import { CoreSitesProvider } from '@providers/sites'; | ||||||
|  | import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; | ||||||
|  | import { AddonModAssignDefaultFeedbackHandler } from './default-feedback-handler'; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Interface that all feedback handlers must implement. | ||||||
|  |  */ | ||||||
|  | export interface AddonModAssignFeedbackHandler extends CoreDelegateHandler { | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Name of the type of feedback the handler supports. E.g. 'file'. | ||||||
|  |      * @type {string} | ||||||
|  |      */ | ||||||
|  |     type: string; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Discard the draft data of the feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {void|Promise<any>} If the function is async, it should return a Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     discardDraft?(assignId: number, userId: number, siteId?: string): void | Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Return the Component to use to display the plugin data. | ||||||
|  |      * It's recommended to return the class of the component, but you can also return an instance of the component. | ||||||
|  |      * | ||||||
|  |      * @param {Injector} injector Injector. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {any|Promise<any>} The component (or promise resolved with component) to use, undefined if not found. | ||||||
|  |      */ | ||||||
|  |     getComponent?(injector: Injector, plugin: any): any | Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Return the draft saved data of the feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {any|Promise<any>} Data (or promise resolved with the data). | ||||||
|  |      */ | ||||||
|  |     getDraft?(assignId: number, userId: number, siteId?: string): any | Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get files used by this plugin. | ||||||
|  |      * The files returned by this function will be prefetched when the user prefetches the assign. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {any[]|Promise<any[]>} The files (or promise resolved with the files). | ||||||
|  |      */ | ||||||
|  |     getPluginFiles?(assign: any, submission: any, plugin: any, siteId?: string): any[] | Promise<any[]>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get a readable name to use for the plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {string} The plugin name. | ||||||
|  |      */ | ||||||
|  |     getPluginName?(plugin: any): string; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if the feedback data has changed for this plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the feedback. | ||||||
|  |      * @param {number} userId User ID of the submission. | ||||||
|  |      * @return {boolean|Promise<boolean>} Boolean (or promise resolved with boolean): whether the data has changed. | ||||||
|  |      */ | ||||||
|  |     hasDataChanged?(assign: any, submission: any, plugin: any, inputData: any, userId: number): boolean | Promise<boolean>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check whether the plugin has draft data stored. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {boolean|Promise<boolean>} Boolean or promise resolved with boolean: whether the plugin has draft data. | ||||||
|  |      */ | ||||||
|  |     hasDraftData?(assignId: number, userId: number, siteId?: string): boolean | Promise<boolean>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether or not the handler is enabled for edit on a site level. | ||||||
|  |      * | ||||||
|  |      * @return {boolean|Promise<boolean>} Whether or not the handler is enabled for edit on a site level. | ||||||
|  |      */ | ||||||
|  |     isEnabledForEdit?(): boolean | Promise<boolean>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prefetch any required data for the plugin. | ||||||
|  |      * This should NOT prefetch files. Files to be prefetched should be returned by the getPluginFiles function. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     prefetch?(assign: any, submission: any, plugin: any, siteId?: string): Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prepare and add to pluginData the data to send to the server based on the draft data saved. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} pluginData Object where to store the data to send. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {void|Promise<any>} If the function is async, it should return a Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     prepareFeedbackData?(assignId: number, userId: number, plugin: any, pluginData: any, siteId?: string): void | Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Save draft data of the feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} data The data to save. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {void|Promise<any>} If the function is async, it should return a Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     saveDraft?(assignId: number, userId: number, plugin: any, data: any, siteId?: string): void | Promise<any>; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Delegate to register plugins for assign feedback. | ||||||
|  |  */ | ||||||
|  | @Injectable() | ||||||
|  | export class AddonModAssignFeedbackDelegate extends CoreDelegate { | ||||||
|  | 
 | ||||||
|  |     protected handlerNameProperty = 'type'; | ||||||
|  | 
 | ||||||
|  |     constructor(logger: CoreLoggerProvider, sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, | ||||||
|  |             protected defaultHandler: AddonModAssignDefaultFeedbackHandler) { | ||||||
|  |         super('AddonModAssignFeedbackDelegate', logger, sitesProvider, eventsProvider); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Discard the draft data of the feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     discardPluginFeedbackData(assignId: number, userId: number, plugin: any, siteId?: string): Promise<any> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'discardDraft', [assignId, userId, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the component to use for a certain feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {Injector} injector Injector. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {Promise<any>} Promise resolved with the component to use, undefined if not found. | ||||||
|  |      */ | ||||||
|  |     getComponentForPlugin(injector: Injector, plugin: any): Promise<any> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'getComponent', [injector, plugin])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Return the draft saved data of the feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved with the draft data. | ||||||
|  |      */ | ||||||
|  |     getPluginDraftData(assignId: number, userId: number, plugin: any, siteId?: string): Promise<any> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'getDraft', [assignId, userId, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get files used by this plugin. | ||||||
|  |      * The files returned by this function will be prefetched when the user prefetches the assign. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any[]>} Promise resolved with the files. | ||||||
|  |      */ | ||||||
|  |     getPluginFiles(assign: any, submission: any, plugin: any, siteId?: string): Promise<any[]> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'getPluginFiles', [assign, submission, plugin, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get a readable name to use for a certain feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} plugin Plugin to get the name for. | ||||||
|  |      * @return {string} Human readable name. | ||||||
|  |      */ | ||||||
|  |     getPluginName(plugin: any): string { | ||||||
|  |         return this.executeFunctionOnEnabled(plugin.type, 'getPluginName', [plugin]); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if the feedback data has changed for a certain plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the feedback. | ||||||
|  |      * @param {number} userId User ID of the submission. | ||||||
|  |      * @return {Promise<boolean>} Promise resolved with true if data has changed, resolved with false otherwise. | ||||||
|  |      */ | ||||||
|  |     hasPluginDataChanged(assign: any, submission: any, plugin: any, inputData: any, userId: number): Promise<boolean> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'hasDataChanged', | ||||||
|  |                 [assign, submission, plugin, inputData, userId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check whether the plugin has draft data stored. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<boolean>} Promise resolved with true if it has draft data. | ||||||
|  |      */ | ||||||
|  |     hasPluginDraftData(assignId: number, userId: number, plugin: any, siteId?: string): Promise<boolean> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'hasDraftData', [assignId, userId, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if a feedback plugin is supported. | ||||||
|  |      * | ||||||
|  |      * @param {string} pluginType Type of the plugin. | ||||||
|  |      * @return {boolean} Whether it's supported. | ||||||
|  |      */ | ||||||
|  |     isPluginSupported(pluginType: string): boolean { | ||||||
|  |         return this.hasHandler(pluginType, true); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if a feedback plugin is supported for edit. | ||||||
|  |      * | ||||||
|  |      * @param {string} pluginType Type of the plugin. | ||||||
|  |      * @return {Promise<boolean>} Whether it's supported for edit. | ||||||
|  |      */ | ||||||
|  |     isPluginSupportedForEdit(pluginType: string): Promise<boolean> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(pluginType, 'isEnabledForEdit')); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prefetch any required data for a feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     prefetch(assign: any, submission: any, plugin: any, siteId?: string): Promise<any> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'prefetch', [assign, submission, plugin, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prepare and add to pluginData the data to submit for a certain feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} pluginData Object where to store the data to send. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when data has been gathered. | ||||||
|  |      */ | ||||||
|  |     preparePluginFeedbackData(assignId: number, userId: number, plugin: any, pluginData: any, siteId?: string): Promise<any> { | ||||||
|  | 
 | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'prepareFeedbackData', | ||||||
|  |                 [assignId, userId, plugin, pluginData, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Save draft data of the feedback plugin. | ||||||
|  |      * | ||||||
|  |      * @param {number} assignId The assignment ID. | ||||||
|  |      * @param {number} userId User ID. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data to save. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when data has been saved. | ||||||
|  |      */ | ||||||
|  |     saveFeedbackDraft(assignId: number, userId: number, plugin: any, inputData: any, siteId?: string): Promise<any> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'saveDraft', | ||||||
|  |                 [assignId, userId, plugin, inputData, siteId])); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										405
									
								
								src/addon/mod/assign/providers/submission-delegate.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										405
									
								
								src/addon/mod/assign/providers/submission-delegate.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,405 @@ | |||||||
|  | // (C) Copyright 2015 Martin Dougiamas
 | ||||||
|  | //
 | ||||||
|  | // Licensed under the Apache License, Version 2.0 (the "License");
 | ||||||
|  | // you may not use this file except in compliance with the License.
 | ||||||
|  | // You may obtain a copy of the License at
 | ||||||
|  | //
 | ||||||
|  | //     http://www.apache.org/licenses/LICENSE-2.0
 | ||||||
|  | //
 | ||||||
|  | // Unless required by applicable law or agreed to in writing, software
 | ||||||
|  | // distributed under the License is distributed on an "AS IS" BASIS,
 | ||||||
|  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | ||||||
|  | // See the License for the specific language governing permissions and
 | ||||||
|  | // limitations under the License.
 | ||||||
|  | 
 | ||||||
|  | import { Injectable, Injector } from '@angular/core'; | ||||||
|  | import { CoreLoggerProvider } from '@providers/logger'; | ||||||
|  | import { CoreEventsProvider } from '@providers/events'; | ||||||
|  | import { CoreSitesProvider } from '@providers/sites'; | ||||||
|  | import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; | ||||||
|  | import { AddonModAssignDefaultSubmissionHandler } from './default-submission-handler'; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Interface that all submission handlers must implement. | ||||||
|  |  */ | ||||||
|  | export interface AddonModAssignSubmissionHandler extends CoreDelegateHandler { | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Name of the type of submission the handler supports. E.g. 'file'. | ||||||
|  |      * @type {string} | ||||||
|  |      */ | ||||||
|  |     type: string; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether the plugin can be edited in offline for existing submissions. In general, this should return false if the | ||||||
|  |      * plugin uses Moodle filters. The reason is that the app only prefetches filtered data, and the user should edit | ||||||
|  |      * unfiltered data. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {boolean|Promise<boolean>} Boolean or promise resolved with boolean: whether it can be edited in offline. | ||||||
|  |      */ | ||||||
|  |     canEditOffline?(assign: any, submission: any, plugin: any): boolean | Promise<boolean>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Should clear temporary data for a cancelled submission. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the submission. | ||||||
|  |      */ | ||||||
|  |     clearTmpData?(assign: any, submission: any, plugin: any, inputData: any): void; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * This function will be called when the user wants to create a new submission based on the previous one. | ||||||
|  |      * It should add to pluginData the data to send to server based in the data in plugin (previous attempt). | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} pluginData Object where to store the data to send. | ||||||
|  |      * @param {number} [userId] User ID. If not defined, site's current user. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {void|Promise<any>} If the function is async, it should return a Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     copySubmissionData?(assign: any, plugin: any, pluginData: any, userId?: number, siteId?: string): void | Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Delete any stored data for the plugin and submission. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} offlineData Offline data stored. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {void|Promise<any>} If the function is async, it should return a Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     deleteOfflineData?(assign: any, submission: any, plugin: any, offlineData: any, siteId?: string): void | Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Return the Component to use to display the plugin data, either in read or in edit mode. | ||||||
|  |      * It's recommended to return the class of the component, but you can also return an instance of the component. | ||||||
|  |      * | ||||||
|  |      * @param {Injector} injector Injector. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {boolean} [edit] Whether the user is editing. | ||||||
|  |      * @return {any|Promise<any>} The component (or promise resolved with component) to use, undefined if not found. | ||||||
|  |      */ | ||||||
|  |     getComponent?(injector: Injector, plugin: any, edit?: boolean): any | Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get files used by this plugin. | ||||||
|  |      * The files returned by this function will be prefetched when the user prefetches the assign. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {any[]|Promise<any[]>} The files (or promise resolved with the files). | ||||||
|  |      */ | ||||||
|  |     getPluginFiles?(assign: any, submission: any, plugin: any, siteId?: string): any[] | Promise<any[]>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get a readable name to use for the plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {string} The plugin name. | ||||||
|  |      */ | ||||||
|  |     getPluginName?(plugin: any): string; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the size of data (in bytes) this plugin will send to copy a previous submission. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {number|Promise<number>} The size (or promise resolved with size). | ||||||
|  |      */ | ||||||
|  |     getSizeForCopy?(assign: any, plugin: any): number | Promise<number>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the size of data (in bytes) this plugin will send to add or edit a submission. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the submission. | ||||||
|  |      * @return {number|Promise<number>} The size (or promise resolved with size). | ||||||
|  |      */ | ||||||
|  |     getSizeForEdit?(assign: any, submission: any, plugin: any, inputData: any): number | Promise<number>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if the submission data has changed for this plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the submission. | ||||||
|  |      * @return {boolean|Promise<boolean>} Boolean (or promise resolved with boolean): whether the data has changed. | ||||||
|  |      */ | ||||||
|  |     hasDataChanged?(assign: any, submission: any, plugin: any, inputData: any): boolean | Promise<boolean>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether or not the handler is enabled for edit on a site level. | ||||||
|  |      * | ||||||
|  |      * @return {boolean|Promise<boolean>} Whether or not the handler is enabled for edit on a site level. | ||||||
|  |      */ | ||||||
|  |     isEnabledForEdit?(): boolean | Promise<boolean>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prefetch any required data for the plugin. | ||||||
|  |      * This should NOT prefetch files. Files to be prefetched should be returned by the getPluginFiles function. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     prefetch?(assign: any, submission: any, plugin: any, siteId?: string): Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prepare and add to pluginData the data to send to the server based on the input data. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the submission. | ||||||
|  |      * @param {any} pluginData Object where to store the data to send. | ||||||
|  |      * @param {boolean} [offline] Whether the user is editing in offline. | ||||||
|  |      * @param {number} [userId] User ID. If not defined, site's current user. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {void|Promise<any>} If the function is async, it should return a Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     prepareSubmissionData?(assign: any, submission: any, plugin: any, inputData: any, pluginData: any, offline?: boolean, | ||||||
|  |         userId?: number, siteId?: string): void | Promise<any>; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prepare and add to pluginData the data to send to the server based on the offline data stored. | ||||||
|  |      * This will be used when performing a synchronization. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} offlineData Offline data stored. | ||||||
|  |      * @param {any} pluginData Object where to store the data to send. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {void|Promise<any>} If the function is async, it should return a Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     prepareSyncData?(assign: any, submission: any, plugin: any, offlineData: any, pluginData: any, siteId?: string) | ||||||
|  |         : void | Promise<any>; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Delegate to register plugins for assign submission. | ||||||
|  |  */ | ||||||
|  | @Injectable() | ||||||
|  | export class AddonModAssignSubmissionDelegate extends CoreDelegate { | ||||||
|  | 
 | ||||||
|  |     protected handlerNameProperty = 'type'; | ||||||
|  | 
 | ||||||
|  |     constructor(logger: CoreLoggerProvider, sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, | ||||||
|  |             protected defaultHandler: AddonModAssignDefaultSubmissionHandler) { | ||||||
|  |         super('AddonModAssignSubmissionDelegate', logger, sitesProvider, eventsProvider); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Whether the plugin can be edited in offline for existing submissions. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {boolean|Promise<boolean>} Promise resolved with boolean: whether it can be edited in offline. | ||||||
|  |      */ | ||||||
|  |     canPluginEditOffline(assign: any, submission: any, plugin: any): Promise<boolean> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'canEditOffline', [assign, submission, plugin])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Clear some temporary data for a certain plugin because a submission was cancelled. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the submission. | ||||||
|  |      */ | ||||||
|  |     clearTmpData(assign: any, submission: any, plugin: any, inputData: any): void { | ||||||
|  |         return this.executeFunctionOnEnabled(plugin.type, 'return', [assign, submission, plugin, inputData]); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Copy the data from last submitted attempt to the current submission for a certain plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} pluginData Object where to store the data to send. | ||||||
|  |      * @param {number} [userId] User ID. If not defined, site's current user. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when the data has been copied. | ||||||
|  |      */ | ||||||
|  |     copyPluginSubmissionData(assign: any, plugin: any, pluginData: any, userId?: number, siteId?: string): void | Promise<any> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'copySubmissionData', | ||||||
|  |                 [assign, plugin, pluginData, userId, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Delete offline data stored for a certain submission and plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} offlineData Offline data stored. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     deletePluginOfflineData(assign: any, submission: any, plugin: any, offlineData: any, siteId?: string): Promise<any> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'deleteOfflineData', | ||||||
|  |                 [assign, submission, plugin, offlineData, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the component to use for a certain submission plugin. | ||||||
|  |      * | ||||||
|  |      * @param {Injector} injector Injector. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {boolean} [edit] Whether the user is editing. | ||||||
|  |      * @return {Promise<any>} Promise resolved with the component to use, undefined if not found. | ||||||
|  |      */ | ||||||
|  |     getComponentForPlugin(injector: Injector, plugin: any, edit?: boolean): Promise<any> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'getComponent', [injector, plugin, edit])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get files used by this plugin. | ||||||
|  |      * The files returned by this function will be prefetched when the user prefetches the assign. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any[]>} Promise resolved with the files. | ||||||
|  |      */ | ||||||
|  |     getPluginFiles(assign: any, submission: any, plugin: any, siteId?: string): Promise<any[]> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'getPluginFiles', [assign, submission, plugin, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get a readable name to use for a certain submission plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} plugin Plugin to get the name for. | ||||||
|  |      * @return {string} Human readable name. | ||||||
|  |      */ | ||||||
|  |     getPluginName(plugin: any): string { | ||||||
|  |         return this.executeFunctionOnEnabled(plugin.type, 'getPluginName', [plugin]); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the size of data (in bytes) this plugin will send to copy a previous submission. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @return {Promise<number>} Promise resolved with size. | ||||||
|  |      */ | ||||||
|  |     getPluginSizeForCopy(assign: any, plugin: any): Promise<number> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'getSizeForCopy', [assign, plugin])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Get the size of data (in bytes) this plugin will send to add or edit a submission. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the submission. | ||||||
|  |      * @return {Promise<number>} Promise resolved with size. | ||||||
|  |      */ | ||||||
|  |     getPluginSizeForEdit(assign: any, submission: any, plugin: any, inputData: any): Promise<number> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'getSizeForEdit', | ||||||
|  |                 [assign, submission, plugin, inputData])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if the submission data has changed for a certain plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the submission. | ||||||
|  |      * @return {Promise<boolean>} Promise resolved with true if data has changed, resolved with false otherwise. | ||||||
|  |      */ | ||||||
|  |     hasPluginDataChanged(assign: any, submission: any, plugin: any, inputData: any): Promise<boolean> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'hasDataChanged', | ||||||
|  |                 [assign, submission, plugin, inputData])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if a submission plugin is supported. | ||||||
|  |      * | ||||||
|  |      * @param {string} pluginType Type of the plugin. | ||||||
|  |      * @return {boolean} Whether it's supported. | ||||||
|  |      */ | ||||||
|  |     isPluginSupported(pluginType: string): boolean { | ||||||
|  |         return this.hasHandler(pluginType, true); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Check if a submission plugin is supported for edit. | ||||||
|  |      * | ||||||
|  |      * @param {string} pluginType Type of the plugin. | ||||||
|  |      * @return {Promise<boolean>} Whether it's supported for edit. | ||||||
|  |      */ | ||||||
|  |     isPluginSupportedForEdit(pluginType: string): Promise<boolean> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(pluginType, 'isEnabledForEdit')); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prefetch any required data for a submission plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when done. | ||||||
|  |      */ | ||||||
|  |     prefetch(assign: any, submission: any, plugin: any, siteId?: string): Promise<any> { | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'prefetch', [assign, submission, plugin, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prepare and add to pluginData the data to submit for a certain submission plugin. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} inputData Data entered by the user for the submission. | ||||||
|  |      * @param {any} pluginData Object where to store the data to send. | ||||||
|  |      * @param {boolean} [offline] Whether the user is editing in offline. | ||||||
|  |      * @param {number} [userId] User ID. If not defined, site's current user. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when data has been gathered. | ||||||
|  |      */ | ||||||
|  |     preparePluginSubmissionData(assign: any, submission: any, plugin: any, inputData: any, pluginData: any, offline?: boolean, | ||||||
|  |             userId?: number, siteId?: string): Promise<any> { | ||||||
|  | 
 | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'prepareSubmissionData', | ||||||
|  |                 [assign, submission, plugin, inputData, pluginData, offline, userId, siteId])); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Prepare and add to pluginData the data to send to server to synchronize an offline submission. | ||||||
|  |      * | ||||||
|  |      * @param {any} assign The assignment. | ||||||
|  |      * @param {any} submission The submission. | ||||||
|  |      * @param {any} plugin The plugin object. | ||||||
|  |      * @param {any} offlineData Offline data stored. | ||||||
|  |      * @param {any} pluginData Object where to store the data to send. | ||||||
|  |      * @param {string} [siteId] Site ID. If not defined, current site. | ||||||
|  |      * @return {Promise<any>} Promise resolved when data has been gathered. | ||||||
|  |      */ | ||||||
|  |     preparePluginSyncData(assign: any, submission: any, plugin: any, offlineData: any, pluginData: any, siteId?: string) | ||||||
|  |             : Promise<any> { | ||||||
|  | 
 | ||||||
|  |         return Promise.resolve(this.executeFunctionOnEnabled(plugin.type, 'prepareSyncData', | ||||||
|  |                 [assign, submission, plugin, offlineData, pluginData, siteId])); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -76,6 +76,7 @@ import { AddonCalendarModule } from '@addon/calendar/calendar.module'; | |||||||
| import { AddonCompetencyModule } from '@addon/competency/competency.module'; | import { AddonCompetencyModule } from '@addon/competency/competency.module'; | ||||||
| import { AddonUserProfileFieldModule } from '@addon/userprofilefield/userprofilefield.module'; | import { AddonUserProfileFieldModule } from '@addon/userprofilefield/userprofilefield.module'; | ||||||
| import { AddonFilesModule } from '@addon/files/files.module'; | import { AddonFilesModule } from '@addon/files/files.module'; | ||||||
|  | import { AddonModAssignModule } from '@addon/mod/assign/assign.module'; | ||||||
| import { AddonModBookModule } from '@addon/mod/book/book.module'; | import { AddonModBookModule } from '@addon/mod/book/book.module'; | ||||||
| import { AddonModChatModule } from '@addon/mod/chat/chat.module'; | import { AddonModChatModule } from '@addon/mod/chat/chat.module'; | ||||||
| import { AddonModChoiceModule } from '@addon/mod/choice/choice.module'; | import { AddonModChoiceModule } from '@addon/mod/choice/choice.module'; | ||||||
| @ -174,6 +175,7 @@ export const CORE_PROVIDERS: any[] = [ | |||||||
|         AddonCompetencyModule, |         AddonCompetencyModule, | ||||||
|         AddonUserProfileFieldModule, |         AddonUserProfileFieldModule, | ||||||
|         AddonFilesModule, |         AddonFilesModule, | ||||||
|  |         AddonModAssignModule, | ||||||
|         AddonModBookModule, |         AddonModBookModule, | ||||||
|         AddonModChatModule, |         AddonModChatModule, | ||||||
|         AddonModChoiceModule, |         AddonModChoiceModule, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user