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 |
=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 login |
71 |
|
72 |
=cut |
73 |
|
74 |
on '--login', run { |
75 |
|
76 |
set 'action' => |
77 |
Jifty->web->new_action( class => 'Login', moniker => 'loginbox' ); |
78 |
set 'next' => Jifty->web->request->continuation |
79 |
|| Jifty::Continuation->new( |
80 |
request => Jifty::Request->new( path => '/transports' ) ); |
81 |
show '/login'; |
82 |
}; |
83 |
|
84 |
=head2 logout |
85 |
|
86 |
=cut |
87 |
|
88 |
before 'logout', run { |
89 |
Jifty->web->request->add_action( |
90 |
moniker => 'logout', |
91 |
class => 'Transports::Action::Logout' |
92 |
); |
93 |
}; |
94 |
|
95 |
|
96 |
# These are dispatcher rules that halos and error handling need to be |
97 |
# able to edit files in place. These should become a plugin of some |
98 |
# sort, when we have that infrastructure. |
99 |
|
100 |
before '*' => run { |
101 |
my $url = Jifty->web->request->path; |
102 |
|
103 |
warn "hmmm.... url = $url\n"; |
104 |
|
105 |
return if ($url eq '/' || $url eq '/login' || $url =~ m#^/__jifty/#); |
106 |
|
107 |
Jifty->api->allow(qr/^Jifty::Action::Devel/) |
108 |
if Jifty->config->framework('DevelMode'); |
109 |
|
110 |
if (not Jifty->web->current_user->id) { |
111 |
warn "send user accessing $url to login form\n"; |
112 |
Jifty->web->tangent( url => '/login' ); |
113 |
} |
114 |
}; |
115 |
|
116 |
on qr'^/__jifty/edit/(.*?)/(.*)$', run { |
117 |
my $editor = Jifty->web->new_action( |
118 |
class => 'Jifty::Action::Devel::FileEditor', |
119 |
moniker => 'editpage', |
120 |
arguments => { |
121 |
source_path => $2, |
122 |
file_type => $1, |
123 |
} |
124 |
); |
125 |
|
126 |
set editor => $editor; |
127 |
show '/__jifty/edit_file'; |
128 |
}; |
129 |
|
130 |
1; |