From 61277e2f41b888ae23f57412bf951daffc0a6343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 13 Jun 2016 12:54:25 +0200 Subject: [PATCH] MOBILE-1654 files: Notify if files cannot be uploaded --- www/addons/files/controllers/index.js | 14 +++++++++----- www/addons/files/controllers/list.js | 14 +++++++++----- www/addons/files/lang/en.json | 1 + www/addons/files/services/files.js | 20 ++++++++++++++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/www/addons/files/controllers/index.js b/www/addons/files/controllers/index.js index 8e6e5bf2895..b48c2be212e 100644 --- a/www/addons/files/controllers/index.js +++ b/www/addons/files/controllers/index.js @@ -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'); + } + }); }; }); diff --git a/www/addons/files/controllers/list.js b/www/addons/files/controllers/list.js index aacef1d0299..98b08f2e2a2 100644 --- a/www/addons/files/controllers/list.js +++ b/www/addons/files/controllers/list.js @@ -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}); + } + }); }; }); diff --git a/www/addons/files/lang/en.json b/www/addons/files/lang/en.json index b1c88e3e35d..cf29d2b5a2c 100644 --- a/www/addons/files/lang/en.json +++ b/www/addons/files/lang/en.json @@ -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.", diff --git a/www/addons/files/services/files.js b/www/addons/files/services/files.js index 38a380791c9..f94f1b08913 100644 --- a/www/addons/files/services/files.js +++ b/www/addons/files/services/files.js @@ -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.