41 |
|
|
42 |
$c->stash->{template_filename} = $template_filename; |
$c->stash->{template_filename} = $template_filename; |
43 |
|
|
44 |
|
# get databases from config |
45 |
|
my @databases; |
46 |
|
my $config_dbs = $c->config->{databases}; |
47 |
|
|
48 |
|
if (! $config_dbs) { |
49 |
|
$c->log->fail("didn't find databases in config"); |
50 |
|
} else { |
51 |
|
# convert to resonable format for TT |
52 |
|
foreach my $db (keys %{ $config_dbs }) { |
53 |
|
my $d = $config_dbs->{$db} || die; |
54 |
|
my $inputs = $d->{input}; |
55 |
|
$c->log->debug("inputs [1]: ", Dumper($inputs)); |
56 |
|
$inputs = [ $inputs ] if (ref($inputs) ne 'ARRAY'); |
57 |
|
$c->log->debug("inputs [2]: ", Dumper($inputs)); |
58 |
|
|
59 |
|
foreach my $i ( @{ $inputs } ) { |
60 |
|
my $el = { |
61 |
|
input => $i->{name}, |
62 |
|
name => $d->{name} || $d, |
63 |
|
prefix => $db . '/' . $i->{name}, |
64 |
|
}; |
65 |
|
push @databases, $el; |
66 |
|
} |
67 |
|
} |
68 |
|
} |
69 |
|
|
70 |
|
$c->stash->{databases} = \@databases; |
71 |
|
|
72 |
$c->stash->{template} = 'editor.tt'; |
$c->stash->{template} = 'editor.tt'; |
73 |
} |
} |
74 |
|
|
103 |
if ($webpac->save_html( $template_full_path, $t )) { |
if ($webpac->save_html( $template_full_path, $t )) { |
104 |
$c->res->output("<span>saved $template_filename, $size bytes</span>"); |
$c->res->output("<span>saved $template_filename, $size bytes</span>"); |
105 |
} else { |
} else { |
106 |
$c->res->output("<span>error saving $template_filename!</span>"); |
$c->res->output("<span class=\"error\">error saving $template_filename!</span>"); |
107 |
} |
} |
108 |
return; |
return; |
109 |
} |
} |
159 |
if ($webpac->save_html( $css_full_path, $t )) { |
if ($webpac->save_html( $css_full_path, $t )) { |
160 |
$c->res->output("<span>saved $css_filename, $size bytes</span>"); |
$c->res->output("<span>saved $css_filename, $size bytes</span>"); |
161 |
} else { |
} else { |
162 |
$c->res->output("<span>error saving $css_filename!</span>"); |
$c->res->output("<span class=\"error\">error saving $css_filename!</span>"); |
163 |
} |
} |
164 |
return; |
return; |
165 |
} |
} |
184 |
|
|
185 |
$c->log->debug('record params '.Dumper($c->req->params)); |
$c->log->debug('record params '.Dumper($c->req->params)); |
186 |
|
|
187 |
my $mfn = $c->req->params->{mfn}; |
my $record_uri = $c->req->params->{record_uri}; |
188 |
|
$record_uri ||= $c->config->{editor}->{default_record_uri} and |
189 |
if (! $mfn) { |
$c->log->warn("using editor: default_record_uri"); |
190 |
$c->log->warn("no mfn, using 1"); |
|
191 |
$mfn = 1; |
if (! $record_uri) { |
192 |
|
$c->log->fatal("record called without record_uri and default_record_uri not found in config under editor"); |
193 |
|
$c->stash->{error} = 'record retrival failed'; |
194 |
|
$c->stash->{template} = 'error.tt'; |
195 |
|
return; |
196 |
} |
} |
197 |
|
|
198 |
my $template_filename = $c->req->params->{template_filename}; |
my $template_filename = $c->req->params->{template_filename}; |
203 |
|
|
204 |
my $webpac = $c->comp('Model::WebPAC'); |
my $webpac = $c->comp('Model::WebPAC'); |
205 |
|
|
206 |
my $html = $webpac->record( mfn => $mfn, template => $template_filename ); |
my $html = $webpac->record( record_uri => $record_uri, template => $template_filename ); |
207 |
|
|
208 |
if ($html) { |
if ($html) { |
209 |
$c->log->debug('check html with tidy'); |
$c->log->debug('check html with tidy'); |
245 |
} else { |
} else { |
246 |
$html .= qq{<div class="tidy tidy_error">Can't parse this record with HTML Tidy!</div>}; |
$html .= qq{<div class="tidy tidy_error">Can't parse this record with HTML Tidy!</div>}; |
247 |
} |
} |
248 |
|
} else { |
249 |
|
$html .= qq{<div class="no_results">Can't find record</div>}; |
250 |
} |
} |
251 |
|
|
|
|
|
252 |
$c->response->content_type('text/html; charset=utf-8'); |
$c->response->content_type('text/html; charset=utf-8'); |
253 |
$c->res->output( $html ); |
$c->response->body( $html ); |
254 |
} |
} |
255 |
|
|
256 |
|
|