Skip to content

Commit 010c26d

Browse files
committed
MOBILE-1987 filepool: Notify file deleted, outdated and downloading
1 parent eed76ba commit 010c26d

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

upgrade.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ information provided here is intended especially for developers.
2323
* A new field has been added to config.json: privacypolicy.
2424
* String identifiers mm.core.elementseparator and mm.core.fieldvalueseparator have been renamed to:
2525
mm.core.listsep and mm.core.labelsep
26+
* Filepool now also throws file events (getFileEventNameByUrl) when files are deleted, outdated or start downloading. It passes an 'action' property to identify the exact action.
2627

2728
=== 3.2 ===
2829

www/core/directives/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ angular.module('mm.core')
204204
$mmFilepool.getFileEventNameByUrl(siteId, fileUrl).then(function(eventName) {
205205
observer = $mmEvents.on(eventName, function(data) {
206206
getState(scope, siteId, fileUrl, timeModified, alwaysDownload);
207-
if (!data.success) {
207+
if (data.action == 'download' && !data.success) {
208208
$mmUtil.showErrorModal('mm.core.errordownloading', true);
209209
}
210210
});

www/core/lib/filepool.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ angular.module('mm.core')
431431
}).then(function() {
432432
// Check if the queue is running.
433433
self.checkQueueProcessing();
434+
self._notifyFileDownloading(siteId, fileId);
434435
return self._getQueuePromise(siteId, fileId);
435436
});
436437
}
@@ -803,6 +804,8 @@ angular.module('mm.core')
803804
addExtension = typeof filePath == "undefined",
804805
pathPromise = filePath ? filePath : self._getFilePath(siteId, fileId, extension);
805806

807+
self._notifyFileDownloading(siteId, fileId);
808+
806809
return $q.when(pathPromise).then(function(filePath) {
807810
if (poolFileObject && poolFileObject.fileId !== fileId) {
808811
$log.error('Invalid object to update passed');
@@ -2055,6 +2058,19 @@ angular.module('mm.core')
20552058
return fileObject.stale || revision > fileObject.revision || timemodified > fileObject.timemodified;
20562059
};
20572060

2061+
/**
2062+
* Notify a file has been deleted.
2063+
*
2064+
* @module mm.core
2065+
* @ngdoc method
2066+
* @name $mmFilepool#_notifyFileDeleted
2067+
* @param {String} siteId The site ID.
2068+
* @param {String} fileId The file ID.
2069+
*/
2070+
self._notifyFileDeleted = function(siteId, fileId) {
2071+
$mmEvents.trigger(self._getFileEventName(siteId, fileId), {action: 'deleted'});
2072+
};
2073+
20582074
/**
20592075
* Notify a file has been downloaded.
20602076
*
@@ -2065,7 +2081,7 @@ angular.module('mm.core')
20652081
* @param {String} fileId The file ID.
20662082
*/
20672083
self._notifyFileDownloaded = function(siteId, fileId) {
2068-
$mmEvents.trigger(self._getFileEventName(siteId, fileId), {success: true});
2084+
$mmEvents.trigger(self._getFileEventName(siteId, fileId), {action: 'download', success: true});
20692085
};
20702086

20712087
/**
@@ -2078,7 +2094,33 @@ angular.module('mm.core')
20782094
* @param {String} fileId The file ID.
20792095
*/
20802096
self._notifyFileDownloadError = function(siteId, fileId) {
2081-
$mmEvents.trigger(self._getFileEventName(siteId, fileId), {success: false});
2097+
$mmEvents.trigger(self._getFileEventName(siteId, fileId), {action: 'download', success: false});
2098+
};
2099+
2100+
/**
2101+
* Notify a file starts being downloaded or added to queue.
2102+
*
2103+
* @module mm.core
2104+
* @ngdoc method
2105+
* @name $mmFilepool#_notifyFileDownloading
2106+
* @param {String} siteId The site ID.
2107+
* @param {String} fileId The file ID.
2108+
*/
2109+
self._notifyFileDownloading = function(siteId, fileId) {
2110+
$mmEvents.trigger(self._getFileEventName(siteId, fileId), {action: 'downloading'});
2111+
};
2112+
2113+
/**
2114+
* Notify a file has been outdated.
2115+
*
2116+
* @module mm.core
2117+
* @ngdoc method
2118+
* @name $mmFilepool#_notifyFileOutdated
2119+
* @param {String} siteId The site ID.
2120+
* @param {String} fileId The file ID.
2121+
*/
2122+
self._notifyFileOutdated = function(siteId, fileId) {
2123+
$mmEvents.trigger(self._getFileEventName(siteId, fileId), {action: 'outdated'});
20822124
};
20832125

20842126
/**
@@ -2352,7 +2394,9 @@ angular.module('mm.core')
23522394
}));
23532395
}
23542396

2355-
return $q.all(promises);
2397+
return $q.all(promises).then(function() {
2398+
self._notifyFileDeleted(siteId, fileId);
2399+
});
23562400
});
23572401
});
23582402
};

0 commit comments

Comments
 (0)