@@ -502,23 +502,32 @@ export default new Router({
502502 ] ,
503503 } ,
504504 {
505- path : '/camps/:campId/:campShortTitle/program/activities/: scheduleEntryId/:activityName?' ,
505+ path : '/camps/:campId/:campShortTitle/program/activity/:activityId/: scheduleEntryId? /:activityName?' ,
506506 name : 'camp/activity' ,
507507 components : {
508508 navigation : NavigationCamp ,
509509 default : ( ) => import ( './views/camp/activity/Activity.vue' ) ,
510510 aside : ( ) => import ( './views/camp/activity/SideBarProgram.vue' ) ,
511511 } ,
512- beforeEnter : all ( [ requireAuth , requireCamp , requireScheduleEntry ] ) ,
512+ beforeEnter : all ( [ requireAuth , requireCamp , requireActivityScheduleEntry ] ) ,
513513 props : {
514514 navigation : ( route ) => ( { camp : campFromRoute ( route ) } ) ,
515- default : ( route ) => ( { scheduleEntry : scheduleEntryFromRoute ( route ) } ) ,
515+ default : ( route ) => ( {
516+ activityId : route . params . activityId ,
517+ scheduleEntryId : route . params . scheduleEntryId ,
518+ } ) ,
516519 aside : ( route ) => ( {
517520 camp : campFromRoute ( route ) ,
518- day : dayFromScheduleEntryInRoute ( route ) ,
521+ activityId : route . params . activityId ,
522+ scheduleEntryId : route . params . scheduleEntryId ,
519523 } ) ,
520524 } ,
521525 } ,
526+ {
527+ path : '/camps/:campId/:campShortTitle/program/activities/:scheduleEntryId/:activityName?' ,
528+ redirect :
529+ '/camps/:campId/:campShortTitle/program/activity/0/:scheduleEntryId?/:activityName?' ,
530+ } ,
522531 {
523532 path : '/' ,
524533 name : 'home' ,
@@ -600,27 +609,48 @@ async function requireCamp(to, from, next) {
600609 }
601610}
602611
603- async function requireScheduleEntry ( to , from , next ) {
604- const scheduleEntry = await scheduleEntryFromRoute ( to )
605- if ( scheduleEntry === undefined ) {
606- next ( {
607- name : 'PageNotFound' ,
608- params : [ to . fullPath , '' ] ,
609- replace : true ,
612+ async function requireActivityScheduleEntry ( to , from , next ) {
613+ await apiStore
614+ . get ( )
615+ . activities ( { id : to . params . activityId } )
616+ . _meta . load . then ( ( activity ) => {
617+ // activity exists
618+ if ( to . params . scheduleEntryId ) {
619+ apiStore
620+ . get ( )
621+ . scheduleEntries ( { id : to . params . scheduleEntryId } )
622+ . _meta . load . then ( ( ) => {
623+ // activity and scheduleEntry exist
624+ next ( )
625+ } )
626+ . catch ( async ( ) => {
627+ // scheduleEntry is not found, use first activity scheduleEntry
628+ to . params . scheduleEntryId = firstActivityScheduleEntry ( activity ) . id
629+ next ( to )
630+ } )
631+ }
632+ next ( )
633+ } )
634+ . catch ( ( ) => {
635+ // activityId does not exist, check if scheduleEntryId exists
636+ if ( to . params . scheduleEntryId ) {
637+ apiStore
638+ . get ( )
639+ . scheduleEntries ( { id : to . params . scheduleEntryId } )
640+ . _meta . load . then ( async ( scheduleEntry ) => {
641+ const activity = await scheduleEntry . activity ( ) . _meta . load
642+ to . params . activityId = activity . id
643+ next ( to )
644+ } )
645+ . catch ( async ( ) => {
646+ // scheduleEntry and activity are not found, fallback to camp program
647+ next ( {
648+ ...to ,
649+ name : 'camp/program' ,
650+ } )
651+ } )
652+ }
610653 } )
611- } else {
612- await scheduleEntry . _meta . load
613- . then ( ( ) => {
614- next ( )
615- } )
616- . catch ( ( ) => {
617- next ( {
618- name : 'PageNotFound' ,
619- params : [ to . fullPath , '' ] ,
620- replace : true ,
621- } )
622- } )
623- }
624654}
625655
626656async function requirePeriod ( to , from , next ) {
@@ -721,13 +751,6 @@ export function periodFromRoute(route) {
721751 return apiStore . get ( ) . periods ( { id : route . params . periodId } )
722752}
723753
724- function scheduleEntryFromRoute ( route ) {
725- if ( ! route . params . scheduleEntryId ) {
726- return undefined
727- }
728- return apiStore . get ( ) . scheduleEntries ( { id : route . params . scheduleEntryId } )
729- }
730-
731754function categoryFromRoute ( route ) {
732755 if ( ! route . params . categoryId ) {
733756 return undefined
@@ -772,13 +795,6 @@ function getContentLayout(route) {
772795 }
773796}
774797
775- function dayFromScheduleEntryInRoute ( route ) {
776- if ( ! route . params . scheduleEntryId ) {
777- return undefined
778- }
779- return apiStore . get ( ) . scheduleEntries ( { id : route . params . scheduleEntryId } ) . day ( )
780- }
781-
782798/**
783799 * @param camp
784800 * @param subroute {'admin' | 'dashboard' | 'program' | 'material' | 'story' | 'home' | 'collaborators' | 'print' }
@@ -856,7 +872,8 @@ export function periodRoute(period, routeName = 'camp/period/program', query = {
856872export function scheduleEntryRoute ( scheduleEntry , query = { } ) {
857873 if ( scheduleEntry . _meta . loading || scheduleEntry . activity ( ) . _meta . loading ) return { }
858874
859- const camp = scheduleEntry . activity ( ) . camp ( )
875+ const activity = scheduleEntry . activity ( )
876+ const camp = activity . camp ( )
860877
861878 // if (camp._meta.loading) return {}
862879
@@ -866,7 +883,8 @@ export function scheduleEntryRoute(scheduleEntry, query = {}) {
866883 campId : camp . id ,
867884 campShortTitle : slugify ( campShortTitle ( camp ) ) ,
868885 scheduleEntryId : scheduleEntry . id ,
869- activityName : slugify ( scheduleEntry . activity ( ) . title ) ,
886+ activityId : activity . id ,
887+ activityName : slugify ( activity . title ) ,
870888 } ,
871889 query,
872890 }
@@ -967,6 +985,21 @@ async function firstFuturePeriod(route) {
967985 )
968986}
969987
988+ export async function firstActivityScheduleEntry ( activity ) {
989+ if ( typeof activity === 'string' ) {
990+ activity = apiStore . get ( ) . activities ( { id : activity } )
991+ }
992+ return activity
993+ . scheduleEntries ( )
994+ . items . reduce (
995+ ( result , current ) =>
996+ result === null || new Date ( result . start ) > new Date ( current . start )
997+ ? current
998+ : result ,
999+ null
1000+ )
1001+ }
1002+
9701003async function redirectToPeriod ( to , from , next , routeName ) {
9711004 const period = await firstFuturePeriod ( to )
9721005 if ( period ) {
0 commit comments