Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,7 @@
$dials_rest_url = "";
$dials_rest_jwt = "";
$dials_rest_url_rings = false;

# Add a button to upload file to CCP4 cloud
#$ccp4_cloud_upload_url = 'https://data.cloud.ccp4.ac.uk/api/data/<%=USERNAME%>/<%=FACILITYNAME%>/<%=IMAGEPREFIX%>_<%=DATACOLLECTIONNUMBER%>/upload';
?>
3 changes: 2 additions & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function setupApplication($mode): Slim
$dhl_enable, $scale_grid, $scale_grid_end_date, $preset_proposal, $timezone,
$valid_components, $enabled_container_types, $synchweb_version, $redirects,
$shipping_service_app_url, $use_shipping_service_redirect, $use_shipping_service_redirect_incoming_shipments,
$dials_rest_url_rings, $closed_proposal_link;
$dials_rest_url_rings, $closed_proposal_link, $ccp4_cloud_upload_url;
$app->contentType('application/json');
$options = $app->container['options'];
$app->response()->body(json_encode(array(
Expand All @@ -97,6 +97,7 @@ function setupApplication($mode): Slim
'shipping_service_app_url_incoming' => $use_shipping_service_redirect_incoming_shipments ? $shipping_service_app_url : null,
'closed_proposal_link' => $closed_proposal_link,
'dials_rest_url_rings' => $dials_rest_url_rings,
'ccp4_cloud_upload_url' => $ccp4_cloud_upload_url,
'redirects' => $redirects
)));
});
Expand Down
92 changes: 82 additions & 10 deletions api/src/Page/Processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ class Processing extends Page {

array('/downstream/:id', 'get', '_downstream'),
array('/downstream/images/:aid(/n/:n)', 'get', '_downstream_images'),
array(
'/downstream/mapmodel/:aid(/n/:n)',
'get',
'_downstream_mapmodel',
),
array(
'/multiplex_jobs/groups/:blSampleGroupId',
'get',
'_get_latest_multiplex_job_result'
),
array('/downstream/mapmodel/:aid(/n/:n)', 'get', '_downstream_mapmodel'),
array('/multiplex_jobs/groups/:blSampleGroupId', 'get', '_get_latest_multiplex_job_result'),

array('/upload', 'post', '_upload_to_cloud'),
);

public static $arg_list = array(
Expand All @@ -44,6 +38,10 @@ class Processing extends Page {
'rmeas' => '[\d\.]+',
'cchalf' => '[\d\.]+',
'ccanom' => '[\d\.]+',
'username' => '(\w|\s|\-|\.)+',
'cloudrunid' => '(\w|\-)+',
'AUTOPROCPROGRAMATTACHMENTID' => '\d+',
'DATACOLLECTIONFILEATTACHMENTID' => '\d+',
);

/**
Expand All @@ -66,6 +64,80 @@ function _map_status($status) {
}
}

function _make_curl_file($file){
$mime = mime_content_type($file);
$info = pathinfo($file);
$name = $info['basename'];
$output = new \CURLFile($file, $mime, $name);
return $output;
}

function _upload_to_cloud() {
global $facility_name, $facility_short, $ccp4_cloud_upload_url;
if (!$this->has_arg('AUTOPROCPROGRAMATTACHMENTID') && !$this->has_arg('DATACOLLECTIONFILEATTACHMENTID')) {
$this->_error('No file specified');
}
if (!$this->has_arg('username')) {
$this->_error('No username specified');
}
if (!$this->has_arg('cloudrunid')) {
$this->_error('No cloudrun id specified');
}
if ($this->has_arg('AUTOPROCPROGRAMATTACHMENTID')) {
$select = ", concat(appa.filepath, '/', appa.filename) as filefullpath";
$join = "INNER JOIN processingjob pj ON dc.datacollectionid = pj.datacollectionid
INNER JOIN autoprocprogram app ON pj.processingjobid = app.processingjobid
INNER JOIN autoprocprogramattachment appa ON app.autoprocprogramid = appa.autoprocprogramid";
$where = "WHERE appa.autoprocprogramattachmentid=:1";
$args = array($this->arg('AUTOPROCPROGRAMATTACHMENTID'));
} else if ($this->has_arg('DATACOLLECTIONFILEATTACHMENTID')) {
$select = ", dcfa.filefullpath";
$join = "INNER JOIN datacollectionfileattachment dcfa ON dc.datacollectionid = dcfa.datacollectionid";
$where = "WHERE dcfa.datacollectionfileattachmentid=:1";
$args = array($this->arg('DATACOLLECTIONFILEATTACHMENTID'));
}
$dc = $this->db->pq(
"SELECT dc.imageprefix, dc.datacollectionnumber, concat(p.proposalcode, p.proposalnumber, '-', s.visit_number) as visit
$select
FROM datacollection dc
INNER JOIN blsession s ON dc.sessionid = s.sessionid
INNER JOIN proposal p ON s.proposalid = p.proposalid
$join
$where",
$args);
$dc = $dc[0];
$dc['USERNAME'] = $this->arg('username');
$dc['FACILITYNAME'] = strtolower(preg_replace( '/[\W]/', '', $facility_name));
$dc['FACILITYSHORT'] = strtolower(preg_replace( '/[\W]/', '', $facility_short));
$url = preg_replace_callback('/<%=(\w+)%>/',
function($mat) use ($dc) {
if (array_key_exists($mat[1], $dc)) {
return $dc[$mat[1]];
}
},
$ccp4_cloud_upload_url);
$ch = curl_init($url);
$headers = array('cloudrun_id: '.$this->arg('cloudrunid'));
$data = array('file' => $this->_make_curl_file($dc['FILEFULLPATH']));
curl_setopt_array(
$ch,
array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_TIMEOUT => 10,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $data,
)
);
$result = json_decode(curl_exec($ch));
curl_close($ch);
if (isset($result->error)) {
$this->_error($result);
} else {
$this->_output($result);
}
}

function _screening_status($where, $ids) {
$screenings = $this->db->pq(
"SELECT dc.datacollectionid, sc.programversion, so.indexingsuccess, so.strategysuccess, so.alignmentsuccess
Expand Down
4 changes: 4 additions & 0 deletions client/src/css/partials/_utility.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
font-weight: bold;
}

.u {
text-decoration: underline;
}

.nowrap {
white-space: nowrap;
}
Expand Down
13 changes: 12 additions & 1 deletion client/src/js/modules/dc/views/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ define(['marionette',
'views/table',
'collections/attachments',
'views/log',
'views/cloudupload',
'utils'],
function(Marionette, Backgrid, TableView, attachments, LogView, utils) {
function(Marionette, Backgrid, TableView, attachments, LogView, CloudUploadView, utils) {


var OptionsCell = Backgrid.Cell.extend({
events: {
'click a.dl': utils.signHandler,
'click a.rsv': 'closeDialog',
'click a.vatlog': 'showLog',
'click a.vatupload': 'showCloudUpload',
},

closeDialog: function() {
Expand All @@ -30,6 +32,11 @@ define(['marionette',
})
},

showCloudUpload: function(e) {
e.preventDefault()
app.dialog.show(new CloudUploadView({ model: this.model, collection: this.model.collection }))
},

render: function() {
// This was using an 'id' passed into the column as the dcid (getOption('id')).
// However, this is not present when loading attachments from a data collection group
Expand All @@ -46,6 +53,10 @@ define(['marionette',
this.$el.append('<a href="/dc/rsv/id/'+dcid+'" class="button rsv"><i class="fa fa-search"></i> Reciprocal Space Viewer</a>')
}

if (app.options.get('ccp4_cloud_upload_url') && this.model.get('FILETYPE') == 'params') {
this.$el.append('<a class="vatupload button" href="#"><i class="fa fa-cloud-upload"></i> CCP4 Cloud</a>')
}

return this
}
})
Expand Down
4 changes: 3 additions & 1 deletion client/src/js/modules/dc/views/autointegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define(['marionette',
},

showAttachments: function(e) {
e.preventDefault()
if (e) e.preventDefault()

this.attachments = new AutoProcAttachments()
this.attachments.queryParams.AUTOPROCPROGRAMID = this.model.get('AID')
Expand All @@ -52,6 +52,8 @@ define(['marionette',
view: new AutoProcAttachmentsView({ collection: this.attachments }),
autosize: true
}))

this.listenTo(this.attachments, 'file:uploaded', this.showAttachments, this)
},

showLog: function(e) {
Expand Down
15 changes: 13 additions & 2 deletions client/src/js/modules/dc/views/autoprocattachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ define(['marionette',
'modules/dc/views/aiplots',
'modules/dc/views/vue-plotly',
'views/log',
'views/cloudupload',
'views/table', 'utils'],
function(Marionette, Backbone, Backgrid,
AIPlotsView, PlotlyPlotView, LogView,
AIPlotsView, PlotlyPlotView, LogView, CloudUploadView,
TableView, utils) {


var OptionsCell = Backgrid.Cell.extend({
events: {
'click a.dl': utils.signHandler,
'click a.vaplog': 'showLog',
'click a.vapplot': 'showPlots',
'click a.vapupload': 'showCloudUpload',
},

render: function() {
Expand All @@ -28,9 +30,18 @@ define(['marionette',
this.$el.append('<a class="vapplot button" href="#"><i class="fa fa-line-chart"></i> View</a>')
}

if (app.options.get('ccp4_cloud_upload_url') && this.model.get('FILETYPE') == 'Result') {
this.$el.append('<a class="vapupload button" href="#"><i class="fa fa-cloud-upload"></i> CCP4 Cloud</a>')
}

return this
},

showCloudUpload: function(e) {
e.preventDefault()
app.dialog.show(new CloudUploadView({ model: this.model, collection: this.model.collection }))
},

showPlots: function(e) {
e.preventDefault()

Expand Down
25 changes: 25 additions & 0 deletions client/src/js/templates/dc/cloudupload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

<div>
In order to upload to CCP4 cloud, we need your CCP4 Cloud username, and your CloudRun Id.<br />
You can find your CloudRun Id on the 'My Account' page of CCP4 Cloud.
</div>
<br />
<div>
Once uploaded, create or select a CCP4 Cloud project and select the task 'Import from Cloud Storage'.<br />
Click 'Select file(s)', then click 'My Cloud Storage'.
</div>
<br />
<div>
See <a class="u" href="https://cloud.ccp4.ac.uk/manuals/html-userguide/jscofe_synchweb.html">here</a> for more information.
</div>
<br />

<div class="table">
<table>
<tr><td><span class="b">Filename: </span></td><td><%-FILENAME%></td></tr>
<tr><td><span class="b">CCP4 Cloud Username: </span></td><td><input name="username"></input></td></tr>
<tr><td><span class="b">CCP4 CloudRun Id: </span></td><td><input name="cloudrunid" placeholder="####-####-####-####"></input></td></tr>
<tr><td><span class="b">Remember these: </span></td><td><input type="checkbox" name="remember"></input></td></tr>
</table>
</div>

71 changes: 71 additions & 0 deletions client/src/js/views/cloudupload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
define([
'backbone',
'views/dialog',
'templates/dc/cloudupload.html',
'jquery.cookie'
], function(
Backbone,
DialogView,
template
) {

return DialogView.extend({
template: template,
title: 'Upload to CCP4 Cloud',

buttons: {
'Upload': 'upload',
'Cancel': 'closeDialog',
},

ui: {
username: 'input[name=username]',
cloudrunid: 'input[name=cloudrunid]',
remember: 'input[name=remember]',
},

upload: function() {
if (this.ui.remember.is(':checked')) {
let cookieOpts = { expires: 365, path: '/' }
$.cookie('ccp4_username', this.ui.username.val(), cookieOpts)
Copy link
Collaborator

@gfrn gfrn Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the native cookie management library instead, since jQuery Cookie was removed? I'm happy to do it

https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie

$.cookie('ccp4_cloudrunid', this.ui.cloudrunid.val(), cookieOpts)
}
let data = { cloudrunid: this.ui.cloudrunid.val(), username: this.ui.username.val() }
if (this.model.get('AUTOPROCPROGRAMATTACHMENTID')) {
data.AUTOPROCPROGRAMATTACHMENTID = this.model.get('AUTOPROCPROGRAMATTACHMENTID')
} else if (this.model.get('DATACOLLECTIONFILEATTACHMENTID')) {
data.DATACOLLECTIONFILEATTACHMENTID = this.model.get('DATACOLLECTIONFILEATTACHMENTID')
}
var self = this
Backbone.ajax({
url: app.apiurl+'/processing/upload',
type: 'POST',
data: data,
success: function() {
app.alert({ className: 'message notify', message: 'File successfully uploaded' })
self.closeDialog()
self.collection.trigger('file:uploaded')

},
error: function(xhr, status, error) {
app.alert({ message: 'Something went wrong uploading this file: '+xhr.responseText })
},
})
},

initialize: function(options) {
this.collection = options.collection
},

onRender: function() {
let ccp4_username = $.cookie('ccp4_username');
let ccp4_cloudrunid = $.cookie('ccp4_cloudrunid');
if (ccp4_username) this.ui.username.val(ccp4_username)
if (ccp4_cloudrunid) this.ui.cloudrunid.val(ccp4_cloudrunid)
if (ccp4_username || ccp4_cloudrunid) this.ui.remember.prop('checked', true)
}


})

})
Loading