/[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 153 by dpavlin, Sat Jun 14 12:31:35 2008 UTC revision 174 by dpavlin, Mon Jun 16 16:48:16 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
12    
13  =cut  =cut
14    
# Line 16  use warnings; Line 18  use warnings;
18  use Jifty::View::Declare -base;  use Jifty::View::Declare -base;
19  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
20    
21  template 'index.html' => page {  =head2 /
22    
23    Display instaces search and some stats
24    
25    =cut
26    
27          title is _('Strix sites');  template 'index.html' => page {
28    
29          h1 { _('Statistics') }          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          dt { _('Number of Strix sites') }          div { _('Number of instances in Strix: %1', $orgs->count ) };
35          dd { $orgs->count }  
36            render_region(
37                    name => 'selected-instances',
38                    path => '/strix/selected-instances'
39            );
40    
41            render_region(
42                    name => 'search-instances',
43                    path => '/strix/search-instances',
44            );
45    
46  };  };
47    
48    =head2 name_diff
49    
50    =cut
51    
52  template 'name_diff' => page {  template 'name_diff' => page {
53    
54          title is _('Strix sites');          title is _('Strix name differences');
55    
56          my $name_diff = A3C::SQL->new({ query => qq{          my $name_diff = A3C::SQL->new({ query => qq{
57                  select                  select
58                          site,hreduorgurl,                          instance,hreduorgurl,
59                          _site_name,o                          _site_name,o
60                  from strix_sites                  from strix_instances
61                  join hr_edu_orgs on cn = site                  join hr_edu_orgs on cn = instance
62                  where o != _site_name                  where o != _site_name
63          }});          }});
64    
65          h1 { _('Name differences') }          if ( $name_diff->count > 0 ) {
66          dd {  
67                  table {                  table {
68                          row {                          row {
69                                  th { _('Site') }                                  th { _('Instance') }
70                                  th { _('Strix site name') }                                  th { _('Strix instance name') }
71                                  th { _('hrEduOrg.o') }                                  th { _('hrEduOrg.o') }
72                          };                          };
73                          while ( my $row = $name_diff->next ) {                          while ( my $row = $name_diff->next ) {
74                                  row {                                  row {
75                                          cell { hyperlink( url => 'http://' . $row->hreduorgurl, label => $row->site ) }                                          cell { hyperlink( url => 'http://' . $row->hreduorgurl, label => $row->instance ) }
76                                          cell { $row->_site_name }                                          cell { $row->_site_name }
77                                          cell { $row->o }                                          cell { $row->o }
78                                  }                                  }
79                          }                          }
80                  }                  }
81            
82            } else {
83                    div { _("Can't find any instance of strix which has different name than data from LDAP") }
84          }          }
85    
86  };  };
87    
88    =head2 sql
89    
90    Execute SQL query on instance
91    
92    =cut
93    
94    template 'sql' => page {
95    
96            title is _('Execute SQL');
97    
98            render_region(
99                    name => 'selected-instances',
100                    path => '/strix/selected-instances'
101            );
102    
103            render_region(
104                    name => 'execute-sql',
105                    path => '/strix/execute-sql',
106            );
107    
108    };
109    
110    sub strix {
111            my $instance = get('instance') || shift || 'new';
112            return Strix->new({ instance => $instance });
113    }
114    
115    =head2 sitemap
116    
117    =cut
118    
119    template 'sitemap' => page {
120    
121            title is _('Sitemap');
122    
123            my $site_id = get('site_id') || 1;
124    
125            my $sitemap = strix->site_navigation( $site_id );
126    
127            sub full_url {
128                    my $p = shift;
129                    hyperlink(
130                            url => 'http://new.cms-qa.skole.hr' . $p->{url},
131                            label => $p->{naziv},
132                    );
133                    if ( $p->{type} eq 'category' ) {
134                            outs_raw(' ');
135                            hyperlink(
136                                    url => '/strix/layout?url=' . $p->{url},
137                                    label => '[layout]',
138                            );
139                    }
140            }
141    
142            sub children {
143                    my $c = shift;
144                    return unless defined $c->{children};
145                    ul {
146                            foreach my $p ( @{ $c->{children} } ) {
147                                    li {
148                                            full_url( $p );
149                                            children( $p );
150                                    }
151                            }
152                    }
153            }
154    
155            ul {
156                    foreach my $p ( @$sitemap ) {
157                            li {
158                                    full_url( $p );
159                                    children( $p );
160                            }
161                    }
162            }
163    
164    };
165    
166    =head2 layout
167    
168    =cut
169    
170    template 'layout' => page {
171    
172            my $url = get('url') || '/';
173    
174            my $category = strix->category( $url );
175    
176            warn dump( $category );
177    
178            title is _('Layout %1 : %2',
179                    $category->{sitename},
180                    $category->{naziv},
181            );
182    
183            hyperlink(
184                    url => 'http://' . $category->{sitename} . '/' . $category->{url},
185                    label => $category->{naziv},
186            );
187    
188            my $layout = strix->layout( $url );
189    
190            pre {
191                    dump( $layout );
192            }
193    
194    };
195    
196    =head1 REGIONS
197    
198    =head2 execute-sql
199    
200    Execute SQL query on instance
201    
202    =cut
203    
204    template 'execute-sql' => sub {
205    
206            my $action = new_action(
207                    class   => 'StrixSQL',
208                    moniker => 'strix-sql',
209                    sticky_on_success => 1,
210                    sticky_on_failure => 1,
211                    arguments => {
212                            strix => get('strix')
213                    }
214            );
215    
216            form {
217                    render_action( $action => [ 'strix', 'sql' ] );
218                    form_submit( label => _('Execute SQL') );
219            };
220    
221            if ( my $sql = $action->result->content('sql') ) {
222                    div { _('Found %1 results', $sql->count ) }
223                    table {
224                            row { map { th { $_ } } $sql->_column_names };
225                            while (my $row = $sql->next) {
226                                    row {
227                                            foreach my $col ( $sql->_column_names ) {
228                                                    cell { $row->$col }
229                                            }
230                                    }
231                            }
232                    }
233            }
234    };
235    
236    =head2 search-instances
237    
238    =cut
239    
240    template 'search-instances' => sub {
241    
242            h1 { _('Find instance') }
243    
244            my $action = new_action(
245                    class   => 'SearchStrixInstance',
246                    moniker => 'search-strix-instance',
247                    sticky_on_success => 1,
248                    sticky_on_failure => 1,
249            );
250    
251    
252            form {
253                    render_action( $action => [ 'instance_contains', '_site_name_contains' ] );
254                    form_submit( label => _('Search') );
255            };
256    
257    #       warn dump( $action->result->content );
258    
259            if ( my $search = $action->result->content('search') ) {
260                    div { _('Found %1 results', $search->count ) }
261                    table {
262                            while (my $strix = $search->next) {
263                                    row {
264                                            cell { tt { $strix->instance } }
265                                            cell { $strix->_site_name }
266                                            cell { show( 'instance-op', 'Create', '+', $strix->instance ) }
267                                    }
268                            }
269                    }
270            }
271    
272    };
273    
274    =head2 selected-instances
275    
276    Show Selected instances for current user
277    
278    =cut
279    
280    template 'selected-instances' => sub {
281            my $self = shift;
282    
283            warn "## IN selected-instances ",dump( @_ );
284    
285            if ( my $op = get 'op' ) {
286                    my $instance = get 'instance' or die "no instance?";
287                    warn "# selected-instances $op on $instance";
288    
289                    my $a;
290    
291                    if ( $op eq 'Create' ) {
292    
293                            $a = new_action(
294                                    class => $op . 'StrixInstanceSelection',
295                                    moniker => $op,
296                                    arguments => {
297                                            instance => $instance,
298                                            by_user => $self->current_user->id,
299                                    },
300                            );
301    
302                    } elsif ( $op eq 'Delete' ) {
303    
304                            my $strix = A3C::Model::StrixInstanceSelection->new;
305                            $strix->load_by_cols( instance => $instance, by_user => $self->current_user->id );
306                            die "can't find instance $instance" unless $strix->id;
307                            $a = $strix->as_delete_action;
308    
309                    }
310                    warn "# argument_values = ",dump( $a->argument_values );
311                    $a->run;
312                    warn "can't $op instance $instance" unless $a->result->success;
313            }
314    
315            my $selected = A3C::Model::StrixInstanceSelectionCollection->new;
316            $selected->limit( column => 'by_user', value => Jifty->web->current_user->id );
317    
318            if ( $selected->count > 0 ) {
319    
320                    div { _('%1 instances selected', $selected->count ) }
321                    table {
322                            while (my $s = $selected->next) {
323                                    row {
324                                            cell { tt { $s->strix->instance } }
325                                            cell { $s->strix->_site_name }
326                                            cell { show( 'instance-op', 'Delete', '-', $s->strix->instance ) }
327                                    }
328                            }
329                    }
330            } else {
331                    div { _('No instances selected') }
332            }
333    };
334    
335    =head2 instance-op
336    
337    Display button to add/remove instance from selection
338    
339      show( 'instance-op', 'Delete', '-', $strix->instace );
340    
341    =cut
342    
343    template 'instance-op' => sub {
344            my $self = shift;
345    
346            warn "# instance-op = ",dump( @_ );
347    
348            my ( $op, $label, $instance ) = @_;
349    
350            form {
351                    hyperlink(
352                            label => $label,
353                            onclick => {
354                                    refresh => 'selected-instances',
355                                    path => '/strix/selected-instances',
356                                    args => {
357                                            instance => $instance,
358                                            op => $op,
359                                    }
360                            },
361                    );
362            }
363    
364    };
365    
366    
367  1;  1;

Legend:
Removed from v.153  
changed lines
  Added in v.174

  ViewVC Help
Powered by ViewVC 1.1.26