MOBILE-3806 my: Add myoverview to my courses page
This commit is contained in:
		
							parent
							
								
									69584e361c
								
							
						
					
					
						commit
						8a04123132
					
				| @ -60,7 +60,7 @@ const mainMenuHomeSiblingRoutes: Routes = [ | ||||
| const mainMenuTabRoutes: Routes = [ | ||||
|     { | ||||
|         path: CoreCoursesMyCoursesMainMenuHandlerService.PAGE_NAME, | ||||
|         loadChildren: () => import('./pages/list/list.module').then(m => m.CoreCoursesListPageModule), | ||||
|         loadChildren: () => import('./pages/my/my.module').then(m => m.CoreCoursesMyCoursesPageModule), | ||||
|     }, | ||||
| ]; | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										32
									
								
								src/core/features/courses/pages/my/my.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/core/features/courses/pages/my/my.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | ||||
| <ion-header> | ||||
|     <ion-toolbar> | ||||
|         <ion-buttons slot="start"> | ||||
|             <ion-back-button [text]="'core.back' | translate"></ion-back-button> | ||||
|         </ion-buttons> | ||||
|         <h1>{{ 'core.courses.mycourses' | translate }}</h1> | ||||
|         <ion-buttons slot="end"> | ||||
|             <ion-button *ngIf="searchEnabled" (click)="openSearch()" [attr.aria-label]="'core.courses.searchcourses' | translate"> | ||||
|                 <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 [priority]="500" [content]="'addon.storagemanager.managestorage' | translate" | ||||
|                     (action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item> | ||||
|             </core-context-menu> | ||||
|             <core-user-menu-button></core-user-menu-button> | ||||
|         </ion-buttons> | ||||
|     </ion-toolbar> | ||||
| </ion-header> | ||||
| <ion-content> | ||||
|     <ion-refresher slot="fixed" (ionRefresh)="refresh($event.target)"> | ||||
|         <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content> | ||||
|     </ion-refresher> | ||||
|     <ion-list> | ||||
|         <!-- My courses blocks. --> | ||||
|         <core-block [block]="{name: 'myoverview', visible: true}" contextLevel="user" [instanceId]="userId" | ||||
|             [extraData]="{'downloadEnabled': downloadEnabled}"> | ||||
|         </core-block> | ||||
|     </ion-list> | ||||
| </ion-content> | ||||
							
								
								
									
										63
									
								
								src/core/features/courses/pages/my/my.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								src/core/features/courses/pages/my/my.module.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | ||||
| // (C) Copyright 2015 Moodle Pty Ltd.
 | ||||
| //
 | ||||
| // Licensed under the Apache License, Version 2.0 (the "License");
 | ||||
| // you may not use this file except in compliance with the License.
 | ||||
| // You may obtain a copy of the License at
 | ||||
| //
 | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| //
 | ||||
| // Unless required by applicable law or agreed to in writing, software
 | ||||
| // distributed under the License is distributed on an "AS IS" BASIS,
 | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | ||||
| // See the License for the specific language governing permissions and
 | ||||
| // limitations under the License.
 | ||||
| 
 | ||||
| import { Injector, NgModule } from '@angular/core'; | ||||
| import { RouterModule, ROUTES, Routes } from '@angular/router'; | ||||
| 
 | ||||
| import { CoreSharedModule } from '@/core/shared.module'; | ||||
| import { CoreBlockComponentsModule } from '@features/block/components/components.module'; | ||||
| 
 | ||||
| import { CoreCoursesMyCoursesPage } from './my'; | ||||
| import { CoreMainMenuComponentsModule } from '@features/mainmenu/components/components.module'; | ||||
| import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module'; | ||||
| 
 | ||||
| function buildRoutes(injector: Injector): Routes { | ||||
|     return [ | ||||
|         { | ||||
|             path: '', | ||||
|             component: CoreCoursesMyCoursesPage, | ||||
|         }, | ||||
|         { | ||||
|             path: 'list', | ||||
|             loadChildren: () => | ||||
|                 import('../list/list.module') | ||||
|                     .then(m => m.CoreCoursesListPageModule), | ||||
|         }, | ||||
|         ...buildTabMainRoutes(injector, { | ||||
|             redirectTo: '', | ||||
|             pathMatch: 'full', | ||||
|         }), | ||||
|     ]; | ||||
| } | ||||
| 
 | ||||
| @NgModule({ | ||||
|     imports: [ | ||||
|         CoreSharedModule, | ||||
|         CoreBlockComponentsModule, | ||||
|         CoreMainMenuComponentsModule, | ||||
|     ], | ||||
|     providers: [ | ||||
|         { | ||||
|             provide: ROUTES, | ||||
|             multi: true, | ||||
|             deps: [Injector], | ||||
|             useFactory: buildRoutes, | ||||
|         }, | ||||
|     ], | ||||
|     declarations: [ | ||||
|         CoreCoursesMyCoursesPage, | ||||
|     ], | ||||
|     exports: [RouterModule], | ||||
| }) | ||||
| export class CoreCoursesMyCoursesPageModule { } | ||||
							
								
								
									
										3
									
								
								src/core/features/courses/pages/my/my.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/core/features/courses/pages/my/my.scss
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| :host ::ng-deep ion-item-divider { | ||||
|     display: none !important; | ||||
| } | ||||
							
								
								
									
										117
									
								
								src/core/features/courses/pages/my/my.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								src/core/features/courses/pages/my/my.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,117 @@ | ||||
| // (C) Copyright 2015 Moodle Pty Ltd.
 | ||||
| //
 | ||||
| // Licensed under the Apache License, Version 2.0 (the "License");
 | ||||
| // you may not use this file except in compliance with the License.
 | ||||
| // You may obtain a copy of the License at
 | ||||
| //
 | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0
 | ||||
| //
 | ||||
| // Unless required by applicable law or agreed to in writing, software
 | ||||
| // distributed under the License is distributed on an "AS IS" BASIS,
 | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | ||||
| // See the License for the specific language governing permissions and
 | ||||
| // limitations under the License.
 | ||||
| 
 | ||||
| import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; | ||||
| import { CoreBlockComponent } from '@features/block/components/block/block'; | ||||
| import { IonRefresher } from '@ionic/angular'; | ||||
| 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'; | ||||
| 
 | ||||
| /** | ||||
|  * Page that shows a my courses. | ||||
|  */ | ||||
| @Component({ | ||||
|     selector: 'page-core-courses-my', | ||||
|     templateUrl: 'my.html', | ||||
|     styleUrls: ['my.scss'], | ||||
| }) | ||||
| export class CoreCoursesMyCoursesPage implements OnInit, OnDestroy { | ||||
| 
 | ||||
|     @ViewChild(CoreBlockComponent) block!: CoreBlockComponent; | ||||
| 
 | ||||
|     searchEnabled = false; | ||||
|     downloadEnabled = false; | ||||
|     downloadCourseEnabled = false; | ||||
|     downloadCoursesEnabled = false; | ||||
|     userId: number; | ||||
| 
 | ||||
|     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(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     ngOnInit(): void { | ||||
|         this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite(); | ||||
|         this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); | ||||
|         this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); | ||||
| 
 | ||||
|         this.downloadEnabled = | ||||
|             (this.downloadCourseEnabled || this.downloadCoursesEnabled) && CoreCourses.getCourseDownloadOptionsEnabled(); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Switch download enabled. | ||||
|      */ | ||||
|     switchDownload(): void { | ||||
|         CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Open page to manage courses storage. | ||||
|      */ | ||||
|     manageCoursesStorage(): void { | ||||
|         CoreNavigator.navigateToSitePath('/storage'); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Go to search courses. | ||||
|      */ | ||||
|     async openSearch(): Promise<void> { | ||||
|         CoreNavigator.navigateToSitePath('/list', { params : { mode: 'search' } }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Refresh the data. | ||||
|      * | ||||
|      * @param refresher Refresher. | ||||
|      */ | ||||
|     async refresh(refresher?: IonRefresher): Promise<void> { | ||||
|         if (this.block) { | ||||
|             await CoreUtils.ignoreErrors(this.block.doRefresh()); | ||||
|         } | ||||
| 
 | ||||
|         refresher?.complete(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     ngOnDestroy(): void { | ||||
|         this.updateSiteObserver?.off(); | ||||
|         this.downloadEnabledObserver?.off(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -26,7 +26,7 @@ import { CoreDashboardHomeHandler } from './dashboard-home'; | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class CoreCoursesMyCoursesMainMenuHandlerService implements CoreMainMenuHandler { | ||||
| 
 | ||||
|     static readonly PAGE_NAME = 'courses'; | ||||
|     static readonly PAGE_NAME = 'my'; | ||||
| 
 | ||||
|     name = 'CoreCoursesMyCourses'; | ||||
|     priority = 900; | ||||
| @ -35,13 +35,20 @@ export class CoreCoursesMyCoursesMainMenuHandlerService implements CoreMainMenuH | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async isEnabled(): Promise<boolean> { | ||||
|         const siteId = CoreSites.getCurrentSiteId(); | ||||
|         const site = CoreSites.getRequiredCurrentSite(); | ||||
| 
 | ||||
|         const siteId = site.getId(); | ||||
|         const disabled = await CoreCourses.isMyCoursesDisabled(siteId); | ||||
| 
 | ||||
|         if (disabled) { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         if (site.isVersionGreaterEqualThan('4.0')) { | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         // Dashboard cannot be disabled on 3.5 or 3.6 so it will never show this tab.
 | ||||
|         const dashboardEnabled = await CoreDashboardHomeHandler.isEnabledForSite(siteId); | ||||
|         const siteHomeEnabled = await CoreSiteHomeHomeHandler.isEnabledForSite(siteId); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user