refactor smid edit interface.
[SMMID.git] / lib / SMMID / Controller / SMID.pm
blob67025c58b4dd73c7d0727e1ae52d15b307815cd5
2 package SMMID::Controller::SMID;
4 use Moose;
6 BEGIN { extends 'Catalyst::Controller'; }
9 sub browse :Path('/browse') Args(0) {
10 my $self = shift;
11 my $c = shift;
14 sub curator :Path('/curator') Args(0) {
15 my $self = shift;
16 my $c = shift;
19 sub smid :Chained('/') PathPart('smid') CaptureArgs(1) {
20 my $self = shift;
21 my $c = shift;
22 $c->stash->{compound_id} = shift;
25 sub detail :Chained('smid') PathPart('') Args(0) {
26 my $self = shift;
27 my $c = shift;
29 if ($c->user()) { $c->stash->{login_user} = $c->user()->get_object->dbuser_id(); }
30 $c->stash->{template} = '/smid/detail.mas';
33 # compatibility with old site
34 sub smid_old : Chained('/') PathPart('detail') Args(1) {
35 my $self = shift;
36 my $c = shift;
37 my $smid_id = shift;
39 # google links sometimes have windows like end characters... remove!
40 $smid_id =~ s/\r//g;
41 chomp($smid_id);
43 print STDERR "SMID ID = |$smid_id|\n";
45 my $row = $c->model('SMIDDB')->resultset("SMIDDB::Result::Compound")->find( { smid_id => $smid_id });
47 my $compound_id;
48 if ($row) {
49 $compound_id = $row->compound_id();
51 else {
52 $c->stash->{template} = '/message.mas';
53 $c->stash->{message} = "The specified SMID does not exist.";
54 return;
56 $c->stash->{compound_id} = $compound_id;
58 if ($c->user()) { $c->stash->{login_user} = $c->user()->get_object->dbuser_id(); }
59 $c->stash->{template} = '/smid/detail.mas';
62 sub add :Path('/smid') Args(0) {
63 my $self = shift;
64 my $c = shift;
66 $c->stash->{action} = 'new';
67 $c->stash->{compound_id} = 0;
68 if ($c->user()) { $c->stash->{login_user} = $c->user()->get_object->dbuser_id(); }
69 $c->stash->{template} = '/smid/detail.mas';
73 sub edit :Chained('smid') PathPart('edit') Args(0) {
74 my $self = shift;
75 my $c = shift;
77 $c->stash->{action} = "edit";
78 if ($c->user()) { $c->stash->{login_user} = $c->user()->get_object->dbuser_id(); }
79 $c->stash->{template} = '/smid/detail.mas';
82 sub add_image :Chained('smid') PathPart('image') Args(0) {
83 my $self = shift;
84 my $c = shift;
86 my $rs = $c->model("SMIDDB")->resultset("SMIDDB::Result::CompoundImage")->search( { compound_id => $c->stash->{compound_id} });
88 my @image_ids;
89 while (my $row = $rs->next()) {
90 push @image_ids, $row->image_id();
93 $c->stash->{image_ids} = \@image_ids;
94 $c->stash->{template} = '/image/index.mas';
98 'SMMID::Controller::SMID';