@@ -7,18 +7,18 @@ import {
77 ExamAttemptLogResource ,
88} from 'kolibri.resources' ;
99
10+ import { getCurrentChannelObject , isUserLoggedIn , isSuperuser } from 'kolibri.coreVue.vuex.getters' ;
11+ import { setChannelInfo , handleApiError } from 'kolibri.coreVue.vuex.actions' ;
12+ import { createQuestionList , selectQuestionFromExercise } from 'kolibri.utils.exams' ;
13+ import { ContentNodeKinds } from 'kolibri.coreVue.vuex.constants' ;
1014import { PageNames } from '../../constants' ;
15+ import { samePageCheckGenerator } from 'kolibri.coreVue.vuex.actions' ;
16+ import { assessmentMetaDataState } from 'kolibri.coreVue.vuex.mappers' ;
17+ import { now } from 'kolibri.utils.serverClock' ;
1118
12- import * as coreActions from 'kolibri.coreVue.vuex.actions' ;
1319import ConditionalPromise from 'kolibri.lib.conditionalPromise' ;
14- import { samePageCheckGenerator } from 'kolibri.coreVue.vuex.actions' ;
15- import * as coreGetters from 'kolibri.coreVue.vuex.getters' ;
16- import * as CoreConstants from 'kolibri.coreVue.vuex.constants' ;
1720import router from 'kolibri.coreVue.router' ;
1821import seededShuffle from 'kolibri.lib.seededshuffle' ;
19- import { createQuestionList , selectQuestionFromExercise } from 'kolibri.utils.exams' ;
20- import { assessmentMetaDataState } from 'kolibri.coreVue.vuex.mappers' ;
21- import { now } from 'kolibri.utils.serverClock' ;
2222import prepareLearnApp from '../prepareLearnApp' ;
2323
2424/**
@@ -88,7 +88,7 @@ function contentState(data, nextContent, ancestors = []) {
8888
8989function _collectionState ( data ) {
9090 return data . map ( item => {
91- if ( item . kind === CoreConstants . ContentNodeKinds . TOPIC ) {
91+ if ( item . kind === ContentNodeKinds . TOPIC ) {
9292 return _topicState ( item ) ;
9393 }
9494 return contentState ( item ) ;
@@ -146,9 +146,9 @@ function redirectToExploreChannel(store) {
146146 store . dispatch ( 'CORE_SET_PAGE_LOADING' , true ) ;
147147 store . dispatch ( 'SET_PAGE_NAME' , PageNames . EXPLORE_ROOT ) ;
148148
149- coreActions . setChannelInfo ( store ) . then (
149+ setChannelInfo ( store ) . then (
150150 ( ) => {
151- const currentChannel = coreGetters . getCurrentChannelObject ( store . state ) ;
151+ const currentChannel = getCurrentChannelObject ( store . state ) ;
152152 if ( currentChannel ) {
153153 router . getInstance ( ) . replace ( {
154154 name : PageNames . EXPLORE_CHANNEL ,
@@ -159,7 +159,7 @@ function redirectToExploreChannel(store) {
159159 }
160160 } ,
161161 error => {
162- coreActions . handleApiError ( store , error ) ;
162+ handleApiError ( store , error ) ;
163163 }
164164 ) ;
165165}
@@ -168,9 +168,9 @@ function redirectToLearnChannel(store) {
168168 store . dispatch ( 'CORE_SET_PAGE_LOADING' , true ) ;
169169 store . dispatch ( 'SET_PAGE_NAME' , PageNames . LEARN_ROOT ) ;
170170
171- coreActions . setChannelInfo ( store ) . then (
171+ setChannelInfo ( store ) . then (
172172 ( ) => {
173- const currentChannel = coreGetters . getCurrentChannelObject ( store . state ) ;
173+ const currentChannel = getCurrentChannelObject ( store . state ) ;
174174 if ( currentChannel ) {
175175 router . getInstance ( ) . replace ( {
176176 name : PageNames . LEARN_CHANNEL ,
@@ -181,7 +181,7 @@ function redirectToLearnChannel(store) {
181181 }
182182 } ,
183183 error => {
184- coreActions . handleApiError ( store , error ) ;
184+ handleApiError ( store , error ) ;
185185 }
186186 ) ;
187187}
@@ -199,12 +199,12 @@ function showExploreTopic(store, channelId, id, isRoot = false) {
199199 const childrenPromise = ContentNodeResource . getCollection ( channelPayload , {
200200 parent : id ,
201201 } ) . fetch ( ) ;
202- const channelsPromise = coreActions . setChannelInfo ( store , channelId ) ;
202+ const channelsPromise = setChannelInfo ( store , channelId ) ;
203203 const ancestorsPromise = ContentNodeResource . fetchAncestors ( id , channelPayload ) ;
204204 ConditionalPromise . all ( [ topicPromise , childrenPromise , ancestorsPromise , channelsPromise ] ) . only (
205205 samePageCheckGenerator ( store ) ,
206206 ( [ topic , children , ancestors ] ) => {
207- const currentChannel = coreGetters . getCurrentChannelObject ( store . state ) ;
207+ const currentChannel = getCurrentChannelObject ( store . state ) ;
208208 if ( ! currentChannel ) {
209209 router . replace ( { name : PageNames . CONTENT_UNAVAILABLE } ) ;
210210 return ;
@@ -216,7 +216,7 @@ function showExploreTopic(store, channelId, id, isRoot = false) {
216216 store . dispatch ( 'SET_PAGE_STATE' , pageState ) ;
217217 // Topics are expensive to compute progress for, so we lazily load progress for them.
218218 const subtopicIds = collection
219- . filter ( item => item . kind === CoreConstants . ContentNodeKinds . TOPIC )
219+ . filter ( item => item . kind === ContentNodeKinds . TOPIC )
220220 . map ( subtopic => subtopic . id ) ;
221221 if ( subtopicIds . length ) {
222222 const topicProgressPromise = ContentNodeProgressResource . getCollection ( channelPayload , {
@@ -235,7 +235,7 @@ function showExploreTopic(store, channelId, id, isRoot = false) {
235235 }
236236 } ,
237237 error => {
238- coreActions . handleApiError ( store , error ) ;
238+ handleApiError ( store , error ) ;
239239 }
240240 ) ;
241241}
@@ -244,8 +244,8 @@ function showExploreChannel(store, channelId) {
244244 store . dispatch ( 'CORE_SET_PAGE_LOADING' , true ) ;
245245 store . dispatch ( 'SET_PAGE_NAME' , PageNames . EXPLORE_CHANNEL ) ;
246246
247- coreActions . setChannelInfo ( store , channelId ) . then ( ( ) => {
248- const currentChannel = coreGetters . getCurrentChannelObject ( store . state ) ;
247+ setChannelInfo ( store , channelId ) . then ( ( ) => {
248+ const currentChannel = getCurrentChannelObject ( store . state ) ;
249249 if ( ! currentChannel ) {
250250 router . replace ( { name : PageNames . CONTENT_UNAVAILABLE } ) ;
251251 return ;
@@ -264,7 +264,7 @@ function showExploreContent(store, channelId, id) {
264264 const nextContentPromise = ContentNodeResource . fetchNextContent ( id , {
265265 channel_id : channelId ,
266266 } ) ;
267- const channelsPromise = coreActions . setChannelInfo ( store , channelId ) ;
267+ const channelsPromise = setChannelInfo ( store , channelId ) ;
268268 const ancestorsPromise = ContentNodeResource . fetchAncestors ( id , {
269269 channel_id : channelId ,
270270 } ) ;
@@ -276,7 +276,7 @@ function showExploreContent(store, channelId, id) {
276276 ] ) . only (
277277 samePageCheckGenerator ( store ) ,
278278 ( [ content , channels , nextContent , ancestors ] ) => {
279- const currentChannel = coreGetters . getCurrentChannelObject ( store . state ) ;
279+ const currentChannel = getCurrentChannelObject ( store . state ) ;
280280 if ( ! currentChannel ) {
281281 router . replace ( { name : PageNames . CONTENT_UNAVAILABLE } ) ;
282282 return ;
@@ -290,7 +290,7 @@ function showExploreContent(store, channelId, id) {
290290 store . dispatch ( 'CORE_SET_TITLE' , `${ pageState . content . title } - ${ currentChannel . title } ` ) ;
291291 } ,
292292 error => {
293- coreActions . handleApiError ( store , error ) ;
293+ handleApiError ( store , error ) ;
294294 }
295295 ) ;
296296}
@@ -320,7 +320,7 @@ function triggerSearch(store, channelId, searchTerm) {
320320 store . dispatch ( 'CORE_SET_PAGE_LOADING' , false ) ;
321321 } )
322322 . catch ( error => {
323- coreActions . handleApiError ( store , error ) ;
323+ handleApiError ( store , error ) ;
324324 } ) ;
325325}
326326
@@ -347,16 +347,16 @@ function redirectToChannelSearch(store) {
347347 store . dispatch ( 'CORE_SET_ERROR' , null ) ;
348348 store . dispatch ( 'CORE_SET_TITLE' , 'Search' ) ;
349349 clearSearch ( store ) ;
350- coreActions . setChannelInfo ( store ) . then (
350+ setChannelInfo ( store ) . then (
351351 ( ) => {
352- const currentChannel = coreGetters . getCurrentChannelObject ( store . state ) ;
352+ const currentChannel = getCurrentChannelObject ( store . state ) ;
353353 router . getInstance ( ) . replace ( {
354354 name : PageNames . SEARCH ,
355355 params : { channel_id : currentChannel . id } ,
356356 } ) ;
357357 } ,
358358 error => {
359- coreActions . handleApiError ( store , error ) ;
359+ handleApiError ( store , error ) ;
360360 }
361361 ) ;
362362}
@@ -368,7 +368,7 @@ function showSearch(store, channelId, searchTerm) {
368368 store . dispatch ( 'CORE_SET_ERROR' , null ) ;
369369 store . dispatch ( 'CORE_SET_TITLE' , 'Search' ) ;
370370 clearSearch ( store ) ;
371- coreActions . setChannelInfo ( store , channelId ) . then ( ( ) => {
371+ setChannelInfo ( store , channelId ) . then ( ( ) => {
372372 if ( searchTerm ) {
373373 triggerSearch ( store , channelId , searchTerm ) ;
374374 } else {
@@ -378,7 +378,7 @@ function showSearch(store, channelId, searchTerm) {
378378}
379379
380380function showExamList ( store , channelId ) {
381- const userIsLoggedIn = coreGetters . isUserLoggedIn ( store . state ) ;
381+ const userIsLoggedIn = isUserLoggedIn ( store . state ) ;
382382 store . dispatch ( 'SET_PAGE_NAME' , PageNames . EXAM_LIST ) ;
383383 store . dispatch ( 'CORE_SET_PAGE_LOADING' , true ) ;
384384
@@ -388,8 +388,8 @@ function showExamList(store, channelId) {
388388 return Promise . resolve ( ) ;
389389 }
390390
391- return coreActions . setChannelInfo ( store , channelId ) . then ( ( ) => {
392- const currentChannel = coreGetters . getCurrentChannelObject ( store . state ) ;
391+ return setChannelInfo ( store , channelId ) . then ( ( ) => {
392+ const currentChannel = getCurrentChannelObject ( store . state ) ;
393393 if ( ! currentChannel ) {
394394 router . replace ( { name : PageNames . CONTENT_UNAVAILABLE } ) ;
395395 return ;
@@ -405,7 +405,7 @@ function showExamList(store, channelId) {
405405 store . dispatch ( 'CORE_SET_TITLE' , `Exams - ${ currentChannel . title } ` ) ;
406406 } ,
407407 error => {
408- coreActions . handleApiError ( store , error ) ;
408+ handleApiError ( store , error ) ;
409409 }
410410 ) ;
411411 } ) ;
@@ -434,7 +434,7 @@ function showExam(store, channelId, id, questionNumber) {
434434 questionNumber = Number ( questionNumber ) ; // eslint-disable-line no-param-reassign
435435
436436 const examPromise = UserExamResource . getModel ( id ) . fetch ( ) ;
437- const channelsPromise = coreActions . setChannelInfo ( store , channelId ) ;
437+ const channelsPromise = setChannelInfo ( store , channelId ) ;
438438 const examLogPromise = ExamLogResource . getCollection ( {
439439 user : store . state . core . session . user_id ,
440440 exam : id ,
@@ -451,15 +451,15 @@ function showExam(store, channelId, id, questionNumber) {
451451 ] ) . only (
452452 samePageCheckGenerator ( store ) ,
453453 ( [ exam , channel , examLogs , examAttemptLogs ] ) => {
454- const currentChannel = coreGetters . getCurrentChannelObject ( store . state ) ;
454+ const currentChannel = getCurrentChannelObject ( store . state ) ;
455455 if ( ! currentChannel ) {
456456 router . replace ( { name : PageNames . CONTENT_UNAVAILABLE } ) ;
457457 return ;
458458 }
459459
460460 const attemptLogs = { } ;
461461
462- if ( store . state . core . session . user_id && ! coreGetters . isSuperuser ( store . state ) ) {
462+ if ( store . state . core . session . user_id && ! isSuperuser ( store . state ) ) {
463463 if ( examLogs . length > 0 && examLogs . some ( log => ! log . closed ) ) {
464464 store . dispatch ( 'SET_EXAM_LOG' , _examLoggingState ( examLogs . find ( log => ! log . closed ) ) ) ;
465465 } else {
@@ -504,10 +504,7 @@ function showExam(store, channelId, id, questionNumber) {
504504
505505 if ( ! shuffledQuestions [ questionNumber ] ) {
506506 // Illegal question number!
507- coreActions . handleError (
508- store ,
509- `Question number ${ questionNumber } is not valid for this exam`
510- ) ;
507+ handleError ( store , `Question number ${ questionNumber } is not valid for this exam` ) ;
511508 } else {
512509 const contentPromise = ContentNodeResource . getCollection (
513510 { channel_id : channelId } ,
@@ -534,7 +531,7 @@ function showExam(store, channelId, id, questionNumber) {
534531
535532 if ( questions . every ( question => ! question . itemId ) ) {
536533 // Exam is drawing solely on malformed exercise data, best to quit now
537- coreActions . handleError ( store , `This exam has no valid questions` ) ;
534+ handleError ( store , `This exam has no valid questions` ) ;
538535 } else {
539536 const itemId = questions [ questionNumber ] . itemId ;
540537
@@ -587,13 +584,13 @@ function showExam(store, channelId, id, questionNumber) {
587584 }
588585 } ,
589586 error => {
590- coreActions . handleApiError ( store , error ) ;
587+ handleApiError ( store , error ) ;
591588 }
592589 ) ;
593590 }
594591 } ,
595592 error => {
596- coreActions . handleApiError ( store , error ) ;
593+ handleApiError ( store , error ) ;
597594 }
598595 ) ;
599596 }
@@ -656,7 +653,7 @@ function closeExam(store) {
656653 const examLog = Object . assign ( { } , store . state . examLog ) ;
657654 examLog . closed = true ;
658655 return ExamLogResource . getModel ( examLog . id ) . save ( examLog ) . catch ( error => {
659- coreActions . handleApiError ( store , error ) ;
656+ handleApiError ( store , error ) ;
660657 } ) ;
661658}
662659
0 commit comments