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.paymentrequired": "moodle",
|
||||
"core.courses.paypalaccepted": "enrol_paypal",
|
||||
"core.courses.refreshcourses": "local_moodlemobileapp",
|
||||
"core.courses.reload": "moodle",
|
||||
"core.courses.removefromfavourites": "block_myoverview",
|
||||
"core.courses.search": "moodle",
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<!-- Download all courses. -->
|
||||
<div *ngIf="downloadCoursesEnabled && downloadEnabled && filteredCourses.length > 1" class="core-button-spinner">
|
||||
<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>
|
||||
</ion-button>
|
||||
|
|
|
@ -415,7 +415,7 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
|
|||
*
|
||||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async initPrefetchCoursesIcons(): Promise<void> {
|
||||
async initPrefetchCoursesIcons(): Promise<void> {
|
||||
if (this.prefetchIconsInitialized || !this.downloadEnabled) {
|
||||
// Already initialized.
|
||||
return;
|
||||
|
|
|
@ -429,7 +429,7 @@ export class CoreCourseHelperProvider {
|
|||
const siteId = CoreSites.getCurrentSiteId();
|
||||
|
||||
// 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;
|
||||
let count = 0;
|
||||
|
@ -1209,7 +1209,7 @@ export class CoreCourseHelperProvider {
|
|||
|
||||
const status = await this.determineCoursesStatus(courses);
|
||||
|
||||
prefetch = this.getCoursePrefetchStatusInfo(status);
|
||||
prefetch = this.getCoursesPrefetchStatusInfo(status);
|
||||
|
||||
if (prefetch.loading) {
|
||||
// It seems all courses are being downloaded, show a download button instead.
|
||||
|
@ -1381,6 +1381,33 @@ export class CoreCourseHelperProvider {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"password": "Enrolment key",
|
||||
"paymentrequired": "This course requires a payment for entry.",
|
||||
"paypalaccepted": "PayPal payments accepted",
|
||||
"refreshcourses": "Refresh courses",
|
||||
"reload": "Reload",
|
||||
"removefromfavourites": "Unstar this course",
|
||||
"search": "Search",
|
||||
|
|
|
@ -9,9 +9,13 @@
|
|||
<ion-icon name="fas-search" slot="icon-only" aria-hidden="true"></ion-icon>
|
||||
</ion-button>
|
||||
<core-context-menu>
|
||||
<core-context-menu-item *ngIf="(downloadCourseEnabled || downloadCoursesEnabled)" [priority]="1000"
|
||||
[content]="'core.settings.showdownloadoptions' | translate" (action)="toggleDownload()" iconAction="toggle"
|
||||
[(toggle)]="downloadEnabled"></core-context-menu-item>
|
||||
<core-context-menu-item *ngIf="downloadCoursesEnabled && myOverviewBlock && myOverviewBlock.filteredCourses.length > 1"
|
||||
[priority]="1000" [content]="myOverviewBlock?.prefetchCoursesData.statusTranslatable | translate"
|
||||
(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"
|
||||
(action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item>
|
||||
</core-context-menu>
|
||||
|
@ -26,7 +30,7 @@
|
|||
<ion-list>
|
||||
<!-- My courses blocks. -->
|
||||
<core-block [block]="{name: 'myoverview', visible: true}" contextLevel="user" [instanceId]="userId"
|
||||
[extraData]="{'downloadEnabled': downloadEnabled}">
|
||||
[extraData]="{'downloadEnabled': true}">
|
||||
</core-block>
|
||||
</ion-list>
|
||||
</ion-content>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { AddonBlockMyOverviewComponent } from '@addons/block/myoverview/components/myoverview/myoverview';
|
||||
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||
import { CoreBlockComponent } from '@features/block/components/block/block';
|
||||
import { IonRefresher } from '@ionic/angular';
|
||||
|
@ -19,7 +20,7 @@ import { CoreNavigator } from '@services/navigator';
|
|||
import { CoreSites } from '@services/sites';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||
import { CoreCourses, CoreCoursesProvider } from '../../services/courses';
|
||||
import { CoreCourses } from '../../services/courses';
|
||||
|
||||
/**
|
||||
* Page that shows a my courses.
|
||||
|
@ -34,28 +35,19 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
|
|||
@ViewChild(CoreBlockComponent) block!: CoreBlockComponent;
|
||||
|
||||
searchEnabled = false;
|
||||
downloadEnabled = false;
|
||||
downloadCourseEnabled = false;
|
||||
downloadCoursesEnabled = false;
|
||||
userId: number;
|
||||
myOverviewBlock?: AddonBlockMyOverviewComponent;
|
||||
|
||||
protected updateSiteObserver: CoreEventObserver;
|
||||
protected downloadEnabledObserver: CoreEventObserver;
|
||||
|
||||
constructor() {
|
||||
// Refresh the enabled flags if site is updated.
|
||||
this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
|
||||
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
|
||||
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
||||
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
|
||||
|
||||
this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && this.downloadEnabled;
|
||||
}, 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();
|
||||
}
|
||||
|
||||
|
@ -64,19 +56,23 @@ export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy {
|
|||
*/
|
||||
ngOnInit(): void {
|
||||
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
|
||||
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
||||
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
|
||||
|
||||
this.downloadEnabled =
|
||||
(this.downloadCourseEnabled || this.downloadCoursesEnabled) && CoreCourses.getCourseDownloadOptionsEnabled();
|
||||
this.loadBlock();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch download enabled.
|
||||
* Load my overview block instance.
|
||||
*/
|
||||
switchDownload(): void {
|
||||
CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled);
|
||||
protected loadBlock(): void {
|
||||
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 {
|
||||
this.updateSiteObserver?.off();
|
||||
this.downloadEnabledObserver?.off();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue