-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kieren Diment
committed
Nov 8, 2010
1 parent
b236755
commit 966f5e1
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package Text::TranscriptMiner::Web::Controller::Annotate; | ||
use warnings; | ||
use strict; | ||
use parent 'Catalyst::Controller'; | ||
use Text::TranscriptMiner::Corpus::Comparisons; | ||
|
||
sub index :Path :Args(0) { | ||
my ($self, $c) = @_; | ||
my $model = Text::TranscriptMiner::Corpus::Comparisons->new({start_dir => $c->config->{start_dir}}); | ||
my $code_tree = $model->get_code_structure(); | ||
$c->stash( code_tree => $code_tree, | ||
groups => $model->groups, | ||
); | ||
} | ||
|
||
sub annotate :Path :Args(1) { | ||
my ($self, $c, $code) = @_; | ||
my $groups = []; | ||
foreach my $p (keys %{$c->req->params}) { | ||
next unless $p =~ /^\d+$/; | ||
$groups->[$p] = $c->req->params->{$p}; | ||
$groups->[$p] = [$groups->[$p]] if ! ref($groups->[$p]); | ||
} | ||
my $paths = [ ]; | ||
get_paths($groups, $paths); | ||
my $model = Text::TranscriptMiner::Corpus::Comparisons-> | ||
new({start_dir => $c->config->{start_dir}}); | ||
my @results; | ||
foreach my $p (@$paths) { | ||
my $item = {}; | ||
$item->{path} = $p; | ||
$item->{code} = $code; | ||
$item->{result} = $model->get_results_for_node([$code, @$p]); | ||
push @results, $item; | ||
} | ||
$c->stash( groups => $groups, | ||
paths => $paths, | ||
code => $code, | ||
results => \@results, | ||
); | ||
} | ||
|
||
|
||
sub do_annotate :Path('do_annotate') :Args(0) { | ||
my ($self, $c) = @_; | ||
use YAML; | ||
my $file = $c->req->params->{file}; | ||
my $notes = $c->req->params->{notes}; | ||
my $code = $c->req->params->{code}; | ||
my $model = Text::TranscriptMiner::Corpus::Comparisons-> | ||
new({start_dir => $c->config->{start_dir}}); | ||
my $response = $model->write_notes($file, $notes, $code); | ||
$c->res->body('response'); | ||
} | ||
|
||
sub get_paths { | ||
my ($groups, $paths, @path_elements) = @_; | ||
my $level = @path_elements; | ||
my ($current, @remaining) = @$groups; | ||
for my $d (@$current){ | ||
if (@remaining){ | ||
get_paths(\@remaining, $paths, @path_elements, $d); | ||
} | ||
else { | ||
push @$paths, [ @path_elements, $d]; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[% USE dumper; %] | ||
[% FOREACH r IN results %] | ||
[% IF r.result.0.txt.size > 0 %] | ||
<h4>[% r.path.join('/') %]</h4> | ||
<p><pre>[% r.result.0.txt.join("\n-----\n") %]</pre> | ||
<form action="do_annotate" method="post" name="[% r.result.0.path %]"> | ||
<input type="hidden" name="file" value="[% r.result.0.path %]"> | ||
<input type="hidden" name="code" value="[% code %]"> | ||
<textarea name="notes" style="height: 10em; width: 72em | ||
[%- IF r.result.0.notes.status == 'outdated'; %]class="outdated"[% END -%] | ||
"> [% r.result.0.notes.notes %] </textarea> | ||
<br><input type="submit" value = "Save Notes"> | ||
</p> | ||
</form> | ||
<hr><br> | ||
[% END %] | ||
[% END %] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[% PROCESS annotate/menu.tt %] | ||
[% render_menu(code_tree); %] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[% MACRO render_menu(corpus) BLOCK -%] | ||
<ul id="tree"> | ||
[% render_submenu(corpus) %] | ||
</div> | ||
[% END %] | ||
|
||
[%- MACRO render_submenu(node) BLOCK -%] | ||
[%- FOREACH item IN node.getAllChildren -%] | ||
[% NEXT IF item.getNodeValue == "descr.txt" %] | ||
<li> [% print_metadata(node) %] | ||
[% IF item.getAllChildren.size %] <ul> [% render_submenu(item) %] </ul> [% END %] </li> | ||
[%- END -%] | ||
[%- END -%] | ||
</ul> | ||
|
||
[% MACRO print_metadata(node) BLOCK -%] | ||
[% FOREACH i IN item.getAllChildren %] | ||
<li id="[% i.getNodeValue() %]"><h3>[% i.getMetaDataFor('description') %]</h3> | ||
<form action="[% c.uri_for(annotate_code, i.getNodeValue()) %]" method="get"> | ||
[% FOREACH group IN groups; SET row = loop.index %] | ||
[% FOREACH g IN group %] | ||
<input type="checkbox" name="[% row %]" value="[% g %]">[% g %]</input> | ||
[% END %] | ||
<br> | ||
[% END %] | ||
<input type="submit" value="Annotate '[% i.getMetaDataFor('description') %]'"> | ||
</li> | ||
[% END %] | ||
[% END %] | ||
|