Merge pull request #1573 from crazyserver/MOBILE-2614

Mobile 2614
main
Juan Leyva 2018-10-22 14:15:05 +02:00 committed by GitHub
commit 56bbcd7edf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 207 additions and 71 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">
<div padding ion-row justify-content-end [hidden]="showFilter">
<!-- "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-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

@ -17,6 +17,7 @@ import { Searchbar } from 'ionic-angular';
import * as moment from 'moment';
import { CoreEventsProvider } from '@providers/events';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitesProvider } from '@providers/sites';
import { CoreCoursesProvider } from '@core/courses/providers/courses';
import { CoreCoursesHelperProvider } from '@core/courses/providers/helper';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
@ -42,6 +43,8 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
future: []
};
selectedFilter = 'inprogress';
sort = 'title';
currentSite: any;
downloadAllCoursesEnabled: boolean;
filteredCourses: any[];
prefetchCoursesData = {
@ -52,6 +55,7 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
};
showFilter = false;
showSelectorFilter = false;
showSortFilter = false;
protected prefetchIconsInitialized = false;
protected isDestroyed;
@ -62,7 +66,8 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
constructor(injector: Injector, private coursesProvider: CoreCoursesProvider,
private courseCompletionProvider: AddonCourseCompletionProvider, private eventsProvider: CoreEventsProvider,
private courseHelper: CoreCourseHelperProvider, private utils: CoreUtilsProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate, private coursesHelper: CoreCoursesHelperProvider) {
private courseOptionsDelegate: CoreCourseOptionsDelegate, private coursesHelper: CoreCoursesHelperProvider,
private sitesProvider: CoreSitesProvider) {
super(injector, 'AddonBlockMyOverviewComponent');
}
@ -85,7 +90,19 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
}
});
this.currentSite = this.sitesProvider.getCurrentSite();
const promises = [];
promises.push(this.currentSite.getLocalSiteConfig('AddonBlockMyOverviewSort', this.sort).then((value) => {
this.sort = value;
}));
promises.push(this.currentSite.getLocalSiteConfig('AddonBlockMyOverviewFilter', this.selectedFilter).then((value) => {
this.selectedFilter = value;
}));
Promise.all(promises).finally(() => {
super.ngOnInit();
});
}
/**
@ -139,29 +156,18 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
});
}));
}).then((courses) => {
const today = moment().unix();
this.showSortFilter = courses.length > 0 && typeof courses[0].lastaccess != 'undefined';
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.sortCourses(courses);
this.courses.filter = '';
this.showFilter = false;
this.showSelectorFilter = (this.courses.past.length + this.courses.future.length) > 0;
this.showSelectorFilter = this.courses.past.length > 0 || this.courses.future.length > 0 || (courses.length > 0 &&
typeof courses[0].enddate != 'undefined');
if (!this.showSelectorFilter) {
// No selector, show all.
this.selectedFilter = 'all';
}
this.filteredCourses = this.courses[this.selectedFilter];
this.initPrefetchCoursesIcons();
@ -243,12 +249,61 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
}
/**
* The selected courses have changed.
* The selected courses filter have changed.
*/
selectedChanged(): void {
this.currentSite.setLocalSiteConfig('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.setLocalSiteConfig('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

@ -15,6 +15,7 @@
import { Component, OnInit, Injector } from '@angular/core';
import * as moment from 'moment';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitesProvider } from '@providers/sites';
import { CoreCoursesProvider } from '@core/courses/providers/courses';
import { CoreCoursesHelperProvider } from '@core/courses/providers/helper';
import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate';
@ -31,6 +32,7 @@ import { AddonBlockTimelineProvider } from '../../providers/timeline';
export class AddonBlockTimelineComponent extends AddonBlockComponent implements OnInit {
sort = 'sortbydates';
filter = 'next30days';
currentSite: any;
timeline = {
events: [],
loaded: false,
@ -49,7 +51,7 @@ export class AddonBlockTimelineComponent extends AddonBlockComponent implements
constructor(injector: Injector, private coursesProvider: CoreCoursesProvider, private utils: CoreUtilsProvider,
private timelineProvider: AddonBlockTimelineProvider, private courseOptionsDelegate: CoreCourseOptionsDelegate,
private coursesHelper: CoreCoursesHelperProvider) {
private coursesHelper: CoreCoursesHelperProvider, private sitesProvider: CoreSitesProvider) {
super(injector, 'AddonBlockTimelineComponent');
}
@ -58,8 +60,15 @@ export class AddonBlockTimelineComponent extends AddonBlockComponent implements
* Component being initialized.
*/
ngOnInit(): void {
this.currentSite = this.sitesProvider.getCurrentSite();
this.currentSite.getLocalSiteConfig('AddonBlockTimelineFilter', this.filter).then((value) => {
this.filter = value;
this.switchFilter();
});
this.currentSite.getLocalSiteConfig('AddonBlockTimelineSort', this.sort).then((value) => {
this.sort = value;
super.ngOnInit();
});
}
/**
@ -167,6 +176,7 @@ export class AddonBlockTimelineComponent extends AddonBlockComponent implements
* Change timeline filter being viewed.
*/
switchFilter(): void {
this.currentSite.setLocalSiteConfig('AddonBlockTimelineFilter', this.filter);
switch (this.filter) {
case 'overdue':
this.dataFrom = -14;
@ -200,6 +210,7 @@ export class AddonBlockTimelineComponent extends AddonBlockComponent implements
* Change timeline sort being viewed.
*/
switchSort(): void {
this.currentSite.setLocalSiteConfig('AddonBlockTimelineSort', this.sort);
if (!this.timeline.loaded && this.sort == 'sortbydates') {
this.fetchContent();
} else if (!this.timelineCourses.loaded && this.sort == 'sortbycourses') {

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

View File

@ -167,7 +167,9 @@ export class CoreSite {
// Variables for the database.
protected WS_CACHE_TABLE = 'wscache';
protected tableSchema = {
protected CONFIG_TABLE = 'core_site_config';
protected tableSchemas = [
{
name: this.WS_CACHE_TABLE,
columns: [
{
@ -188,7 +190,23 @@ export class CoreSite {
type: 'INTEGER'
}
]
};
},
{
name: this.CONFIG_TABLE,
columns: [
{
name: 'name',
type: 'TEXT',
unique: true,
notNull: true
},
{
name: 'value'
}
]
}
];
// Versions of Moodle releases.
protected MOODLE_RELEASES = {
@ -248,7 +266,7 @@ export class CoreSite {
*/
initDB(): void {
this.db = this.dbProvider.getDB('Site-' + this.id);
this.db.createTableFromSchema(this.tableSchema);
this.db.createTablesFromSchema(this.tableSchemas);
}
/**
@ -1544,4 +1562,44 @@ export class CoreSite {
return this.MOODLE_RELEASES[releases[position + 1]];
}
/**
* Deletes a site setting.
*
* @param {string} name The config name.
* @return {Promise<any>} Promise resolved when done.
*/
deleteSiteConfig(name: string): Promise<any> {
return this.db.deleteRecords(this.CONFIG_TABLE, { name: name });
}
/**
* Get a site setting on local device.
*
* @param {string} name The config name.
* @param {any} [defaultValue] Default value to use if the entry is not found.
* @return {Promise<any>} Resolves upon success along with the config data. Reject on failure.
*/
getLocalSiteConfig(name: string, defaultValue?: any): Promise<any> {
return this.db.getRecord(this.CONFIG_TABLE, { name: name }).then((entry) => {
return entry.value;
}).catch((error) => {
if (typeof defaultValue != 'undefined') {
return defaultValue;
}
return Promise.reject(error);
});
}
/**
* Set a site setting on local device.
*
* @param {string} name The config name.
* @param {number|string} value The config value. Can only store number or strings.
* @return {Promise<any>} Promise resolved when done.
*/
setLocalSiteConfig(name: string, value: number | string): Promise<any> {
return this.db.insertRecord(this.CONFIG_TABLE, { name: name, value: value });
}
}

View File

@ -1,4 +1,4 @@
$core-progress-bar-height: 10px !default;
$core-progress-bar-height: 8px !default;
ion-app.app-root core-progress-bar {
@include padding(null, 55px, null, null);
@ -11,7 +11,7 @@ ion-app.app-root core-progress-bar {
line-height: 40px;
font-size: 1.4rem;
color: $gray-darker;
@include position(-15px, 10px, null, null);
@include position(-16px, 10px, null, null);
position: absolute;
}
@ -19,7 +19,7 @@ ion-app.app-root core-progress-bar {
-webkit-appearance: none;
appearance: none;
height: $core-progress-bar-height;
margin: 15px 0;
margin: 16px 0;
padding: 0;
display: block;
width: 100%;
@ -27,15 +27,15 @@ ion-app.app-root core-progress-bar {
.progress-bar-fallback,
&[value]::-webkit-progress-bar {
background-color: $gray-lighter;
border-radius: 999px;
border: 1px solid $gray-light;
border-radius: 0;
border:0;
box-shadow: none;
}
.progress-bar-fallback span,
&[value]::-webkit-progress-value {
background-color: $core-progressbar-color;
border-radius: 999px;
border-radius: 0;
}
.progress-bar-fallback {

View File

@ -8,11 +8,6 @@ ion-app.app-root core-courses-course-progress {
.core-course-thumb {
background: nth($core-course-image-background, $i + 1);
}
progress .progress-bar-fallback span,
progress[value]::-webkit-progress-value {
background-color: nth($core-course-image-background, $i + 1);
}
}
}