diff --git a/scripts/langindex.json b/scripts/langindex.json index 2e3002fd5..11613e9a0 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -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", diff --git a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts index 215ca90b5..566ddc0b8 100644 --- a/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts +++ b/src/addon/block/activitymodules/components/activitymodules/activitymodules.ts @@ -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'); diff --git a/src/addon/block/myoverview/components/myoverview/addon-block-myoverview.html b/src/addon/block/myoverview/components/myoverview/addon-block-myoverview.html index a7043ba4d..589048b3f 100644 --- a/src/addon/block/myoverview/components/myoverview/addon-block-myoverview.html +++ b/src/addon/block/myoverview/components/myoverview/addon-block-myoverview.html @@ -18,12 +18,13 @@
- {{ 'addon.block_myoverview.all' | translate }}∫ - {{ 'addon.block_myoverview.inprogress' | translate }} - {{ 'addon.block_myoverview.future' | translate }} - {{ 'addon.block_myoverview.past' | translate }} - {{ 'addon.block_myoverview.favourites' | translate }} - {{ 'addon.block_myoverview.hiddencourses' | translate }} + {{ 'addon.block_myoverview.allincludinghidden' | translate }} + {{ 'addon.block_myoverview.all' | translate }} + {{ 'addon.block_myoverview.inprogress' | translate }} + {{ 'addon.block_myoverview.future' | translate }} + {{ 'addon.block_myoverview.past' | translate }} + {{ 'addon.block_myoverview.favourites' | translate }} + {{ 'addon.block_myoverview.hiddencourses' | translate }}
diff --git a/src/addon/block/myoverview/components/myoverview/myoverview.ts b/src/addon/block/myoverview/components/myoverview/myoverview.ts index e6c807c13..064ddc747 100644 --- a/src/addon/block/myoverview/components/myoverview/myoverview.ts +++ b/src/addon/block/myoverview/components/myoverview/myoverview.ts @@ -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 { diff --git a/src/addon/block/myoverview/lang/en.json b/src/addon/block/myoverview/lang/en.json index 386ecd222..7f4c4ec30 100644 --- a/src/addon/block/myoverview/lang/en.json +++ b/src/addon/block/myoverview/lang/en.json @@ -1,4 +1,5 @@ { + "allincludinghidden": "All", "all": "All (except hidden)", "favourites": "Starred", "future": "Future", diff --git a/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts b/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts index 62d429f49..fd94dc7c2 100644 --- a/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts +++ b/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts @@ -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) { diff --git a/src/addon/block/recentlyaccesseditems/components/recentlyaccesseditems/recentlyaccesseditems.ts b/src/addon/block/recentlyaccesseditems/components/recentlyaccesseditems/recentlyaccesseditems.ts index f36f5ad74..60041df84 100644 --- a/src/addon/block/recentlyaccesseditems/components/recentlyaccesseditems/recentlyaccesseditems.ts +++ b/src/addon/block/recentlyaccesseditems/components/recentlyaccesseditems/recentlyaccesseditems.ts @@ -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) { diff --git a/src/addon/block/starredcourses/components/starredcourses/starredcourses.ts b/src/addon/block/starredcourses/components/starredcourses/starredcourses.ts index 3e02be6a5..6be095a75 100644 --- a/src/addon/block/starredcourses/components/starredcourses/starredcourses.ts +++ b/src/addon/block/starredcourses/components/starredcourses/starredcourses.ts @@ -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) { diff --git a/src/addon/block/timeline/components/timeline/timeline.ts b/src/addon/block/timeline/components/timeline/timeline.ts index 1fa7a3f3b..b585ede3e 100644 --- a/src/addon/block/timeline/components/timeline/timeline.ts +++ b/src/addon/block/timeline/components/timeline/timeline.ts @@ -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) { diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 93afb0faf..c6a0d0d41 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -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", diff --git a/src/core/block/classes/base-block-component.ts b/src/core/block/classes/base-block-component.ts index bd2a39ff4..4562a95ce 100644 --- a/src/core/block/classes/base-block-component.ts +++ b/src/core/block/classes/base-block-component.ts @@ -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(); }