-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathInstrument.pm
71 lines (58 loc) · 1.95 KB
/
Instrument.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
=head1 NAME
Tuba::Instrument : Controller class for instruments.
=cut
package Tuba::Instrument;
use Tuba::DB::Objects qw/-nicknames/;
use Mojo::Base qw/Tuba::Controller/;
=head1 ROUTES
=head1 show
Show metadata about a instrument.
=cut
sub show {
my $c = shift;
my $identifier = $c->stash('instrument_identifier');
my $meta = Instrument->meta;
my $object = Instrument->new( identifier => $identifier ) ->load( speculative => 1 )
or return $c->reply->not_found;
$c->stash(object => $object);
$c->stash(meta => $meta);
$c->SUPER::show(@_);
}
sub make_tree_for_show {
my $c = shift;
my $instrument = shift;
my $obj = $c->SUPER::make_tree_for_show($instrument, @_);
$obj->{platforms} = [
map +{
uri => "/platform/".$_->identifier,
identifier => $_->identifier,
name => $_->name,
description => $_->description,
description_attribution => $_->description,
}, $instrument->platforms
];
return $obj;
}
sub update_rel_form {
my $c = shift;
$c->stash(relationships => [ map Instrument->meta->relationship($_), qw/platforms/ ]);
$c->stash(controls => {
platforms => { template => 'many_to_many' },
});
$c->SUPER::update_rel_form(@_);
}
sub update_rel {
my $c = shift;
my $instrument = $c->_this_object;
$c->stash(tab => "update_rel_form");
if (my $platform_id = $c->param('delete_map_platforms')) {
my $map = Tuba::DB::Object::InstrumentInstance->new(
platform_identifier => $platform_id,
instrument_identifier => $instrument->identifier)->load(
speculative => 1) or return $c->redirect_without_error("Could not find $platform_id");
$map->delete(audit_user => $c->audit_user, audit_note => $c->audit_note) or return $c->update_error($map->error);
$c->flash(info => "Deleted $platform_id");
}
return $c->SUPER::update_rel(@_);
}
1;