Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Restore: Filebrowser adjustments
  • Loading branch information
fbergkemper committed Oct 20, 2017
1 parent 0f1d99f commit 275905b
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 55 deletions.
8 changes: 4 additions & 4 deletions module/Restore/src/Restore/Controller/RestoreController.php
Expand Up @@ -272,11 +272,11 @@ private function getDirectories()
else {
$jobids = $this->getRestoreModel()->getJobIds($this->bsock, $this->restore_params['jobid'],$this->restore_params['mergefilesets'],$this->restore_params['mergejobs']);
$this->restore_params['jobids'] = $jobids;
$this->directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobids'], $this->restore_params['id'], $this->restore_params['limit']);
$this->directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobids'], $this->restore_params['id']);
}
}
else {
$this->directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobid'], $this->restore_params['id'], $this->restore_params['limit']);
$this->directories = $this->getRestoreModel()->getDirectories($this->bsock, $this->restore_params['jobid'], $this->restore_params['id']);
}
}
catch(Exception $e) {
Expand All @@ -300,11 +300,11 @@ private function getFiles()
else {
$jobids = $this->getRestoreModel()->getJobIds($this->bsock, $this->restore_params['jobid'],$this->restore_params['mergefilesets'],$this->restore_params['mergejobs']);
$this->restore_params['jobids'] = $jobids;
$this->files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobids'], $this->restore_params['id'], $this->restore_params['limit']);
$this->files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobids'], $this->restore_params['id']);
}
}
else {
$this->files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobid'], $this->restore_params['id'], $this->restore_params['limit']);
$this->files = $this->getRestoreModel()->getFiles($this->bsock, $this->restore_params['jobid'], $this->restore_params['id']);
}
}
catch(Exception $e) {
Expand Down
115 changes: 78 additions & 37 deletions module/Restore/src/Restore/Model/RestoreModel.php
Expand Up @@ -34,34 +34,63 @@ class RestoreModel
* @param $bsock
* @param $jobid
* @param $pathid
* @param $limit
*
* @return array
*/
public function getDirectories(&$bsock=null, $jobid=null, $pathid=null, $limit=null) {
public function getDirectories(&$bsock=null, $jobid=null, $pathid=null) {
if(isset($bsock)) {
if($pathid == null || $pathid== "#") {
$cmd = '.bvfs_lsdirs jobid='.$jobid.' path=';
}
else {
$cmd = '.bvfs_lsdirs jobid='.$jobid.' pathid='.abs($pathid).' limit='.$limit;
}
$result = $bsock->send_command($cmd, 2, $jobid);
$directories = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
if(empty($directories['result']['directories'])) {
$cmd = '.bvfs_lsdirs jobid='.$jobid.' path=@ limit='.$limit;
$result = $bsock->send_command($cmd, 2, $jobid);

$limit = 1000;
$offset = 0;
$retval = array();

while (true) {

if($pathid == null || $pathid== "#") {
$cmd_1 = '.bvfs_lsdirs jobid='.$jobid.' path= limit='.$limit.' offset='.$offset;
}
else {
$cmd_1 = '.bvfs_lsdirs jobid='.$jobid.' pathid='.abs($pathid).' limit='.$limit.' offset='.$offset;
}

$result = $bsock->send_command($cmd_1, 2, $jobid);
$directories = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);

if(empty($directories['result']['directories'])) {
return null;
$cmd_2 = '.bvfs_lsdirs jobid='.$jobid.' path=@ limit='.$limit;
$result = $bsock->send_command($cmd_2, 2, $jobid);
$directories = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
if(count($directories['result']['directories']) == 2) {
$retval = array_merge($retval, $directories['result']['directories']);
// as . and .. are always returned, filter possible duplicates of . and .. (current and parent dir)
foreach($retval as $key => $value) {
if($retval[$key]['name'] === "." || $retval[$key]['name'] === "..")
unset($retval[$key]);
}
return $retval;
}
else {
$retval = array_merge($retval, $directories['result']['directories']);
}
}
// no more results?
elseif (count($directories['result']['directories']) == 2) {
$retval = array_merge($retval, $directories['result']['directories']);
// as . and .. are always returned, filter possible duplicates of . and .. (current and parent dir)
foreach($retval as $key => $value) {
if($retval[$key]['name'] === "." || $retval[$key]['name'] === "..")
unset($retval[$key]);
}
return $retval;
}
// continue
else {
return $directories['result']['directories'];
$retval = array_merge($retval, $directories['result']['directories']);
}
$offset = $offset + $limit;

}
else {
return $directories['result']['directories'];
}

}
else {
throw new \Exception('Missing argument.');
Expand All @@ -74,34 +103,46 @@ public function getDirectories(&$bsock=null, $jobid=null, $pathid=null, $limit=n
* @param $bsock
* @param $jobid
* @param $pathid
* @param $limit
*
* @return array
*/
public function getFiles(&$bsock=null, $jobid=null, $pathid=null, $limit=null) {
if(isset($bsock, $limit)) {
if($pathid == null || $pathid == "#") {
$cmd = '.bvfs_lsfiles jobid='.$jobid.' path=';
}
else {
$cmd = '.bvfs_lsfiles jobid='.$jobid.' pathid='.abs($pathid).' limit='.$limit;
}
$result = $bsock->send_command($cmd, 2, $jobid);
$files = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
if(empty($files['result']['files'])) {
$cmd = '.bvfs_lsfiles jobid='.$jobid.' path=@ limit='.$limit;
$result = $bsock->send_command($cmd, 2, $jobid);
public function getFiles(&$bsock=null, $jobid=null, $pathid=null) {
if(isset($bsock)) {

$limit = 1000;
$offset = 0;
$retval = array();

while (true) {

if($pathid == null || $pathid == "#") {
$cmd_1 = '.bvfs_lsfiles jobid='.$jobid.' path= limit='.$limit.' offset='.$offset;
}
else {
$cmd_1 = '.bvfs_lsfiles jobid='.$jobid.' pathid='.abs($pathid).' limit='.$limit.' offset='.$offset;
}

$result = $bsock->send_command($cmd_1, 2, $jobid);
$files = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);

if(empty($files['result']['files'])) {
return null;
$cmd_2 = '.bvfs_lsfiles jobid='.$jobid.' path=@ limit='.$limit.' offset='.$offset;
$result = $bsock->send_command($cmd_2, 2, $jobid);
$files = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
if(empty($files['result']['files'])) {
return $retval;
}
else {
$retval = array_merge($retval, $files['result']['files']);
}
}
else {
return $files['result']['files'];
$retval = array_merge($retval, $files['result']['files']);
}
$offset = $offset + $limit;

}
else {
return $files['result']['files'];
}

}
else {
throw new \Exception('Missing argument.');
Expand Down
44 changes: 30 additions & 14 deletions module/Restore/view/restore/restore/index.phtml
Expand Up @@ -98,6 +98,7 @@ $this->headTitle($title);
echo '<p>'.$this->formRow($form->get('restorejob')).'</p>';
echo '<p>'.$this->formRow($form->get('replace')).'</p>';
echo '<p>'.$this->formRow($form->get('where')).'</p>';
echo '<p><br />'.$this->formSubmit($form->get('submit')->setAttribute('class','btn btn-primary')).'</p>';
// Hidden fields
echo $this->formRow($form->get('checked_files'));
echo $this->formRow($form->get('checked_directories'));
Expand All @@ -120,7 +121,7 @@ $this->headTitle($title);
echo '<strong>';
echo $this->translate("File selection");
echo '</strong>';

/*
echo '<div class="form-group">';
echo '<label class="control-label col-md-1">';
echo $this->formLabel($form->get('limit'));
Expand All @@ -129,8 +130,8 @@ $this->headTitle($title);
echo $this->formText($form->get('limit'));
echo '</div>';
echo '</div>';

echo '<div class="panel panel-default" style="height: 600px; overflow: scroll;"><div id="filebrowser"></div></div>';
*/
echo '<div class="panel panel-default" style="height: 550px; overflow: auto; resize: both;"><div id="filebrowser"></div></div>';

/*
echo '<div class="input-group">';
Expand All @@ -143,12 +144,7 @@ $this->headTitle($title);
}
?>
</div>
</div>

<div class="row">
<div class="col-md-3">
<?php echo $this->formSubmit($form->get('submit')->setAttribute('class','btn btn-primary')); ?>
</div>
</div>

<?php
Expand All @@ -167,6 +163,15 @@ $this->headTitle($title);
echo $this->headLink()->prependStylesheet($this->basePath() . '/css/jstree.min.css');
?>

<style>

.jsTreeGridHeader {
background-color: #eeeeee;
color: #000000;
}

</style>

<script type="text/javascript">

function format_bytes(v) {
Expand Down Expand Up @@ -271,27 +276,37 @@ $this->headTitle($title);
});

$('#filebrowser').jstree({
'plugins' : [ "grid", "checkbox", "state", "sort", "search", "types" ],
'core' : {
'animation': false,
'force_text': true,
'error': function () {
alert('Oops, something went wrong, probably too many files.')
},
'data' :{
'url' : '<?php echo $this->basePath() . "/restore/filebrowser?type=" . $this->restore_params['type'] . "&jobid=" . $this->restore_params['jobid'] . "&mergefilesets=" . $this->restore_params['mergefilesets'] . "&mergejobs=" . $this->restore_params['mergejobs'] . "&limit=" . $this->restore_params['limit']; ?>',
'dataType' : 'json',
'data' : function (node) {
return { 'id' : node.id };
},
//'error' : alert('Error loading filetree') // debug
}
},
},
'plugins' : [ "grid", "checkbox", "state", "sort", "search", "types" ],
'grid' : {
width: '100%',
fixedHeader: true,
resizable: false,
columns: [
{
width: 500,
width: '100%',
height: '100%',
header: '<?php echo $this->translate("Name"); ?>',
headerClass: 'jsTreeGridHeader',
title: "_DATA_"
},
{
width: 125,
width: 150,
header: '<?php echo $this->translate("Size"); ?>',
headerClass: 'jsTreeGridHeader',
value: function(node) {
if(node.data.stat.size == 0) {
return null;
Expand All @@ -302,7 +317,9 @@ $this->headTitle($title);
}
},
{
width: 150,
header: '<?php echo $this->translate("Date"); ?>',
headerClass: 'jsTreeGridHeader',
value: function(node) {
if(node.data.stat.mtime == 0) {
return null;
Expand All @@ -313,7 +330,6 @@ $this->headTitle($title);
}
}
],
resizable: true,
},
'search' : {
"case_sensitive" : false,
Expand Down

0 comments on commit 275905b

Please sign in to comment.