/[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 234 - (show 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 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 name_diff
49
50 =cut
51
52 template 'name_diff' => page {
53
54 title is _('Strix name differences');
55
56 render_region(
57 name => 'selected-instances',
58 path => '/strix/selected-instances'
59 );
60
61 my $name_diff = A3C::SQL->new({ query => qq{
62 select
63 instance,hreduorgurl,
64 _site_name,o
65 from strix_instances
66 join hr_edu_orgs on cn = instance
67 where o != _site_name
68 }});
69
70 if ( $name_diff->count > 0 ) {
71
72 table {
73 row {
74 th {}
75 th { _('Instance') }
76 th { _('Strix instance name') }
77 th { _('hrEduOrg.o') }
78 };
79 while ( my $row = $name_diff->next ) {
80 row {
81 cell { show( 'instance-op', 'Create', '+', $row->instance ) }
82 cell { $row->instance }
83 cell { $row->_site_name }
84 cell { $row->o }
85 }
86 }
87 }
88
89 } else {
90 div { _("Can't find any instance of strix which has different name than data from LDAP") }
91 }
92
93 };
94
95 =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 =head2 sql
143
144 Execute SQL query on instance
145
146 =cut
147
148 template 'sql' => page {
149
150 title is _('Execute SQL');
151
152 render_region(
153 name => 'selected-instances',
154 path => '/strix/selected-instances'
155 );
156
157 render_region(
158 name => 'execute-sql',
159 path => '/strix/execute-sql',
160 );
161
162 };
163
164 sub strix {
165 my $instance = get('instance');
166 return Strix->new({ instance => $instance });
167 }
168
169 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 =head2 navigation
179
180 =cut
181
182 template 'navigation' => page {
183
184 title is _('Site navigation');
185
186 render_region(
187 name => 'selected-instances',
188 path => '/strix/selected-instances'
189 );
190
191 render_region(
192 name => 'strix-site',
193 path => '/strix/site'
194 );
195
196 };
197
198 =head1 REGIONS
199
200 =head2 execute-sql
201
202 Execute SQL query on instance
203
204 =cut
205
206 template 'execute-sql' => sub {
207
208 my $sql = get('sql') || Jifty->web->session->get('sql');
209 warn ">>>> sql = $sql";
210 my $instance = get('instance');
211 warn ">>>> instance = $instance";
212
213 my $action = new_action(
214 class => 'StrixSQL',
215 moniker => 'strix-sql',
216 sticky_on_success => 1,
217 sticky_on_failure => 1,
218 arguments => {
219 instance => $instance,
220 sql => $sql,
221 },
222 );
223
224 form {
225 render_action( $action, [ 'instance', 'sql' ] );
226 form_submit( label => _('Execute SQL') );
227 };
228
229 if ( my $sql = $action->result->content('sql') ) {
230 Jifty->web->session->set( sql => $sql->query );
231 div { _('Found %1 results for %2', $sql->count, $instance ) }
232 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 warn ">>>> sql (at end) = ",Jifty->web->session->get('sql');
244 };
245
246 =head2 search-instances
247
248 =cut
249
250 template 'search-instances' => sub {
251
252 h1 { _('Find instance') }
253
254 my $action = new_action(
255 class => 'SearchStrixInstance',
256 moniker => 'search-strix-instance',
257 sticky_on_success => 1,
258 sticky_on_failure => 1,
259 );
260
261
262 form {
263 render_action( $action => [ 'instance_contains', '_site_name_contains' ] );
264 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 cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
275 cell { tt { $strix->instance } }
276 cell { $strix->_site_name }
277 }
278 }
279 }
280 }
281
282 };
283
284 =head2 selected-instances
285
286 Show Selected instances for current user
287
288 =cut
289
290 template 'selected-instances' => sub {
291 my $self = shift;
292
293 # warn "## IN selected-instances ",dump( @_ );
294
295 if ( my $op = get 'op' ) {
296 my $op_instance = get 'op_instance';
297 return unless $op_instance;
298 warn "# selected-instances $op on $op_instance";
299
300 my $a;
301
302 if ( $op eq 'Create' ) {
303
304 $a = new_action(
305 class => $op . 'StrixInstanceSelection',
306 moniker => $op,
307 arguments => {
308 instance => $op_instance,
309 by_user => $self->current_user->id,
310 },
311 );
312
313 } elsif ( $op eq 'Delete' ) {
314
315 my $strix = A3C::Model::StrixInstanceSelection->new;
316 $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 $a = $strix->as_delete_action;
319
320 }
321 # warn "# argument_values = ",dump( $a->argument_values );
322 $a->run;
323
324 if ( $a->result->error ) {
325 div {
326 { class is 'note error' }
327 $a->result->error;
328 }
329 }
330
331 set( op => '' );
332 }
333
334 my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
335 $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
336
337 if ( $selected->count > 0 ) {
338
339 my $instance = get('instance');
340 warn "# selected-instances -- selected: $instance\n";
341
342 div { _('%1 instances selected', $selected->count ) };
343 table {
344 while (my $s = $selected->next) {
345 row {
346 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 } }
356 cell { $s->instance->_site_name }
357 cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) }
358 }
359 }
360 }
361 } else {
362 div { _('No instances selected') }
363 }
364 };
365
366 =head2 instance-op
367
368 Display button to add/remove instance from selection
369
370 show( 'instance-op', 'Delete', '-', $strix->instace );
371
372 =cut
373
374 template 'instance-op' => sub {
375 my $self = shift;
376
377 # warn "# instance-op = ",dump( @_ );
378
379 my ( $op, $label, $instance ) = @_;
380
381 form {
382 hyperlink(
383 label => $label,
384 onclick => {
385 refresh => 'selected-instances',
386 path => '/strix/selected-instances',
387 args => {
388 op_instance => $instance,
389 op => $op,
390 }
391 },
392 );
393 }
394
395 };
396
397 =head2 site
398
399 =cut
400
401 template 'site' => sub {
402
403 my $action = new_action(
404 class => 'StrixSelectSite',
405 moniker => 'strix-select-site',
406 );
407
408 warn "# action = ", dump( $action );
409
410 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 } },
424 { refresh => 'strix-site-layout', path => '/__jifty/empty' },
425 ];
426
427 form {
428 render_param( $action, 'instance', onchange => $magic );
429 render_param( $action, 'site_id', onchange => $magic );
430 form_submit( label => _('Show navigation'), onclick => $magic );
431 };
432
433 warn "## select-site action ",dump( $action->result );
434
435 render_region(
436 name => 'layout',
437 path => '/__jifty/empty',
438 );
439
440 if ( my $site_id = $action->result->content('site_id') ) {
441 show('navigation-tree', $action->result->content('instance'), $site_id);
442 }
443 };
444
445 =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 =head1 PRIVATE TEMPLATES
483
484 =head2 navigation-tree-category
485
486 show('navigation-tree-category',$kat_row);
487
488 =cut
489
490 private template 'navigation-tree-category' => sub {
491 my $self = shift;
492 #warn "## navigation-tree-category",dump( @_ );
493 my $p = shift;
494 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 if ( $p->{type} eq 'category' ) {
507 hyperlink(
508 # url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
509 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 outs_raw('&nbsp;');
522 strix_link( $p->{url}, '>>' );
523 };
524
525 =head2 navigation-tree
526
527 show('navigation-tree',$instance,$site_id);
528
529 =cut
530
531 private template 'navigation-tree' => sub {
532 my $self = shift;
533 my ( $instance, $site_id ) = @_;
534
535 warn "## navigation-tree instance: $instance site_id: $site_id";
536
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 if ( defined( $p->{class} ) ) {
546 { class is $p->{class} };
547 }
548 show( 'navigation-tree-category', $p );
549 children( $p );
550 }
551 }
552 }
553 }
554
555 my $strix = Strix->new({ instance => $instance });
556
557 my $navigation = $strix->site_navigation( $site_id );
558 #warn "## navigation = ",dump( $navigation );
559 if ( $navigation ) {
560 ul {
561 { class is 'navigation' };
562 foreach my $p ( @$navigation ) {
563 li {
564 show( 'navigation-tree-category', $p );
565 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 1;

  ViewVC Help
Powered by ViewVC 1.1.26