Skip to content

Commit

Permalink
Added option to save file list to server. Closes #9.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewels committed Nov 6, 2015
1 parent b4f708a commit 2e517e1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
23 changes: 9 additions & 14 deletions ajax/write_bash.php
Expand Up @@ -21,32 +21,27 @@


/*
Script to write out the processing bash script to a file
Script to write out the cluster flow filenames file to the cluster
*/

require_once('../includes/start.php');

if(isset($_POST['output']) && isset($_POST['project_id']) && is_numeric($_POST['project_id'])){
if(isset($_POST['contents']) && isset($_POST['project_id']) && is_numeric($_POST['project_id'])){

$project_q = mysqli_query($dblink, "SELECT * FROM `projects` WHERE `id` = '".$_POST['project_id']."'");
$project = mysqli_fetch_array($project_q);

if(isset($_POST['bash_fn'])){
$bash_fn = preg_replace("/[^A-Za-z0-9_\.]/", '_', $_POST['bash_fn']);
} else {
$bash_fn = $project['name'].'_labrador_bash_'.date('d_m_Y').'.bash';
}

$filename = $project['name'].'_labrador_downloads_'.date('d_m_Y').'.txt';
$dir = $data_root.$project['name'].'/';
$fn = $dir.$bash_fn;
$fn = $dir.$filename;

// Save history message
$query = sprintf("INSERT INTO `history` (`project_id`, `user_id`, `note`, `time`) VALUES ('%d', '%d', '%s', '%d')",
$project['id'], $user['id'], mysqli_real_escape_string($dblink, "Saved bash script $bash_fn"), time());
$project['id'], $user['id'], mysqli_real_escape_string($dblink, "Saved file names file '$filename'"), time());
mysqli_query($dblink, $query);

// Write file contents
# $output = "# Bash script produced by Labrador at ".date('H:i, l \t\h\e jS F Y')."\n# Script written for the ".$_POST['server']." server\n\n";
$output .= $_POST['output'];
$output = $_POST['contents'];
$output = str_replace("\r", "", $output);

// Check the directory exists
Expand All @@ -61,10 +56,10 @@
fwrite($fh, $output);
fclose($fh);

echo 'Bash script saved.';
echo 'File saved.';

} else {
echo 'Missing vars to save bash script';
echo 'Missing vars to save file';
}

?>
7 changes: 6 additions & 1 deletion datasets.php
Expand Up @@ -327,7 +327,12 @@
<div class="modal-footer">
<p class="muted pull-left">NB: Works with <a href="http://clusterflow.io">Cluster Flow</a>.</p>
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary" id="datasets_download_file">Download</a>
<button class="btn" id="datasets_download_file">Download</button>
<button class="btn btn-primary" id="datasets_save_to_server" data-projectid="<?php echo $project_id; ?>">Save to cluster</button>
<p class="text-left muted">
Cluster location:<br>
<code style="font-size: 10px;" id="datasetsr_save_to_server_path"><?php echo $data_root.$project['name'].'/'.$project['name'].'_labrador_downloads_'.date('d_m_Y').'.txt'; ?></code>
</p>
</div>
</div>

Expand Down
11 changes: 10 additions & 1 deletion js/datasets.js
Expand Up @@ -53,10 +53,19 @@ $('#sra-links-modal').on('show', function () {
$('#sra-links-modal .modal-body pre').html(file);
});

$('#datasets_download_file').click(function(){
$('#datasets_download_file').click(function(e){
e.preventDefault();
var file = $('#sra-links-modal .modal-body pre').text();
$('<a href="data:text/plain,'+encodeURIComponent(file)+'" download="sra_downloads.txt">')[0].click()
});
$('#datasets_save_to_server').click(function(e){
e.preventDefault();
var contents = $('#sra-links-modal .modal-body pre').text();
var project_id = $('#datasets_save_to_server').data('projectid');
$.post('ajax/write_bash.php', {'contents': contents, 'project_id': project_id}, function(data){
alert(data);
});
});

// Edit - Batch update checked datasets
$('.bulk_update').keyup(function(e){
Expand Down
4 changes: 1 addition & 3 deletions js/processing.js
Expand Up @@ -267,11 +267,9 @@ $('#save_bash_script').click(function(e){
}
});
function saveBashScript (){
var server = $('#server').val();
var output = $('#bash_preview pre').text();
var project_id = $('#project_id').val();
var bash_fn = $('#bash_script_fn').val();
$.post('ajax/write_bash.php', {'output': output, 'project_id': project_id, 'server': server, 'bash_fn': bash_fn}, function(data){
$.post('ajax/write_bash.php', {'contents': output, 'project_id': project_id}, function(data){
alert(data);
});
}
Expand Down
2 changes: 1 addition & 1 deletion processing.php
Expand Up @@ -292,7 +292,7 @@
<fieldset>
<legend>Step 4: Save Script</legend>
<?php $bash_fn = $project['name'].'_labrador_bash_'.date('d_m_Y').'.bash'; ?>
<p>Script will be saved to <code><?php echo $data_root.$project['name']; ?>/<input type="text" id="bash_script_fn" value="<?php echo $bash_fn; ?>" class="input-xxlarge" style="font-family:monospace;"></code>
<p>Script will be saved to <code><?php echo $data_root.$project['name'].'/'.$bash_fn; ?></code>
<span class="help-block">If this file already exists, it will be overwritten.</span></p>
<div class="form-actions">
<button type="submit" id="save_bash_script" class="btn btn-large btn-primary">Save Bash Script</button>
Expand Down

0 comments on commit 2e517e1

Please sign in to comment.