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

  ViewVC Help
Powered by ViewVC 1.1.26