@@ -38,7 +38,12 @@ import {
3838 AddonModFeedbackSyncResult ,
3939} from '../../services/feedback-sync' ;
4040import { AddonModFeedbackPrefetchHandler } from '../../services/handlers/prefetch' ;
41- import { ADDON_MOD_FEEDBACK_COMPONENT , ADDON_MOD_FEEDBACK_FORM_SUBMITTED , ADDON_MOD_FEEDBACK_PAGE_NAME } from '../../constants' ;
41+ import {
42+ ADDON_MOD_FEEDBACK_COMPONENT ,
43+ ADDON_MOD_FEEDBACK_FORM_SUBMITTED ,
44+ ADDON_MOD_FEEDBACK_PAGE_NAME ,
45+ AddonModFeedbackIndexTabName ,
46+ } from '../../constants' ;
4247
4348/**
4449 * Component that displays a feedback index page.
@@ -51,7 +56,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
5156
5257 @ViewChild ( CoreTabsComponent ) tabsComponent ?: CoreTabsComponent ;
5358
54- @Input ( ) tab = 'overview' ;
59+ @Input ( ) selectedTab : AddonModFeedbackIndexTabName = AddonModFeedbackIndexTabName . OVERVIEW ;
5560 @Input ( ) group = 0 ;
5661
5762 component = ADDON_MOD_FEEDBACK_COMPONENT ;
@@ -75,9 +80,9 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
7580 closeTimeReadable : '' ,
7681 } ;
7782
78- tabsLoaded = {
79- overview : false ,
80- analysis : false ,
83+ tabs = {
84+ overview : { name : AddonModFeedbackIndexTabName . OVERVIEW , label : 'addon.mod_feedback.overview' , loaded : false } ,
85+ analysis : { name : AddonModFeedbackIndexTabName . ANALYSIS , label : 'addon.mod_feedback.analysis' , loaded : false } ,
8186 } ;
8287
8388 protected submitObserver : CoreEventObserver ;
@@ -92,12 +97,12 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
9297
9398 // Listen for form submit events.
9499 this . submitObserver = CoreEvents . on ( ADDON_MOD_FEEDBACK_FORM_SUBMITTED , async ( data ) => {
95- if ( ! this . feedback || data . feedbackId != this . feedback . id ) {
100+ if ( ! this . feedback || data . feedbackId !== this . feedback . id ) {
96101 return ;
97102 }
98103
99- this . tabsLoaded . analysis = false ;
100- this . tabsLoaded . overview = false ;
104+ this . tabs . analysis . loaded = false ;
105+ this . tabs . overview . loaded = false ;
101106 this . showLoading = true ;
102107
103108 // Prefetch data if needed.
@@ -110,7 +115,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
110115 }
111116
112117 // Load the right tab.
113- if ( data . tab != this . tab ) {
118+ if ( data . tab !== this . selectedTab ) {
114119 this . tabChanged ( data . tab ) ;
115120 } else {
116121 this . loadContent ( true ) ;
@@ -149,7 +154,9 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
149154 */
150155 protected callAnalyticsLogEvent ( ) : void {
151156 this . analyticsLogEvent ( 'mod_feedback_view_feedback' , {
152- url : this . tab === 'analysis' ? `/mod/feedback/analysis.php?id=${ this . module . id } ` : undefined ,
157+ url : this . selectedTab === AddonModFeedbackIndexTabName . ANALYSIS
158+ ? `/mod/feedback/analysis.php?id=${ this . module . id } `
159+ : undefined ,
153160 } ) ;
154161 }
155162
@@ -168,8 +175,8 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
168175 promises . push ( AddonModFeedback . invalidateResumePageData ( this . feedback . id ) ) ;
169176 }
170177
171- this . tabsLoaded . analysis = false ;
172- this . tabsLoaded . overview = false ;
178+ this . tabs . analysis . loaded = false ;
179+ this . tabs . overview . loaded = false ;
173180
174181 await Promise . all ( promises ) ;
175182 }
@@ -178,7 +185,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
178185 * @inheritdoc
179186 */
180187 protected isRefreshSyncNeeded ( syncEventData : AddonModFeedbackAutoSyncData ) : boolean {
181- if ( this . feedback && syncEventData . feedbackId == this . feedback . id ) {
188+ if ( syncEventData . feedbackId === this . feedback ? .id ) {
182189 // Refresh the data.
183190 this . content ?. scrollToTop ( ) ;
184191
@@ -207,12 +214,17 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
207214 this . access = await AddonModFeedback . getFeedbackAccessInformation ( this . feedback . id , { cmId : this . module . id } ) ;
208215
209216 this . showAnalysis = ( this . access . canviewreports || this . access . canviewanalysis ) && ! this . access . isempty ;
217+
218+ this . tabs . analysis . label = this . access . canviewreports
219+ ? 'addon.mod_feedback.analysis'
220+ : 'addon.mod_feedback.completed_feedbacks' ;
221+
210222 this . firstSelectedTab = 0 ;
211223 if ( ! this . showAnalysis ) {
212- this . tab = 'overview' ;
224+ this . selectedTab = AddonModFeedbackIndexTabName . OVERVIEW ;
213225 }
214226
215- if ( this . tab == 'analysis' ) {
227+ if ( this . selectedTab === AddonModFeedbackIndexTabName . ANALYSIS ) {
216228 this . firstSelectedTab = 1 ;
217229
218230 return await this . fetchFeedbackAnalysisData ( ) ;
@@ -227,42 +239,44 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
227239
228240 if ( this . tabsReady ) {
229241 // Make sure the right tab is selected.
230- this . tabsComponent ?. selectTab ( this . tab || 'overview' ) ;
242+ this . tabsComponent ?. selectTab ( this . selectedTab ?? AddonModFeedbackIndexTabName . OVERVIEW ) ;
231243 }
232244 }
233245 }
234246
235247 /**
236248 * Convenience function to get feedback overview data.
237- *
238- * @returns Resolved when done.
239249 */
240250 protected async fetchFeedbackOverviewData ( ) : Promise < void > {
251+ if ( ! this . access || ! this . feedback ) {
252+ return ;
253+ }
254+
241255 const promises : Promise < void > [ ] = [ ] ;
242256
243- if ( this . access ! . cancomplete && this . access ! . cansubmit && this . access ! . isopen ) {
244- promises . push ( AddonModFeedback . getResumePage ( this . feedback ! . id , { cmId : this . module . id } ) . then ( ( goPage ) => {
257+ if ( this . access . cancomplete && this . access . cansubmit && this . access . isopen ) {
258+ promises . push ( AddonModFeedback . getResumePage ( this . feedback . id , { cmId : this . module . id } ) . then ( ( goPage ) => {
245259 this . goPage = goPage > 0 ? goPage : undefined ;
246260
247261 return ;
248262 } ) ) ;
249263 }
250264
251- if ( this . access ! . canedititems ) {
252- this . overview . timeopen = ( this . feedback ! . timeopen || 0 ) * 1000 ;
265+ if ( this . access . canedititems ) {
266+ this . overview . timeopen = ( this . feedback . timeopen || 0 ) * 1000 ;
253267 this . overview . openTimeReadable = this . overview . timeopen ? CoreTimeUtils . userDate ( this . overview . timeopen ) : '' ;
254- this . overview . timeclose = ( this . feedback ! . timeclose || 0 ) * 1000 ;
268+ this . overview . timeclose = ( this . feedback . timeclose || 0 ) * 1000 ;
255269 this . overview . closeTimeReadable = this . overview . timeclose ? CoreTimeUtils . userDate ( this . overview . timeclose ) : '' ;
256270 }
257- if ( this . access ! . canviewanalysis ) {
271+ if ( this . access . canviewanalysis ) {
258272 // Get groups (only for teachers).
259273 promises . push ( this . fetchGroupInfo ( this . module . id ) ) ;
260274 }
261275
262276 try {
263277 await Promise . all ( promises ) ;
264278 } finally {
265- this . tabsLoaded . overview = true ;
279+ this . tabs . overview . loaded = true ;
266280 }
267281 }
268282
@@ -273,15 +287,14 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
273287 */
274288 protected async fetchFeedbackAnalysisData ( ) : Promise < void > {
275289 try {
276- if ( this . access ! . canviewanalysis ) {
290+ if ( this . access ? .canviewanalysis ) {
277291 // Get groups (only for teachers).
278292 await this . fetchGroupInfo ( this . module . id ) ;
279293 } else {
280- this . tabChanged ( 'overview' ) ;
294+ this . tabChanged ( AddonModFeedbackIndexTabName . OVERVIEW ) ;
281295 }
282-
283296 } finally {
284- this . tabsLoaded . analysis = true ;
297+ this . tabs . analysis . loaded = true ;
285298 }
286299 }
287300
@@ -419,7 +432,7 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
419432 * Open attempts page.
420433 */
421434 openAttempts ( ) : void {
422- if ( ! this . access ! . canviewreports || this . completedCount <= 0 ) {
435+ if ( ! this . access || ! this . access . canviewreports || this . completedCount <= 0 ) {
423436 return ;
424437 }
425438
@@ -438,11 +451,11 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
438451 *
439452 * @param tabName New tab name.
440453 */
441- tabChanged ( tabName : string ) : void {
442- const tabHasChanged = this . tab !== undefined && this . tab !== tabName ;
443- this . tab = tabName ;
454+ tabChanged ( tabName : AddonModFeedbackIndexTabName ) : void {
455+ const tabHasChanged = this . selectedTab !== undefined && this . selectedTab !== tabName ;
456+ this . selectedTab = tabName ;
444457
445- if ( ! this . tabsLoaded [ this . tab ] ) {
458+ if ( ! this . tabs [ this . selectedTab ] . loaded ) {
446459 this . loadContent ( false , false , true ) ;
447460 }
448461
@@ -455,17 +468,20 @@ export class AddonModFeedbackIndexComponent extends CoreCourseModuleMainActivity
455468 * Set group to see the analysis.
456469 *
457470 * @param groupId Group ID.
458- * @returns Resolved when done.
459471 */
460472 async setGroup ( groupId : number ) : Promise < void > {
473+ if ( ! this . feedback ) {
474+ return ;
475+ }
476+
461477 this . group = groupId ;
462478
463- const analysis = await AddonModFeedback . getAnalysis ( this . feedback ! . id , { groupId, cmId : this . module . id } ) ;
479+ const analysis = await AddonModFeedback . getAnalysis ( this . feedback . id , { groupId, cmId : this . module . id } ) ;
464480
465481 this . completedCount = analysis . completedcount ;
466482 this . itemsCount = analysis . itemscount ;
467483
468- if ( this . tab == 'analysis' ) {
484+ if ( this . selectedTab === AddonModFeedbackIndexTabName . ANALYSIS ) {
469485 let num = 1 ;
470486
471487 this . items = < AddonModFeedbackItem [ ] > analysis . itemsdata . map ( ( itemData ) => {
0 commit comments