1 |
package Transports::Dispatcher; |
2 |
use Jifty::Dispatcher -base; |
3 |
|
4 |
# Default page |
5 |
#on '/', run { |
6 |
# redirect( '/new'); |
7 |
#}; |
8 |
|
9 |
=head1 Transports operations |
10 |
|
11 |
=head2 /transports/create/new |
12 |
|
13 |
=cut |
14 |
|
15 |
on '/transports/create/new' => run { |
16 |
|
17 |
my $landscape_id = get('landscape_id'); |
18 |
if (! $landscape_id) { |
19 |
|
20 |
my $landscapes = Transports::Model::UserOnLandscapeCollection->new(); |
21 |
$landscapes->limit( |
22 |
column => 'user_on', |
23 |
value => Jifty->web->current_user->id, |
24 |
quote_value => 0, |
25 |
); |
26 |
$landscapes->order_by( column => 'landscape' ); |
27 |
|
28 |
if ($landscapes->count == 0) { |
29 |
show '/transports/create/no_landscape'; |
30 |
} elsif ($landscapes->count == 1) { |
31 |
$landscape_id = $landscapes->first->id; |
32 |
} else { |
33 |
set landscapes => $landscapes; |
34 |
show '/transports/create/landscape'; |
35 |
} |
36 |
} |
37 |
|
38 |
my $transport = Jifty->web->new_action( |
39 |
class => 'CreateTransport', |
40 |
monkier => 'create', |
41 |
); |
42 |
|
43 |
my $l = Transports::Model::Landscape->new(); |
44 |
$l->load_by_cols( id => $landscape_id ); |
45 |
|
46 |
warn "Can't find landscape with id $landscape_id" unless ($l->id); |
47 |
|
48 |
my $s = Transports::Model::SourceCollection->new(); |
49 |
$s->limit( |
50 |
column => 'landscape', |
51 |
value => $landscape_id, |
52 |
); |
53 |
$transport->arguments->{'source'}->{'valid_values'}->[0]->{'collection'} = $s; |
54 |
|
55 |
my $d = Transports::Model::DestinationCollection->new(); |
56 |
$d->limit( |
57 |
column => 'landscape', |
58 |
value => $landscape_id, |
59 |
); |
60 |
$transport->arguments->{'destination'}->{'valid_values'}->[0]->{'collection'} = $d; |
61 |
|
62 |
set 'landscape_id' => $landscape_id; |
63 |
set 'transport' => $transport; |
64 |
|
65 |
show '/transports/create/new'; |
66 |
}; |
67 |
|
68 |
=head1 Login and logout operations |
69 |
|
70 |
=head2 logout |
71 |
|
72 |
=cut |
73 |
|
74 |
before '/logout', run { |
75 |
Jifty->web->request->add_action( |
76 |
moniker => 'logout', |
77 |
class => 'Transports::Action::Logout' |
78 |
); |
79 |
warn "added Transports::Action::Logout"; |
80 |
}; |
81 |
|
82 |
|
83 |
# These are dispatcher rules that halos and error handling need to be |
84 |
# able to edit files in place. These should become a plugin of some |
85 |
# sort, when we have that infrastructure. |
86 |
|
87 |
before '*', run { |
88 |
|
89 |
my $url = Jifty->web->request->path; |
90 |
|
91 |
warn "before url: $url"; |
92 |
|
93 |
next_rule if ($url eq '/' || $url =~ m#^/(?:login|logout|__jifty)/*#); |
94 |
|
95 |
Jifty->api->allow(qr/^Jifty::Action::Devel/) |
96 |
if Jifty->config->framework('DevelMode'); |
97 |
|
98 |
if (not Jifty->web->current_user->id) { |
99 |
warn "send user accessing $url to login form\n"; |
100 |
Jifty->web->tangent( url => '/login' ); |
101 |
} |
102 |
|
103 |
}; |
104 |
|
105 |
on qr'^/__jifty/edit/(.*?)/(.*)$', run { |
106 |
my $editor = Jifty->web->new_action( |
107 |
class => 'Jifty::Action::Devel::FileEditor', |
108 |
moniker => 'editpage', |
109 |
arguments => { |
110 |
source_path => $2, |
111 |
file_type => $1, |
112 |
} |
113 |
); |
114 |
|
115 |
set editor => $editor; |
116 |
show '/__jifty/edit_file'; |
117 |
}; |
118 |
|
119 |
use Data::Dumper; |
120 |
foreach my $s ( qw/SETUP RUN CLEANUP/ ) { |
121 |
Jifty->log->debug("$s rules:\n", join("\n", |
122 |
map { my ($on,$what) = @$_ ; "\t$on $what" } @{ 'RULES_' . $s } ) |
123 |
); |
124 |
} |
125 |
|
126 |
1; |