Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented File Listing within a Job #14

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion application/config/application.php
Expand Up @@ -12,5 +12,7 @@
'login' => 'Login',
'usersettings' => 'UserSettings',
'settings' => 'Settings',
'directors' => 'Directors'],
'directors' => 'Directors',
'historyfiles' => 'HistoryFiles'
],
'defaultview' => 'DashboardView' ];
97 changes: 97 additions & 0 deletions application/models/historyfiles.model.php
@@ -0,0 +1,97 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of historyfiles
*
* @author gorlando
*/
class HistoryFiles_Model extends CModel {

public function getHistoryFiles($jobId, $limit, $offset){
$used_types = array();
$sql_query = "SELECT `Job`.`Name`, `Job`.`JobStatus`, `File`.`FileIndex`, CONCAT(`Path`.`Path`, `Filename`.`Name`) as Path
FROM `File`, `Path`, `Filename`, `Job`
WHERE `File`.`JobId` = $jobId
AND `Path`.`PathId` = `File`.`PathId`
AND `Filename`.`FilenameId` = `File`.`FilenameId`
AND `Job`.`JobId` = `File`.`JobId`
ORDER BY `File`.`FileIndex` ASC
LIMIT ".($offset*$limit).",$limit ;";
$result = $this->run_query($sql_query);

$used_types = $result->fetchAll();

return $used_types;
}

public function getCountHistoryFiles($jobId){
$used_types = array();
$sql_query = "SELECT COUNT(*) as count
FROM `File`, `Path`, `Filename`, `Job`
WHERE `File`.`JobId` = $jobId
AND `Path`.`PathId` = `File`.`PathId`
AND `Filename`.`FilenameId` = `File`.`FilenameId`
AND `Job`.`JobId` = `File`.`JobId`
ORDER BY `File`.`FileIndex` ASC;";
$result = $this->run_query($sql_query);

$used_types = $result->fetchAll();

return $used_types[0]['count'];
}

public function getJobNameAndJobStatusByJobId($jobId){
$used_types = array();
$sql_query = "SELECT distinct `Job`.`Name`, `Job`.`JobStatus`
FROM `Job`
WHERE `Job`.`JobId` = $jobId;";
$result = $this->run_query($sql_query);

$used_types = $result->fetchAll();
if(count($used_types) != 0){
$used_types = $used_types[0];

switch ($used_types['jobstatus']) {
case 'R':
$used_types['jobstatus'] = 'Running';
break;
case 'F':
case 'S':
case 'M':
case 'm':
case 's':
case 'j':
case 'c':
case 'd':
case 't':
case 'p':
case 'C':
$used_types['jobstatus'] = 'Waiting';
break;
case 'T':
$used_types['jobstatus'] = 'Completed';
break;
case 'E':
$used_types['jobstatus'] = 'Completed with errors';
break;
case 'f':
$used_types['jobstatus'] = 'Failed';
break;
case 'A':
$used_types['jobstatus'] = 'Canceled';
break;
default:
$used_types['jobstatus'] = 'All';
break;
}
}

return $used_types;
}
}
47 changes: 47 additions & 0 deletions application/views/historyfiles.view.php
@@ -0,0 +1,47 @@
<?php

/**
* Description of historyfiles
*
* @author gorlando
*/
class HistoryFilesView extends CView {

public function __construct() {

$this->templateName = 'historyfiles.tpl';
$this->name = 'History Files';
$this->title = 'History Files';

parent::init();
}

public function prepare() {
$rows_per_page = 10;

$historyFiles = new HistoryFiles_Model();
$jobId = $_GET['jobId'];
$this->assign('jobid', $jobId);
$jobInfo = $historyFiles->getJobNameAndJobStatusByJobId($jobId);
$this->assign('job_info', $jobInfo);
$files_count = $historyFiles->getCountHistoryFiles($jobId);
$this->assign('history_files_count', $files_count);

//pagination
$pagination_active = FALSE;
if($files_count > $rows_per_page){
$pagination_active = TRUE;
}
$this->assign('pagination_active', $pagination_active);
$current_page = 0;
if(array_key_exists('paginationCurrentPage', $_GET)){
$current_page = $_GET['paginationCurrentPage'];
}
$this->assign('pagination_current_page', $current_page);
$this->assign('pagination_rows_per_page', $rows_per_page);

$files = $historyFiles->getHistoryFiles($jobId, $rows_per_page, $current_page);
$this->assign('history_files', $files);
$this->assign('history_files_count_paging', count($files));
}
}
8 changes: 7 additions & 1 deletion application/views/templates/backupjob-report.tpl
Expand Up @@ -62,7 +62,13 @@
<tr>
<td>{$job.jobid}</td>
<td>{$job.joblevel}</td>
<td>{$job.jobfiles}</td>
<td>
{if ($job.jobfiles > 0) }
<a href="index.php?page=historyfiles&jobId={$job.jobid}">{$job.jobfiles}</a>
{else}
{$job.jobfiles}
{/if}
</td>
<td>{$job.jobbytes}</td>
<td>{$job.starttime}</td>
<td>{$job.endtime}</td>
Expand Down
68 changes: 68 additions & 0 deletions application/views/templates/historyfiles.tpl
@@ -0,0 +1,68 @@
<div class="container-fluid" id="jobsreport">

<div class="page-header">
<h3>{$page_name} <small>{t}Bacula History Files{/t}</small></h3>
</div>

<div class="row">

<!-- Backup job report -->
<div class="panel panel-default">
<div class="panel-heading"><b>{t}Job Info{/t}</b></div>
<div class="panel-body">
<div>
<b>{t}Job Name{/t}</b>: <a href="index.php?page=backupjob&backupjob_name={$job_info.name}">{$job_info.name}</a>
<br>
<b>{t}Job Status{/t}</b>: {$job_info.jobstatus}
</div>
</div> <!-- end div class=panel-body -->
</div> <!-- end div class=panel ... -->

<div class="table-responsive">
<table class="table table-condensed table-hover table-striped table-bordered text-center">
<tr>
<th class="text-center">{t}File Index{/t}</th>
<th class="text-center">{t}File Path{/t}</th>
</tr>
{foreach from=$history_files item=file}
<tr>
<td>#{$file.fileindex}</td>
<td class="text-left">{$file.path}</td>
</tr>
{foreachelse}
<tr>
<td colspan="4">{t}No file(s) to display{/t}</td>
</tr>
{/foreach}
</table>
</div>

<div class="alert alert-info text-center" role="alert">

{if $pagination_active}
<div class="bs-example" data-example-id="simple-pager">
<nav aria-label="...">
<ul class="pager">
<li>
{if $pagination_current_page == 0}
<a class="disabled">Previous</a>
{else}
<a href="index.php?page=historyfiles&jobId={$jobid}&paginationCurrentPage={$pagination_current_page-1}">Previous</a>
{/if}
</li>
<li>Found <b>{$history_files_count}</b> File(s)</b></li>
<li>
{if $history_files_count_paging == $pagination_rows_per_page}
<a href="index.php?page=historyfiles&jobId={$jobid}&paginationCurrentPage={$pagination_current_page+1}">Next</a>
{else}
<a class="disabled">Next</a>
{/if}
</li>
</ul>
</nav>
</div>
{/if}
</div>
</div>

</div>