/[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 172 by dpavlin, Mon Jun 16 13:32:01 2008 UTC revision 200 by dpavlin, Tue Jun 17 23:06:31 2008 UTC
# Line 6  A3C::View::Strix Line 6  A3C::View::Strix
6    
7  =head1 DESCRIPTION  =head1 DESCRIPTION
8    
9  Display information about Strix sites  Display information about Strix instances
10    
11  =head1 TEMPLATES  =head1 TEMPLATES
12    
# Line 20  use Data::Dump qw/dump/; Line 20  use Data::Dump qw/dump/;
20    
21  =head2 /  =head2 /
22    
23  Display sites search and some stats  Display instaces search and some stats
24    
25  =cut  =cut
26    
27  template 'index.html' => page {  template 'index.html' => page {
28    
29          title is _('Strix sites');          title is _('Strix instances');
30    
31          my $orgs = A3C::Model::StrixSiteCollection->new;          my $orgs = A3C::Model::StrixInstanceCollection->new;
32          $orgs->unlimit;          $orgs->unlimit;
33    
34          div { _('Number of sites in Strix: %1', $orgs->count ) };          div { _('Number of instances in Strix: %1', $orgs->count ) };
35    
36          render_region(          render_region(
37                  name => 'selected-sites',                  name => 'selected-instances',
38                  path => '/strix/selected-sites'                  path => '/strix/selected-instances'
39          );          );
40    
41          render_region(          render_region(
42                  name => 'search-sites',                  name => 'search-instances',
43                  path => '/strix/search-sites',                  path => '/strix/search-instances',
44          );          );
45    
46  };  };
# Line 53  template 'name_diff' => page { Line 53  template 'name_diff' => page {
53    
54          title is _('Strix name differences');          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{          my $name_diff = A3C::SQL->new({ query => qq{
62                  select                  select
63                          site,hreduorgurl,                          instance,hreduorgurl,
64                          _site_name,o                          _site_name,o
65                  from strix_sites                  from strix_instances
66                  join hr_edu_orgs on cn = site                  join hr_edu_orgs on cn = instance
67                  where o != _site_name                  where o != _site_name
68          }});          }});
69    
# Line 66  template 'name_diff' => page { Line 71  template 'name_diff' => page {
71    
72                  table {                  table {
73                          row {                          row {
74                                  th { _('Site') }                                  th {}
75                                  th { _('Strix site name') }                                  th { _('Instance') }
76                                    th { _('Strix instance name') }
77                                  th { _('hrEduOrg.o') }                                  th { _('hrEduOrg.o') }
78                          };                          };
79                          while ( my $row = $name_diff->next ) {                          while ( my $row = $name_diff->next ) {
80                                  row {                                  row {
81                                          cell { hyperlink( url => 'http://' . $row->hreduorgurl, label => $row->site ) }                                          cell { show( 'instance-op', 'Create', '+', $row->instance ) }
82                                            cell { $row->instance }
83                                          cell { $row->_site_name }                                          cell { $row->_site_name }
84                                          cell { $row->o }                                          cell { $row->o }
85                                  }                                  }
# Line 80  template 'name_diff' => page { Line 87  template 'name_diff' => page {
87                  }                  }
88                    
89          } else {          } else {
90                  div { _("Can't find any site in strix which has different name than data from LDAP") }                  div { _("Can't find any instance of strix which has different name than data from LDAP") }
91          }          }
92    
93  };  };
94    
95  =head2 sql  =head2 sql
96    
97  Execute SQL query on site  Execute SQL query on instance
98    
99  =cut  =cut
100    
# Line 96  template 'sql' => page { Line 103  template 'sql' => page {
103          title is _('Execute SQL');          title is _('Execute SQL');
104    
105          render_region(          render_region(
106                  name => 'selected-sites',                  name => 'selected-instances',
107                  path => '/strix/selected-sites'                  path => '/strix/selected-instances'
108          );          );
109    
110          render_region(          render_region(
# Line 107  template 'sql' => page { Line 114  template 'sql' => page {
114    
115  };  };
116    
117  =head2 sitemap  sub strix {
118            my $instance = get('instance');
119            return Strix->new({ instance => $instance });
120    }
121    
122    =head2 site-navigation
123    
124  =cut  =cut
125    
126  template 'sitemap' => page {  sub strix_link {
127            my ( $url, $label ) = @_;
128            hyperlink(
129                    url => 'http://' . get('instance') . '.cms-qa.skole.hr' . $url,
130                    label => $label || $url,
131                    target => 'strix',
132            );
133    }
134    
135          title is _('Sitemap');  template 'site-navigation' => page {
136    
137          my $strix = Strix->new({ site => 'new' });          title is _('Site navigation');
         my $sitemap = $strix->site_navigation( 1 );  
138    
139          sub full_url {          render_region(
140                  my $p = shift;                  name => 'selected-instances',
141                  hyperlink(                  path => '/strix/selected-instances'
142                          url => 'http://new.cms-qa.skole.hr' . $p->{url},          );
                         label => $p->{naziv},  
                 );  
         }  
143    
144          sub children {          render_region(
145                  my $c = shift;                  name => 'select-strix-site',
146                  return unless defined $c->{children};                  path => '/strix/select-site'
147                  ul {          );
                         foreach my $p ( @{ $c->{children} } ) {  
                                 li {  
                                         full_url( $p );  
                                         children( $p );  
                                 }  
                         }  
                 }  
         }  
148    
149          ul {  };
150                  foreach my $p ( @$sitemap ) {  
151                          li {  =head2 layout
152                                  full_url( $p );  
153                                  children( $p );  =cut
154                          }  
155                  }  template 'layout' => page {
156    
157            my $url = get('url') || '/';
158    
159            my $category = strix->category( $url );
160    
161            warn dump( $category );
162    
163            title is _('Layout %1 : %2',
164                    $category->{sitename},
165                    $category->{naziv},
166            );
167    
168            render_region(
169                    name => 'selected-instances',
170                    path => '/strix/selected-instances'
171            );
172    
173            strix_link( $category->{url}, $category->{naziv} );
174    
175            my $layout = strix->layout( $url );
176    
177            pre {
178                    dump( $layout );
179          }          }
180    
181  };  };
# Line 154  template 'sitemap' => page { Line 184  template 'sitemap' => page {
184    
185  =head2 execute-sql  =head2 execute-sql
186    
187  Execute SQL query on site  Execute SQL query on instance
188    
189  =cut  =cut
190    
# Line 166  template 'execute-sql' => sub { Line 196  template 'execute-sql' => sub {
196                  sticky_on_success => 1,                  sticky_on_success => 1,
197                  sticky_on_failure => 1,                  sticky_on_failure => 1,
198                  arguments => {                  arguments => {
199                          strix => get('strix')                          instance => get('instance')
200                  }                  }
201          );          );
202    
203          form {          form {
204                  render_action( $action => [ 'strix', 'sql' ] );                  render_action( $action => [ 'instance', 'sql' ] );
205                  form_submit( label => _('Execute SQL') );                  form_submit( label => _('Execute SQL') );
206          };          };
207    
# Line 190  template 'execute-sql' => sub { Line 220  template 'execute-sql' => sub {
220          }          }
221  };  };
222    
223  =head2 search-sites  =head2 search-instances
224    
225  =cut  =cut
226    
227  template 'search-sites' => sub {  template 'search-instances' => sub {
228    
229          h1 { _('Find site') }          h1 { _('Find instance') }
230    
231          my $action = new_action(          my $action = new_action(
232                  class   => 'SearchStrixSite',                  class   => 'SearchStrixInstance',
233                  moniker => 'search-strix-site',                  moniker => 'search-strix-instance',
234                  sticky_on_success => 1,                  sticky_on_success => 1,
235                  sticky_on_failure => 1,                  sticky_on_failure => 1,
236          );          );
237    
238    
239          form {          form {
240                  render_action( $action => [ 'site_contains', '_site_name_contains' ] );                  render_action( $action => [ 'instance_contains', '_site_name_contains' ] );
241                  form_submit( label => _('Search') );                  form_submit( label => _('Search') );
242          };          };
243    
# Line 218  template 'search-sites' => sub { Line 248  template 'search-sites' => sub {
248                  table {                  table {
249                          while (my $strix = $search->next) {                          while (my $strix = $search->next) {
250                                  row {                                  row {
251                                          cell { tt { $strix->site } }                                          cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
252                                            cell { tt { $strix->instance } }
253                                          cell { $strix->_site_name }                                          cell { $strix->_site_name }
                                         cell { show( 'site-op', 'Create', '+', $strix->site ) }  
254                                  }                                  }
255                          }                          }
256                  }                  }
# Line 228  template 'search-sites' => sub { Line 258  template 'search-sites' => sub {
258    
259  };  };
260    
261  =head2 selected-sites  =head2 selected-instances
262    
263  Show Selected sites for current user  Show Selected instances for current user
264    
265  =cut  =cut
266    
267  template 'selected-sites' => sub {  template 'selected-instances' => sub {
268          my $self = shift;          my $self = shift;
269    
270          warn "## IN selected-sites ",dump( @_ );  #       warn "## IN selected-instances ",dump( @_ );
271    
272          if ( my $op = get 'op' ) {          if ( my $op = get 'op' ) {
273                  my $site = get 'site' or die "no site?";                  my $op_instance = get 'op_instance' or die "no op_instance?";
274                  warn "# selected-sites $op on $site";                  warn "# selected-instances $op on $op_instance";
275    
276                  my $a;                  my $a;
277    
278                  if ( $op eq 'Create' ) {                  if ( $op eq 'Create' ) {
279    
280                          $a = new_action(                          $a = new_action(
281                                  class => $op . 'StrixSiteSelection',                                  class => $op . 'StrixInstanceSelection',
282                                  moniker => $op,                                  moniker => $op,
283                                  arguments => {                                  arguments => {
284                                          strix => $site,                                          instance => $op_instance,
285                                          by_user => $self->current_user->id,                                          by_user => $self->current_user->id,
286                                  },                                  },
287                          );                          );
288    
289                  } elsif ( $op eq 'Delete' ) {                  } elsif ( $op eq 'Delete' ) {
290    
291                          my $strix = A3C::Model::StrixSiteSelection->new;                          my $strix = A3C::Model::StrixInstanceSelection->new;
292                          $strix->load_by_cols( strix => $site, by_user => $self->current_user->id );                          $strix->load_by_cols( instance => $op_instance, by_user => $self->current_user->id );
293                          die "can't find site $site" unless $strix->id;                          warn "can't find instance $op_instance" unless $strix->id;
294                          $a = $strix->as_delete_action;                          $a = $strix->as_delete_action;
295    
296                  }                  }
297                  warn "# argument_values = ",dump( $a->argument_values );  #               warn "# argument_values = ",dump( $a->argument_values );
298                  $a->run;                  $a->run;
299                  warn "can't $op site $site" unless $a->result->success;  
300                    if ( $a->result->error ) {
301                            div {
302                                    { class is 'note error' }
303                                    $a->result->error;
304                            }
305                    }
306    
307                    set( op => '' );
308          }          }
309    
310          my $selected = A3C::Model::StrixSiteSelectionCollection->new;          my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
311          $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );          $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
312    
313          if ( $selected->count > 0 ) {          if ( $selected->count > 0 ) {
314    
315                  div { _('%1 sites selected', $selected->count ) }                  my $instance = get('instance');
316                    warn "# selected-instances -- selected: $instance\n";
317    
318                    div { _('%1 instances selected', $selected->count ) };
319                  table {                  table {
320                          while (my $s = $selected->next) {                          while (my $s = $selected->next) {
321                                  row {                                  row {
322                                          cell { tt { $s->strix->site } }                                          cell { tt {
323                                          cell { $s->strix->_site_name }                                                  if ( $s->instance->instance eq $instance ) {
324                                          cell { show( 'site-op', 'Delete', '-', $s->strix->site ) }                                                          b { $instance }
325                                                    } else {
326                                                            hyperlink(
327                                                                    url => '?instance=' . $s->instance->instance,
328                                                                    label => $s->instance->instance
329                                                            )
330                                                    }
331                                            } }
332                                            cell { $s->instance->_site_name }
333                                            cell { show( 'instance-op', 'Delete', '-', $s->instance->instance ) }
334                                  }                                  }
335                          }                          }
336                  }                  }
337          } else {          } else {
338                  div { _('No sites selected') }                  div { _('No instances selected') }
339          }          }
340  };  };
341    
342  =head2 site-op  =head2 instance-op
343    
344  Display button to add/remove site from selection  Display button to add/remove instance from selection
345    
346    show( 'site-op', 'Delete', '-', $strix->site );    show( 'instance-op', 'Delete', '-', $strix->instace );
347    
348  =cut  =cut
349    
350  template 'site-op' => sub {  template 'instance-op' => sub {
351          my $self = shift;          my $self = shift;
352    
353          warn "# site-op = ",dump( @_ );  #       warn "# instance-op = ",dump( @_ );
354    
355          my ( $op, $label, $site ) = @_;          my ( $op, $label, $instance ) = @_;
356    
357          form {          form {
358                  hyperlink(                  hyperlink(
359                          label => $label,                          label => $label,
360                          onclick => {                          onclick => {
361                                  refresh => 'selected-sites',                                  refresh => 'selected-instances',
362                                  path => '/strix/selected-sites',                                  path => '/strix/selected-instances',
363                                  args => {                                  args => {
364                                          site => $site,                                          op_instance => $instance,
365                                          op => $op,                                          op => $op,
366                                  }                                  }
367                          },                          },
# Line 320  template 'site-op' => sub { Line 370  template 'site-op' => sub {
370    
371  };  };
372    
373    =head2 select-site
374    
375    =cut
376    
377    template 'select-site' => sub {
378    
379            my $action = new_action(
380                    class   => 'StrixSelectSite',
381                    moniker => 'strix-select-site',
382            );
383    
384            warn "# action = ", dump( $action );
385    
386            warn "# argument_values = ", dump( $action->argument_values );
387    
388            if ( ! $action->argument_value('instance') ) {
389                    $action->argument_value( 'instance', get('instance') );
390                    warn "# run action with instance\n";
391                    $action->run;
392            }
393    
394            my $magic = [
395                    { submit => $action, refresh_self => 1 },
396                    # this is basically a closure
397                    { refresh => 'selected-instances', path => '/strix/selected-instances', args => {
398                            instance => { result_of => $action, name => 'instance' }
399                    } }
400            ];
401    
402            form {
403                    render_param( $action, 'instance', onchange => $magic );
404                    render_param( $action, 'site_id', onchange => $magic );
405                    form_submit( label => _('Show navigation'), onclick => $magic );
406            };
407    
408            warn "## select-site action ",dump( $action->result );
409    
410            if ( my $site_id = $action->result->content('site_id') ) {
411                    show('strix-site-navigation-tree', $action->result->content('instance'), $site_id);
412            }
413    };
414    
415    =head1 PRIVATE TEMPLATES
416    
417    =head2 strix-site-navigation-tree
418    
419      show('strix-site-navigation-tree',$instance,$site_id);
420    
421    =cut
422    
423    private template 'strix-site-navigation-tree' => sub {
424            my $self = shift;
425            my ( $instance, $site_id ) = @_;
426    
427            warn ">>>> instance: $instance site_id: $site_id";
428    
429            set 'instance' => $instance;
430    
431            sub full_url {
432                    my $p = shift;
433                    strix_link( $p->{url}, $p->{naziv} );
434                    if ( $p->{type} eq 'category' ) {
435                            outs_raw(' ');
436                            hyperlink(
437                                    url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
438                                    label => _('layout'),
439                                    class => 'layout',
440                            );
441                    }
442            }
443    
444            sub children {
445                    my $c = shift;
446                    return unless defined $c->{children};
447                    ul {
448                            foreach my $p ( @{ $c->{children} } ) {
449                                    li {
450                                            { class is $p->{class} };
451                                            full_url( $p );
452                                            children( $p );
453                                    }
454                            }
455                    }
456            }
457    
458            my $strix = Strix->new({ instance => $instance });
459    
460            my @navigation = @{ $strix->site_navigation( $site_id ) };
461            if ( @navigation ) {
462                    ul {
463                            foreach my $p ( @navigation ) {
464                                    li {
465                                            full_url( $p );
466                                            children( $p );
467                                    }
468                            }
469                    }
470            } else {
471                    div {
472                            { class is 'note error' }
473                            _('No navigation found for instance %1 site_id %2', $instance, $site_id)
474                    }
475    
476            }
477    
478    };
479    
480  1;  1;

Legend:
Removed from v.172  
changed lines
  Added in v.200

  ViewVC Help
Powered by ViewVC 1.1.26