diff --git a/scripts/langindex.json b/scripts/langindex.json index 0c05cd558..4cdb865ae 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -13,11 +13,13 @@ "addon.block_myoverview.all": "block_myoverview", "addon.block_myoverview.future": "block_myoverview", "addon.block_myoverview.inprogress": "block_myoverview", + "addon.block_myoverview.lastaccessed": "block_myoverview", "addon.block_myoverview.morecourses": "block_myoverview", "addon.block_myoverview.nocoursesfuture": "block_myoverview", "addon.block_myoverview.nocoursesinprogress": "block_myoverview", "addon.block_myoverview.nocoursespast": "block_myoverview", "addon.block_myoverview.past": "block_myoverview", + "addon.block_myoverview.title": "block_myoverview", "addon.block_timeline.duedate": "block_timeline", "addon.block_timeline.next30days": "block_timeline", "addon.block_timeline.next3months": "block_timeline", diff --git a/src/addon/block/myoverview/component/addon-block-myoverview.html b/src/addon/block/myoverview/component/addon-block-myoverview.html index 8a5cf1324..e12f8e3ee 100644 --- a/src/addon/block/myoverview/component/addon-block-myoverview.html +++ b/src/addon/block/myoverview/component/addon-block-myoverview.html @@ -6,22 +6,31 @@ - -
- - {{ 'addon.block_myoverview.all' | translate }}∫ - {{ 'addon.block_myoverview.inprogress' | translate }} - {{ 'addon.block_myoverview.future' | translate }} - {{ 'addon.block_myoverview.past' | translate }} - +
+ + + + {{ 'addon.block_myoverview.all' | translate }}∫ + {{ 'addon.block_myoverview.inprogress' | translate }} + {{ 'addon.block_myoverview.future' | translate }} + {{ 'addon.block_myoverview.past' | translate }} + + + + + + {{ 'addon.block_myoverview.title' | translate }} + {{ 'addon.block_myoverview.lastaccessed' | translate }} + + -
+ {{prefetchCoursesData[selectedFilter].badge}} -
+
diff --git a/src/addon/block/myoverview/component/myoverview.ts b/src/addon/block/myoverview/component/myoverview.ts index ae339862f..1638d3c4a 100644 --- a/src/addon/block/myoverview/component/myoverview.ts +++ b/src/addon/block/myoverview/component/myoverview.ts @@ -43,6 +43,7 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement future: [] }; selectedFilter = 'inprogress'; + sort = 'title'; currentSite: any; downloadAllCoursesEnabled: boolean; filteredCourses: any[]; @@ -54,6 +55,7 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement }; showFilter = false; showSelectorFilter = false; + showSortFilter = false; protected prefetchIconsInitialized = false; protected isDestroyed; @@ -89,8 +91,16 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement }); this.currentSite = this.sitesProvider.getCurrentSite(); - this.currentSite.getSiteConfig('AddonBlockMyOverviewFilter', this.selectedFilter).then((value) => { + + const promises = []; + promises.push(this.currentSite.getSiteConfig('AddonBlockMyOverviewSort', this.sort).then((value) => { + this.sort = value; + })); + promises.push(this.currentSite.getSiteConfig('AddonBlockMyOverviewFilter', this.selectedFilter).then((value) => { this.selectedFilter = value; + })); + + Promise.all(promises).finally(() => { super.ngOnInit(); }); } @@ -146,26 +156,12 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement }); })); }).then((courses) => { - const today = moment().unix(); - - this.courses.all = courses; - this.courses.past = []; - this.courses.inprogress = []; - this.courses.future = []; - - courses.forEach((course) => { - if ((course.enddate && course.enddate < today) || course.completed) { - // Courses that have already ended. - this.courses.past.push(course); - } else if (course.startdate > today) { - // Courses that have not started yet. - this.courses.future.push(course); - } else { - // Courses still in progress. - this.courses.inprogress.push(course); - } + this.showSortFilter = courses.some((course) => { + return typeof course.lastaccess != 'undefined'; }); + this.sortCourses(courses); + this.courses.filter = ''; this.showFilter = false; this.showSelectorFilter = this.courses.past.length > 0 || this.courses.future.length > 0 || courses.some((course) => { @@ -256,13 +252,61 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement } /** - * The selected courses have changed. + * The selected courses filter have changed. */ selectedChanged(): void { this.currentSite.setSiteConfig('AddonBlockMyOverviewFilter', this.selectedFilter); this.filteredCourses = this.courses[this.selectedFilter]; } + /** + * Sort and init courses filters. + * @param {any[]} courses Courses to sort. + */ + sortCourses(courses: any[]): void { + if (this.showSortFilter) { + if (this.sort == 'lastaccess') { + courses.sort((a, b) => { + return b.lastaccess - a.lastaccess; + }); + } else if (this.sort == 'title') { + courses.sort((a, b) => { + const compareA = a.fullname.toLowerCase(), + compareB = b.fullname.toLowerCase(); + + return compareA.localeCompare(compareB); + }); + } + } + + this.courses.all = courses; + this.courses.past = []; + this.courses.inprogress = []; + this.courses.future = []; + + const today = moment().unix(); + courses.forEach((course) => { + if ((course.enddate && course.enddate < today) || course.completed) { + // Courses that have already ended. + this.courses.past.push(course); + } else if (course.startdate > today) { + // Courses that have not started yet. + this.courses.future.push(course); + } else { + // Courses still in progress. + this.courses.inprogress.push(course); + } + }); + } + + /** + * The selected courses sort filter have changed. + */ + switchSort(): void { + this.currentSite.setSiteConfig('AddonBlockMyOverviewSort', this.sort); + this.sortCourses(this.courses.all); + } + /** * Show or hide the filter. */ diff --git a/src/addon/block/myoverview/lang/en.json b/src/addon/block/myoverview/lang/en.json index b18d8b53e..3e7c5ea22 100644 --- a/src/addon/block/myoverview/lang/en.json +++ b/src/addon/block/myoverview/lang/en.json @@ -6,5 +6,7 @@ "morecourses": "More courses", "nocoursesfuture": "No future courses", "nocoursesinprogress": "No in progress courses", - "nocoursespast": "No past courses" + "nocoursespast": "No past courses", + "lastaccessed": "Last accessed", + "title": "Title" } diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index d8dbc7f79..aec95a8ca 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -13,11 +13,13 @@ "addon.block_myoverview.all": "All", "addon.block_myoverview.future": "Future", "addon.block_myoverview.inprogress": "In progress", + "addon.block_myoverview.lastaccessed": "Last accessed", "addon.block_myoverview.morecourses": "More courses", "addon.block_myoverview.nocoursesfuture": "No future courses", "addon.block_myoverview.nocoursesinprogress": "No in progress courses", "addon.block_myoverview.nocoursespast": "No past courses", "addon.block_myoverview.past": "Past", + "addon.block_myoverview.title": "Title", "addon.block_timeline.duedate": "Due date", "addon.block_timeline.next30days": "Next 30 days", "addon.block_timeline.next3months": "Next 3 months", @@ -1070,7 +1072,7 @@ "core.areyousure": "Are you sure?", "core.back": "Back", "core.cancel": "Cancel", - "core.cannotconnect": "Cannot connect: Verify that you have correctly typed the URL and that your site uses Moodle 2.4 or later.", + "core.cannotconnect": "Cannot connect: verify that you have typed correctly the URL.", "core.cannotdownloadfiles": "File downloading is disabled. Please contact your site administrator.", "core.captureaudio": "Record audio", "core.capturedimage": "Taken picture.", @@ -1354,6 +1356,7 @@ "core.login.selectsite": "Please select your site:", "core.login.signupplugindisabled": "{{$a}} is not enabled.", "core.login.siteaddress": "Site address", + "core.login.sitehasredirect": "Your site contains at least one HTTP redirect. The app cannot follow redirects, this could be the issue that's preventing the app from connecting to your site.", "core.login.siteinmaintenance": "Your site is in maintenance mode", "core.login.sitepolicynotagreederror": "Site policy not agreed.", "core.login.siteurl": "Site URL", @@ -1408,6 +1411,7 @@ "core.more": "more", "core.mygroups": "My groups", "core.name": "Name", + "core.networkerroriframemsg": "This content is not available offline. Please connect to the internet and try again.", "core.networkerrormsg": "There was a problem connecting to the site. Please check your connection and try again.", "core.never": "Never", "core.next": "Next",