Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIMS-261: Allow download of PDB files #857

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
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) {
})


})
})
Loading