-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlateUpload.pm
110 lines (79 loc) · 2.68 KB
/
PlateUpload.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
package LIMS2::WebApp::Controller::User::PlateUpload;
use Moose;
use namespace::autoclean;
use Try::Tiny;
BEGIN {extends 'Catalyst::Controller'; }
=head1 NAME
LIMS2::WebApp::Controller::UI::PlateUpload - Catalyst Controller
=head1 DESCRIPTION
Catalyst Controller.
=head1 METHODS
=cut
sub begin :Private {
my ( $self, $c ) = @_;
$c->assert_user_roles( 'edit' );
}
sub plate_upload_step1 :Path( '/user/plate_upload_step1' ) :Args(0) {
my ( $self, $c ) = @_;
my @process_types = map{ $_->id } @{ $c->model('Golgi')->list_process_types };
$c->stash(
process_types => [ grep{ !/create_di/ } @process_types ],
);
}
sub plate_upload_step2 :Path( '/user/plate_upload_step2' ) :Args(0) {
my ( $self, $c ) = @_;
my $process_type = $c->request->params->{process_type};
unless ( $process_type ) {
$c->flash->{error_msg} = 'You must specify a process type';
return $c->res->redirect('/user/plate_upload_step1');
}
$c->stash(
process_type => $process_type,
process_fields => $c->model('Golgi')->get_process_fields( { process_type => $process_type } ),
plate_types => $c->model('Golgi')->get_process_plate_types( { process_type => $process_type } ),
);
return;
}
sub plate_upload_complete :Path( '/user/plate_upload_complete' ) :Args(0) {
my ( $self, $c ) = @_;
$c->stash( $c->request->params );
my $params = $c->request->params;
my $well_data = $c->request->upload('datafile');
unless ( $well_data ) {
$c->stash->{error_msg} = 'No csv file with well data specified';
$c->go( 'plate_upload_step2' );
}
unless ( $params->{plate_name} ) {
$c->stash->{error_msg} = 'Must specify a plate name';
$c->go( 'plate_upload_step2' );
}
unless ( $params->{plate_type} ) {
$c->stash->{error_msg} = 'Must specify a plate type';
$c->go( 'plate_upload_step2' );
}
$params->{species} ||= $c->session->{selected_species};
$params->{created_by} = $c->user->name;
my $plate;
$c->model('Golgi')->txn_do(
sub {
try{
$plate = $c->model('Golgi')->create_plate_csv_upload( $params, $well_data->fh );
}
catch {
$c->stash->{error_msg} = 'Error encountered while creating plate: ' . $_;
$c->go( 'plate_upload_step2' );
$c->model('Golgi')->txn_rollback;
};
}
);
#TODO clear stash
$c->stash->{plate} = $plate;
}
=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;