Merge pull request #2161 from crazyserver/MOBILE-3190

MOBILE-3190 block_myoverview: Add 3.8 course filters except custom
main
Juan Leyva 2019-11-22 09:51:00 +01:00 committed by GitHub
commit c35f9311d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 97 additions and 35 deletions

View File

@ -39,6 +39,7 @@
"addon.block_glossaryrandom.pluginname": "block_glossary_random",
"addon.block_learningplans.pluginname": "block_lp",
"addon.block_myoverview.all": "block_myoverview",
"addon.block_myoverview.allincludinghidden": "block_myoverview",
"addon.block_myoverview.favourites": "block_myoverview",
"addon.block_myoverview.future": "block_myoverview",
"addon.block_myoverview.hiddencourses": "block_myoverview",

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, OnInit, Injector, Input } from '@angular/core';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component';
@ -36,7 +35,7 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i
protected fetchContentDefaultError = 'Error getting activity modules data.';
constructor(injector: Injector, protected utils: CoreUtilsProvider, protected courseProvider: CoreCourseProvider,
constructor(injector: Injector, protected courseProvider: CoreCourseProvider,
protected translate: TranslateService, protected moduleDelegate: CoreCourseModuleDelegate) {
super(injector, 'AddonBlockActivityModulesComponent');

View File

@ -18,12 +18,13 @@
<div padding [hidden]="showFilter || !showSelectorFilter" class="safe-padding-horizontal">
<!-- "Time" selector. -->
<ion-select text-start [title]="'core.show' | translate" [(ngModel)]="selectedFilter" (ngModelChange)="selectedChanged()" interface="popover" class="core-button-select">
<ion-option value="all">{{ 'addon.block_myoverview.all' | translate }}</ion-option>
<ion-option value="inprogress" [disabled]="disableInProgress">{{ 'addon.block_myoverview.inprogress' | translate }}</ion-option>
<ion-option value="future" [disabled]="disableFuture">{{ 'addon.block_myoverview.future' | translate }}</ion-option>
<ion-option value="past" [disabled]="disablePast">{{ 'addon.block_myoverview.past' | translate }}</ion-option>
<ion-option value="favourite" *ngIf="showFavourite" [disabled]="disableFavourite">{{ 'addon.block_myoverview.favourites' | translate }}</ion-option>
<ion-option value="hidden" *ngIf="showHidden" [disabled]="disableHidden">{{ 'addon.block_myoverview.hiddencourses' | translate }}</ion-option>
<ion-option value="allincludinghidden" *ngIf="showFilters.allincludinghidden != 'hidden'">{{ 'addon.block_myoverview.allincludinghidden' | translate }}</ion-option>
<ion-option value="all" *ngIf="showFilters.all != 'hidden'">{{ 'addon.block_myoverview.all' | translate }}</ion-option>
<ion-option value="inprogress" *ngIf="showFilters.inprogress != 'hidden'" [disabled]="showFilters.inprogress == 'disabled'">{{ 'addon.block_myoverview.inprogress' | translate }}</ion-option>
<ion-option value="future" *ngIf="showFilters.future != 'hidden'" [disabled]="showFilters.future == 'disabled'">{{ 'addon.block_myoverview.future' | translate }}</ion-option>
<ion-option value="past" *ngIf="showFilters.past != 'hidden'" [disabled]="showFilters.past == 'disabled'">{{ 'addon.block_myoverview.past' | translate }}</ion-option>
<ion-option value="favourite" *ngIf="showFilters.favourite != 'hidden'" [disabled]="showFilters.favourite == 'disabled'">{{ 'addon.block_myoverview.favourites' | translate }}</ion-option>
<ion-option value="hidden" *ngIf="showFilters.hidden != 'hidden'" [disabled]="showFilters.hidden == 'disabled'">{{ 'addon.block_myoverview.hiddencourses' | translate }}</ion-option>
</ion-select>
</div>
<core-empty-box *ngIf="courses[selectedFilter].length == 0" image="assets/img/icons/courses.svg" [message]="'addon.block_myoverview.nocourses' | translate"></core-empty-box>

View File

@ -15,7 +15,6 @@
import { Component, OnInit, Input, OnDestroy, ViewChild, Injector, OnChanges, SimpleChange } from '@angular/core';
import { Searchbar } from 'ionic-angular';
import { CoreEventsProvider } from '@providers/events';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { CoreSitesProvider } from '@providers/sites';
import { CoreCoursesProvider } from '@core/courses/providers/courses';
@ -39,6 +38,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
courses = {
filter: '',
all: [],
allincludinghidden: [],
past: [],
inprogress: [],
future: [],
@ -51,24 +51,27 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
filteredCourses: any[];
prefetchCoursesData = {
all: {},
allincludinghidden: {},
inprogress: {},
past: {},
future: {},
favourite: {},
hidden: {}
};
showFilters = { // Options are show, disabled, hidden.
all: 'show',
allincludinghidden: 'show',
past: 'show',
inprogress: 'show',
future: 'show',
favourite: 'show',
hidden: 'show'
};
showFilter = false;
showFavourite = false;
showHidden = false;
showSelectorFilter = false;
showSortFilter = false;
downloadCourseEnabled: boolean;
downloadCoursesEnabled: boolean;
disableInProgress = false;
disablePast = false;
disableFuture = false;
disableFavourite = false;
disableHidden = false;
protected prefetchIconsInitialized = false;
protected isDestroyed;
@ -79,7 +82,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
constructor(injector: Injector, private coursesProvider: CoreCoursesProvider,
private courseCompletionProvider: AddonCourseCompletionProvider, private eventsProvider: CoreEventsProvider,
private courseHelper: CoreCourseHelperProvider, private utils: CoreUtilsProvider,
private courseHelper: CoreCourseHelperProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate, private coursesHelper: CoreCoursesHelperProvider,
private sitesProvider: CoreSitesProvider, private timeUtils: CoreTimeUtilsProvider) {
@ -173,18 +176,49 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
this.initCourseFilters(courses);
this.courses.filter = '';
this.showFilter = false;
this.disableInProgress = this.courses.inprogress.length === 0;
this.disablePast = this.courses.past.length === 0;
this.disableFuture = this.courses.future.length === 0;
const config = this.block.configs;
this.showSelectorFilter = courses.length > 0 && (this.courses.past.length > 0 || this.courses.future.length > 0 ||
typeof courses[0].enddate != 'undefined');
this.showHidden = this.showSelectorFilter && typeof courses[0].hidden != 'undefined';
this.disableHidden = this.courses.hidden.length === 0;
this.showFavourite = this.showSelectorFilter && typeof courses[0].isfavourite != 'undefined';
this.disableFavourite = this.courses.favourite.length === 0;
if (!this.showSelectorFilter || (this.selectedFilter === 'inprogress' && this.disableInProgress)) {
this.courses.filter = '';
this.showFilter = false;
this.showFilters.all = this.getShowFilterValue(!config || config.displaygroupingall.value == '1',
this.courses.all.length === 0);
// Do not show allincludinghiddenif config it's not present (before 3.8).
this.showFilters.allincludinghidden =
this.getShowFilterValue(config && config.displaygroupingallincludinghidden.value == '1',
this.courses.allincludinghidden.length === 0);
this.showFilters.inprogress = this.getShowFilterValue(!config || config.displaygroupinginprogress.value == '1',
this.courses.inprogress.length === 0);
this.showFilters.past = this.getShowFilterValue(!config || config.displaygroupingpast.value == '1',
this.courses.past.length === 0);
this.showFilters.future = this.getShowFilterValue(!config || config.displaygroupingfuture.value == '1',
this.courses.future.length === 0);
this.showSelectorFilter = courses.length > 0 && (this.courses.past.length > 0 || this.courses.future.length > 0 ||
typeof courses[0].enddate != 'undefined');
this.showFilters.hidden = this.getShowFilterValue(
this.showSelectorFilter && typeof courses[0].hidden != 'undefined' &&
(!config || config.displaygroupinghidden.value == '1'),
this.courses.hidden.length === 0);
this.showFilters.favourite = this.getShowFilterValue(
this.showSelectorFilter && typeof courses[0].isfavourite != 'undefined' &&
(!config || config.displaygroupingstarred.value == '1'),
this.courses.favourite.length === 0);
if (this.showSelectorFilter) {
// Check if any selector is shown and not disabled.
this.showSelectorFilter = Object.keys(this.showFilters).some((key) => {
return this.showFilters[key] == 'show';
});
}
if (!this.showSelectorFilter || (this.selectedFilter === 'inprogress' && this.showFilters.inprogress == 'disabled')) {
// No selector, or the default option is disabled, show all.
this.selectedFilter = 'all';
}
@ -194,6 +228,17 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
});
}
/**
* Helper function to help with filter values.
*
* @param showCondition If true, filter will be shown.
* @param disabledCondition If true, and showCondition is also met, it will be shown as disabled.
* @return show / disabled / hidden value.
*/
protected getShowFilterValue(showCondition: boolean, disabledCondition: boolean): string {
return showCondition ? (disabledCondition ? 'disabled' : 'show') : 'hidden';
}
/**
* The filter has changed.
*
@ -283,6 +328,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
}
this.courses.all = [];
this.courses.allincludinghidden = [];
this.courses.past = [];
this.courses.inprogress = [];
this.courses.future = [];
@ -291,6 +337,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
const today = this.timeUtils.timestamp();
courses.forEach((course) => {
this.courses.allincludinghidden.push(course);
if (course.hidden) {
this.courses.hidden.push(course);
} else {

View File

@ -1,4 +1,5 @@
{
"allincludinghidden": "All",
"all": "All (except hidden)",
"favourites": "Starred",
"future": "Future",

View File

@ -14,7 +14,6 @@
import { Component, OnInit, OnDestroy, Injector, Input, OnChanges, SimpleChange } from '@angular/core';
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';
@ -47,7 +46,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
constructor(injector: Injector, private coursesProvider: CoreCoursesProvider,
private courseCompletionProvider: AddonCourseCompletionProvider, private eventsProvider: CoreEventsProvider,
private courseHelper: CoreCourseHelperProvider, private utils: CoreUtilsProvider,
private courseHelper: CoreCourseHelperProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate, private coursesHelper: CoreCoursesHelperProvider,
private sitesProvider: CoreSitesProvider) {

View File

@ -19,7 +19,6 @@ import { CoreBlockBaseComponent } from '@core/block/classes/base-block-component
import {
AddonBlockRecentlyAccessedItemsProvider, AddonBlockRecentlyAccessedItemsItem
} from '../../providers/recentlyaccesseditems';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
/**
@ -35,7 +34,7 @@ export class AddonBlockRecentlyAccessedItemsComponent extends CoreBlockBaseCompo
protected fetchContentDefaultError = 'Error getting recently accessed items data.';
constructor(injector: Injector, @Optional() private navCtrl: NavController,
private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider,
private sitesProvider: CoreSitesProvider,
private recentItemsProvider: AddonBlockRecentlyAccessedItemsProvider,
private contentLinksHelper: CoreContentLinksHelperProvider) {

View File

@ -14,7 +14,6 @@
import { Component, OnInit, OnDestroy, Injector, Input, OnChanges, SimpleChange } from '@angular/core';
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';
@ -47,7 +46,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
constructor(injector: Injector, private coursesProvider: CoreCoursesProvider,
private courseCompletionProvider: AddonCourseCompletionProvider, private eventsProvider: CoreEventsProvider,
private courseHelper: CoreCourseHelperProvider, private utils: CoreUtilsProvider,
private courseHelper: CoreCourseHelperProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate, private coursesHelper: CoreCoursesHelperProvider,
private sitesProvider: CoreSitesProvider) {

View File

@ -13,7 +13,6 @@
// limitations under the License.
import { Component, OnInit, Injector } from '@angular/core';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { CoreSitesProvider } from '@providers/sites';
import { CoreCoursesProvider } from '@core/courses/providers/courses';
@ -50,7 +49,7 @@ export class AddonBlockTimelineComponent extends CoreBlockBaseComponent implemen
protected courseIds = [];
protected fetchContentDefaultError = 'Error getting timeline data.';
constructor(injector: Injector, private coursesProvider: CoreCoursesProvider, private utils: CoreUtilsProvider,
constructor(injector: Injector, private coursesProvider: CoreCoursesProvider,
private timelineProvider: AddonBlockTimelineProvider, private courseOptionsDelegate: CoreCourseOptionsDelegate,
private coursesHelper: CoreCoursesHelperProvider, private sitesProvider: CoreSitesProvider,
private timeUtils: CoreTimeUtilsProvider) {

View File

@ -38,6 +38,7 @@
"addon.block_glossaryrandom.pluginname": "Random glossary entry",
"addon.block_learningplans.pluginname": "Learning plans",
"addon.block_myoverview.all": "All (except hidden)",
"addon.block_myoverview.allincludinghidden": "All",
"addon.block_myoverview.favourites": "Starred",
"addon.block_myoverview.future": "Future",
"addon.block_myoverview.hiddencourses": "Hidden",

View File

@ -15,6 +15,8 @@
import { Injector, OnInit, Input } from '@angular/core';
import { CoreLoggerProvider } from '@providers/logger';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreTextUtilsProvider } from '@providers/utils/text';
/**
* Template class to easily create components for blocks.
@ -31,10 +33,14 @@ export class CoreBlockBaseComponent implements OnInit {
protected fetchContentDefaultError: string; // Default error to show when loading contents.
protected domUtils: CoreDomUtilsProvider;
protected textUtils: CoreTextUtilsProvider;
protected utils: CoreUtilsProvider;
protected logger;
constructor(injector: Injector, loggerName: string = 'AddonBlockComponent') {
this.domUtils = injector.get(CoreDomUtilsProvider);
this.utils = injector.get(CoreUtilsProvider);
this.textUtils = injector.get(CoreTextUtilsProvider);
const loggerProvider = injector.get(CoreLoggerProvider);
this.logger = loggerProvider.getInstance(loggerName);
}
@ -43,6 +49,16 @@ export class CoreBlockBaseComponent implements OnInit {
*/
ngOnInit(): void {
this.loaded = false;
if (this.block.configs && this.block.configs.length > 0) {
this.block.configs.map((config) => {
config.value = this.textUtils.parseJSON(config.value);
return config;
});
this.block.configs = this.utils.arrayToObject(this.block.configs, 'name');
}
this.loadContent();
}