/[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

Contents of /lib/A3C/View/Strix.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 244 - (show annotations)
Wed Oct 1 21:05:00 2008 UTC (13 years, 3 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 package A3C::View::Strix;
2
3 =head1 NAME
4
5 A3C::View::Strix
6
7 =head1 DESCRIPTION
8
9 Display information about Strix instances
10
11 =head1 TEMPLATES
12
13 =cut
14
15 use strict;
16 use warnings;
17
18 use Jifty::View::Declare -base;
19 use Data::Dump qw/dump/;
20
21 =head2 /
22
23 Display instaces search and some stats
24
25 =cut
26
27 template 'index.html' => page {
28
29 title is _('Strix instances');
30
31 my $orgs = A3C::Model::StrixInstanceCollection->new;
32 $orgs->unlimit;
33
34 div { _('Number of instances in Strix: %1', $orgs->count ) };
35
36 render_region(
37 name => 'selected-instances',
38 path => '/strix/selected-instances'
39 );
40
41 render_region(
42 name => 'search-instances',
43 path => '/strix/search-instances',
44 );
45
46 };
47
48 =head2 errors
49
50 =cut
51
52 template 'errors' => page {
53
54 title is _('Strix errors');
55
56 render_region(
57 name => 'selected-instances',
58 path => '/strix/selected-instances'
59 );
60
61 h2 { _('Name differences') }
62
63 my $diff = A3C::SQL->new({ query => qq{
64 select
65 instance,hreduorgurl,
66 _site_name,o
67 from strix_instances
68 join hr_edu_orgs on cn = instance
69 where o != _site_name
70 }});
71
72 if ( $diff->count > 0 ) {
73
74 div { { class is 'note' } _("Found %1 instances with name in configuration different from name in LDAP", $diff->count) }
75
76 table {
77 row {
78 th {}
79 th { _('Instance') }
80 th { _('Strix instance name') }
81 th { _('hrEduOrg.o') }
82 };
83 while ( my $row = $diff->next ) {
84 row {
85 cell { show( 'instance-op', 'Create', '+', $row->instance ) }
86 cell { $row->instance }
87 cell { $row->_site_name }
88 cell { $row->o }
89 }
90 }
91 }
92
93 } else {
94 div { _("Can't find any instance of strix which has different name than data from LDAP") }
95 }
96
97 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 };
130
131 =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 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 order by l,o
147 }});
148
149 if ( $sql->count > 0 ) {
150
151 div { { class is 'note' } _("Found total of %1 strix instances", $sql->count) }
152
153 table {
154 row {
155 th { _('hrEduOrgUrl') }
156 th { _('o') }
157 th { _('l') }
158 th { _('postalAddress') }
159 th { _('telephoneNumber') }
160 th { _('facsimileTelephoneNumber') }
161 th { _('hits') }
162 th { _('edits') }
163 };
164 while ( my $row = $sql->next ) {
165 row {
166 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 cell { $row->o }
174 cell { $row->l }
175 cell { $row->postalAddress }
176 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 }
181 }
182 }
183
184 } else {
185 div { _("Can't find any strix instances") }
186 }
187
188 };
189
190 =head2 sql
191
192 Execute SQL query on instance
193
194 =cut
195
196 template 'sql' => page {
197
198 title is _('Execute SQL');
199
200 render_region(
201 name => 'selected-instances',
202 path => '/strix/selected-instances'
203 );
204
205 render_region(
206 name => 'execute-sql',
207 path => '/strix/execute-sql',
208 );
209
210 };
211
212 sub strix {
213 my $instance = get('instance');
214 return Strix->new({ instance => $instance });
215 }
216
217 sub strix_link {
218 my ( $url, $label ) = @_;
219 hyperlink(
220 url => 'http://' . get('instance') . Jifty->config->app('strix')->{domain} . $url,
221 label => $label || $url,
222 target => 'strix',
223 );
224 }
225
226 =head2 navigation
227
228 =cut
229
230 template 'navigation' => page {
231
232 title is _('Site navigation');
233
234 render_region(
235 name => 'selected-instances',
236 path => '/strix/selected-instances'
237 );
238
239 render_region(
240 name => 'strix-site',
241 path => '/strix/site'
242 );
243
244 };
245
246 =head1 REGIONS
247
248 =head2 execute-sql
249
250 Execute SQL query on instance
251
252 =cut
253
254 template 'execute-sql' => sub {
255
256 my $sql = get('sql') || Jifty->web->session->get('sql');
257 warn ">>>> sql = $sql";
258 my $instance = get('instance');
259 warn ">>>> instance = $instance";
260
261 my $action = new_action(
262 class => 'StrixSQL',
263 moniker => 'strix-sql',
264 sticky_on_success => 1,
265 sticky_on_failure => 1,
266 arguments => {
267 instance => $instance,
268 sql => $sql,
269 },
270 );
271
272 form {
273 render_action( $action, [ 'instance', 'sql' ] );
274 form_submit( label => _('Execute SQL') );
275 };
276
277 if ( my $sql = $action->result->content('sql') ) {
278 Jifty->web->session->set( sql => $sql->query );
279 div { _('Found %1 results for %2', $sql->count, $instance ) }
280 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 warn ">>>> sql (at end) = ",Jifty->web->session->get('sql');
292 };
293
294 =head2 search-instances
295
296 =cut
297
298 template 'search-instances' => sub {
299
300 h1 { _('Find instance') }
301
302 my $action = new_action(
303 class => 'SearchStrixInstance',
304 moniker => 'search-strix-instance',
305 sticky_on_success => 1,
306 sticky_on_failure => 1,
307 );
308
309
310 form {
311 render_action( $action => [ 'instance_contains', '_site_name_contains' ] );
312 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 cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
323 cell { tt { $strix->instance } }
324 cell { $strix->_site_name }
325 }
326 }
327 }
328 }
329
330 };
331
332 =head2 selected-instances
333
334 Show Selected instances for current user
335
336 =cut
337
338 template 'selected-instances' => sub {
339 my $self = shift;
340
341 # warn "## IN selected-instances ",dump( @_ );
342
343 if ( my $op = get 'op' ) {
344 my $op_instance = get 'op_instance';
345 return unless $op_instance;
346 warn "# selected-instances $op on $op_instance";
347
348 my $a;
349
350 if ( $op eq 'Create' ) {
351
352 $a = new_action(
353 class => $op . 'StrixInstanceSelection',
354 moniker => $op,
355 arguments => {
356 instance => $op_instance,
357 by_user => $self->current_user->id,
358 },
359 );
360
361 } elsif ( $op eq 'Delete' ) {
362
363 my $strix = A3C::Model::StrixInstanceSelection->new;
364 $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 $a = $strix->as_delete_action;
367
368 }
369 # warn "# argument_values = ",dump( $a->argument_values );
370 $a->run;
371
372 if ( $a->result->error ) {
373 div {
374 { class is 'note error' }
375 $a->result->error;
376 }
377 }
378
379 set( op => '' );
380 }
381
382 my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
383 $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
384
385 if ( $selected->count > 0 ) {
386
387 my $instance = get('instance');
388 warn "# selected-instances -- selected: $instance\n";
389
390 div { _('%1 instances selected', $selected->count ) };
391 table {
392 while (my $s = $selected->next) {
393 row {
394 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 } }
404 cell { $s->instance->_site_name }
405 cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) }
406 }
407 }
408 }
409 } else {
410 div { _('No instances selected') }
411 }
412 };
413
414 =head2 instance-op
415
416 Display button to add/remove instance from selection
417
418 show( 'instance-op', 'Delete', '-', $strix->instace );
419
420 =cut
421
422 template 'instance-op' => sub {
423 my $self = shift;
424
425 # warn "# instance-op = ",dump( @_ );
426
427 my ( $op, $label, $instance ) = @_;
428
429 form {
430 hyperlink(
431 label => $label,
432 onclick => {
433 refresh => 'selected-instances',
434 path => '/strix/selected-instances',
435 args => {
436 op_instance => $instance,
437 op => $op,
438 }
439 },
440 );
441 }
442
443 };
444
445 =head2 site
446
447 =cut
448
449 template 'site' => sub {
450
451 my $action = new_action(
452 class => 'StrixSelectSite',
453 moniker => 'strix-select-site',
454 );
455
456 warn "# action = ", dump( $action );
457
458 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 } },
472 { refresh => 'strix-site-layout', path => '/__jifty/empty' },
473 ];
474
475 form {
476 render_param( $action, 'instance', onchange => $magic );
477 render_param( $action, 'site_id', onchange => $magic );
478 form_submit( label => _('Show navigation'), onclick => $magic );
479 };
480
481 warn "## select-site action ",dump( $action->result );
482
483 render_region(
484 name => 'layout',
485 path => '/__jifty/empty',
486 );
487
488 if ( my $site_id = $action->result->content('site_id') ) {
489 show('navigation-tree', $action->result->content('instance'), $site_id);
490 }
491 };
492
493 =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 =head1 PRIVATE TEMPLATES
531
532 =head2 navigation-tree-category
533
534 show('navigation-tree-category',$kat_row);
535
536 =cut
537
538 private template 'navigation-tree-category' => sub {
539 my $self = shift;
540 #warn "## navigation-tree-category",dump( @_ );
541 my $p = shift;
542 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 if ( $p->{type} eq 'category' ) {
555 hyperlink(
556 # url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
557 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 outs_raw('&nbsp;');
570 strix_link( $p->{url}, '>>' );
571 };
572
573 =head2 navigation-tree
574
575 show('navigation-tree',$instance,$site_id);
576
577 =cut
578
579 private template 'navigation-tree' => sub {
580 my $self = shift;
581 my ( $instance, $site_id ) = @_;
582
583 warn "## navigation-tree instance: $instance site_id: $site_id";
584
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 if ( defined( $p->{class} ) ) {
594 { class is $p->{class} };
595 }
596 show( 'navigation-tree-category', $p );
597 children( $p );
598 }
599 }
600 }
601 }
602
603 my $strix = Strix->new({ instance => $instance });
604
605 my $navigation = $strix->site_navigation( $site_id );
606 #warn "## navigation = ",dump( $navigation );
607 if ( $navigation ) {
608 ul {
609 { class is 'navigation' };
610 foreach my $p ( @$navigation ) {
611 li {
612 show( 'navigation-tree-category', $p );
613 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 1;

  ViewVC Help
Powered by ViewVC 1.1.26