Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions api/src/Page/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Download extends Page

'ppl' => '\w+',
'aid' => '\w+',
'cid' => '\d+',

'filetype' => '\w+',
'blsampleid' => '\d+',
Expand All @@ -49,6 +50,7 @@ class Download extends Page
public static $dispatch = array(
array('/plots', 'get', '_auto_processing_plots'),
array('/csv/visit/:visit', 'get', '_csv_report'),
array('/csv/container/:cid', 'get', '_dispensing_csv'),
array('/sign', 'post', '_sign_url'),
array('/data/visit/:visit', 'get', '_download_visit'),
array('/attachments', 'get', '_get_attachments'),
Expand Down Expand Up @@ -317,6 +319,52 @@ function _csv_report()
}
}

# ------------------------------------------------------------------------
# CSV Report of dispensing positions for a plate
function _dispensing_csv()
{
if (!$this->has_arg('cid'))
$this->_error('No container id specified');
$rows = $this->db->pq("SELECT c.code, s.location, ct.name, ct.capacity, ct.wellperrow,
bsp.posx, bsp.posy, si.imagefullpath, si.micronsperpixelx, si.micronsperpixely
FROM blsample s
INNER JOIN container c ON c.containerid = s.containerid
INNER JOIN blsampleimage si ON si.blsampleid = s.blsampleid
LEFT OUTER JOIN containertype ct ON (c.containertypeid IS NOT NULL AND c.containertypeid = ct.containertypeid) OR (c.containertypeid IS NULL AND c.containertype = ct.name)
LEFT OUTER JOIN
(SELECT * FROM blsampleposition bsp1 WHERE bsp1.blsamplepositionid =
(SELECT MAX(blsamplepositionid) FROM blsampleposition bsp2 WHERE bsp2.blsampleid = bsp1.blsampleid AND bsp2.positiontype='dispensing')
) bsp ON bsp.blsampleid = s.blsampleid
WHERE c.containerid=:1
ORDER BY s.location+0",
array($this->arg('cid')));
$plate = $rows[0];
$rowNames = range("A", "H");
$dropNames = range("a", "z");
// SWISSCI 3 Drop have drops a/c/d
if ($plate["NAME"] == "SWISSCI 3 Drop") {
$dropNames = array_merge(array("a"), range("c","z"));
}
$dropsPerWell = $plate["CAPACITY"] / (count($rowNames) * $plate["WELLPERROW"]);
$this->app->response->headers->set("Content-type", "text/csv");
$this->_set_disposition_attachment($this->app->response, $plate["CODE"] . "_targets.csv");
list($width, $height, $type, $attr) = getimagesize($plate['IMAGEFULLPATH']);
foreach ($rows as $r) {
if (!isset($r["POSX"]) || !isset($r["POSY"])) {
continue; # skip empty rows
}
$wellNumber = intval(($r["LOCATION"] - 1) / $dropsPerWell); # 0 indexed
$rowNumber = intval($wellNumber / $plate["WELLPERROW"]); # 0 indexed
$row = $rowNames[$rowNumber];
$column = str_pad($wellNumber - ($rowNumber * $plate["WELLPERROW"]) + 1, 2, 0, STR_PAD_LEFT); # pad with a zero if needed
$dropNumber = intval($r["LOCATION"] - ($dropsPerWell * $wellNumber)); # 1 indexed
$drop = $dropNames[$dropNumber-1];
$xval = round(($r["POSX"] - $width/2) * $r["MICRONSPERPIXELX"]); # integers
$yval = round(($height/2 - $r["POSY"]) * $r["MICRONSPERPIXELY"]); # integers
print $row . $column . $drop . "," . $xval . "," . $yval . "\n";
}
}


# ------------------------------------------------------------------------
# Get dc attachmmnts
Expand Down
28 changes: 28 additions & 0 deletions client/src/js/modules/shipment/views/containerplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ define(['marionette',
'click @ui.adr': 'setAddSubsampleRegion',
'click @ui.addis': 'setAddDispensing',
'click @ui.deldis': 'deleteDispensing',
'click a.csv_dispensing': 'downloadDispensingCSV',
'click a.add_inspection': 'showAddInspection',
'click a.view_sched': 'showViewSchedule',
'click @ui.play': 'playInspection',
Expand Down Expand Up @@ -309,6 +310,33 @@ define(['marionette',
'change:QUEUED': 'updatedQueued',
},

downloadDispensingCSV: function(e) {
e.preventDefault()
this.signHandler(app.apiurl+'/download/csv/container/'+this.model.get('CONTAINERID'));
},

signHandler(url) {
this.sign({
url: url,
callback: function(resp) {
window.location = url+'?token='+resp.token
}
})
},

sign(options) {
Backbone.ajax({
url: app.apiurl+'/download/sign',
method: 'POST',
data: {
validity: options.url.replace(app.apiurl, ''),
},
success: function(resp) {
if (options && options.callback) options.callback(resp)
}
})
},

setSampleStatusShown: function() {

const showCurrentScore = this.ui.sampleStatusCurrent.is(':checked')
Expand Down
10 changes: 6 additions & 4 deletions client/src/js/templates/shipment/containerplateimage.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,23 @@ <h1 class="no_mobile">Plate Details</h1>
</li>
<% } %>

<% if (IMAGERID) { %>
<li class="clearfix">
<span class="label">Actions</span>

<div class="text_table">
<% if (IMAGERID) { %>
<div class="queue"></div>

<div>
<select name="INSPECTIONTYPEID"></select>
<span class="adhoc"></span>
</div>
<div class="return"></div>
<div class="return"></div><br />
<% } %>
<div><a href="#" class="button csv_dispensing"><i class="fa fa-file-o"></i> <span>Download Dispensing CSV</span></a></div>
</div>
</li>
<% } %>


<li class="clearfix">
<span class="label tw-align-top">Location History</span>
Expand Down
Loading