diff --git a/api/src/Page/Download.php b/api/src/Page/Download.php index 9f9794d20..f15095db1 100644 --- a/api/src/Page/Download.php +++ b/api/src/Page/Download.php @@ -35,6 +35,7 @@ class Download extends Page 'ppl' => '\w+', 'aid' => '\w+', + 'cid' => '\d+', 'filetype' => '\w+', 'blsampleid' => '\d+', @@ -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'), @@ -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 diff --git a/client/src/js/modules/shipment/views/containerplate.js b/client/src/js/modules/shipment/views/containerplate.js index 87980a4c4..359c3805c 100644 --- a/client/src/js/modules/shipment/views/containerplate.js +++ b/client/src/js/modules/shipment/views/containerplate.js @@ -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', @@ -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') diff --git a/client/src/js/templates/shipment/containerplateimage.html b/client/src/js/templates/shipment/containerplateimage.html index b784387c7..7b14e20fb 100644 --- a/client/src/js/templates/shipment/containerplateimage.html +++ b/client/src/js/templates/shipment/containerplateimage.html @@ -173,21 +173,23 @@

Plate Details

<% } %> - <% if (IMAGERID) { %>
  • Actions - +
    + <% if (IMAGERID) { %>
    -
    +

    + <% } %> +
    Download Dispensing CSV
  • - <% } %> +
  • Location History