MOBILE-3806 my: Always show Download courses on my courses page
parent
3f201849a4
commit
f69deb31b9
|
@ -1556,6 +1556,7 @@
|
||||||
"core.courses.password": "local_moodlemobileapp",
|
"core.courses.password": "local_moodlemobileapp",
|
||||||
"core.courses.paymentrequired": "moodle",
|
"core.courses.paymentrequired": "moodle",
|
||||||
"core.courses.paypalaccepted": "enrol_paypal",
|
"core.courses.paypalaccepted": "enrol_paypal",
|
||||||
|
"core.courses.refreshcourses": "local_moodlemobileapp",
|
||||||
"core.courses.reload": "moodle",
|
"core.courses.reload": "moodle",
|
||||||
"core.courses.removefromfavourites": "block_myoverview",
|
"core.courses.removefromfavourites": "block_myoverview",
|
||||||
"core.courses.search": "moodle",
|
"core.courses.search": "moodle",
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<!-- Download all courses. -->
|
<!-- Download all courses. -->
|
||||||
<div *ngIf="downloadCoursesEnabled && downloadEnabled && filteredCourses.length > 1" class="core-button-spinner">
|
<div *ngIf="downloadCoursesEnabled && downloadEnabled && filteredCourses.length > 1" class="core-button-spinner">
|
||||||
<ion-button *ngIf="!prefetchCoursesData.loading" fill="clear" color="dark" (click)="prefetchCourses()"
|
<ion-button *ngIf="!prefetchCoursesData.loading" fill="clear" color="dark" (click)="prefetchCourses()"
|
||||||
[attr.aria-label]="'core.courses.downloadcourses' | translate">
|
[attr.aria-label]="prefetchCoursesData.statusTranslatable | translate">
|
||||||
<ion-icon [name]="prefetchCoursesData.icon" slot="icon-only" aria-hidden="true">
|
<ion-icon [name]="prefetchCoursesData.icon" slot="icon-only" aria-hidden="true">
|
||||||
</ion-icon>
|
</ion-icon>
|
||||||
</ion-button>
|
</ion-button>
|
||||||
|
|
|
@ -415,7 +415,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
||||||
*
|
*
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected async initPrefetchCoursesIcons(): Promise<void> {
|
async initPrefetchCoursesIcons(): Promise<void> {
|
||||||
if (this.prefetchIconsInitialized || !this.downloadEnabled) {
|
if (this.prefetchIconsInitialized || !this.downloadEnabled) {
|
||||||
// Already initialized.
|
// Already initialized.
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -429,7 +429,7 @@ export class CoreCourseHelperProvider {
|
||||||
const siteId = CoreSites.getCurrentSiteId();
|
const siteId = CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
// Confirm the download without checking size because it could take a while.
|
// Confirm the download without checking size because it could take a while.
|
||||||
await CoreDomUtils.showConfirm(Translate.instant('core.areyousure'));
|
await CoreDomUtils.showConfirm(Translate.instant('core.areyousure'), Translate.instant('core.courses.downloadcourses'));
|
||||||
|
|
||||||
const total = courses.length;
|
const total = courses.length;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
@ -1209,7 +1209,7 @@ export class CoreCourseHelperProvider {
|
||||||
|
|
||||||
const status = await this.determineCoursesStatus(courses);
|
const status = await this.determineCoursesStatus(courses);
|
||||||
|
|
||||||
prefetch = this.getCoursePrefetchStatusInfo(status);
|
prefetch = this.getCoursesPrefetchStatusInfo(status);
|
||||||
|
|
||||||
if (prefetch.loading) {
|
if (prefetch.loading) {
|
||||||
// It seems all courses are being downloaded, show a download button instead.
|
// It seems all courses are being downloaded, show a download button instead.
|
||||||
|
@ -1381,6 +1381,33 @@ export class CoreCourseHelperProvider {
|
||||||
return prefetchStatus;
|
return prefetchStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a courses status icon and the langkey to use as a title from status.
|
||||||
|
*
|
||||||
|
* @param status Courses status.
|
||||||
|
* @return Prefetch status info.
|
||||||
|
*/
|
||||||
|
getCoursesPrefetchStatusInfo(status: string): CorePrefetchStatusInfo {
|
||||||
|
const prefetchStatus: CorePrefetchStatusInfo = {
|
||||||
|
status: status,
|
||||||
|
icon: this.getPrefetchStatusIcon(status, false),
|
||||||
|
statusTranslatable: '',
|
||||||
|
loading: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (status == CoreConstants.DOWNLOADED) {
|
||||||
|
// Always show refresh icon, we cannot know if there's anything new in course options.
|
||||||
|
prefetchStatus.statusTranslatable = 'core.courses.refreshcourses';
|
||||||
|
} else if (status == CoreConstants.DOWNLOADING) {
|
||||||
|
prefetchStatus.statusTranslatable = 'core.downloading';
|
||||||
|
prefetchStatus.loading = true;
|
||||||
|
} else {
|
||||||
|
prefetchStatus.statusTranslatable = 'core.courses.downloadcourses';
|
||||||
|
}
|
||||||
|
|
||||||
|
return prefetchStatus;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the icon given the status and if trust the download status.
|
* Get the icon given the status and if trust the download status.
|
||||||
*
|
*
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
"password": "Enrolment key",
|
"password": "Enrolment key",
|
||||||
"paymentrequired": "This course requires a payment for entry.",
|
"paymentrequired": "This course requires a payment for entry.",
|
||||||
"paypalaccepted": "PayPal payments accepted",
|
"paypalaccepted": "PayPal payments accepted",
|
||||||
|
"refreshcourses": "Refresh courses",
|
||||||
"reload": "Reload",
|
"reload": "Reload",
|
||||||
"removefromfavourites": "Unstar this course",
|
"removefromfavourites": "Unstar this course",
|
||||||
"search": "Search",
|
"search": "Search",
|
||||||
|
|
|
@ -9,9 +9,13 @@
|
||||||
<ion-icon name="fas-search" slot="icon-only" aria-hidden="true"></ion-icon>
|
<ion-icon name="fas-search" slot="icon-only" aria-hidden="true"></ion-icon>
|
||||||
</ion-button>
|
</ion-button>
|
||||||
<core-context-menu>
|
<core-context-menu>
|
||||||
<core-context-menu-item *ngIf="(downloadCourseEnabled || downloadCoursesEnabled)" [priority]="1000"
|
<core-context-menu-item *ngIf="downloadCoursesEnabled && myOverviewBlock && myOverviewBlock.filteredCourses.length > 1"
|
||||||
[content]="'core.settings.showdownloadoptions' | translate" (action)="toggleDownload()" iconAction="toggle"
|
[priority]="1000" [content]="myOverviewBlock?.prefetchCoursesData.statusTranslatable | translate"
|
||||||
[(toggle)]="downloadEnabled"></core-context-menu-item>
|
(action)="myOverviewBlock?.prefetchCourses()"
|
||||||
|
[iconAction]="myOverviewBlock?.prefetchCoursesData.loading ? 'spinner' : myOverviewBlock?.prefetchCoursesData.icon"
|
||||||
|
[badge]="myOverviewBlock?.prefetchCoursesData.badge"
|
||||||
|
[badgeA11yText]="myOverviewBlock?.prefetchCoursesData.badgeA11yText">
|
||||||
|
</core-context-menu-item>
|
||||||
<core-context-menu-item [priority]="500" [content]="'addon.storagemanager.managestorage' | translate"
|
<core-context-menu-item [priority]="500" [content]="'addon.storagemanager.managestorage' | translate"
|
||||||
(action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item>
|
(action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item>
|
||||||
</core-context-menu>
|
</core-context-menu>
|
||||||
|
@ -26,7 +30,7 @@
|
||||||
<ion-list>
|
<ion-list>
|
||||||
<!-- My courses blocks. -->
|
<!-- My courses blocks. -->
|
||||||
<core-block [block]="{name: 'myoverview', visible: true}" contextLevel="user" [instanceId]="userId"
|
<core-block [block]="{name: 'myoverview', visible: true}" contextLevel="user" [instanceId]="userId"
|
||||||
[extraData]="{'downloadEnabled': downloadEnabled}">
|
[extraData]="{'downloadEnabled': true}">
|
||||||
</core-block>
|
</core-block>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { AddonBlockMyOverviewComponent } from '@addons/block/myoverview/components/myoverview/myoverview';
|
||||||
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||||
import { CoreBlockComponent } from '@features/block/components/block/block';
|
import { CoreBlockComponent } from '@features/block/components/block/block';
|
||||||
import { IonRefresher } from '@ionic/angular';
|
import { IonRefresher } from '@ionic/angular';
|
||||||
|
@ -19,7 +20,7 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { CoreCourses, CoreCoursesProvider } from '../../services/courses';
|
import { CoreCourses } from '../../services/courses';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that shows a my courses.
|
* Page that shows a my courses.
|
||||||
|
@ -34,28 +35,19 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
|
||||||
@ViewChild(CoreBlockComponent) block!: CoreBlockComponent;
|
@ViewChild(CoreBlockComponent) block!: CoreBlockComponent;
|
||||||
|
|
||||||
searchEnabled = false;
|
searchEnabled = false;
|
||||||
downloadEnabled = false;
|
|
||||||
downloadCourseEnabled = false;
|
|
||||||
downloadCoursesEnabled = false;
|
downloadCoursesEnabled = false;
|
||||||
userId: number;
|
userId: number;
|
||||||
|
myOverviewBlock?: AddonBlockMyOverviewComponent;
|
||||||
|
|
||||||
protected updateSiteObserver: CoreEventObserver;
|
protected updateSiteObserver: CoreEventObserver;
|
||||||
protected downloadEnabledObserver: CoreEventObserver;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// Refresh the enabled flags if site is updated.
|
// Refresh the enabled flags if site is updated.
|
||||||
this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
|
this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
|
||||||
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
|
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
|
||||||
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
|
||||||
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
|
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
|
||||||
|
|
||||||
this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && this.downloadEnabled;
|
|
||||||
}, CoreSites.getCurrentSiteId());
|
}, CoreSites.getCurrentSiteId());
|
||||||
|
|
||||||
this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => {
|
|
||||||
this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && data.enabled;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.userId = CoreSites.getCurrentSiteUserId();
|
this.userId = CoreSites.getCurrentSiteUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,19 +56,23 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
|
||||||
*/
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
|
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
|
||||||
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
|
||||||
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
|
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
|
||||||
|
|
||||||
this.downloadEnabled =
|
this.loadBlock();
|
||||||
(this.downloadCourseEnabled || this.downloadCoursesEnabled) && CoreCourses.getCourseDownloadOptionsEnabled();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch download enabled.
|
* Load my overview block instance.
|
||||||
*/
|
*/
|
||||||
switchDownload(): void {
|
protected loadBlock(): void {
|
||||||
CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled);
|
setTimeout(() => {
|
||||||
|
if (!this.block) {
|
||||||
|
return this.loadBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.myOverviewBlock = this.block?.dynamicComponent?.instance as AddonBlockMyOverviewComponent;
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,7 +107,6 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
|
||||||
*/
|
*/
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.updateSiteObserver?.off();
|
this.updateSiteObserver?.off();
|
||||||
this.downloadEnabledObserver?.off();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue