/[transports]/trunk/lib/Transports/Dispatcher.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/Transports/Dispatcher.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26