Skip to content

Commit

Permalink
user can now flag crispr primers as validated too
Browse files Browse the repository at this point in the history
  • Loading branch information
af11-sanger committed Jan 7, 2015
1 parent ada11af commit b24c9d3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
5 changes: 3 additions & 2 deletions lib/LIMS2/Report/AssemblyPlate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ sub _build_crispr_primers {
foreach my $crispr_data (values %{ $self->well_crisprs_data }){
my $crispr = $crispr_data->{obj};
my $crispr_type = $crispr_data->{type};
my $key = $crispr->id . "(" . $crispr_type . ")";
my $key = $crispr->id . " (" . $crispr_type . ")";
foreach my $primer ($crispr->crispr_primers->all){
next if $primer->is_rejected;
push @{ $crispr_primers->{$key} },
{ type => $primer->primer_name, is_validated => $primer->is_validated };
{ type => $primer->primer_name->primer_name, is_validated => $primer->is_validated };
}
}
return $crispr_primers;
Expand Down Expand Up @@ -210,6 +210,7 @@ override structured_data => sub {
my $data;
$data->{plate_type} = "ASSEMBLY";
$data->{genotyping_primers} = $self->genotyping_primers;
$data->{crispr_primers} = $self->crispr_primers;
return $data;
};

Expand Down
18 changes: 12 additions & 6 deletions lib/LIMS2/WebApp/Controller/User/Primers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,27 @@ sub toggle_crispr_primer_validation_state : Path( '/user/toggle_crispr_primer_va

$c->assert_user_roles('edit');

my $crispr_id = $c->request->param('crispr_id');
my $crispr_pair_id = $c->request->param('crispr_pair_id');
my $primer_type = $c->request->param('primer_type');

my $search = {
primer_name => $primer_type,
is_rejected => [ 0, undef ],
};

if($crispr_id){
$search->{crispr_id} = $crispr_id;
my $crispr_key = $c->request->param('crispr_key');
my ($id,$type) = ($crispr_key =~ / (\d*) \s* \( (\w*) \) /ixms);

unless ($id and $type){
$c->stash->{json_data} = { error => "Could not identify crispr ID and type in string $crispr_key" };
$c->forward('View::JSON');
return;
}

if($crispr_pair_id){
$search->{crispr_pair_id} = $crispr_pair_id;
if($type eq "crispr"){
$search->{crispr_id} = $id;
}
elsif($type eq "crispr_pair"){
$search->{crispr_pair_id} = $id;
}

my $primer = $c->model('Golgi')->schema->resultset('CrisprPrimer')->find($search);
Expand Down
65 changes: 36 additions & 29 deletions root/site/user/report/simple_table.tt
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,47 @@
var not_valid_label = '<span class="label label-default validation-status pull-right">Not Validated</span>';
var button_html = '<button class="btn btn-mini">Change validation state</button>';

[% FOREACH design_id IN extra_data.genotyping_primers.keys %]
console.log('[% design_id %]');
[% FOREACH primer IN extra_data.genotyping_primers.$design_id %]
var cell = getCell('[% primer.type %]','Design ID','[% design_id %]');
[% genotyping = { hash_element => 'genotyping_primers', key_column => 'Design ID', key_param => 'design_id', url => '/user/toggle_genotyping_primer_validation_state' } %]

// add the validation state toggle button, ajax reqest and callback
$(button_html).appendTo(cell).click(function(e){
console.log('button has been clicked');
var this_cell = $(this).parent();
var uri = "[% c.uri_for('/user/toggle_genotyping_primer_validation_state',{ design_id => design_id, primer_type => primer.type })%]";
$.ajax(uri).done(function(data){
console.log(data);
if(data.success){
this_cell.children('.validation-status').remove();
if(data.is_validated == 1){
console.log("new state: validated");
this_cell.append(valid_label);
}
else{
console.log("new state: not validated");
this_cell.append(not_valid_label);
[% crispr = { hash_element => 'crispr_primers', key_column => 'Crispr ID', key_param => 'crispr_key', url => '/user/toggle_crispr_primer_validation_state' } %]

[% FOREACH profile IN [genotyping,crispr] %]

[% hash_element = profile.hash_element %]
[% url = profile.url %]
[% key_param = profile.key_param %]

[% FOREACH key IN extra_data.$hash_element.keys %]
[% FOREACH primer IN extra_data.$hash_element.$key %]
var cell = getCell('[% primer.type %]','[% profile.key_column %]','[% key %]');

// add the validation state toggle button, ajax reqest and callback
$(button_html).appendTo(cell).click(function(e){
var this_cell = $(this).parent();
var uri = "[% c.uri_for( url, { $key_param => key, primer_type => primer.type })%]";
$.ajax(uri).done(function(data){
console.log(data);
if(data.success){
this_cell.children('.validation-status').remove();
if(data.is_validated == 1){
this_cell.append(valid_label);
}
else{
this_cell.append(not_valid_label);
}
}
}
// if not successful we change nothing..
// if not successful we change nothing..
});
});
});

// add initial validation status label
[% IF primer.is_validated %]
cell.append(valid_label);
[% ELSE %]
cell.append(not_valid_label);
[% END %]
// add initial validation status label
[% IF primer.is_validated %]
cell.append(valid_label);
[% ELSE %]
cell.append(not_valid_label);
[% END %]

[% END %]
[% END %]
[% END %]
[% END %]
Expand Down

0 comments on commit b24c9d3

Please sign in to comment.