Skip to content

Commit 0fad8c1

Browse files
committed
MOBILE-2178 modules: Show last download time if no timemodified
1 parent ab6db79 commit 0fad8c1

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

www/core/components/course/services/helper.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ angular.module('mm.core.course')
2323
*/
2424
.factory('$mmCourseHelper', function($q, $mmCoursePrefetchDelegate, $mmFilepool, $mmUtil, $mmCourse, $mmSite, $state, $mmText,
2525
mmCoreNotDownloaded, mmCoreOutdated, mmCoreDownloading, mmCoreCourseAllSectionsId, $mmSitesManager, $mmAddonManager,
26-
$controller, $mmCourseDelegate, $translate, $mmEvents, mmCoreEventPackageStatusChanged, mmCoreNotDownloadable) {
26+
$controller, $mmCourseDelegate, $translate, $mmEvents, mmCoreEventPackageStatusChanged, mmCoreNotDownloadable,
27+
mmCoreDownloaded) {
2728

2829
var self = {},
2930
calculateSectionStatus = false;
@@ -243,9 +244,10 @@ angular.module('mm.core.course')
243244
* @param {Object} module Module to get the info from.
244245
* @param {Number} courseid Course ID the section belongs to.
245246
* @param {Number} [invalidateCache=false] Invalidates the cache first.
247+
* @param {String} [component] Component of the module.
246248
* @return {Promise} Promise resolved with the download size, timemodified and module status.
247249
*/
248-
self.getModulePrefetchInfo = function(module, courseId, invalidateCache) {
250+
self.getModulePrefetchInfo = function(module, courseId, invalidateCache, component) {
249251

250252
var moduleInfo = {
251253
size: false,
@@ -255,6 +257,7 @@ angular.module('mm.core.course')
255257
status: false,
256258
statusIcon: false
257259
},
260+
siteId = $mmSite.getId(),
258261
promises = [];
259262

260263
if (typeof invalidateCache != "undefined" && invalidateCache) {
@@ -298,6 +301,22 @@ angular.module('mm.core.course')
298301
}
299302
}));
300303

304+
// Get the time it was downloaded (if it was downloaded).
305+
promises.push($mmFilepool.getPackageData(siteId, component, module.id).then(function(data) {
306+
if (data && data.downloadtime && (data.status == mmCoreOutdated || data.status == mmCoreDownloaded)) {
307+
moduleInfo.downloadtime = data.downloadtime;
308+
var now = $mmUtil.timestamp();
309+
if (now - data.downloadtime < 7 * 86400) {
310+
moduleInfo.downloadtimeReadable = moment(data.downloadtime * 1000).fromNow();
311+
} else {
312+
moduleInfo.downloadtimeReadable = moment(data.downloadtime * 1000).calendar();
313+
}
314+
}
315+
}).catch(function() {
316+
// Not downloaded.
317+
moduleInfo.downloadtime = 0;
318+
}));
319+
301320
return $q.all(promises).then(function () {
302321
return moduleInfo;
303322
});
@@ -711,14 +730,16 @@ angular.module('mm.core.course')
711730
* @return {Promise} Promise resolved when done.
712731
*/
713732
self.fillContextMenu = function(scope, module, courseId, invalidateCache, component) {
714-
return self.getModulePrefetchInfo(module, courseId, invalidateCache).then(function(moduleInfo) {
733+
return self.getModulePrefetchInfo(module, courseId, invalidateCache, component).then(function(moduleInfo) {
715734
scope.size = moduleInfo.size > 0 ? moduleInfo.sizeReadable : 0;
716735
scope.prefetchStatusIcon = moduleInfo.statusIcon;
717736

718737
if (moduleInfo.status != mmCoreNotDownloadable) {
719738
// Module is downloadable, calculate timemodified.
720739
if (moduleInfo.timemodified > 0) {
721740
scope.timemodified = $translate.instant('mm.core.lastmodified') + ': ' + moduleInfo.timemodifiedReadable;
741+
} else if (moduleInfo.downloadtime > 0) {
742+
scope.timemodified = $translate.instant('mm.core.lastdownloaded') + ': ' + moduleInfo.downloadtimeReadable;
722743
} else {
723744
// Cannot calculate time modified, show a default text.
724745
scope.timemodified = $translate.instant('mm.core.download');

www/core/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"info": "Info",
9595
"ios": "iOS",
9696
"labelsep": ": ",
97+
"lastdownloaded": "Last downloaded",
9798
"lastmodified": "Last modified",
9899
"lastsync": "Last synchronization",
99100
"listsep": ",",

0 commit comments

Comments
 (0)