/[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 244 - (hide annotations)
Wed Oct 1 21:05:00 2008 UTC (15 years, 7 months ago) by dpavlin
File size: 12397 byte(s)
- include hits and editrs on /strix/instances
- added conf.php and stats instance mismatch on /strix/errors

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

  ViewVC Help
Powered by ViewVC 1.1.26