MCPcopy Index your code
hub / github.com/codecombat/codecombat / routeDirectly

Method routeDirectly

app/core/Router.js:632–731  ·  view source on GitHub ↗
(path, args, options)

Source from the content-addressed store, hash-verified

630 }
631
632 routeDirectly (path, args, options) {
633 if (args == null) { args = [] }
634 if (options == null) { options = {} }
635 this.vueRouter.push(`/${Backbone.history.getFragment()}`).catch(e => console.error('vue router push warning:', e))
636
637 if (window.alreadyLoadedView) {
638 path = window.alreadyLoadedView
639 }
640
641 if (!options.recursive) { this.viewLoad = new ViewLoadTimer() }
642 if (options.redirectStudents && me.isStudent() && !me.isAdmin()) {
643 return this.redirectHome()
644 }
645 if (options.redirectTeachers && me.isTeacher() && !me.isAdmin()) {
646 return this.redirectHome()
647 }
648 if (options.teachersOnly && !(me.isTeacher() || me.isAdmin())) {
649 return this.routeDirectly('teachers/RestrictedToTeachersView')
650 }
651 if (options.studentsOnly && !(me.isStudent() || me.isAdmin())) {
652 return this.routeDirectly('courses/RestrictedToStudentsView')
653 }
654 const leavingMessage = _.result(globalVar.currentView, 'onLeaveMessage')
655 if (leavingMessage) {
656 // Custom messages don't work any more, main browsers just show generic ones. So, this could be refactored.
657 if (!confirm(leavingMessage)) {
658 return this.navigate(this.path, { replace: true })
659 } else {
660 globalVar.currentView.onLeaveMessage = _.noop // to stop repeat confirm calls
661 }
662 }
663
664 // TODO: Combine these two?
665 if (features.playViewsOnly && !(_.string.startsWith(document.location.pathname, '/play') || (document.location.pathname === '/admin'))) {
666 delete window.alreadyLoadedView
667 return this.navigate('/play', { trigger: true, replace: true })
668 }
669 if (features.playOnly && !/^(views)?\/?play/.test(path)) {
670 delete window.alreadyLoadedView
671 path = 'play/CampaignView'
672 }
673
674 if (!_.string.startsWith(path, 'views/')) { path = `views/${path}` }
675 return Promise.all([
676 dynamicRequire[path](), // Load the view file
677 // The locale load is already initialized by `application`, just need the promise
678 locale.load(me.get('preferredLanguage', true)),
679 ]).then((...args1) => {
680 let view
681 const [ViewClass] = Array.from(args1[0])
682 if (!ViewClass) { return go('NotFoundView') }
683
684 // send url info to teachers
685 if (utils.useWebsocket && me.isStudent()) {
686 const {
687 wsBus,
688 } = globalVar.application
689 Object.entries((wsBus.wsInfos != null ? wsBus.wsInfos.friends : undefined) != null ? (wsBus.wsInfos != null ? wsBus.wsInfos.friends : undefined) : {}).forEach((...args2) => {

Callers 15

''Method · 0.95
homeMethod · 0.95
'impact'Method · 0.95
'partners'Method · 0.95
'apcsp'Method · 0.95
'apcspportal'Method · 0.95
'apcsportal'Method · 0.95
'codequest'Method · 0.95
ozariaMethod · 0.95
'mobile'Method · 0.95

Calls 15

redirectHomeMethod · 0.95
navigateMethod · 0.95
mergeViewMethod · 0.95
openViewMethod · 0.95
goFunction · 0.85
isStudentMethod · 0.80
isAdminMethod · 0.80
isTeacherMethod · 0.80
logMethod · 0.80
setViewMethod · 0.80
recordMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected