Skip to content

Commit 01776e0

Browse files
committed
MOBILE-1701 assign: Submission and feedback files always outdated
1 parent e0bd739 commit 01776e0

File tree

6 files changed

+47
-39
lines changed

6 files changed

+47
-39
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="item item-text-wrap" ng-if="files.length">
22
<h2>{{plugin.name}}</h2>
3-
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}"></mm-file>
3+
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}" always-download="true"></mm-file>
44
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="item item-text-wrap" ng-if="files.length">
22
<h2>{{plugin.name}}</h2>
3-
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}"></mm-file>
3+
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}" always-download="true"></mm-file>
44
</div>

www/addons/mod/assign/submission/file/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ <h2 class="item item-text-wrap item-divider">{{plugin.name}}</h2>
66

77
<div class="item item-text-wrap" ng-if="files.length && !edit">
88
<h2>{{plugin.name}}</h2>
9-
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}"></mm-file>
9+
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}" always-download="true"></mm-file>
1010
</div>

www/addons/mod/assign/templates/feedbackplugin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h2>{{plugin.name}}</h2>
88
<p><mm-format-text ng-if="text" expand-title="{{plugin.name}}" shorten fullview-on-click="true" newlines-on-fullview="true" watch="true" component="{{assignComponent}}" component-id="{{assign.id}}">
99
{{text}}
1010
</mm-format-text></p>
11-
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}"></mm-file>
11+
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}" always-download="true"></mm-file>
1212
</div>
1313
</span>
1414
</span>

www/addons/mod/assign/templates/submissionplugin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h2>{{plugin.name}}</h2>
88
<p><mm-format-text ng-if="text" expand-title="{{plugin.name}}" shorten fullview-on-click="true" newlines-on-fullview="true" watch="true" component="{{assignComponent}}" component-id="{{assign.id}}">
99
{{text}}
1010
</mm-format-text></p>
11-
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}"></mm-file>
11+
<mm-file ng-repeat="file in files" file="file" component="{{assignComponent}}" component-id="{{assign.id}}" always-download="true"></mm-file>
1212
</div>
1313
</span>
1414
</span>

www/core/directives/file.js

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,56 +29,61 @@ angular.module('mm.core')
2929
* 'filename': Name of the file.
3030
* 'fileurl' or 'url': File URL.
3131
* 'filesize': Optional. Size of the file.
32-
* @param {String} [component] Component the file belongs to.
33-
* @param {Number} [componentId] Component ID.
34-
* @param {Boolean} [timemodified] If set, the value will be used to check if the file is outdated.
35-
* @param {Boolean} [canDelete] True if file can be deleted, false otherwise.
36-
* @param {Function} [onDelete] Function to call when the delete button is clicked.
32+
* @param {String} [component] Component the file belongs to.
33+
* @param {Number} [componentId] Component ID.
34+
* @param {Boolean} [timemodified] If set, the value will be used to check if the file is outdated.
35+
* @param {Boolean} [canDelete] True if file can be deleted, false otherwise.
36+
* @param {Function} [onDelete] Function to call when the delete button is clicked.
37+
* @param {Boolean} [alwaysDownload] True if refresh button should be shown even if the file is not outdated. Defaults to false.
38+
* Use it for files that you cannot determine if they're outdated or not.
3739
*/
3840
.directive('mmFile', function($q, $mmUtil, $mmFilepool, $mmSite, $mmApp, $mmEvents, $mmFS, mmCoreDownloaded, mmCoreDownloading,
3941
mmCoreNotDownloaded, mmCoreOutdated) {
4042

4143
/**
4244
* Convenience function to get the file state and set scope variables based on it.
4345
*
44-
* @param {Object} scope Directive's scope.
45-
* @param {String} siteId Site ID.
46-
* @param {String} fileUrl File URL.
47-
* @param {Number} [timeModified] File's timemodified.
46+
* @param {Object} scope Directive's scope.
47+
* @param {String} siteId Site ID.
48+
* @param {String} fileUrl File URL.
49+
* @param {Number} [timeModified] File's timemodified.
50+
* @param {Boolean} alwaysDownload True to show refresh button even if the file is not outdated.
4851
* @return {Void}
4952
*/
50-
function getState(scope, siteId, fileUrl, timeModified) {
53+
function getState(scope, siteId, fileUrl, timeModified, alwaysDownload) {
5154
return $mmFilepool.getFileStateByUrl(siteId, fileUrl, timeModified).then(function(state) {
5255
var canDownload = $mmSite.canDownloadFiles();
5356
scope.isDownloaded = state === mmCoreDownloaded || state === mmCoreOutdated;
5457
scope.isDownloading = canDownload && state === mmCoreDownloading;
55-
scope.showDownload = canDownload && (state === mmCoreNotDownloaded || state === mmCoreOutdated);
58+
scope.showDownload = canDownload && (state === mmCoreNotDownloaded || state === mmCoreOutdated ||
59+
(alwaysDownload && state === mmCoreDownloaded));
5660
});
5761
}
5862

5963
/**
6064
* Convenience function to download a file.
6165
*
62-
* @param {Object} scope Directive's scope.
63-
* @param {String} siteId Site ID.
64-
* @param {String} fileUrl File URL.
65-
* @param {String} component Component the file belongs to.
66-
* @param {Number} componentId Component ID.
67-
* @param {Number} [timeModified] File's timemodified.
68-
* @return {Promise} Promise resolved when file is downloaded.
66+
* @param {Object} scope Directive's scope.
67+
* @param {String} siteId Site ID.
68+
* @param {String} fileUrl File URL.
69+
* @param {String} component Component the file belongs to.
70+
* @param {Number} componentId Component ID.
71+
* @param {Number} [timeModified] File's timemodified.
72+
* @param {Boolean} alwaysDownload True to show refresh button even if the file is not outdated.
73+
* @return {Promise} Promise resolved when file is downloaded.
6974
*/
70-
function downloadFile(scope, siteId, fileUrl, component, componentId, timeModified) {
75+
function downloadFile(scope, siteId, fileUrl, component, componentId, timeModified, alwaysDownload) {
7176
if (!$mmSite.canDownloadFiles()) {
7277
$mmUtil.showErrorModal('mm.core.cannotdownloadfiles', true);
7378
return $q.reject();
7479
}
7580

7681
scope.isDownloading = true;
7782
return $mmFilepool.downloadUrl(siteId, fileUrl, false, component, componentId, timeModified).then(function(localUrl) {
78-
getState(scope, siteId, fileUrl, timeModified); // Update state.
83+
getState(scope, siteId, fileUrl, timeModified, alwaysDownload); // Update state.
7984
return localUrl;
8085
}, function() {
81-
return getState(scope, siteId, fileUrl, timeModified).then(function() {
86+
return getState(scope, siteId, fileUrl, timeModified, alwaysDownload).then(function() {
8287
if (scope.isDownloaded) {
8388
return localUrl;
8489
} else {
@@ -91,16 +96,17 @@ angular.module('mm.core')
9196
/**
9297
* Convenience function to open a file, downloading it if needed.
9398
*
94-
* @param {Object} scope Directive's scope.
95-
* @param {String} siteId Site ID.
96-
* @param {String} fileUrl File URL.
97-
* @param {String} fileSize File size.
98-
* @param {String} component Component the file belongs to.
99-
* @param {Number} componentId Component ID.
100-
* @param {Number} [timeModified] File's timemodified.
99+
* @param {Object} scope Directive's scope.
100+
* @param {String} siteId Site ID.
101+
* @param {String} fileUrl File URL.
102+
* @param {String} fileSize File size.
103+
* @param {String} component Component the file belongs to.
104+
* @param {Number} componentId Component ID.
105+
* @param {Number} [timeModified] File's timemodified.
106+
* @param {Boolean} alwaysDownload True to show refresh button even if the file is not outdated.
101107
* @return {Promise} Promise resolved when file is opened.
102108
*/
103-
function openFile(scope, siteId, fileUrl, fileSize, component, componentId, timeModified) {
109+
function openFile(scope, siteId, fileUrl, fileSize, component, componentId, timeModified, alwaysDownload) {
104110
var fixedUrl = $mmSite.fixPluginfileURL(fileUrl),
105111
promise;
106112

@@ -125,11 +131,11 @@ angular.module('mm.core')
125131
return;
126132
}
127133
// Download and then return the local URL.
128-
return downloadFile(scope, siteId, fileUrl, component, componentId, timeModified);
134+
return downloadFile(scope, siteId, fileUrl, component, componentId, timeModified, alwaysDownload);
129135
}, function() {
130136
// Start the download if in wifi, but return the URL right away so the file is opened.
131137
if (isWifi && isOnline) {
132-
downloadFile(scope, siteId, fileUrl, component, componentId, timeModified);
138+
downloadFile(scope, siteId, fileUrl, component, componentId, timeModified, alwaysDownload);
133139
}
134140

135141
if (scope.isDownloading || !scope.isDownloaded || isOnline) {
@@ -176,6 +182,7 @@ angular.module('mm.core')
176182
siteId = $mmSite.getId(),
177183
component = attrs.component,
178184
componentId = attrs.componentId,
185+
alwaysDownload = attrs.alwaysDownload && attrs.alwaysDownload !== 'false',
179186
observer;
180187

181188
if (!fileName) {
@@ -185,11 +192,11 @@ angular.module('mm.core')
185192

186193
scope.filename = fileName;
187194
scope.fileicon = $mmFS.getFileIcon(fileName);
188-
getState(scope, siteId, fileUrl, timeModified);
195+
getState(scope, siteId, fileUrl, timeModified, alwaysDownload);
189196

190197
$mmFilepool.getFileEventNameByUrl(siteId, fileUrl).then(function(eventName) {
191198
observer = $mmEvents.on(eventName, function(data) {
192-
getState(scope, siteId, fileUrl, timeModified);
199+
getState(scope, siteId, fileUrl, timeModified, alwaysDownload);
193200
if (!data.success) {
194201
$mmUtil.showErrorModal('mm.core.errordownloading', true);
195202
}
@@ -212,7 +219,8 @@ angular.module('mm.core')
212219

213220
if (openAfterDownload) {
214221
// File needs to be opened now. If file needs to be downloaded, skip the queue.
215-
openFile(scope, siteId, fileUrl, fileSize, component, componentId, timeModified).catch(function(error) {
222+
openFile(scope, siteId, fileUrl, fileSize, component, componentId, timeModified, alwaysDownload)
223+
.catch(function(error) {
216224
$mmUtil.showErrorModal(error);
217225
});
218226
} else {

0 commit comments

Comments
 (0)