refactor(values): created hierarchical 'machine' object
parent
2b7caece6c
commit
e517d6a82d
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
/* process functions */
|
||||
function getByteString($bytes) {
|
||||
$symbol = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
$exp = ($bytes ? floor(log($bytes)/log(1024)) : 0);
|
||||
|
|
@ -19,45 +20,40 @@
|
|||
}
|
||||
function getDriveValues($drives) {
|
||||
foreach ($drives as $drive) {
|
||||
array_push(
|
||||
$drive,
|
||||
disk_total_space($drive[1]),
|
||||
disk_free_space($drive[1])
|
||||
);
|
||||
array_push(
|
||||
$drive,
|
||||
getDifference($drive[3], $drive[4])
|
||||
);
|
||||
array_push(
|
||||
$drive,
|
||||
getPercentageUsed($drive[3], $drive[5])
|
||||
);
|
||||
$drive->spaceFree = disk_free_space($drive->location);
|
||||
$drive->spaceTotal = disk_total_space($drive->location);
|
||||
$drive->spaceUsed = getDifference(
|
||||
$drive->spaceFree, $drive->spaceTotal);
|
||||
$drive->spacePercentageUsed = getPercentageUsed(
|
||||
$drive->spaceTotal, $drive->spaceUsed);
|
||||
}
|
||||
return $drives;
|
||||
}
|
||||
|
||||
/* display functions */
|
||||
function printDrive($drive) {
|
||||
echo '
|
||||
<div class="drive">
|
||||
<h3>' . $drive[0] . '</h3>
|
||||
<h3>' . $drive->name . '</h3>
|
||||
<svg class="chart">
|
||||
<circle class="pie" />
|
||||
<circle
|
||||
id="' . $drive[0] . '"
|
||||
id="' . $drive->name . '"
|
||||
class="piece"
|
||||
stroke-dasharray="' . ($drive[5] ?
|
||||
$drive[5] : 0) * 31.4 / 100 . ' 31.4"
|
||||
stroke-dasharray="' . ($drive->spacePercentageUsed ?
|
||||
$drive->spacePercentageUsed : 0) * 31.4 / 100 . ' 31.4"
|
||||
/>
|
||||
</svg>
|
||||
<h5>Free Space: <em>' . getByteString($drive[3]) . '</em></h5>
|
||||
<h5>Used Space: <em>' . getByteString($drive[4]) . '</em></h5>
|
||||
<h5>Free Space: <em>' . getByteString($drive->spaceFree) . '</em></h5>
|
||||
<h5>Used Space: <em>' . getByteString($drive->spaceUsed) . '</em></h5>
|
||||
</div>';
|
||||
}
|
||||
function printService($service) {
|
||||
echo '
|
||||
<a href="' . $service[1] . '">
|
||||
<div class="service" id="' . $service[0] . '">
|
||||
<h3>' . $service[0] . '</h3>
|
||||
<h4>' . $service[2] . '</h4>
|
||||
<a href="' . $service->location . '">
|
||||
<div class="service" id="' . $service->name . '">
|
||||
<h3>' . $service->name . '</h3>
|
||||
<h4>' . $service->description . '</h4>
|
||||
</div>
|
||||
</a>';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
require 'values.php';
|
||||
require 'functions.php';
|
||||
|
||||
$driveValues = getDriveValues($drives);
|
||||
$driveValues = getDriveValues($machine->drives);
|
||||
?>
|
||||
<title><?php echo $machine[0] ?> - homo.casa</title>
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
|
|
@ -24,13 +24,13 @@
|
|||
<body>
|
||||
|
||||
<header>
|
||||
<?php echo '<h1>' . $machine[0] . '</h1>
|
||||
<p id="' . $machine[0] . '">' . $machine[1] . '</p>'; ?>
|
||||
<?php echo '<h1>' . $machine->name . '</h1>
|
||||
<p id="' . $machine->name . '">' . $machine->description . '</p>'; ?>
|
||||
</header>
|
||||
|
||||
<div id="drives">
|
||||
<?php
|
||||
echo "<h2>" . $driveLabel . "</h2>";
|
||||
echo "<h2>" . $machine->driveLabel . "</h2>";
|
||||
|
||||
foreach ($driveValues as $drive) {
|
||||
printDrive($drive);
|
||||
|
|
@ -40,17 +40,17 @@
|
|||
|
||||
<div id="services">
|
||||
<?php
|
||||
echo "<h2>" . $serviceLabel . "</h2>
|
||||
echo "<h2>" . $machine->serviceLabel . "</h2>
|
||||
<p>note: authentication required for access.</p>";
|
||||
|
||||
foreach ($services as $service) {
|
||||
foreach ($machine->services as $service) {
|
||||
printService($service);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<?php echo '<p id="' . $footer[0] . '">' . $footer[1] . '
|
||||
<?php echo '<p id="' . $machine->footer->name . '">' . $machine->footer->description . '
|
||||
</p>';?>
|
||||
</footer>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,32 @@
|
|||
<?php
|
||||
$machine = array(
|
||||
"Machine",
|
||||
"machine description"
|
||||
);
|
||||
$driveLabel = "Drives";
|
||||
$drives = array(
|
||||
array("disk1", "/disk1/location/", "disk1 description"),
|
||||
array("disk2", "/disk2/location/", "disk2 description"),
|
||||
array("disk3", "/disk3/location/", "disk3 description")
|
||||
);
|
||||
$serviceLabel = "Services";
|
||||
$services = array(
|
||||
array("service1", "https://service1.example.com", "service1 description"),
|
||||
array("service2", "https://service2.example.com", "service2 description"),
|
||||
array("service3", "https://service3.example.com", "service3 description")
|
||||
);
|
||||
$footer = array(
|
||||
"footer",
|
||||
"footer description"
|
||||
);
|
||||
$machine->name = "Machine";
|
||||
$machine->description = "machine description";
|
||||
|
||||
$disk1->name = "disk1";
|
||||
$disk1->description = "disk1 description";
|
||||
$disk1->location = "/disk1/location/";
|
||||
$disk2->name = "disk2";
|
||||
$disk2->description = "disk2 description";
|
||||
$disk2->location = "/disk2/location/";
|
||||
$disk3->name = "disk3";
|
||||
$disk3->description = "disk3 description";
|
||||
$disk3->location = "/disk3/location/";
|
||||
|
||||
$service1->name = "service1";
|
||||
$service1->description = "service1 description";
|
||||
$service1->location = "https://service1.example.com";
|
||||
$service2->name = "service2";
|
||||
$service2->description = "service2 description";
|
||||
$service2->location = "https://service2.example.com";
|
||||
$service3->name = "service3";
|
||||
$service3->description = "service3 description";
|
||||
$service3->location = "https://service3.example.com";
|
||||
|
||||
$machine->driveLabel = "Drives";
|
||||
$machine->drives = array($disk1, $disk2, $disk3);
|
||||
$machine->serviceLabel = "Services";
|
||||
$machine->services = array($service1, $service2, $service3);
|
||||
|
||||
$machine->footer->name = "footer";
|
||||
$machine->footer->description = "footer description";
|
||||
?>
|
||||
|
|
|
|||
Loading…
Reference in New Issue