MOBILE-2614 myoverview: Add lastaccess sort

main
Pau Ferrer Ocaña 2018-10-18 11:04:37 +02:00
parent c77a33edd5
commit 603ae1566f
5 changed files with 93 additions and 32 deletions

View File

@ -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",

View File

@ -6,22 +6,31 @@
</core-navbar-buttons>
<core-loading [hideUntil]="loaded" class="core-loading-center">
<!-- "Time" selector. -->
<div padding class="clearfix" [hidden]="showFilter" ion-row justify-content-end>
<ion-select [hidden]="!showSelectorFilter" [title]="'core.show' | translate" [(ngModel)]="selectedFilter" ion-col (ngModelChange)="selectedChanged()" interface="popover" class="core-button-select">
<ion-option value="all">{{ 'addon.block_myoverview.all' | translate }}</ion-option>
<ion-option value="inprogress">{{ 'addon.block_myoverview.inprogress' | translate }}</ion-option>
<ion-option value="future">{{ 'addon.block_myoverview.future' | translate }}</ion-option>
<ion-option value="past">{{ 'addon.block_myoverview.past' | translate }}</ion-option>
</ion-select>
<div padding ion-row justify-content-end [hidden]="showFilter">
<!-- "Time" selector. -->
<ion-col [hidden]="!showSelectorFilter">
<ion-select text-start [title]="'core.show' | translate" [(ngModel)]="selectedFilter" ion-col (ngModelChange)="selectedChanged()" interface="popover" class="core-button-select">
<ion-option value="all">{{ 'addon.block_myoverview.all' | translate }}</ion-option>
<ion-option value="inprogress">{{ 'addon.block_myoverview.inprogress' | translate }}</ion-option>
<ion-option value="future">{{ 'addon.block_myoverview.future' | translate }}</ion-option>
<ion-option value="past">{{ 'addon.block_myoverview.past' | translate }}</ion-option>
</ion-select>
</ion-col>
<!-- "Sort" selector. -->
<ion-col [hidden]="!showSortFilter">
<ion-select text-start [(ngModel)]="sort" (ngModelChange)="switchSort()" interface="popover" class="core-button-select">
<ion-option value="title">{{ 'addon.block_myoverview.title' | translate }}</ion-option>
<ion-option value="lastaccess">{{ 'addon.block_myoverview.lastaccessed' | translate }}</ion-option>
</ion-select>
</ion-col>
<!-- Download all courses. -->
<div *ngIf="downloadAllCoursesEnabled && courses[selectedFilter] && courses[selectedFilter].length > 1" class="core-button-spinner" ion-col text-end col-1>
<ion-col *ngIf="downloadAllCoursesEnabled && courses[selectedFilter] && courses[selectedFilter].length > 1" class="core-button-spinner" text-end col-1>
<button *ngIf="prefetchCoursesData[selectedFilter].icon && prefetchCoursesData[selectedFilter].icon != 'spinner'" ion-button icon-only clear color="dark" (click)="prefetchCourses()">
<core-icon [name]="prefetchCoursesData[selectedFilter].icon"></core-icon>
</button>
<ion-badge class="core-course-download-courses-progress" *ngIf="prefetchCoursesData[selectedFilter].badge">{{prefetchCoursesData[selectedFilter].badge}}</ion-badge>
<ion-spinner *ngIf="!prefetchCoursesData[selectedFilter].icon || prefetchCoursesData[selectedFilter].icon == 'spinner'"></ion-spinner>
</div>
</ion-col>
</div>
<ng-container *ngIf="courses[selectedFilter].length == 0">
<core-empty-box *ngIf="selectedFilter == 'inprogress'" image="assets/img/icons/courses.svg" [message]="'addon.block_myoverview.nocoursesinprogress' | translate"></core-empty-box>

View File

@ -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.
*/

View File

@ -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"
}

View File

@ -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",