/[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 234 - (hide annotations)
Mon Sep 1 18:53:59 2008 UTC (15 years, 7 months ago) by dpavlin
File size: 11051 byte(s)
report strix instance and contact data
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 234 =head2 instances
96    
97     =cut
98    
99     template 'instances' => page {
100    
101     title is _('Strix instances');
102    
103     my $sql = A3C::SQL->new({ query => qq{
104     select
105     hrEduOrgUrl, o, l, postalAddress, telephoneNumber, facsimileTelephoneNumber
106     from strix_instances
107     join hr_edu_orgs on cn = instance
108     order by l,o
109     }});
110    
111     if ( $sql->count > 0 ) {
112    
113     table {
114     row {
115     th { _('hrEduOrgUrl') }
116     th { _('o') }
117     th { _('l') }
118     th { _('postalAddress') }
119     th { _('telephoneNumber') }
120     th { _('facsimileTelephoneNumber') }
121     };
122     while ( my $row = $sql->next ) {
123     row {
124     cell { outs_raw '<a href="' . $row->hrEduOrgUrl . '">' . $row->hrEduOrgUrl . '</a>' }
125     cell { $row->o }
126     cell { $row->l }
127     cell { $row->postalAddress }
128     cell { $row->telephoneNumber }
129     cell { $row->facsimileTelephoneNumber }
130     }
131     }
132     }
133    
134     div { _("Found total of %1 strix instances", $sql->count) }
135    
136     } else {
137     div { _("Can't find any strix instances") }
138     }
139    
140     };
141    
142 dpavlin 161 =head2 sql
143    
144 dpavlin 174 Execute SQL query on instance
145 dpavlin 161
146     =cut
147    
148     template 'sql' => page {
149    
150     title is _('Execute SQL');
151    
152 dpavlin 166 render_region(
153 dpavlin 174 name => 'selected-instances',
154     path => '/strix/selected-instances'
155 dpavlin 166 );
156    
157     render_region(
158     name => 'execute-sql',
159     path => '/strix/execute-sql',
160     );
161    
162     };
163    
164 dpavlin 174 sub strix {
165 dpavlin 186 my $instance = get('instance');
166 dpavlin 174 return Strix->new({ instance => $instance });
167     }
168    
169 dpavlin 187 sub strix_link {
170     my ( $url, $label ) = @_;
171     hyperlink(
172     url => 'http://' . get('instance') . '.cms-qa.skole.hr' . $url,
173     label => $label || $url,
174     target => 'strix',
175     );
176     }
177    
178 dpavlin 211 =head2 navigation
179    
180     =cut
181    
182 dpavlin 205 template 'navigation' => page {
183 dpavlin 172
184 dpavlin 197 title is _('Site navigation');
185 dpavlin 172
186 dpavlin 183 render_region(
187 dpavlin 200 name => 'selected-instances',
188     path => '/strix/selected-instances'
189     );
190    
191     render_region(
192 dpavlin 211 name => 'strix-site',
193     path => '/strix/site'
194 dpavlin 183 );
195    
196 dpavlin 172 };
197    
198 dpavlin 166 =head1 REGIONS
199    
200     =head2 execute-sql
201    
202 dpavlin 174 Execute SQL query on instance
203 dpavlin 166
204     =cut
205    
206     template 'execute-sql' => sub {
207    
208 dpavlin 221 my $sql = get('sql') || Jifty->web->session->get('sql');
209     warn ">>>> sql = $sql";
210     my $instance = get('instance');
211     warn ">>>> instance = $instance";
212    
213 dpavlin 161 my $action = new_action(
214     class => 'StrixSQL',
215     moniker => 'strix-sql',
216     sticky_on_success => 1,
217     sticky_on_failure => 1,
218 dpavlin 166 arguments => {
219 dpavlin 221 instance => $instance,
220     sql => $sql,
221     },
222 dpavlin 161 );
223    
224     form {
225 dpavlin 221 render_action( $action, [ 'instance', 'sql' ] );
226 dpavlin 161 form_submit( label => _('Execute SQL') );
227     };
228    
229     if ( my $sql = $action->result->content('sql') ) {
230 dpavlin 221 Jifty->web->session->set( sql => $sql->query );
231     div { _('Found %1 results for %2', $sql->count, $instance ) }
232 dpavlin 161 table {
233     row { map { th { $_ } } $sql->_column_names };
234     while (my $row = $sql->next) {
235     row {
236     foreach my $col ( $sql->_column_names ) {
237     cell { $row->$col }
238     }
239     }
240     }
241     }
242     }
243 dpavlin 221 warn ">>>> sql (at end) = ",Jifty->web->session->get('sql');
244 dpavlin 161 };
245    
246 dpavlin 174 =head2 search-instances
247 dpavlin 157
248     =cut
249    
250 dpavlin 174 template 'search-instances' => sub {
251 dpavlin 157
252 dpavlin 174 h1 { _('Find instance') }
253 dpavlin 157
254     my $action = new_action(
255 dpavlin 174 class => 'SearchStrixInstance',
256     moniker => 'search-strix-instance',
257 dpavlin 157 sticky_on_success => 1,
258     sticky_on_failure => 1,
259     );
260    
261    
262     form {
263 dpavlin 174 render_action( $action => [ 'instance_contains', '_site_name_contains' ] );
264 dpavlin 157 form_submit( label => _('Search') );
265     };
266    
267     # warn dump( $action->result->content );
268    
269     if ( my $search = $action->result->content('search') ) {
270     div { _('Found %1 results', $search->count ) }
271     table {
272     while (my $strix = $search->next) {
273     row {
274 dpavlin 189 cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
275 dpavlin 174 cell { tt { $strix->instance } }
276 dpavlin 157 cell { $strix->_site_name }
277     }
278     }
279     }
280     }
281    
282     };
283    
284 dpavlin 174 =head2 selected-instances
285 dpavlin 157
286 dpavlin 174 Show Selected instances for current user
287 dpavlin 157
288     =cut
289    
290 dpavlin 174 template 'selected-instances' => sub {
291 dpavlin 157 my $self = shift;
292    
293 dpavlin 186 # warn "## IN selected-instances ",dump( @_ );
294 dpavlin 157
295     if ( my $op = get 'op' ) {
296 dpavlin 211 my $op_instance = get 'op_instance';
297     return unless $op_instance;
298 dpavlin 186 warn "# selected-instances $op on $op_instance";
299 dpavlin 157
300     my $a;
301    
302     if ( $op eq 'Create' ) {
303    
304     $a = new_action(
305 dpavlin 174 class => $op . 'StrixInstanceSelection',
306 dpavlin 157 moniker => $op,
307     arguments => {
308 dpavlin 186 instance => $op_instance,
309 dpavlin 157 by_user => $self->current_user->id,
310     },
311     );
312    
313     } elsif ( $op eq 'Delete' ) {
314    
315 dpavlin 174 my $strix = A3C::Model::StrixInstanceSelection->new;
316 dpavlin 186 $strix->load_by_cols( instance => $op_instance, by_user => $self->current_user->id );
317     warn "can't find instance $op_instance" unless $strix->id;
318 dpavlin 157 $a = $strix->as_delete_action;
319    
320     }
321 dpavlin 186 # warn "# argument_values = ",dump( $a->argument_values );
322 dpavlin 157 $a->run;
323 dpavlin 186
324     if ( $a->result->error ) {
325     div {
326     { class is 'note error' }
327     $a->result->error;
328     }
329     }
330    
331     set( op => '' );
332 dpavlin 157 }
333    
334 dpavlin 174 my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
335 dpavlin 157 $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
336    
337     if ( $selected->count > 0 ) {
338    
339 dpavlin 186 my $instance = get('instance');
340 dpavlin 200 warn "# selected-instances -- selected: $instance\n";
341 dpavlin 186
342 dpavlin 183 div { _('%1 instances selected', $selected->count ) };
343 dpavlin 157 table {
344     while (my $s = $selected->next) {
345     row {
346 dpavlin 186 cell { tt {
347     if ( $s->instance->instance eq $instance ) {
348     b { $instance }
349     } else {
350     hyperlink(
351     url => '?instance=' . $s->instance->instance,
352     label => $s->instance->instance
353     )
354     }
355 dpavlin 183 } }
356     cell { $s->instance->_site_name }
357     cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) }
358 dpavlin 157 }
359     }
360     }
361     } else {
362 dpavlin 174 div { _('No instances selected') }
363 dpavlin 157 }
364     };
365    
366 dpavlin 174 =head2 instance-op
367 dpavlin 157
368 dpavlin 174 Display button to add/remove instance from selection
369 dpavlin 157
370 dpavlin 174 show( 'instance-op', 'Delete', '-', $strix->instace );
371 dpavlin 157
372     =cut
373    
374 dpavlin 174 template 'instance-op' => sub {
375 dpavlin 157 my $self = shift;
376    
377 dpavlin 186 # warn "# instance-op = ",dump( @_ );
378 dpavlin 157
379 dpavlin 174 my ( $op, $label, $instance ) = @_;
380 dpavlin 157
381     form {
382     hyperlink(
383     label => $label,
384     onclick => {
385 dpavlin 174 refresh => 'selected-instances',
386     path => '/strix/selected-instances',
387 dpavlin 157 args => {
388 dpavlin 186 op_instance => $instance,
389 dpavlin 157 op => $op,
390     }
391     },
392     );
393     }
394    
395     };
396    
397 dpavlin 211 =head2 site
398 dpavlin 157
399 dpavlin 197 =cut
400    
401 dpavlin 211 template 'site' => sub {
402 dpavlin 197
403     my $action = new_action(
404     class => 'StrixSelectSite',
405     moniker => 'strix-select-site',
406     );
407    
408 dpavlin 200 warn "# action = ", dump( $action );
409 dpavlin 197
410 dpavlin 200 warn "# argument_values = ", dump( $action->argument_values );
411    
412     if ( ! $action->argument_value('instance') ) {
413     $action->argument_value( 'instance', get('instance') );
414     warn "# run action with instance\n";
415     $action->run;
416     }
417    
418     my $magic = [
419     { submit => $action, refresh_self => 1 },
420     # this is basically a closure
421     { refresh => 'selected-instances', path => '/strix/selected-instances', args => {
422     instance => { result_of => $action, name => 'instance' }
423 dpavlin 211 } },
424     { refresh => 'strix-site-layout', path => '/__jifty/empty' },
425 dpavlin 200 ];
426    
427 dpavlin 197 form {
428 dpavlin 200 render_param( $action, 'instance', onchange => $magic );
429     render_param( $action, 'site_id', onchange => $magic );
430     form_submit( label => _('Show navigation'), onclick => $magic );
431 dpavlin 197 };
432    
433     warn "## select-site action ",dump( $action->result );
434    
435 dpavlin 211 render_region(
436     name => 'layout',
437     path => '/__jifty/empty',
438     );
439    
440 dpavlin 197 if ( my $site_id = $action->result->content('site_id') ) {
441 dpavlin 214 show('navigation-tree', $action->result->content('instance'), $site_id);
442 dpavlin 197 }
443     };
444    
445 dpavlin 217 =head2 layout
446    
447     Shows layout for C<url>
448    
449     =cut
450    
451     template 'layout' => sub {
452    
453     my $url = get('url') || '/';
454     my $category = strix->category( $url );
455     my $layout = strix->layout( $url );
456    
457     h1 { $category->{naziv} }
458     pre {
459     dump( $layout );
460     }
461    
462     };
463    
464     =head2 category
465    
466     Show category data for C<url>
467    
468     =cut
469    
470     template 'category' => sub {
471    
472     my $url = get('url') || '/';
473     my $category = strix->category( $url );
474    
475     h1 { $category->{naziv} }
476     pre {
477     dump( $category );
478     }
479    
480     };
481    
482 dpavlin 197 =head1 PRIVATE TEMPLATES
483    
484 dpavlin 214 =head2 navigation-tree-category
485 dpavlin 197
486 dpavlin 214 show('navigation-tree-category',$kat_row);
487 dpavlin 197
488     =cut
489    
490 dpavlin 214 private template 'navigation-tree-category' => sub {
491 dpavlin 211 my $self = shift;
492 dpavlin 214 #warn "## navigation-tree-category",dump( @_ );
493 dpavlin 211 my $p = shift;
494 dpavlin 217 hyperlink(
495     onclick => {
496     region => 'strix-site-layout', # FIXME do we have to hard-code region name here?
497     replace_with => '/strix/category',
498     args => {
499     url => $p->{url},
500     instance => get('instance'),
501     }
502     },
503     label => $p->{naziv},
504     );
505     outs_raw('&nbsp;');
506 dpavlin 211 if ( $p->{type} eq 'category' ) {
507     hyperlink(
508 dpavlin 217 # url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
509 dpavlin 211 onclick => {
510     region => 'strix-site-layout', # FIXME do we have to hard-code region name here?
511     replace_with => '/strix/layout',
512     args => {
513     url => $p->{url},
514     instance => get('instance'),
515     }
516     },
517     label => _('layout'),
518     class => 'layout',
519     );
520     }
521 dpavlin 217 outs_raw('&nbsp;');
522     strix_link( $p->{url}, '>>' );
523 dpavlin 211 };
524    
525 dpavlin 214 =head2 navigation-tree
526    
527     show('navigation-tree',$instance,$site_id);
528    
529     =cut
530    
531     private template 'navigation-tree' => sub {
532 dpavlin 197 my $self = shift;
533     my ( $instance, $site_id ) = @_;
534    
535 dpavlin 217 warn "## navigation-tree instance: $instance site_id: $site_id";
536 dpavlin 197
537     set 'instance' => $instance;
538    
539     sub children {
540     my $c = shift;
541     return unless defined $c->{children};
542     ul {
543     foreach my $p ( @{ $c->{children} } ) {
544     li {
545 dpavlin 212 if ( defined( $p->{class} ) ) {
546     { class is $p->{class} };
547     }
548 dpavlin 214 show( 'navigation-tree-category', $p );
549 dpavlin 197 children( $p );
550     }
551     }
552     }
553     }
554    
555     my $strix = Strix->new({ instance => $instance });
556    
557 dpavlin 214 my $navigation = $strix->site_navigation( $site_id );
558     #warn "## navigation = ",dump( $navigation );
559     if ( $navigation ) {
560 dpavlin 197 ul {
561 dpavlin 217 { class is 'navigation' };
562 dpavlin 214 foreach my $p ( @$navigation ) {
563 dpavlin 197 li {
564 dpavlin 214 show( 'navigation-tree-category', $p );
565 dpavlin 197 children( $p );
566     }
567     }
568     }
569     } else {
570     div {
571     { class is 'note error' }
572     _('No navigation found for instance %1 site_id %2', $instance, $site_id)
573     }
574    
575     }
576    
577     };
578    
579 dpavlin 142 1;

  ViewVC Help
Powered by ViewVC 1.1.26