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 runs' => url
=> '/runs' );
12 $top->child( 'Preferences' => url
=> '/prefs' );
13 $top->child( 'Logout' => url
=> '/logout' );
14 # TODO - check if there is new data to import and tangent to
15 # import page if there is
16 # (only do this if data has already been imported, because the
17 # user might want to import 'old' data first if not)
19 elsif ($1 !~ /^login|^signup/) {
25 my $emped_id = Jifty
->web->current_user->user_object->empedid;
26 Jifty
->log->debug('empedid: ' . $emped_id);
28 # user has not set his emped_id yet, send him off to preferences
32 = glob("/Volumes/*/iPod_Control/Device/Trainer/Workouts/Empeds/$emped_id/latest/*.xml");
34 = glob("/Volumes/*/iPod_Control/Device/Trainer/Workouts/Empeds/$emped_id/synched/*.xml");
35 Jifty
->log->debug('new files: ' . join q{, }, @new_files);
36 Jifty
->log->debug('old files: ' . join q{, }, @old_files);
38 my $workouts = KratosOrange
::Model
::WorkoutCollection
->new();
40 column
=> 'user_info_empedid',
43 if (! $workouts->count && scalar @old_files) {
44 # this user has no workouts recorded, let him import ones
46 tangent
'/import_synched';
49 # if new files are available, import them
50 foreach my $file (@new_files) {
51 my $workout = KratosOrange
::Model
::Workout
->new_from_XML($file);
52 # move file to 'synched' folder
53 my $new_location = $file;
54 $new_location =~ s/latest/synched/g;
55 rename($file, $new_location);
61 on
qr{ /workout/(\d+)/chart }xms => run
{
63 set
'workout_id' => $workout_id;
68 on
'/prefs' => show
'preferences';
70 on
'/import_synched' => show
'import_synched';