Skip to content

Commit

Permalink
Enabled downloads to user's folder
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaskavouras committed Feb 19, 2021
1 parent 9e1349f commit b053f6f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 108 deletions.
64 changes: 24 additions & 40 deletions models/DownloadDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ public function downloadHelixDataset($folder,$dataset_id,$provider)
$title='';
$version='';

if (empty($folder))
{
$warning="You must choose a folder to store the dataset";
return ['warning'=>$warning];
}
elseif (!$content->success==1)
if (!$content->success==1)
{
$error='The dataset id you provided is not valid';
return ['error'=>$error];
Expand Down Expand Up @@ -152,12 +147,7 @@ public function downloadZenodoDataset($folder,$dataset_id,$provider)

$status=$response->headers['http-code'];

if (empty($folder))
{
$warning="You must choose a folder to store the dataset";
return ['warning'=>$warning];
}
elseif ($status!='200')
if ($status!='200')
{
$error=json_decode($response->content,true)['message'];
return ['error'=>$error];
Expand Down Expand Up @@ -208,41 +198,35 @@ public function downloadFromUrl($folder,$dataset_id,$provider)
$warning='';
$success='';

if (empty($folder))

$title=basename($dataset_id);
$version="0";


$finalFolder=Yii::$app->params['userDataPath'] . '/' . explode('@',Userw::getCurrentUser()['username'])[0] . '/' . $folder . '/'. "Downloads_from_Url/";

if(!file_exists($finalFolder))
{
$warning="You must choose a folder to store the dataset";
return ['warning'=>$warning];
exec("mkdir $finalFolder");
}
else
{
$title=basename($dataset_id);
$version="0";


$finalFolder=Yii::$app->params['userDataPath'] . '/' . explode('@',Userw::getCurrentUser()['username'])[0] . '/' . $folder . '/'. "Downloads_from_Url/";

if(!file_exists($finalFolder))
{
exec("mkdir $finalFolder");
}

$command="wget -nc -P $finalFolder $dataset_id";
exec($command,$out,$ret);

$command="wget -nc -P $finalFolder $dataset_id";
exec($command,$out,$ret);



if ($ret!=0)
{
$warning="The file could not be downloaded";
}
else
{
$success='The dataset has been successfully downloaded';
if ($ret!=0)
{
$warning="The file could not be downloaded";
}
else
{
$success='The dataset has been successfully downloaded';

}

}



return ['error'=>$error,'warning'=>$warning,'success'=>$success, 'version'=>'', 'title'=>''];
}
Expand Down
11 changes: 5 additions & 6 deletions views/filebrowser/download_dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<?=Html::textInput('dataset_helix',$isystemMount,['id' => 'helix-mount','class'=>'mount-field-helix dataset-input-size','readonly'=>true,]).'&nbsp;&nbsp;'
. Html::a("$select_icon Select",'javascript:void(0);',['class'=>'select-mount-button-helix btn btn-success btn-md']).'&nbsp'
. Html::a("$clear_icon Clear",'javascript:void(0);',['class'=>'clear-mount-button-helix btn btn-danger btn-md'])?>
<div class="col-md-8 message_folder_helix hidden" id='message-folder-helix'> Dataset folder can not be blank </div>

</div>
</div>
<div class="row helix_field helix_hide">&nbsp;</div>
Expand Down Expand Up @@ -151,20 +151,20 @@
<div class="col-md-4 labels"> Dataset ID<?=$required?> <?=$help_id?></div>
<div class="col-md-8"><?=$form->field($model,'dataset_id')->textInput(['class'=>'form-control'])->label("")?></div>
</div>
<div class="row body-row zenodo_field">
<div class="row body-row zenodo_field zenodo_hide">
<div class="col-md-4 label-dataset">Select dataset folder<?=$required?> <?=$help_dataset_folder?></div>
<div class="col-md-8">
<?=Html::textInput('dataset_zenodo',$isystemMount,['id' => 'zenodo-mount','class'=>'mount-field-zenodo
dataset-input-size','readonly'=>true,]).'&nbsp;&nbsp;'
. Html::a("$select_icon Select",'javascript:void(0);',['class'=>'select-mount-button-zenodo btn btn-success btn-md']).'&nbsp'
. Html::a("$clear_icon Clear",'javascript:void(0);',['class'=>'clear-mount-button-zenodo btn btn-danger btn-md'])?>
<div class="col-md-8 message_folder_zenodo hidden" id='message-folder-zenodo'> Dataset folder can not be blank </div>

</div>

</div>
<div class="row zenodo_field zenodo_hide">&nbsp;</div>
<div class="row zenodo_field zenodo_hide">&nbsp;</div>
<div class="form-group zenodo_field text-center">
<div class="form-group zenodo_field zenodo_hide text-center">
<?= Html::submitButton("$submit_icon Submit", ['class' => 'btn btn-primary', 'name'=>'zenodo-submit']) ?>
</div>

Expand Down Expand Up @@ -193,13 +193,12 @@
dataset-input-size','readonly'=>true,]).'&nbsp;&nbsp;'
. Html::a("$select_icon Select",'javascript:void(0);',['class'=>'select-mount-button-url btn btn-success btn-md']).'&nbsp'
. Html::a("$clear_icon Clear",'javascript:void(0);',['class'=>'clear-mount-button-url btn btn-danger btn-md'])?>
<div class="col-md-8 message_folder_url hidden" id='message-folder-url'> Dataset folder can not be blank </div>
</div>

</div>
<div class="row">&nbsp;</div>
<div class="row">&nbsp;</div>
<div class="form-group url_field text-center">
<div class="form-group url_field url_hide text-center">
<?= Html::submitButton("$submit_icon Submit", ['class' => 'btn btn-primary', 'name'=>'url-submit']) ?>
</div>

Expand Down
19 changes: 0 additions & 19 deletions web/css/components/downloadDataset.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,6 @@ margin-bottom:10px;
border:solid 1px #a94442;
}

.message_folder_helix
{
padding-left: 0px;
color:#a94442;
}

.message_folder_zenodo
{
padding-left: 0px;
color:#a94442;
}

.message_folder_url
{
padding-left: 0px;
color:#a94442;
}



.dataset-input-size
{
Expand Down
46 changes: 3 additions & 43 deletions web/js/components/downloadDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ $(document).ready(function()



var datasetfolder=$("#helix-mount").val();
var submit=0;

if($(".hidden_element_box").is(':empty'))
{

Expand All @@ -122,15 +119,8 @@ $(document).ready(function()
$(".blue-rounded-textbox").addClass('red-border');
}

if(datasetfolder=='')
{

event.preventDefault();
$("#message-folder-helix").removeClass('hidden');
$(".mount-field-helix").css("border-color", "#a94442");
}

if(!$(".hidden_element_box").is(':empty') && !(datasetfolder==''))
if(!$(".hidden_element_box").is(':empty'))
{

$('.modal').modal({
Expand Down Expand Up @@ -219,21 +209,6 @@ $(document).ready(function()

$("#zenodo-form").submit(function(event){

var datasetfolder=$("#zenodo-mount").val();
var submit=0;


if(datasetfolder=='')
{
event.preventDefault();
$("#message-folder-zenodo").removeClass('hidden');
$(".mount-field-zenodo").css("border-color", "#a94442");

}


if(!(datasetfolder==''))
{

$('.modal').modal({
backdrop: 'static',
Expand All @@ -248,7 +223,7 @@ $(document).ready(function()
$('.modal').modal('hide');
}
}, 2000);
}


});

Expand Down Expand Up @@ -296,22 +271,7 @@ $(document).ready(function()

$("#url-form").submit(function(event){

var datasetfolder=$("#url-mount").val();
var submit=0;


if(datasetfolder=='')
{
event.preventDefault();
$("#message-folder-url").removeClass('hidden');
$(".mount-field-url").css("border-color", "#a94442");

}


if(!(datasetfolder==''))
{

$('.modal').modal({
backdrop: 'static',
keyboard: false
Expand All @@ -325,7 +285,7 @@ $(document).ready(function()
$('.modal').modal('hide');
}
}, 2000);
}


});

Expand Down

0 comments on commit b053f6f

Please sign in to comment.