Skip to content

Commit

Permalink
Merge pull request #529 from crazyserver/MOBILE-1654-311
Browse files Browse the repository at this point in the history
MOBILE-1654 files: Notify if files cannot be uploaded
  • Loading branch information
jleyva authored Jun 13, 2016
2 parents 95d28f0 + 61277e2 commit adc68d9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
14 changes: 9 additions & 5 deletions www/addons/files/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ angular.module('mm.addons.files')
$scope.canDownload = $mmSite.canDownloadFiles;

$scope.add = function() {
if (!$mmApp.isOnline()) {
$mmUtil.showErrorModal('mma.files.errormustbeonlinetoupload', true);
} else {
$state.go('site.files-upload');
}
$mmaFiles.versionCanUploadFiles().then(function(canUpload) {
if (!canUpload) {
$mmUtil.showErrorModal('mma.files.erroruploadnotworking', true);
} else if (!$mmApp.isOnline()) {
$mmUtil.showErrorModal('mma.files.errormustbeonlinetoupload', true);
} else {
$state.go('site.files-upload');
}
});
};

});
14 changes: 9 additions & 5 deletions www/addons/files/controllers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ angular.module('mm.addons.files')

// When we are in the root of the private files we can add more files.
$scope.add = function() {
if (!$mmApp.isOnline()) {
$mmUtil.showErrorModal('mma.files.errormustbeonlinetoupload', true);
} else {
$state.go('site.files-upload', {root: root, path: path});
}
$mmaFiles.versionCanUploadFiles().then(function(canUpload) {
if (!canUpload) {
$mmUtil.showErrorModal('mma.files.erroruploadnotworking', true);
} else if (!$mmApp.isOnline()) {
$mmUtil.showErrorModal('mma.files.errormustbeonlinetoupload', true);
} else {
$state.go('site.files-upload', {root: root, path: path});
}
});
};
});
1 change: 1 addition & 0 deletions www/addons/files/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"errornoapp": "You don't have an app installed to perform this action.",
"errorreadingfile": "Error reading file.",
"errorreceivefilenosites": "There are no sites stored. Please add a site before trying to upload a file.",
"erroruploadnotworking": "Unfortunately it is currently not possible to upload files to your site.",
"errorwhiledownloading": "An error occured while trying to download the file.",
"errorwhileuploading": "An error occured during the file upload.",
"errorwhilerecordingaudio": "An error occured while trying to record audio.",
Expand Down
20 changes: 20 additions & 0 deletions www/addons/files/services/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ angular.module('mm.addons.files')
return $mmSite.wsAvailable('core_files_get_files');
};

/**
* Check the Moodle version in order to check if upload files is working.
*
* @module mm.addons.files
* @ngdoc method
* @name $mmaFiles#versionCanUploadFiles
* @param {String} [siteId] Id of the site to check. If not defined, use current site.
* @return {Promise} Resolved with true if WS is working, false otherwise.
*/
self.versionCanUploadFiles = function(siteId) {
siteId = siteId || $mmSite.getId();

return $mmSitesManager.getSite(siteId).then(function(site) {
var version = site.getInfo().version;

// Uploading is not working right now for Moodle 3.1.0 (2016052300).
return version && (parseInt(version) != 2016052300);
});
};

/**
* Checks if there is a new file received in iOS. If more than one file is found, treat only the first one.
* The file returned is marked as "treated" and will be deleted in the next execution.
Expand Down

0 comments on commit adc68d9

Please sign in to comment.