/
PlateEdit.pm
111 lines (82 loc) · 2.71 KB
/
PlateEdit.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
99
100
101
102
103
104
105
106
107
108
109
110
111
package LIMS2::WebApp::Controller::User::PlateEdit;
use Moose;
use namespace::autoclean;
use Try::Tiny;
BEGIN {extends 'Catalyst::Controller'; }
=head1 NAME
LIMS2::WebApp::Controller::User::PlateEdit - Catalyst Controller
=head1 DESCRIPTION
Catalyst Controller.
=head1 METHODS
=cut
sub begin :Private {
my ( $self, $c ) = @_;
unless ( $c->request->params->{id} ) {
$c->flash->{error_msg} = 'No plate_id specified';
$c->res->redirect( $c->uri_for('/user/browse_plates') );
return;
}
$c->assert_user_roles( 'edit' );
return;
}
sub index :Path( '/user/edit_plate' ) :Args(0) {
my ( $self, $c ) = @_;
my $plate = $c->model('Golgi')->retrieve_plate( $c->request->params );
$c->stash(
plate => $plate,
);
return;
}
sub delete_plate :Path( '/user/delete_plate' ) :Args(0) {
my ( $self, $c ) = @_;
my $params = $c->request->params;
$c->model('Golgi')->txn_do(
sub {
try{
$c->model('Golgi')->delete_plate( { id => $params->{id} } );
$c->flash->{success_msg} = 'Deleted plate ' . $params->{name};
$c->res->redirect( $c->uri_for('/user/browse_plates') );
}
catch {
$c->flash->{error_msg} = 'Error encountered while deleting plate: ' . $_;
$c->model('Golgi')->txn_rollback;
$c->res->redirect( $c->uri_for('/user/view_plate', { id => $params->{id} }) );
};
}
);
}
sub rename_plate :Path( '/user/rename_plate' ) :Args(0) {
my ( $self, $c ) = @_;
my $params = $c->request->params;
unless ( $params->{new_name} ) {
$c->flash->{error_msg} = 'You must specify a new plate name';
$c->res->redirect( $c->uri_for('/user/view_plate', { id => $params->{id} }) );
return;
}
$c->model('Golgi')->txn_do(
sub {
try{
$c->model('Golgi')->rename_plate(
{ id => $params->{id},
new_name => $params->{new_name}
}
);
$c->flash->{success_msg} = 'Renamed plate from ' . $params->{name}
. ' to ' . $params->{new_name};
}
catch {
$c->flash->{error_msg} = 'Error encountered while renaming plate: ' . $_;
$c->model('Golgi')->txn_rollback;
};
}
);
$c->res->redirect( $c->uri_for('/user/view_plate', { id => $params->{id} }) );
}
=head1 AUTHOR
Sajith Perera
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
__PACKAGE__->meta->make_immutable;
1;