-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathImage.pm
99 lines (82 loc) · 2.64 KB
/
Image.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
=head1 NAME
Tuba::Image : Controller class for images.
=cut
package Tuba::Image;
use Mojo::Base qw/Tuba::Controller/;
use File::Temp;
use YAML::XS qw/DumpFile LoadFile/;
use Path::Class qw/file dir/;
use File::Basename qw/basename/;
use Tuba::Log;
use Tuba::DB::Objects qw/-nicknames/;
use Tuba::Util qw[new_uuid];
=head1 ROUTES
=head1 show
Show metadata about an image.
=cut
sub show {
my $c = shift;
my $identifier = $c->stash('image_identifier');
my $meta = Image->meta;
my $object = Image->new( identifier => $identifier )
->load( speculative => 1, with => [qw/figures/] )
or return $c->render_not_found_or_redirect;
$c->stash(object => $object);
$c->stash(meta => $meta);
$c->SUPER::show(@_);
}
sub update_rel_form {
my $c = shift;
$c->stash(relationships => [ map Image->meta->relationship($_), qw/figures/ ]);
$c->stash(controls => {
figures => sub {
my ($c,$obj) = @_;
+{ template => 'figure', params => { no_thumbnails => 1 } }
},
});
$c->SUPER::update_rel_form(@_);
}
sub update_rel {
my $c = shift;
my $object = $c->_this_object or return $c->reply->not_found;
$object->meta->error_mode('return');
$c->stash(object => $object);
$c->stash(meta => $object->meta);
if (my $new = $c->param('new_figure')) {
my $img = $c->Tuba::Search::autocomplete_str_to_object($new);
$object->add_figures($img);
$object->save(audit_user => $c->audit_user, audit_note => $c->audit_note) or do {
$c->flash(error => $object->error);
return $c->update_rel_form(@_);
};
}
for my $id ($c->param('delete_figure')) {
ImageFigureMaps->delete_objects(
where => [{figure_identifier => $id, image_identifier => $object->identifier}],
audit_user => $c->audit_user, audit_note => $c->audit_note);
$c->flash(message => 'Saved changes');
}
return $c->SUPER::update_rel(@_);
}
sub create_form {
my $c = shift;
$c->param(identifier => new_uuid());
return $c->SUPER::create_form(@_);
}
sub list {
my $c = shift;
my $report = $c->stash('report_identifier') or return $c->SUPER::list(@_);
my $all = $c->param('all');
my @page = $all ? () : (page => $c->page, per_page => $c->per_page);
$c->stash(objects => Images->get_objects(
query => [report_identifier => $report ],
require_objects => [qw/figures/],
@page
));
$c->set_pages( Images->get_objects_count(
query => [report_identifier => $report ],
require_objects => [qw/figures/],
));
return $c->SUPER::list(@_);
}
1;