/[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

Diff of /lib/A3C/View/Strix.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 186 by dpavlin, Mon Jun 16 22:56:14 2008 UTC revision 234 by dpavlin, Mon Sep 1 18:53:59 2008 UTC
# Line 92  template 'name_diff' => page { Line 92  template 'name_diff' => page {
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
# Line 119  sub strix { Line 166  sub strix {
166          return Strix->new({ instance => $instance });          return Strix->new({ instance => $instance });
167  }  }
168    
169  =head2 sitemap  sub strix_link {
170            my ( $url, $label ) = @_;
171  =cut          hyperlink(
172                    url => 'http://' . get('instance') . '.cms-qa.skole.hr' . $url,
173  template 'sitemap' => page {                  label => $label || $url,
174                    target => 'strix',
         title is _('Sitemap %1', get('instance'));  
   
         render_region(  
                 name => 'selected-instances',  
                 path => '/strix/selected-instances'  
175          );          );
176    }
177    
178          my $site_id = get('site_id') || 1;  =head2 navigation
   
         my $sitemap = strix->site_navigation( $site_id );  
   
         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('&nbsp;');  
                         hyperlink(  
                                 url => '/strix/layout?url=' . $p->{url},  
                                 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  
179    
180  =cut  =cut
181    
182  template 'layout' => page {  template 'navigation' => page {
183    
184          my $url = get('url') || '/';          title is _('Site navigation');
   
         my $category = strix->category( $url );  
   
         warn dump( $category );  
   
         title is _('Layout %1 : %2',  
                 $category->{sitename},  
                 $category->{naziv},  
         );  
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          hyperlink(          render_region(
192                  url => 'http://' . $category->{sitename} . '/' . $category->{url},                  name => 'strix-site',
193                  label => $category->{naziv},                  path => '/strix/site'
194          );          );
195    
         my $layout = strix->layout( $url );  
   
         pre {  
                 dump( $layout );  
         }  
   
196  };  };
197    
198  =head1 REGIONS  =head1 REGIONS
# Line 222  Execute SQL query on instance Line 205  Execute SQL query on instance
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) {
# Line 250  template 'execute-sql' => sub { Line 240  template 'execute-sql' => sub {
240                          }                          }
241                  }                  }
242          }          }
243            warn ">>>> sql (at end) = ",Jifty->web->session->get('sql');
244  };  };
245    
246  =head2 search-instances  =head2 search-instances
# Line 280  template 'search-instances' => sub { Line 271  template 'search-instances' => sub {
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                  }                  }
# Line 302  template 'selected-instances' => sub { Line 293  template 'selected-instances' => sub {
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 $op_instance = get 'op_instance' or die "no op_instance?";                  my $op_instance = get 'op_instance';
297                    return unless $op_instance;
298                  warn "# selected-instances $op on $op_instance";                  warn "# selected-instances $op on $op_instance";
299    
300                  my $a;                  my $a;
# Line 345  template 'selected-instances' => sub { Line 337  template 'selected-instances' => sub {
337          if ( $selected->count > 0 ) {          if ( $selected->count > 0 ) {
338    
339                  my $instance = get('instance');                  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 {
# Line 401  template 'instance-op' => sub { Line 394  template 'instance-op' => sub {
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('&nbsp;');
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('&nbsp;');
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;

Legend:
Removed from v.186  
changed lines
  Added in v.234

  ViewVC Help
Powered by ViewVC 1.1.26