/[A3C]/lib/A3C/View/Strix.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 /lib/A3C/View/Strix.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 200 - (hide annotations)
Tue Jun 17 23:06:31 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 8880 byte(s)
- run action if there isn't instance to populate bottom menu correctly
- refresh selected-instances with result of action (example of action closure usage)
1 dpavlin 142 package A3C::View::Strix;
2    
3     =head1 NAME
4    
5     A3C::View::Strix
6    
7     =head1 DESCRIPTION
8    
9 dpavlin 174 Display information about Strix instances
10 dpavlin 142
11 dpavlin 157 =head1 TEMPLATES
12    
13 dpavlin 142 =cut
14    
15     use strict;
16     use warnings;
17    
18     use Jifty::View::Declare -base;
19     use Data::Dump qw/dump/;
20    
21 dpavlin 157 =head2 /
22    
23 dpavlin 174 Display instaces search and some stats
24 dpavlin 157
25     =cut
26    
27 dpavlin 142 template 'index.html' => page {
28    
29 dpavlin 174 title is _('Strix instances');
30 dpavlin 153
31 dpavlin 174 my $orgs = A3C::Model::StrixInstanceCollection->new;
32 dpavlin 166 $orgs->unlimit;
33    
34 dpavlin 174 div { _('Number of instances in Strix: %1', $orgs->count ) };
35 dpavlin 166
36 dpavlin 157 render_region(
37 dpavlin 174 name => 'selected-instances',
38     path => '/strix/selected-instances'
39 dpavlin 157 );
40    
41     render_region(
42 dpavlin 174 name => 'search-instances',
43     path => '/strix/search-instances',
44 dpavlin 157 );
45    
46 dpavlin 153 };
47    
48 dpavlin 157 =head2 name_diff
49    
50     =cut
51    
52 dpavlin 153 template 'name_diff' => page {
53    
54 dpavlin 166 title is _('Strix name differences');
55 dpavlin 153
56 dpavlin 183 render_region(
57     name => 'selected-instances',
58     path => '/strix/selected-instances'
59     );
60    
61 dpavlin 142 my $name_diff = A3C::SQL->new({ query => qq{
62     select
63 dpavlin 174 instance,hreduorgurl,
64 dpavlin 142 _site_name,o
65 dpavlin 174 from strix_instances
66     join hr_edu_orgs on cn = instance
67 dpavlin 142 where o != _site_name
68     }});
69    
70 dpavlin 166 if ( $name_diff->count > 0 ) {
71    
72 dpavlin 142 table {
73     row {
74 dpavlin 183 th {}
75 dpavlin 174 th { _('Instance') }
76     th { _('Strix instance name') }
77 dpavlin 142 th { _('hrEduOrg.o') }
78     };
79     while ( my $row = $name_diff->next ) {
80     row {
81 dpavlin 183 cell { show( 'instance-op', 'Create', '+', $row->instance ) }
82     cell { $row->instance }
83 dpavlin 142 cell { $row->_site_name }
84     cell { $row->o }
85     }
86     }
87     }
88 dpavlin 166
89     } else {
90 dpavlin 174 div { _("Can't find any instance of strix which has different name than data from LDAP") }
91 dpavlin 142 }
92    
93     };
94    
95 dpavlin 161 =head2 sql
96    
97 dpavlin 174 Execute SQL query on instance
98 dpavlin 161
99     =cut
100    
101     template 'sql' => page {
102    
103     title is _('Execute SQL');
104    
105 dpavlin 166 render_region(
106 dpavlin 174 name => 'selected-instances',
107     path => '/strix/selected-instances'
108 dpavlin 166 );
109    
110     render_region(
111     name => 'execute-sql',
112     path => '/strix/execute-sql',
113     );
114    
115     };
116    
117 dpavlin 174 sub strix {
118 dpavlin 186 my $instance = get('instance');
119 dpavlin 174 return Strix->new({ instance => $instance });
120     }
121    
122 dpavlin 197 =head2 site-navigation
123 dpavlin 172
124     =cut
125    
126 dpavlin 187 sub strix_link {
127     my ( $url, $label ) = @_;
128     hyperlink(
129     url => 'http://' . get('instance') . '.cms-qa.skole.hr' . $url,
130     label => $label || $url,
131     target => 'strix',
132     );
133     }
134    
135 dpavlin 197 template 'site-navigation' => page {
136 dpavlin 172
137 dpavlin 197 title is _('Site navigation');
138 dpavlin 172
139 dpavlin 183 render_region(
140 dpavlin 200 name => 'selected-instances',
141     path => '/strix/selected-instances'
142     );
143    
144     render_region(
145 dpavlin 197 name => 'select-strix-site',
146     path => '/strix/select-site'
147 dpavlin 183 );
148    
149 dpavlin 172 };
150    
151 dpavlin 174 =head2 layout
152    
153     =cut
154    
155     template 'layout' => page {
156    
157     my $url = get('url') || '/';
158    
159     my $category = strix->category( $url );
160    
161     warn dump( $category );
162    
163     title is _('Layout %1 : %2',
164     $category->{sitename},
165     $category->{naziv},
166     );
167    
168 dpavlin 186 render_region(
169     name => 'selected-instances',
170     path => '/strix/selected-instances'
171     );
172    
173 dpavlin 187 strix_link( $category->{url}, $category->{naziv} );
174 dpavlin 174
175     my $layout = strix->layout( $url );
176    
177     pre {
178     dump( $layout );
179     }
180    
181     };
182    
183 dpavlin 166 =head1 REGIONS
184    
185     =head2 execute-sql
186    
187 dpavlin 174 Execute SQL query on instance
188 dpavlin 166
189     =cut
190    
191     template 'execute-sql' => sub {
192    
193 dpavlin 161 my $action = new_action(
194     class => 'StrixSQL',
195     moniker => 'strix-sql',
196     sticky_on_success => 1,
197     sticky_on_failure => 1,
198 dpavlin 166 arguments => {
199 dpavlin 183 instance => get('instance')
200 dpavlin 166 }
201 dpavlin 161 );
202    
203     form {
204 dpavlin 183 render_action( $action => [ 'instance', 'sql' ] );
205 dpavlin 161 form_submit( label => _('Execute SQL') );
206     };
207    
208     if ( my $sql = $action->result->content('sql') ) {
209     div { _('Found %1 results', $sql->count ) }
210     table {
211     row { map { th { $_ } } $sql->_column_names };
212     while (my $row = $sql->next) {
213     row {
214     foreach my $col ( $sql->_column_names ) {
215     cell { $row->$col }
216     }
217     }
218     }
219     }
220     }
221     };
222    
223 dpavlin 174 =head2 search-instances
224 dpavlin 157
225     =cut
226    
227 dpavlin 174 template 'search-instances' => sub {
228 dpavlin 157
229 dpavlin 174 h1 { _('Find instance') }
230 dpavlin 157
231     my $action = new_action(
232 dpavlin 174 class => 'SearchStrixInstance',
233     moniker => 'search-strix-instance',
234 dpavlin 157 sticky_on_success => 1,
235     sticky_on_failure => 1,
236     );
237    
238    
239     form {
240 dpavlin 174 render_action( $action => [ 'instance_contains', '_site_name_contains' ] );
241 dpavlin 157 form_submit( label => _('Search') );
242     };
243    
244     # warn dump( $action->result->content );
245    
246     if ( my $search = $action->result->content('search') ) {
247     div { _('Found %1 results', $search->count ) }
248     table {
249     while (my $strix = $search->next) {
250     row {
251 dpavlin 189 cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
252 dpavlin 174 cell { tt { $strix->instance } }
253 dpavlin 157 cell { $strix->_site_name }
254     }
255     }
256     }
257     }
258    
259     };
260    
261 dpavlin 174 =head2 selected-instances
262 dpavlin 157
263 dpavlin 174 Show Selected instances for current user
264 dpavlin 157
265     =cut
266    
267 dpavlin 174 template 'selected-instances' => sub {
268 dpavlin 157 my $self = shift;
269    
270 dpavlin 186 # warn "## IN selected-instances ",dump( @_ );
271 dpavlin 157
272     if ( my $op = get 'op' ) {
273 dpavlin 186 my $op_instance = get 'op_instance' or die "no op_instance?";
274     warn "# selected-instances $op on $op_instance";
275 dpavlin 157
276     my $a;
277    
278     if ( $op eq 'Create' ) {
279    
280     $a = new_action(
281 dpavlin 174 class => $op . 'StrixInstanceSelection',
282 dpavlin 157 moniker => $op,
283     arguments => {
284 dpavlin 186 instance => $op_instance,
285 dpavlin 157 by_user => $self->current_user->id,
286     },
287     );
288    
289     } elsif ( $op eq 'Delete' ) {
290    
291 dpavlin 174 my $strix = A3C::Model::StrixInstanceSelection->new;
292 dpavlin 186 $strix->load_by_cols( instance => $op_instance, by_user => $self->current_user->id );
293     warn "can't find instance $op_instance" unless $strix->id;
294 dpavlin 157 $a = $strix->as_delete_action;
295    
296     }
297 dpavlin 186 # warn "# argument_values = ",dump( $a->argument_values );
298 dpavlin 157 $a->run;
299 dpavlin 186
300     if ( $a->result->error ) {
301     div {
302     { class is 'note error' }
303     $a->result->error;
304     }
305     }
306    
307     set( op => '' );
308 dpavlin 157 }
309    
310 dpavlin 174 my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
311 dpavlin 157 $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
312    
313     if ( $selected->count > 0 ) {
314    
315 dpavlin 186 my $instance = get('instance');
316 dpavlin 200 warn "# selected-instances -- selected: $instance\n";
317 dpavlin 186
318 dpavlin 183 div { _('%1 instances selected', $selected->count ) };
319 dpavlin 157 table {
320     while (my $s = $selected->next) {
321     row {
322 dpavlin 186 cell { tt {
323     if ( $s->instance->instance eq $instance ) {
324     b { $instance }
325     } else {
326     hyperlink(
327     url => '?instance=' . $s->instance->instance,
328     label => $s->instance->instance
329     )
330     }
331 dpavlin 183 } }
332     cell { $s->instance->_site_name }
333     cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) }
334 dpavlin 157 }
335     }
336     }
337     } else {
338 dpavlin 174 div { _('No instances selected') }
339 dpavlin 157 }
340     };
341    
342 dpavlin 174 =head2 instance-op
343 dpavlin 157
344 dpavlin 174 Display button to add/remove instance from selection
345 dpavlin 157
346 dpavlin 174 show( 'instance-op', 'Delete', '-', $strix->instace );
347 dpavlin 157
348     =cut
349    
350 dpavlin 174 template 'instance-op' => sub {
351 dpavlin 157 my $self = shift;
352    
353 dpavlin 186 # warn "# instance-op = ",dump( @_ );
354 dpavlin 157
355 dpavlin 174 my ( $op, $label, $instance ) = @_;
356 dpavlin 157
357     form {
358     hyperlink(
359     label => $label,
360     onclick => {
361 dpavlin 174 refresh => 'selected-instances',
362     path => '/strix/selected-instances',
363 dpavlin 157 args => {
364 dpavlin 186 op_instance => $instance,
365 dpavlin 157 op => $op,
366     }
367     },
368     );
369     }
370    
371     };
372    
373 dpavlin 197 =head2 select-site
374 dpavlin 157
375 dpavlin 197 =cut
376    
377     template 'select-site' => sub {
378    
379     my $action = new_action(
380     class => 'StrixSelectSite',
381     moniker => 'strix-select-site',
382     );
383    
384 dpavlin 200 warn "# action = ", dump( $action );
385 dpavlin 197
386 dpavlin 200 warn "# argument_values = ", dump( $action->argument_values );
387    
388     if ( ! $action->argument_value('instance') ) {
389     $action->argument_value( 'instance', get('instance') );
390     warn "# run action with instance\n";
391     $action->run;
392     }
393    
394     my $magic = [
395     { submit => $action, refresh_self => 1 },
396     # this is basically a closure
397     { refresh => 'selected-instances', path => '/strix/selected-instances', args => {
398     instance => { result_of => $action, name => 'instance' }
399     } }
400     ];
401    
402 dpavlin 197 form {
403 dpavlin 200 render_param( $action, 'instance', onchange => $magic );
404     render_param( $action, 'site_id', onchange => $magic );
405     form_submit( label => _('Show navigation'), onclick => $magic );
406 dpavlin 197 };
407    
408     warn "## select-site action ",dump( $action->result );
409    
410     if ( my $site_id = $action->result->content('site_id') ) {
411     show('strix-site-navigation-tree', $action->result->content('instance'), $site_id);
412     }
413     };
414    
415     =head1 PRIVATE TEMPLATES
416    
417     =head2 strix-site-navigation-tree
418    
419     show('strix-site-navigation-tree',$instance,$site_id);
420    
421     =cut
422    
423     private template 'strix-site-navigation-tree' => sub {
424     my $self = shift;
425     my ( $instance, $site_id ) = @_;
426    
427     warn ">>>> instance: $instance site_id: $site_id";
428    
429     set 'instance' => $instance;
430    
431     sub full_url {
432     my $p = shift;
433     strix_link( $p->{url}, $p->{naziv} );
434     if ( $p->{type} eq 'category' ) {
435     outs_raw(' ');
436     hyperlink(
437     url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
438     label => _('layout'),
439     class => 'layout',
440     );
441     }
442     }
443    
444     sub children {
445     my $c = shift;
446     return unless defined $c->{children};
447     ul {
448     foreach my $p ( @{ $c->{children} } ) {
449     li {
450     { class is $p->{class} };
451     full_url( $p );
452     children( $p );
453     }
454     }
455     }
456     }
457    
458     my $strix = Strix->new({ instance => $instance });
459    
460     my @navigation = @{ $strix->site_navigation( $site_id ) };
461     if ( @navigation ) {
462     ul {
463     foreach my $p ( @navigation ) {
464     li {
465     full_url( $p );
466     children( $p );
467     }
468     }
469     }
470     } else {
471     div {
472     { class is 'note error' }
473     _('No navigation found for instance %1 site_id %2', $instance, $site_id)
474     }
475    
476     }
477    
478     };
479    
480 dpavlin 142 1;

  ViewVC Help
Powered by ViewVC 1.1.26