MOBILE-2614 blocks: Improve some WS checks

main
Pau Ferrer Ocaña 2018-10-22 12:43:36 +02:00
parent 603ae1566f
commit 0024f701d0
3 changed files with 15 additions and 18 deletions

View File

@ -93,10 +93,10 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
this.currentSite = this.sitesProvider.getCurrentSite();
const promises = [];
promises.push(this.currentSite.getSiteConfig('AddonBlockMyOverviewSort', this.sort).then((value) => {
promises.push(this.currentSite.getLocalSiteConfig('AddonBlockMyOverviewSort', this.sort).then((value) => {
this.sort = value;
}));
promises.push(this.currentSite.getSiteConfig('AddonBlockMyOverviewFilter', this.selectedFilter).then((value) => {
promises.push(this.currentSite.getLocalSiteConfig('AddonBlockMyOverviewFilter', this.selectedFilter).then((value) => {
this.selectedFilter = value;
}));
@ -156,17 +156,14 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
});
}));
}).then((courses) => {
this.showSortFilter = courses.some((course) => {
return typeof course.lastaccess != 'undefined';
});
this.showSortFilter = courses.length > 0 && typeof courses[0].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) => {
return typeof course.enddate != 'undefined';
});
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';
@ -255,7 +252,7 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
* The selected courses filter have changed.
*/
selectedChanged(): void {
this.currentSite.setSiteConfig('AddonBlockMyOverviewFilter', this.selectedFilter);
this.currentSite.setLocalSiteConfig('AddonBlockMyOverviewFilter', this.selectedFilter);
this.filteredCourses = this.courses[this.selectedFilter];
}
@ -303,7 +300,7 @@ export class AddonBlockMyOverviewComponent extends AddonBlockComponent implement
* The selected courses sort filter have changed.
*/
switchSort(): void {
this.currentSite.setSiteConfig('AddonBlockMyOverviewSort', this.sort);
this.currentSite.setLocalSiteConfig('AddonBlockMyOverviewSort', this.sort);
this.sortCourses(this.courses.all);
}

View File

@ -61,11 +61,11 @@ export class AddonBlockTimelineComponent extends AddonBlockComponent implements
*/
ngOnInit(): void {
this.currentSite = this.sitesProvider.getCurrentSite();
this.currentSite.getSiteConfig('AddonBlockTimelineFilter', this.filter).then((value) => {
this.currentSite.getLocalSiteConfig('AddonBlockTimelineFilter', this.filter).then((value) => {
this.filter = value;
this.switchFilter();
});
this.currentSite.getSiteConfig('AddonBlockTimelineSort', this.sort).then((value) => {
this.currentSite.getLocalSiteConfig('AddonBlockTimelineSort', this.sort).then((value) => {
this.sort = value;
super.ngOnInit();
});
@ -176,7 +176,7 @@ export class AddonBlockTimelineComponent extends AddonBlockComponent implements
* Change timeline filter being viewed.
*/
switchFilter(): void {
this.currentSite.setSiteConfig('AddonBlockTimelineFilter', this.filter);
this.currentSite.setLocalSiteConfig('AddonBlockTimelineFilter', this.filter);
switch (this.filter) {
case 'overdue':
this.dataFrom = -14;
@ -210,7 +210,7 @@ export class AddonBlockTimelineComponent extends AddonBlockComponent implements
* Change timeline sort being viewed.
*/
switchSort(): void {
this.currentSite.setSiteConfig('AddonBlockTimelineSort', this.sort);
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

@ -1573,13 +1573,13 @@ export class CoreSite {
}
/**
* Get a site setting.
* 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.
*/
getSiteConfig(name: string, defaultValue?: any): Promise<any> {
getLocalSiteConfig(name: string, defaultValue?: any): Promise<any> {
return this.db.getRecord(this.CONFIG_TABLE, { name: name }).then((entry) => {
return entry.value;
}).catch((error) => {
@ -1592,13 +1592,13 @@ export class CoreSite {
}
/**
* Set a site setting.
* 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.
*/
setSiteConfig(name: string, value: number | string): Promise<any> {
setLocalSiteConfig(name: string, value: number | string): Promise<any> {
return this.db.insertRecord(this.CONFIG_TABLE, { name: name, value: value });
}
}