Skip to content

Commit 37dd413

Browse files
ndg63276Mark Williams
andauthored
LIMS-261: Allow download of PDB files (#857)
* LIMS-261: Allow download of PDB files * LIMS-261: Use RCSB for links * LIMS-261: Use EBI instead of RCSB --------- Co-authored-by: Mark Williams <[email protected]>
1 parent d19fb86 commit 37dd413

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

api/src/Page/Sample.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class Sample extends Page
195195
array('/pdbs(/pid/:pid)', 'get', '_get_pdbs'),
196196
array('/pdbs', 'post', '_add_pdb'),
197197
array('/pdbs(/:pdbid)', 'delete', '_remove_pdb'),
198+
array('/pdbs/download/:pdbid', 'get', '_download_pdb'),
198199

199200
array('/concentrationtypes', 'get', '_concentration_types'),
200201
array('/componenttypes', 'get', '_component_types'),
@@ -2062,6 +2063,21 @@ function _get_pdbs()
20622063
$this->_output($rows);
20632064
}
20642065

2066+
# ------------------------------------------------------------------------
2067+
# Download a pdb file
2068+
function _download_pdb()
2069+
{
2070+
if (!$this->has_arg('pdbid'))
2071+
$this->_error('No PDB id specified');
2072+
2073+
$pdb = $this->db->pq("SELECT name, contents FROM pdb WHERE pdbid = :1", array($this->arg('pdbid')));
2074+
$pdb = $pdb[0];
2075+
2076+
header('Content-Type:text/plain');
2077+
header('Content-Disposition:attachment;filename='.$pdb['NAME']);
2078+
print $pdb['CONTENTS'];
2079+
}
2080+
20652081
# ------------------------------------------------------------------------
20662082
# Add a new pdb
20672083
function _add_pdb()

client/src/js/modules/samples/views/pdbs.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
define(['marionette'], function(Marionette) {
1+
define(['marionette', 'utils'], function(Marionette, utils) {
22

33

44
var UserItem = Marionette.ItemView.extend({
5-
template: _.template('<%-NAME%> <% if (CODE) { %>[CODE]<% } else { %>[File]<% } %> <span class="r"><a class="button button-notext delete" href="#"><i class="fa fa-times"></i> <span>Delete</span></a></span>'),
5+
template: _.template(''),
66
tagName: 'li',
77
attributes: { 'data-testid': 'protein-pdb-list-item' },
88
events: {
9-
'click a.delete': 'deleteUser',
9+
'click a.delete': 'deletePDB',
10+
'click a.download': utils.signHandler,
1011
},
1112

12-
deleteUser: function(e) {
13+
render: function() {
14+
UserItem.__super__.render.call(this)
15+
const linkButton = '<a class="button button-notext" href="https://www.ebi.ac.uk/pdbe/entry/pdb/'+this.model.get('CODE')+'"><i class="fa fa-link"></i> <span>EBI</span></a>'
16+
const deleteButton = '<a class="button button-notext delete" href="#"><i class="fa fa-times"></i> <span>Delete</span></a>'
17+
const downloadButton = '<a class="button button-notext download" href="'+app.apiurl+'/sample/pdbs/download/'+this.model.get('PDBID')+'"><i class="fa fa-download"></i> <span>Download</span></a>'
18+
if (this.model.get('CODE')) {
19+
this.$el.append(this.model.get('NAME')+' [Code] <span class="r">'+linkButton+' '+deleteButton+'</span>')
20+
} else {
21+
this.$el.append(this.model.get('NAME')+' [File] <span class="r">'+downloadButton+' '+deleteButton+'</span>')
22+
}
23+
},
24+
25+
deletePDB: function(e) {
1326
this.model.destroy()
1427
},
1528
})
@@ -30,4 +43,4 @@ define(['marionette'], function(Marionette) {
3043
})
3144

3245

33-
})
46+
})

0 commit comments

Comments
 (0)