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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26