/[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 211 by dpavlin, Fri Jun 20 15:35:21 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    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  =cut
134    
135  template 'sitemap' => page {  template 'navigation' => page {
136    
137          title is _('Sitemap');          title is _('Site navigation');
138    
139          my $strix = Strix->new({ site => 'new' });          render_region(
140          my $sitemap = $strix->site_navigation( 1 );                  name => 'selected-instances',
141                    path => '/strix/selected-instances'
142            );
143    
144          sub full_url {          render_region(
145                  my $p = shift;                  name => 'strix-site',
146                  hyperlink(                  path => '/strix/site'
147                          url => 'http://new.cms-qa.skole.hr' . $p->{url},          );
                         label => $p->{naziv},  
                 );  
         }  
148    
149          sub children {  };
                 my $c = shift;  
                 return unless defined $c->{children};  
                 ul {  
                         foreach my $p ( @{ $c->{children} } ) {  
                                 li {  
                                         full_url( $p );  
                                         children( $p );  
                                 }  
                         }  
                 }  
         }  
150    
151          ul {  =head2 layout
152                  foreach my $p ( @$sitemap ) {  
153                          li {  =cut
154                                  full_url( $p );  
155                                  children( $p );  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  };  };
# Line 154  template 'sitemap' => page { Line 174  template 'sitemap' => page {
174    
175  =head2 execute-sql  =head2 execute-sql
176    
177  Execute SQL query on site  Execute SQL query on instance
178    
179  =cut  =cut
180    
# Line 166  template 'execute-sql' => sub { Line 186  template 'execute-sql' => sub {
186                  sticky_on_success => 1,                  sticky_on_success => 1,
187                  sticky_on_failure => 1,                  sticky_on_failure => 1,
188                  arguments => {                  arguments => {
189                          strix => get('strix')                          instance => get('instance')
190                  }                  }
191          );          );
192    
193          form {          form {
194                  render_action( $action => [ 'strix', 'sql' ] );                  render_action( $action => [ 'instance', 'sql' ] );
195                  form_submit( label => _('Execute SQL') );                  form_submit( label => _('Execute SQL') );
196          };          };
197    
# Line 190  template 'execute-sql' => sub { Line 210  template 'execute-sql' => sub {
210          }          }
211  };  };
212    
213  =head2 search-sites  =head2 search-instances
214    
215  =cut  =cut
216    
217  template 'search-sites' => sub {  template 'search-instances' => sub {
218    
219          h1 { _('Find site') }          h1 { _('Find instance') }
220    
221          my $action = new_action(          my $action = new_action(
222                  class   => 'SearchStrixSite',                  class   => 'SearchStrixInstance',
223                  moniker => 'search-strix-site',                  moniker => 'search-strix-instance',
224                  sticky_on_success => 1,                  sticky_on_success => 1,
225                  sticky_on_failure => 1,                  sticky_on_failure => 1,
226          );          );
227    
228    
229          form {          form {
230                  render_action( $action => [ 'site_contains', '_site_name_contains' ] );                  render_action( $action => [ 'instance_contains', '_site_name_contains' ] );
231                  form_submit( label => _('Search') );                  form_submit( label => _('Search') );
232          };          };
233    
# Line 218  template 'search-sites' => sub { Line 238  template 'search-sites' => sub {
238                  table {                  table {
239                          while (my $strix = $search->next) {                          while (my $strix = $search->next) {
240                                  row {                                  row {
241                                          cell { tt { $strix->site } }                                          cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
242                                            cell { tt { $strix->instance } }
243                                          cell { $strix->_site_name }                                          cell { $strix->_site_name }
                                         cell { show( 'site-op', 'Create', '+', $strix->site ) }  
244                                  }                                  }
245                          }                          }
246                  }                  }
# Line 228  template 'search-sites' => sub { Line 248  template 'search-sites' => sub {
248    
249  };  };
250    
251  =head2 selected-sites  =head2 selected-instances
252    
253  Show Selected sites for current user  Show Selected instances for current user
254    
255  =cut  =cut
256    
257  template 'selected-sites' => sub {  template 'selected-instances' => sub {
258          my $self = shift;          my $self = shift;
259    
260          warn "## IN selected-sites ",dump( @_ );  #       warn "## IN selected-instances ",dump( @_ );
261    
262          if ( my $op = get 'op' ) {          if ( my $op = get 'op' ) {
263                  my $site = get 'site' or die "no site?";                  my $op_instance = get 'op_instance';
264                  warn "# selected-sites $op on $site";                  return unless $op_instance;
265                    warn "# selected-instances $op on $op_instance";
266    
267                  my $a;                  my $a;
268    
269                  if ( $op eq 'Create' ) {                  if ( $op eq 'Create' ) {
270    
271                          $a = new_action(                          $a = new_action(
272                                  class => $op . 'StrixSiteSelection',                                  class => $op . 'StrixInstanceSelection',
273                                  moniker => $op,                                  moniker => $op,
274                                  arguments => {                                  arguments => {
275                                          strix => $site,                                          instance => $op_instance,
276                                          by_user => $self->current_user->id,                                          by_user => $self->current_user->id,
277                                  },                                  },
278                          );                          );
279    
280                  } elsif ( $op eq 'Delete' ) {                  } elsif ( $op eq 'Delete' ) {
281    
282                          my $strix = A3C::Model::StrixSiteSelection->new;                          my $strix = A3C::Model::StrixInstanceSelection->new;
283                          $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 );
284                          die "can't find site $site" unless $strix->id;                          warn "can't find instance $op_instance" unless $strix->id;
285                          $a = $strix->as_delete_action;                          $a = $strix->as_delete_action;
286    
287                  }                  }
288                  warn "# argument_values = ",dump( $a->argument_values );  #               warn "# argument_values = ",dump( $a->argument_values );
289                  $a->run;                  $a->run;
290                  warn "can't $op site $site" unless $a->result->success;  
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::StrixSiteSelectionCollection->new;          my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
302          $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );          $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
303    
304          if ( $selected->count > 0 ) {          if ( $selected->count > 0 ) {
305    
306                  div { _('%1 sites selected', $selected->count ) }                  my $instance = get('instance');
307                    warn "# selected-instances -- selected: $instance\n";
308    
309                    div { _('%1 instances selected', $selected->count ) };
310                  table {                  table {
311                          while (my $s = $selected->next) {                          while (my $s = $selected->next) {
312                                  row {                                  row {
313                                          cell { tt { $s->strix->site } }                                          cell { tt {
314                                          cell { $s->strix->_site_name }                                                  if ( $s->instance->instance eq $instance ) {
315                                          cell { show( 'site-op', 'Delete', '-', $s->strix->site ) }                                                          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 {          } else {
329                  div { _('No sites selected') }                  div { _('No instances selected') }
330          }          }
331  };  };
332    
333  =head2 site-op  =head2 instance-op
334    
335  Display button to add/remove site from selection  Display button to add/remove instance from selection
336    
337    show( 'site-op', 'Delete', '-', $strix->site );    show( 'instance-op', 'Delete', '-', $strix->instace );
338    
339  =cut  =cut
340    
341  template 'site-op' => sub {  template 'instance-op' => sub {
342          my $self = shift;          my $self = shift;
343    
344          warn "# site-op = ",dump( @_ );  #       warn "# instance-op = ",dump( @_ );
345    
346          my ( $op, $label, $site ) = @_;          my ( $op, $label, $instance ) = @_;
347    
348          form {          form {
349                  hyperlink(                  hyperlink(
350                          label => $label,                          label => $label,
351                          onclick => {                          onclick => {
352                                  refresh => 'selected-sites',                                  refresh => 'selected-instances',
353                                  path => '/strix/selected-sites',                                  path => '/strix/selected-instances',
354                                  args => {                                  args => {
355                                          site => $site,                                          op_instance => $instance,
356                                          op => $op,                                          op => $op,
357                                  }                                  }
358                          },                          },
# Line 320  template 'site-op' => sub { Line 361  template 'site-op' => sub {
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('strix-site-navigation-tree', $action->result->content('instance'), $site_id);
409            }
410    };
411    
412    =head1 PRIVATE TEMPLATES
413    
414    =head2 strix-site-navigation-tree
415    
416      show('strix-site-navigation-tree',$instance,$site_id);
417    
418    =cut
419    
420    private template 'select-category' => sub {
421            my $self = shift;
422            my $p = shift;
423            strix_link( $p->{url}, $p->{naziv} );
424            if ( $p->{type} eq 'category' ) {
425                    outs_raw(' ');
426                    hyperlink(
427    #                       url => '/strix/layout?url=' . $p->{url} . ';instance=' . get('instance'),
428                            onclick => {
429                                    region => 'strix-site-layout',  # FIXME do we have to hard-code region name here?
430                                    replace_with => '/strix/layout',
431                                    args => {
432                                            url => $p->{url},
433                                            instance => get('instance'),
434                                    }
435                            },
436                            label => _('layout'),
437                            class => 'layout',
438                    );
439            }
440    };
441    
442    private template 'strix-site-navigation-tree' => sub {
443            my $self = shift;
444            my ( $instance, $site_id ) = @_;
445    
446            warn ">>>> instance: $instance site_id: $site_id";
447    
448            set 'instance' => $instance;
449    
450    
451            sub children {
452                    my $c = shift;
453                    return unless defined $c->{children};
454                    ul {
455                            foreach my $p ( @{ $c->{children} } ) {
456                                    li {
457                                            { class is $p->{class} };
458                                            show( 'select-category', $p );
459                                            children( $p );
460                                    }
461                            }
462                    }
463            }
464    
465            my $strix = Strix->new({ instance => $instance });
466    
467            my @navigation = @{ $strix->site_navigation( $site_id ) };
468            if ( @navigation ) {
469                    ul {
470                            foreach my $p ( @navigation ) {
471                                    li {
472                                            show( 'select-category', $p );
473                                            children( $p );
474                                    }
475                            }
476                    }
477            } else {
478                    div {
479                            { class is 'note error' }
480                            _('No navigation found for instance %1 site_id %2', $instance, $site_id)
481                    }
482    
483            }
484    
485    };
486    
487  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26