Skip to content

Commit

Permalink
LIMS-261: Allow download of PDB files (#857)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
ndg63276 and Mark Williams authored Nov 12, 2024
1 parent d19fb86 commit 37dd413
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
16 changes: 16 additions & 0 deletions api/src/Page/Sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class Sample extends Page
array('/pdbs(/pid/:pid)', 'get', '_get_pdbs'),
array('/pdbs', 'post', '_add_pdb'),
array('/pdbs(/:pdbid)', 'delete', '_remove_pdb'),
array('/pdbs/download/:pdbid', 'get', '_download_pdb'),

array('/concentrationtypes', 'get', '_concentration_types'),
array('/componenttypes', 'get', '_component_types'),
Expand Down Expand Up @@ -2062,6 +2063,21 @@ function _get_pdbs()
$this->_output($rows);
}

# ------------------------------------------------------------------------
# Download a pdb file
function _download_pdb()
{
if (!$this->has_arg('pdbid'))
$this->_error('No PDB id specified');

$pdb = $this->db->pq("SELECT name, contents FROM pdb WHERE pdbid = :1", array($this->arg('pdbid')));
$pdb = $pdb[0];

header('Content-Type:text/plain');
header('Content-Disposition:attachment;filename='.$pdb['NAME']);
print $pdb['CONTENTS'];
}

# ------------------------------------------------------------------------
# Add a new pdb
function _add_pdb()
Expand Down
23 changes: 18 additions & 5 deletions client/src/js/modules/samples/views/pdbs.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
define(['marionette'], function(Marionette) {
define(['marionette', 'utils'], function(Marionette, utils) {


var UserItem = Marionette.ItemView.extend({
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>'),
template: _.template(''),
tagName: 'li',
attributes: { 'data-testid': 'protein-pdb-list-item' },
events: {
'click a.delete': 'deleteUser',
'click a.delete': 'deletePDB',
'click a.download': utils.signHandler,
},

deleteUser: function(e) {
render: function() {
UserItem.__super__.render.call(this)
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>'
const deleteButton = '<a class="button button-notext delete" href="#"><i class="fa fa-times"></i> <span>Delete</span></a>'
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>'
if (this.model.get('CODE')) {
this.$el.append(this.model.get('NAME')+' [Code] <span class="r">'+linkButton+' '+deleteButton+'</span>')
} else {
this.$el.append(this.model.get('NAME')+' [File] <span class="r">'+downloadButton+' '+deleteButton+'</span>')
}
},

deletePDB: function(e) {
this.model.destroy()
},
})
Expand All @@ -30,4 +43,4 @@ define(['marionette'], function(Marionette) {
})


})
})

0 comments on commit 37dd413

Please sign in to comment.