Skip to content

Commit

Permalink
Dashboard: improve data visualization (#35)
Browse files Browse the repository at this point in the history
Show backup time in human format and not like crontab.
  • Loading branch information
Federico Ballarini authored and gsanchietti committed Feb 15, 2019
1 parent db9e909 commit 739c799
Showing 1 changed file with 25 additions and 5 deletions.
Expand Up @@ -25,15 +25,22 @@
*
* @author Giacomo Sanchietti
*/

class Backup extends \Nethgui\Controller\AbstractController
{

public $sortId = 30;

private $backup = array();

private function readBackup()

private function formatDay($d,$view){
$days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
return $view->translate($days[$d]);
}

private function readBackup($view)
{

$backup = array();
$status_file = "/var/spool/backup/status-backup-data";
if (file_exists($status_file)) {
Expand All @@ -48,7 +55,19 @@ private function readBackup()
$backup['vfs'] = $br['VFSType'] ? $br['VFSType'] : '-';
$backup['status'] = $br['status'];
$backup['time'] = $br['BackupTime'];


$hour = explode(" ",$backup['time']);

if($hour[1] == "*" && $hour[2] == "*" && $hour[3] == "*" && $hour[4] == "*"){
$backup['time'] = $view->translate('EveryHour')." ".sprintf('%02d',$hour[0]);
}else if($hour[2] == "*" && $hour[3] == "*" && $hour[4] == "*"){
$backup['time'] = $view->translate('EveryDay')." ".sprintf('%02d',$hour[1]).":".sprintf('%02d',$hour[0]);
}else if($hour[2] == "*" && $hour[3] == "*"){
$backup['time'] = $view->translate('EveryWeek')." ".$this->formatDay($hour[4],$view)." at ".sprintf('%02d',$hour[1]).":".sprintf('%02d',$hour[0]);
}else if($hour[3] == "*" && $hour[4] == "*"){
$backup['time'] = $view->translate('EveryMonth')." ".$hour[2]." at ".sprintf('%02d',$hour[1]).":".sprintf('%02d',$hour[0]);
}

$disk_usage_file = "/var/spool/backup/disk_usage-backup-data";
if (file_exists($disk_usage_file)) {
$file = file_get_contents("$disk_usage_file");
Expand All @@ -72,10 +91,11 @@ public function process()
public function prepareView(\Nethgui\View\ViewInterface $view)
{
if (!$this->backup) {
$this->backup = $this->readBackup();
$this->backup = $this->readBackup($view);
}
foreach ($this->backup as $k => $v) {
$view['backup_' . $k] = $v;
}
}
}

}

0 comments on commit 739c799

Please sign in to comment.