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 |
=head2 sql |
143 |
|
|
144 |
Execute SQL query on instance |
Execute SQL query on instance |
162 |
}; |
}; |
163 |
|
|
164 |
sub strix { |
sub strix { |
165 |
my $instance = get('instance') || shift || 'new'; |
my $instance = get('instance'); |
166 |
return Strix->new({ instance => $instance }); |
return Strix->new({ instance => $instance }); |
167 |
} |
} |
168 |
|
|
169 |
=head2 sitemap |
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 |
=cut |
181 |
|
|
182 |
template 'sitemap' => page { |
template 'navigation' => page { |
183 |
|
|
184 |
title is _('Sitemap'); |
title is _('Site navigation'); |
185 |
|
|
186 |
render_region( |
render_region( |
187 |
name => 'selected-instances', |
name => 'selected-instances', |
188 |
path => '/strix/selected-instances' |
path => '/strix/selected-instances' |
189 |
); |
); |
190 |
|
|
191 |
my $site_id = get('site_id') || 1; |
render_region( |
192 |
|
name => 'strix-site', |
193 |
my $sitemap = strix->site_navigation( $site_id ); |
path => '/strix/site' |
|
|
|
|
sub full_url { |
|
|
my $p = shift; |
|
|
hyperlink( |
|
|
url => 'http://new.cms-qa.skole.hr' . $p->{url}, |
|
|
label => $p->{naziv}, |
|
|
); |
|
|
if ( $p->{type} eq 'category' ) { |
|
|
outs_raw(' '); |
|
|
hyperlink( |
|
|
url => '/strix/layout?url=' . $p->{url}, |
|
|
label => '[layout]', |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
sub children { |
|
|
my $c = shift; |
|
|
return unless defined $c->{children}; |
|
|
ul { |
|
|
foreach my $p ( @{ $c->{children} } ) { |
|
|
li { |
|
|
{ class is $p->{class} }; |
|
|
full_url( $p ); |
|
|
children( $p ); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
ul { |
|
|
foreach my $p ( @$sitemap ) { |
|
|
li { |
|
|
full_url( $p ); |
|
|
children( $p ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
=head2 layout |
|
|
|
|
|
=cut |
|
|
|
|
|
template 'layout' => page { |
|
|
|
|
|
my $url = get('url') || '/'; |
|
|
|
|
|
my $category = strix->category( $url ); |
|
|
|
|
|
warn dump( $category ); |
|
|
|
|
|
title is _('Layout %1 : %2', |
|
|
$category->{sitename}, |
|
|
$category->{naziv}, |
|
|
); |
|
|
|
|
|
hyperlink( |
|
|
url => 'http://' . $category->{sitename} . '/' . $category->{url}, |
|
|
label => $category->{naziv}, |
|
194 |
); |
); |
195 |
|
|
|
my $layout = strix->layout( $url ); |
|
|
|
|
|
pre { |
|
|
dump( $layout ); |
|
|
} |
|
|
|
|
196 |
}; |
}; |
197 |
|
|
198 |
=head1 REGIONS |
=head1 REGIONS |
205 |
|
|
206 |
template 'execute-sql' => sub { |
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( |
my $action = new_action( |
214 |
class => 'StrixSQL', |
class => 'StrixSQL', |
215 |
moniker => 'strix-sql', |
moniker => 'strix-sql', |
216 |
sticky_on_success => 1, |
sticky_on_success => 1, |
217 |
sticky_on_failure => 1, |
sticky_on_failure => 1, |
218 |
arguments => { |
arguments => { |
219 |
instance => get('instance') |
instance => $instance, |
220 |
} |
sql => $sql, |
221 |
|
}, |
222 |
); |
); |
223 |
|
|
224 |
form { |
form { |
225 |
render_action( $action => [ 'instance', 'sql' ] ); |
render_action( $action, [ 'instance', 'sql' ] ); |
226 |
form_submit( label => _('Execute SQL') ); |
form_submit( label => _('Execute SQL') ); |
227 |
}; |
}; |
228 |
|
|
229 |
if ( my $sql = $action->result->content('sql') ) { |
if ( my $sql = $action->result->content('sql') ) { |
230 |
div { _('Found %1 results', $sql->count ) } |
Jifty->web->session->set( sql => $sql->query ); |
231 |
|
div { _('Found %1 results for %2', $sql->count, $instance ) } |
232 |
table { |
table { |
233 |
row { map { th { $_ } } $sql->_column_names }; |
row { map { th { $_ } } $sql->_column_names }; |
234 |
while (my $row = $sql->next) { |
while (my $row = $sql->next) { |
240 |
} |
} |
241 |
} |
} |
242 |
} |
} |
243 |
|
warn ">>>> sql (at end) = ",Jifty->web->session->get('sql'); |
244 |
}; |
}; |
245 |
|
|
246 |
=head2 search-instances |
=head2 search-instances |
271 |
table { |
table { |
272 |
while (my $strix = $search->next) { |
while (my $strix = $search->next) { |
273 |
row { |
row { |
274 |
|
cell { show( 'instance-op', 'Create', '+', $strix->instance ) } |
275 |
cell { tt { $strix->instance } } |
cell { tt { $strix->instance } } |
276 |
cell { $strix->_site_name } |
cell { $strix->_site_name } |
|
cell { show( 'instance-op', 'Create', '+', $strix->instance ) } |
|
277 |
} |
} |
278 |
} |
} |
279 |
} |
} |
290 |
template 'selected-instances' => sub { |
template 'selected-instances' => sub { |
291 |
my $self = shift; |
my $self = shift; |
292 |
|
|
293 |
warn "## IN selected-instances ",dump( @_ ); |
# warn "## IN selected-instances ",dump( @_ ); |
294 |
|
|
295 |
if ( my $op = get 'op' ) { |
if ( my $op = get 'op' ) { |
296 |
my $instance = get 'instance' or die "no instance?"; |
my $op_instance = get 'op_instance'; |
297 |
warn "# selected-instances $op on $instance"; |
return unless $op_instance; |
298 |
|
warn "# selected-instances $op on $op_instance"; |
299 |
|
|
300 |
my $a; |
my $a; |
301 |
|
|
305 |
class => $op . 'StrixInstanceSelection', |
class => $op . 'StrixInstanceSelection', |
306 |
moniker => $op, |
moniker => $op, |
307 |
arguments => { |
arguments => { |
308 |
instance => $instance, |
instance => $op_instance, |
309 |
by_user => $self->current_user->id, |
by_user => $self->current_user->id, |
310 |
}, |
}, |
311 |
); |
); |
313 |
} elsif ( $op eq 'Delete' ) { |
} elsif ( $op eq 'Delete' ) { |
314 |
|
|
315 |
my $strix = A3C::Model::StrixInstanceSelection->new; |
my $strix = A3C::Model::StrixInstanceSelection->new; |
316 |
$strix->load_by_cols( instance => $instance, by_user => $self->current_user->id ); |
$strix->load_by_cols( instance => $op_instance, by_user => $self->current_user->id ); |
317 |
die "can't find instance $instance" unless $strix->id; |
warn "can't find instance $op_instance" unless $strix->id; |
318 |
$a = $strix->as_delete_action; |
$a = $strix->as_delete_action; |
319 |
|
|
320 |
} |
} |
321 |
warn "# argument_values = ",dump( $a->argument_values ); |
# warn "# argument_values = ",dump( $a->argument_values ); |
322 |
$a->run; |
$a->run; |
323 |
warn "can't $op instance $instance" unless $a->result->success; |
|
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; |
my $selected = A3C::Model::StrixInstanceSelectionCollection->new; |
336 |
|
|
337 |
if ( $selected->count > 0 ) { |
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 ) }; |
div { _('%1 instances selected', $selected->count ) }; |
343 |
table { |
table { |
344 |
while (my $s = $selected->next) { |
while (my $s = $selected->next) { |
345 |
row { |
row { |
346 |
cell { tt { |
cell { tt { |
347 |
hyperlink( |
if ( $s->instance->instance eq $instance ) { |
348 |
url => '?instance=' . $s->instance->instance, |
b { $instance } |
349 |
label => $s->instance->instance |
} else { |
350 |
) |
hyperlink( |
351 |
|
url => '?instance=' . $s->instance->instance, |
352 |
|
label => $s->instance->instance |
353 |
|
) |
354 |
|
} |
355 |
} } |
} } |
356 |
cell { $s->instance->_site_name } |
cell { $s->instance->_site_name } |
357 |
cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) } |
cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) } |
374 |
template 'instance-op' => sub { |
template 'instance-op' => sub { |
375 |
my $self = shift; |
my $self = shift; |
376 |
|
|
377 |
warn "# instance-op = ",dump( @_ ); |
# warn "# instance-op = ",dump( @_ ); |
378 |
|
|
379 |
my ( $op, $label, $instance ) = @_; |
my ( $op, $label, $instance ) = @_; |
380 |
|
|
385 |
refresh => 'selected-instances', |
refresh => 'selected-instances', |
386 |
path => '/strix/selected-instances', |
path => '/strix/selected-instances', |
387 |
args => { |
args => { |
388 |
instance => $instance, |
op_instance => $instance, |
389 |
op => $op, |
op => $op, |
390 |
} |
} |
391 |
}, |
}, |
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(' '); |
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(' '); |
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; |
1; |