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

  ViewVC Help
Powered by ViewVC 1.1.26