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

  ViewVC Help
Powered by ViewVC 1.1.26