Skip to content

Commit 08b6294

Browse files
authored
Merge pull request #908 from dpalou/MOBILE-1986
Mobile 1986
2 parents 2e74b21 + 0a8d609 commit 08b6294

File tree

12 files changed

+224
-46
lines changed

12 files changed

+224
-46
lines changed

www/addons/files/services/files.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ angular.module('mm.addons.files')
2626
"itemid": 0,
2727
"filepath": "",
2828
"filename": ""
29-
},
30-
moodle310version = 2016052300;
29+
};
3130

3231
/**
3332
* Check if core_files_get_files WS call is available.
@@ -429,8 +428,7 @@ angular.module('mm.addons.files')
429428
siteId = siteId || $mmSite.getId();
430429

431430
return $mmSitesManager.getSite(siteId).then(function(site) {
432-
var version = parseInt(site.getInfo().version, 10);
433-
return version && version >= moodle310version;
431+
return site.isVersionGreaterEqualThan('3.1.0');
434432
});
435433
};
436434

@@ -447,16 +445,12 @@ angular.module('mm.addons.files')
447445
siteId = siteId || $mmSite.getId();
448446

449447
return $mmSitesManager.getSite(siteId).then(function(site) {
450-
var version = parseInt(site.getInfo().version, 10);
451-
if (!version) {
452-
// Cannot determine version, return false.
453-
return false;
454-
} else if (version == moodle310version) {
455-
// Uploading is not working right now for Moodle 3.1.0 (2016052300).
456-
return false;
457-
} else if (version > moodle310version) {
448+
if (site.isVersionGreaterEqualThan('3.1.1')) {
458449
// In Moodle 3.1.1 or higher we need a WS to move to private files.
459450
return self.canMoveFromDraftToPrivate(siteId);
451+
} else if (site.isVersionGreaterEqualThan('3.1.0')) {
452+
// Upload private files doesn't work for Moodle 3.1.0 due to a bug.
453+
return false;
460454
}
461455

462456
return true;

www/addons/mod/assign/controllers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ angular.module('mm.addons.mod_assign')
111111
$scope.summary = response.gradingsummary;
112112

113113
$scope.needsGradingAvalaible = response.gradingsummary.submissionsneedgradingcount > 0 &&
114-
parseInt($mmSite.getInfo().version, 10) >= 2016110200;
114+
$mmSite.isVersionGreaterEqualThan('3.2');
115115
}).catch(function() {
116116
// Fail silently (WS is not available, fallback).
117117
return $q.when();

www/addons/mod/assign/submission/onlinetext/handlers.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,8 @@ angular.module('mm.addons.mod_assign')
137137
*/
138138
self.isEnabledForEdit = function() {
139139
// There's a bug in Moodle 3.1.0 that doesn't allow submitting HTML, so we'll disable this plugin in that case.
140-
// Bug was fixed in 3.1.1 minor release (2016052301) and in master version 2016070700.
141-
var version = parseInt($mmSite.getInfo().version, 10),
142-
localMobileEnabled = $mmSite.checkIfAppUsesLocalMobile();
143-
144-
return (version >= 2016052301 && version < 2016052400) || version >= 2016070700 || localMobileEnabled;
140+
// Bug was fixed in 3.1.1 minor release and in 3.2.
141+
return $mmSite.isVersionGreaterEqualThan('3.1.1') || $mmSite.checkIfAppUsesLocalMobile();
145142
};
146143

147144
/**

www/addons/mod/book/services/book.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,7 @@ angular.module('mm.addons.mod_book')
353353
siteId = siteId || $mmSite.getId();
354354

355355
return $mmSitesManager.getSite(siteId).then(function(site) {
356-
var version = site.getInfo().version;
357-
// Require Moodle 2.9.
358-
return version && (parseInt(version) >= 2015051100) && site.canDownloadFiles();
356+
return site.isVersionGreaterEqualThan('2.9') && site.canDownloadFiles();
359357
});
360358
};
361359

www/addons/mod/forum/controllers/newdiscussion.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ angular.module('mm.addons.mod_forum')
5959
// We need to check which of the returned groups the user can post to.
6060
promise = validateVisibleGroups(forumgroups, refresh);
6161
} else {
62-
// WS already filters groups, no need to do it ourselves.
63-
promise = $q.when(forumgroups);
62+
// WS already filters groups, no need to do it ourselves. Add "All participants" if needed.
63+
promise = addAllParticipantsOption(forumgroups, true);
6464
}
6565

6666
return promise.then(function(forumgroups) {
@@ -135,8 +135,8 @@ angular.module('mm.addons.mod_forum')
135135
return false;
136136
}).then(function(canAdd) {
137137
if (canAdd) {
138-
// The user can post to all groups, return them all.
139-
return forumgroups;
138+
// The user can post to all groups, add the "All participants" option and return them all.
139+
return addAllParticipantsOption(forumgroups);
140140
} else {
141141
// The user can't post to all groups, let's check which groups he can post to.
142142
var promises = [],
@@ -189,6 +189,37 @@ angular.module('mm.addons.mod_forum')
189189
return filtered;
190190
}
191191

192+
// Add the "All participants" option to a list of groups if the user can add a discussion to all participants.
193+
function addAllParticipantsOption(groups, check) {
194+
var promise;
195+
196+
if (!$mmaModForum.isAllParticipantsFixed()) {
197+
// All participants has a bug, don't add it.
198+
return $q.when(groups);
199+
} else if (check) {
200+
// We need to check if the user can add a discussion to all participants.
201+
promise = $mmaModForum.canAddDiscussionToAll(forumId).catch(function() {
202+
// The call failed, let's assume he can't.
203+
return false;
204+
});
205+
} else {
206+
// No need to check, assume the user can.
207+
promise = $q.when(true);
208+
}
209+
210+
return promise.then(function(canAdd) {
211+
if (canAdd) {
212+
groups.unshift({
213+
courseid: courseId,
214+
id: -1,
215+
name: $translate.instant('mm.core.allparticipants')
216+
});
217+
}
218+
219+
return groups;
220+
});
221+
}
222+
192223
fetchDiscussionData().finally(function() {
193224
$scope.groupsLoaded = true;
194225
});

www/addons/mod/forum/services/forum.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ angular.module('mm.addons.mod_forum')
203203
self.canAddAttachments = function(siteId) {
204204
return $mmSitesManager.getSite(siteId).then(function(site) {
205205
// Attachments allowed from Moodle 3.1.
206-
var version = parseInt(site.getInfo().version, 10);
207-
return version && version >= 2016052300;
206+
return site.isVersionGreaterEqualThan('3.1');
208207
});
209208
};
210209

@@ -268,6 +267,18 @@ angular.module('mm.addons.mod_forum')
268267
return undefined;
269268
};
270269

270+
/**
271+
* There was a bug adding new discussions to All Participants (see MDL-57962). Check if it's fixed.
272+
*
273+
* @module mm.addons.mod_forum
274+
* @ngdoc method
275+
* @name $mmaModForum#isAllParticipantsFixed
276+
* @return {Boolean} True if fixed, false otherwise.
277+
*/
278+
self.isAllParticipantsFixed = function() {
279+
return $mmSite.isVersionGreaterEqualThan(['3.1.5', '3.2.2']);
280+
};
281+
271282
/**
272283
* Check if canAddDiscussion is available.
273284
*

www/addons/mod/imscp/services/imscp.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ angular.module('mm.addons.mod_imscp')
358358
siteId = siteId || $mmSite.getId();
359359

360360
return $mmSitesManager.getSite(siteId).then(function(site) {
361-
var version = site.getInfo().version;
362-
// Require Moodle 2.9.
363-
return version && (parseInt(version) >= 2015051100) && site.canDownloadFiles();
361+
return site.isVersionGreaterEqualThan('2.9') && site.canDownloadFiles();
364362
});
365363
};
366364

www/addons/mod/wiki/services/wiki.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,8 @@ angular.module('mm.addons.mod_wiki')
448448
}
449449

450450
if (lockonly) {
451-
var version = $mmSite.getInfo().version;
452-
453451
// This parameter requires Moodle 3.2. It saves network usage.
454-
if (version && parseInt(version, 10) >= 2016100700) {
452+
if ($mmSite.isVersionGreaterEqualThan('3.2')) {
455453
params.lockonly = 1;
456454
}
457455
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,7 @@ angular.module('mm.core.course')
597597
}
598598

599599
return $mmSitesManager.getSite(siteId).then(function(site) {
600-
var version = parseInt(site.getInfo().version, 10);
601-
602-
if (version >= 2015051100) {
600+
if (site.isVersionGreaterEqualThan('2.9')) {
603601
// From Moodle 2.9 the course contents can be filtered, so maybe the module doesn't have contents
604602
// because they were filtered. Try to get its contents.
605603
return self.getModule(module.id, courseId, sectionId, preferCache, ignoreCache, siteId).then(function(mod) {

www/core/lib/site.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,32 @@ angular.module('mm.core')
498498
* Check if a certain feature is disabled in the site.
499499
*/
500500

501+
/**
502+
* @module mm.core
503+
* @ngdoc method
504+
* @name $mmSite#isVersionGreaterEqualThan
505+
* @param {Mixed} versions Version or list of versions to check.
506+
* @return {Boolean} True if greater or equal, false otherwise.
507+
* @description
508+
*
509+
* Check if the site version is greater than one or some versions.
510+
* This function accepts a string or an array of strings. If array, the last version must be the highest.
511+
*
512+
* If a string is supplied (e.g. '3.2.1'), it will check if the site version is greater or equal than this version.
513+
*
514+
* If an array of versions is supplied, it will check if the site version is greater or equal than the last version,
515+
* or if it's higher or equal than any of the other releases supplied but lower than the next major release. The last
516+
* version of the array must be the highest version.
517+
* For example, if the values supplied are ['3.0.5', '3.2.3', '3.3.1'] the function will return true if the site version
518+
* is either:
519+
* - Greater or equal than 3.3.1.
520+
* - Greater or equal than 3.2.3 but lower than 3.3.
521+
* - Greater or equal than 3.0.5 but lower than 3.1.
522+
*
523+
* This function only accepts versions from 2.4.0 and above. If any of the versions supplied isn't found, it will assume
524+
* it's the last released major version.
525+
*/
526+
501527
/**
502528
* @module mm.core
503529
* @ngdoc method

0 commit comments

Comments
 (0)