--- lib/A3C/View/Strix.pm 2008/06/16 23:24:25 187
+++ lib/A3C/View/Strix.pm 2008/10/01 20:22:22 242
@@ -45,19 +45,21 @@
};
-=head2 name_diff
+=head2 errors
=cut
-template 'name_diff' => page {
+template 'errors' => page {
- title is _('Strix name differences');
+ title is _('Strix errors');
render_region(
name => 'selected-instances',
path => '/strix/selected-instances'
);
+ h2 { _('Name differences') }
+
my $name_diff = A3C::SQL->new({ query => qq{
select
instance,hreduorgurl,
@@ -92,6 +94,53 @@
};
+=head2 instances
+
+=cut
+
+template 'instances' => page {
+
+ title is _('Strix instances');
+
+ my $sql = A3C::SQL->new({ query => qq{
+ select
+ hrEduOrgUrl, o, l, postalAddress, telephoneNumber, facsimileTelephoneNumber
+ from strix_instances
+ join hr_edu_orgs on cn = instance
+ order by l,o
+ }});
+
+ if ( $sql->count > 0 ) {
+
+ table {
+ row {
+ th { _('hrEduOrgUrl') }
+ th { _('o') }
+ th { _('l') }
+ th { _('postalAddress') }
+ th { _('telephoneNumber') }
+ th { _('facsimileTelephoneNumber') }
+ };
+ while ( my $row = $sql->next ) {
+ row {
+ cell { outs_raw '' . $row->hrEduOrgUrl . '' }
+ cell { $row->o }
+ cell { $row->l }
+ cell { $row->postalAddress }
+ cell { $row->telephoneNumber }
+ cell { $row->facsimileTelephoneNumber }
+ }
+ }
+ }
+
+ div { _("Found total of %1 strix instances", $sql->count) }
+
+ } else {
+ div { _("Can't find any strix instances") }
+ }
+
+};
+
=head2 sql
Execute SQL query on instance
@@ -119,99 +168,32 @@
return Strix->new({ instance => $instance });
}
-=head2 sitemap
-
-=cut
-
sub strix_link {
my ( $url, $label ) = @_;
hyperlink(
- url => 'http://' . get('instance') . '.cms-qa.skole.hr' . $url,
+ url => 'http://' . get('instance') . Jifty->config->app('strix')->{domain} . $url,
label => $label || $url,
target => 'strix',
);
}
-template 'sitemap' => page {
-
- title is _('Sitemap %1', get('instance'));
-
- render_region(
- name => 'selected-instances',
- path => '/strix/selected-instances'
- );
-
- my $site_id = get('site_id') || 1;
-
- my $sitemap = strix->site_navigation( $site_id );
-
- sub full_url {
- my $p = shift;
- strix_link( $p->{url}, $p->{naziv} );
- if ( $p->{type} eq 'category' ) {
- outs_raw(' ');
- hyperlink(
- url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
- label => _('layout'),
- class => '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
+=head2 navigation
=cut
-template 'layout' => page {
+template 'navigation' => page {
- my $url = get('url') || '/';
-
- my $category = strix->category( $url );
-
- warn dump( $category );
-
- title is _('Layout %1 : %2',
- $category->{sitename},
- $category->{naziv},
- );
+ title is _('Site navigation');
render_region(
name => 'selected-instances',
path => '/strix/selected-instances'
);
- strix_link( $category->{url}, $category->{naziv} );
-
- my $layout = strix->layout( $url );
-
- pre {
- dump( $layout );
- }
+ render_region(
+ name => 'strix-site',
+ path => '/strix/site'
+ );
};
@@ -225,23 +207,30 @@
template 'execute-sql' => sub {
+ my $sql = get('sql') || Jifty->web->session->get('sql');
+ warn ">>>> sql = $sql";
+ my $instance = get('instance');
+ warn ">>>> instance = $instance";
+
my $action = new_action(
class => 'StrixSQL',
moniker => 'strix-sql',
sticky_on_success => 1,
sticky_on_failure => 1,
arguments => {
- instance => get('instance')
- }
+ instance => $instance,
+ sql => $sql,
+ },
);
form {
- render_action( $action => [ 'instance', 'sql' ] );
+ render_action( $action, [ 'instance', 'sql' ] );
form_submit( label => _('Execute SQL') );
};
if ( my $sql = $action->result->content('sql') ) {
- div { _('Found %1 results', $sql->count ) }
+ Jifty->web->session->set( sql => $sql->query );
+ div { _('Found %1 results for %2', $sql->count, $instance ) }
table {
row { map { th { $_ } } $sql->_column_names };
while (my $row = $sql->next) {
@@ -253,6 +242,7 @@
}
}
}
+ warn ">>>> sql (at end) = ",Jifty->web->session->get('sql');
};
=head2 search-instances
@@ -283,9 +273,9 @@
table {
while (my $strix = $search->next) {
row {
+ cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
cell { tt { $strix->instance } }
cell { $strix->_site_name }
- cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
}
}
}
@@ -305,7 +295,8 @@
# warn "## IN selected-instances ",dump( @_ );
if ( my $op = get 'op' ) {
- my $op_instance = get 'op_instance' or die "no op_instance?";
+ my $op_instance = get 'op_instance';
+ return unless $op_instance;
warn "# selected-instances $op on $op_instance";
my $a;
@@ -348,6 +339,7 @@
if ( $selected->count > 0 ) {
my $instance = get('instance');
+ warn "# selected-instances -- selected: $instance\n";
div { _('%1 instances selected', $selected->count ) };
table {
@@ -404,5 +396,186 @@
};
+=head2 site
+
+=cut
+
+template 'site' => sub {
+
+ my $action = new_action(
+ class => 'StrixSelectSite',
+ moniker => 'strix-select-site',
+ );
+
+ warn "# action = ", dump( $action );
+
+ warn "# argument_values = ", dump( $action->argument_values );
+
+ if ( ! $action->argument_value('instance') ) {
+ $action->argument_value( 'instance', get('instance') );
+ warn "# run action with instance\n";
+ $action->run;
+ }
+
+ my $magic = [
+ { submit => $action, refresh_self => 1 },
+ # this is basically a closure
+ { refresh => 'selected-instances', path => '/strix/selected-instances', args => {
+ instance => { result_of => $action, name => 'instance' }
+ } },
+ { refresh => 'strix-site-layout', path => '/__jifty/empty' },
+ ];
+
+ form {
+ render_param( $action, 'instance', onchange => $magic );
+ render_param( $action, 'site_id', onchange => $magic );
+ form_submit( label => _('Show navigation'), onclick => $magic );
+ };
+
+ warn "## select-site action ",dump( $action->result );
+
+ render_region(
+ name => 'layout',
+ path => '/__jifty/empty',
+ );
+
+ if ( my $site_id = $action->result->content('site_id') ) {
+ show('navigation-tree', $action->result->content('instance'), $site_id);
+ }
+};
+
+=head2 layout
+
+Shows layout for C
+
+=cut
+
+template 'layout' => sub {
+
+ my $url = get('url') || '/';
+ my $category = strix->category( $url );
+ my $layout = strix->layout( $url );
+
+ h1 { $category->{naziv} }
+ pre {
+ dump( $layout );
+ }
+
+};
+
+=head2 category
+
+Show category data for C
+
+=cut
+
+template 'category' => sub {
+
+ my $url = get('url') || '/';
+ my $category = strix->category( $url );
+
+ h1 { $category->{naziv} }
+ pre {
+ dump( $category );
+ }
+
+};
+
+=head1 PRIVATE TEMPLATES
+
+=head2 navigation-tree-category
+
+ show('navigation-tree-category',$kat_row);
+
+=cut
+
+private template 'navigation-tree-category' => sub {
+ my $self = shift;
+ #warn "## navigation-tree-category",dump( @_ );
+ my $p = shift;
+ hyperlink(
+ onclick => {
+ region => 'strix-site-layout', # FIXME do we have to hard-code region name here?
+ replace_with => '/strix/category',
+ args => {
+ url => $p->{url},
+ instance => get('instance'),
+ }
+ },
+ label => $p->{naziv},
+ );
+ outs_raw(' ');
+ if ( $p->{type} eq 'category' ) {
+ hyperlink(
+# url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
+ onclick => {
+ region => 'strix-site-layout', # FIXME do we have to hard-code region name here?
+ replace_with => '/strix/layout',
+ args => {
+ url => $p->{url},
+ instance => get('instance'),
+ }
+ },
+ label => _('layout'),
+ class => 'layout',
+ );
+ }
+ outs_raw(' ');
+ strix_link( $p->{url}, '>>' );
+};
+
+=head2 navigation-tree
+
+ show('navigation-tree',$instance,$site_id);
+
+=cut
+
+private template 'navigation-tree' => sub {
+ my $self = shift;
+ my ( $instance, $site_id ) = @_;
+
+ warn "## navigation-tree instance: $instance site_id: $site_id";
+
+ set 'instance' => $instance;
+
+ sub children {
+ my $c = shift;
+ return unless defined $c->{children};
+ ul {
+ foreach my $p ( @{ $c->{children} } ) {
+ li {
+ if ( defined( $p->{class} ) ) {
+ { class is $p->{class} };
+ }
+ show( 'navigation-tree-category', $p );
+ children( $p );
+ }
+ }
+ }
+ }
+
+ my $strix = Strix->new({ instance => $instance });
+
+ my $navigation = $strix->site_navigation( $site_id );
+ #warn "## navigation = ",dump( $navigation );
+ if ( $navigation ) {
+ ul {
+ { class is 'navigation' };
+ foreach my $p ( @$navigation ) {
+ li {
+ show( 'navigation-tree-category', $p );
+ children( $p );
+ }
+ }
+ }
+ } else {
+ div {
+ { class is 'note error' }
+ _('No navigation found for instance %1 site_id %2', $instance, $site_id)
+ }
+
+ }
+
+};
1;