@@ -16,7 +16,7 @@ import {
1616 AddonCourseCompletion ,
1717 AddonCourseCompletionCourseCompletionStatus ,
1818} from '@addons/coursecompletion/services/coursecompletion' ;
19- import { Component , OnInit } from '@angular/core' ;
19+ import { Component , computed , OnInit , signal } from '@angular/core' ;
2020import { CoreUser , CoreUserProfile } from '@features/user/services/user' ;
2121import { CoreAnalytics , CoreAnalyticsEventType } from '@services/analytics' ;
2222import { CoreLoadings } from '@services/overlays/loadings' ;
@@ -26,6 +26,7 @@ import { Translate } from '@singletons';
2626import { CoreTime } from '@singletons/time' ;
2727import { CoreAlerts } from '@services/overlays/alerts' ;
2828import { CoreSharedModule } from '@/core/shared.module' ;
29+ import { AddonCourseCompletionAggregation } from '@addons/coursecompletion/constants' ;
2930
3031/**
3132 * Page that displays the course completion report.
@@ -39,16 +40,36 @@ import { CoreSharedModule } from '@/core/shared.module';
3940} )
4041export default class AddonCourseCompletionReportPage implements OnInit {
4142
42- protected userId ! : number ;
43- protected logView : ( ) => void ;
43+ protected readonly aggregationType = AddonCourseCompletionAggregation ;
44+ protected readonly userId = signal ( 0 ) ;
45+ protected logView ! : ( ) => void ;
4446
45- courseId ! : number ;
46- completionLoaded = false ;
47- completion ?: AddonCourseCompletionCourseCompletionStatus ;
48- showSelfComplete = false ;
49- tracked = true ; // Whether completion is tracked.
50- statusText ?: string ;
51- user ?: CoreUserProfile ;
47+ readonly courseId = signal ( 0 ) ;
48+ readonly loaded = signal ( false ) ;
49+ readonly completion = signal < AddonCourseCompletionCourseCompletionStatus | undefined > ( undefined ) ;
50+
51+ readonly showSelfComplete = computed ( ( ) => {
52+ const completion = this . completion ( ) ;
53+ const userId = this . userId ( ) ;
54+
55+ if ( ! completion ) {
56+ return false ;
57+ }
58+
59+ return AddonCourseCompletion . canMarkSelfCompleted ( userId , completion ) ;
60+ } ) ;
61+
62+ readonly tracked = signal ( true ) ; // Whether completion is tracked.
63+ readonly statusText = computed ( ( ) => {
64+ const completion = this . completion ( ) ;
65+ if ( ! completion ) {
66+ return '' ;
67+ }
68+
69+ return AddonCourseCompletion . getCompletedStatusText ( completion ) ;
70+ } ) ;
71+
72+ readonly user = signal < CoreUserProfile | undefined > ( undefined ) ;
5273
5374 constructor ( ) {
5475 this . logView = CoreTime . once ( ( ) => {
@@ -57,8 +78,8 @@ export default class AddonCourseCompletionReportPage implements OnInit {
5778 ws : 'core_completion_get_course_completion_status' ,
5879 name : Translate . instant ( 'addon.coursecompletion.coursecompletion' ) ,
5980 data : {
60- course : this . courseId ,
61- user : this . userId ,
81+ course : this . courseId ( ) ,
82+ user : this . userId ( ) ,
6283 } ,
6384 url : `/blocks/completionstatus/details.php?course=${ this . courseId } &user=${ this . userId } ` ,
6485 } ) ;
@@ -70,8 +91,8 @@ export default class AddonCourseCompletionReportPage implements OnInit {
7091 */
7192 ngOnInit ( ) : void {
7293 try {
73- this . courseId = CoreNavigator . getRequiredRouteNumberParam ( 'courseId' ) ;
74- this . userId = CoreNavigator . getRouteNumberParam ( 'userId' ) || CoreSites . getCurrentSiteUserId ( ) ;
94+ this . courseId . set ( CoreNavigator . getRequiredRouteNumberParam ( 'courseId' ) ) ;
95+ this . userId . set ( CoreNavigator . getRouteNumberParam ( 'userId' ) || CoreSites . getCurrentSiteUserId ( ) ) ;
7596 } catch ( error ) {
7697 CoreAlerts . showError ( error ) ;
7798 CoreNavigator . back ( ) ;
@@ -80,7 +101,7 @@ export default class AddonCourseCompletionReportPage implements OnInit {
80101 }
81102
82103 this . fetchCompletion ( ) . finally ( ( ) => {
83- this . completionLoaded = true ;
104+ this . loaded . set ( true ) ;
84105 } ) ;
85106 }
86107
@@ -89,19 +110,16 @@ export default class AddonCourseCompletionReportPage implements OnInit {
89110 */
90111 protected async fetchCompletion ( ) : Promise < void > {
91112 try {
92- this . user = await CoreUser . getProfile ( this . userId , this . courseId , true ) ;
93-
94- this . completion = await AddonCourseCompletion . getCompletion ( this . courseId , this . userId ) ;
113+ this . user . set ( await CoreUser . getProfile ( this . userId ( ) , this . courseId ( ) , true ) ) ;
95114
96- this . statusText = AddonCourseCompletion . getCompletedStatusText ( this . completion ) ;
97- this . showSelfComplete = AddonCourseCompletion . canMarkSelfCompleted ( this . userId , this . completion ) ;
115+ this . completion . set ( await AddonCourseCompletion . getCompletion ( this . courseId ( ) , this . userId ( ) ) ) ;
98116
99- this . tracked = true ;
117+ this . tracked . set ( true ) ;
100118 this . logView ( ) ;
101119 } catch ( error ) {
102- if ( error && error . errorcode == 'notenroled' ) {
120+ if ( error ? .errorcode = == 'notenroled' ) {
103121 // Not enrolled error, probably a teacher.
104- this . tracked = false ;
122+ this . tracked . set ( false ) ;
105123 } else {
106124 CoreAlerts . showError ( error , { default : Translate . instant ( 'addon.coursecompletion.couldnotloadreport' ) } ) ;
107125 }
@@ -114,7 +132,7 @@ export default class AddonCourseCompletionReportPage implements OnInit {
114132 * @param refresher Refresher instance.
115133 */
116134 async refreshCompletion ( refresher ?: HTMLIonRefresherElement ) : Promise < void > {
117- await AddonCourseCompletion . invalidateCourseCompletion ( this . courseId , this . userId ) . finally ( ( ) => {
135+ await AddonCourseCompletion . invalidateCourseCompletion ( this . courseId ( ) , this . userId ( ) ) . finally ( ( ) => {
118136 this . fetchCompletion ( ) . finally ( ( ) => {
119137 refresher ?. complete ( ) ;
120138 } ) ;
@@ -134,7 +152,7 @@ export default class AddonCourseCompletionReportPage implements OnInit {
134152 const modal = await CoreLoadings . show ( 'core.sending' , true ) ;
135153
136154 try {
137- await AddonCourseCompletion . markCourseAsSelfCompleted ( this . courseId ) ;
155+ await AddonCourseCompletion . markCourseAsSelfCompleted ( this . courseId ( ) ) ;
138156
139157 await this . refreshCompletion ( ) ;
140158 } catch ( error ) {
0 commit comments