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