Skip to content

Commit 4bde6c0

Browse files
committed
MOBILE-1701 assign: Fix outdated and apply delegates to prefetch
1 parent 6377904 commit 4bde6c0

File tree

8 files changed

+359
-91
lines changed

8 files changed

+359
-91
lines changed

www/addons/mod/assign/feedback/editpdf/handlers.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ angular.module('mm.addons.mod_assign')
2121
* @ngdoc service
2222
* @name $mmaModAssignFeedbackEditpdfHandler
2323
*/
24-
.factory('$mmaModAssignFeedbackEditpdfHandler', function() {
24+
.factory('$mmaModAssignFeedbackEditpdfHandler', function($mmaModAssign, $mmFilepool, $q, mmaModAssignComponent) {
2525

2626
var self = {};
2727

@@ -43,6 +43,20 @@ angular.module('mm.addons.mod_assign')
4343
return 'mma-mod-assign-feedback-editpdf';
4444
};
4545

46+
/**
47+
* Get files used by this plugin.
48+
* The files returned by this function will be prefetched when the user prefetches the assign.
49+
*
50+
* @param {Object} assign Assignment.
51+
* @param {Object} submission Data returned by $mmaModAssign#getSubmissionStatus.
52+
* @param {Object} plugin Plugin.
53+
* @param {String} [siteId] Site ID. If not defined, current site.
54+
* @return {Promise} Promise resolved when prefetch is done.
55+
*/
56+
self.getPluginFiles = function(assign, submission, plugin, siteId) {
57+
return $mmaModAssign.getSubmissionPluginAttachments(plugin);
58+
};
59+
4660
return self;
4761
})
4862

www/addons/mod/assign/feedback/file/handlers.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ angular.module('mm.addons.mod_assign')
2121
* @ngdoc service
2222
* @name $mmaModAssignFeedbackFileHandler
2323
*/
24-
.factory('$mmaModAssignFeedbackFileHandler', function() {
24+
.factory('$mmaModAssignFeedbackFileHandler', function($mmaModAssign, $mmFilepool, $q, mmaModAssignComponent) {
2525

2626
var self = {};
2727

@@ -43,6 +43,20 @@ angular.module('mm.addons.mod_assign')
4343
return 'mma-mod-assign-feedback-file';
4444
};
4545

46+
/**
47+
* Get files used by this plugin.
48+
* The files returned by this function will be prefetched when the user prefetches the assign.
49+
*
50+
* @param {Object} assign Assignment.
51+
* @param {Object} submission Data returned by $mmaModAssign#getSubmissionStatus.
52+
* @param {Object} plugin Plugin.
53+
* @param {String} [siteId] Site ID. If not defined, current site.
54+
* @return {Promise} Promise resolved when prefetch is done.
55+
*/
56+
self.getPluginFiles = function(assign, submission, plugin, siteId) {
57+
return $mmaModAssign.getSubmissionPluginAttachments(plugin);
58+
};
59+
4660
return self;
4761
})
4862

www/addons/mod/assign/services/feedbackdelegate.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,29 @@ angular.module('mm.addons.mod_assign')
8383
}
8484
};
8585

86+
/**
87+
* Get files used by this plugin.
88+
* The files returned by this function will be prefetched when the user prefetches the assign.
89+
*
90+
* @module mm.addons.mod_assign
91+
* @ngdoc method
92+
* @name $mmaModAssignFeedbackDelegate#getPluginFiles
93+
* @param {Object} assign Assignment.
94+
* @param {Object} submission Data returned by $mmaModAssign#getSubmissionStatus.
95+
* @param {Object} plugin Plugin.
96+
* @param {String} [siteId] Site ID. If not defined, current site.
97+
* @return {Promise} Promise resolved with the files.
98+
*/
99+
self.getPluginFiles = function(assign, submission, plugin, siteId) {
100+
siteId = siteId || $mmSite.getId();
101+
102+
var handler = self.getPluginHandler(plugin.type);
103+
if (handler && handler.getPluginFiles) {
104+
return $q.when(handler.getPluginFiles(assign, submission, plugin, siteId));
105+
}
106+
return $q.when([]);
107+
};
108+
86109
/**
87110
* Check if a time belongs to the last update handlers call.
88111
* This is to handle the cases where updateHandlers don't finish in the same order as they're called.
@@ -113,6 +136,28 @@ angular.module('mm.addons.mod_assign')
113136
return typeof enabledHandlers[pluginType] != 'undefined';
114137
};
115138

139+
/**
140+
* Prefetch any required data for a feedback plugin.
141+
*
142+
* @module mm.addons.mod_assign
143+
* @ngdoc method
144+
* @name $mmaModAssignFeedbackDelegate#prefetch
145+
* @param {Object} assign Assignment.
146+
* @param {Object} submission Data returned by $mmaModAssign#getSubmissionStatus.
147+
* @param {Object} plugin Plugin.
148+
* @param {String} [siteId] Site ID. If not defined, current site.
149+
* @return {Promise} Promise resolved when data has been prefetched.
150+
*/
151+
self.prefetch = function(assign, submission, plugin, siteId) {
152+
siteId = siteId || $mmSite.getId();
153+
154+
var handler = self.getPluginHandler(plugin.type);
155+
if (handler && handler.prefetch) {
156+
return $q.when(handler.prefetch(assign, submission, plugin, siteId));
157+
}
158+
return $q.when();
159+
};
160+
116161
/**
117162
* Register a feedback plugin handler. The handler will be used when submitting an assign.
118163
*

0 commit comments

Comments
 (0)