1 package KratosOrange
::Dispatcher
;
4 use Jifty
::Dispatcher
-base
;
7 if (Jifty
->web->current_user->id) {
8 # authenticated user, show options
9 my $top = Jifty
->web->navigation;
10 $top->child( 'Home' => url
=> '/' );
11 $top->child( 'My workouts' => url
=> '/workouts' );
12 $top->child( 'Preferences' => url
=> '/prefs' );
13 $top->child( 'Logout' => url
=> '/logout' );
15 elsif ($1 !~ /^login|^signup/) {
21 my $emped_id = Jifty
->web->current_user->user_object->empedid;
22 Jifty
->log->debug('empedid: ' . $emped_id);
24 # user has not set his emped_id yet, send him off to preferences
28 = glob("/Volumes/*/iPod_Control/Device/Trainer/Workouts/Empeds/$emped_id/latest/*.xml");
30 = glob("/Volumes/*/iPod_Control/Device/Trainer/Workouts/Empeds/$emped_id/synched/*.xml");
31 Jifty
->log->debug('new files: ' . join q{, }, @new_files);
32 Jifty
->log->debug('old files: ' . join q{, }, @old_files);
34 my $workouts = KratosOrange
::Model
::WorkoutCollection
->new();
36 column
=> 'user_info_empedid',
39 if (! $workouts->count && scalar @old_files) {
40 # this user has no workouts recorded, let him import ones
42 tangent
'/import_synched';
45 # if new files are available, import them
46 foreach my $file (@new_files) {
47 my $workout = KratosOrange
::Model
::Workout
->new_from_XML($file);
48 # move file to 'synched' folder
49 my $new_location = $file;
50 $new_location =~ s/latest/synched/g;
51 rename($file, $new_location);
57 on
qr{ \A /workout/(\d+) \z }xms => run
{
59 set
'workout_id' => $workout_id;
63 on
qr{ \A /workout/(\d+)/chart \z }xms => run
{
65 set
'workout_id' => $workout_id;
69 on
qr{ \A /workout/(\d+)/edit \z }xms => run
{
71 set
'workout_id' => $workout_id;
75 on
'/workouts' => show
'workouts';
76 on
'/prefs' => show
'preferences';
77 on
'/import_synched' => show
'import_synched';