Commit be918944 authored by Florian Kaiser's avatar Florian Kaiser
Browse files

translate "default" and "none" quota values

parent e157df20
......@@ -22,6 +22,7 @@ class Application extends App {
return new PageController(
$c->query('AppName'),
$c->query('Request'),
$c->query('OCP\IConfig'),
$c->query('UsageDAO')
);
});
......
......@@ -12,6 +12,7 @@
namespace OCA\StorageUsage\Controller;
use OCP\IRequest;
use OCP\IConfig;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
......@@ -21,11 +22,13 @@ use OCA\StorageUsage\Db\UsageDAO;
class PageController extends Controller {
private $usagedao;
protected $usagedao;
protected $config;
public function __construct($AppName, IRequest $request, UsageDAO $usagedao) {
public function __construct($AppName, IRequest $request, IConfig $config, UsageDAO $usagedao) {
parent::__construct($AppName, $request);
$this->config = $config;
$this->usagedao = $usagedao;
}
......@@ -36,6 +39,23 @@ class PageController extends Controller {
*/
public function index() {
$data = $this->usagedao->getUsage();
$defaultQuota = $this->config->getAppValue('files', 'default_quota', 'none');
for ($i=0; $i < count($data); ++$i) {
$data[$i]['bytes'] = intval($data[$i]['bytes']);
if ($data[$i]['quotastring'] == "none") {
$data[$i]['quotavalue'] = INF;
} else if ($data[$i]['quotastring'] == "default") {
$data[$i]['quotastring'] = "default (" . $defaultQuota . ")";
$data[$i]['quotavalue'] = \OCP\Util::computerFileSize($defaultQuota);
} else {
$data[$i]['quotavalue'] = \OCP\Util::computerFileSize($data[$i]['quotastring']);
}
// workaround for division by zero - 1B is good enough
if ($data[$i]['quotavalue'] == 0) $data[$i]['quotavalue'] = 1;
}
$params = [ 'data' => $data ];
return new TemplateResponse('storageusage', 'main', $params); // templates/main.php
}
......
......@@ -31,11 +31,6 @@ class UsageDAO {
$stmt->closeCursor();
for ($i=0; $i < count($result); ++$i) {
$result[$i]['bytes'] = intval($result[$i]['bytes']);
$result[$i]['quotavalue'] = \OCP\Util::computerFileSize($result[$i]['quotastring']);
}
return $result;
}
......
......@@ -41,9 +41,9 @@
<tr class="<?php if ($alt=!$alt) echo 'alt';?>">
<td><?php p($row['username']); ?></td>
<td><?php p($row['objects']); ?></td>
<td><?php p($this->human_file_size($row['bytes'])); ?></td>
<td><?php p($row['quotastring']); ?></td>
<td><div class="storageusage-progress" storageusage-percent="<?php p($row['bytes'] / $row['quotavalue']); ?>"></div></td>
<td storageusage-bytes="<?php p($row['bytes']); ?>"><?php p($this->human_file_size($row['bytes'])); ?></td>
<td storageusage-quotavalue="<?php p($row['quotavalue']); ?>"><?php p($row['quotastring']); ?></td>
<td><div class="storageusage-progress" storageusage-percent="<?php p((int) ($row['bytes'] / $row['quotavalue'])); ?>"></div></td>
</tr>
<?php } ?>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment