Reworked Device Table and added table features

This commit is contained in:
2024-05-27 18:07:30 +02:00
parent 3e5166313e
commit fa3c1b8766
9 changed files with 522 additions and 393 deletions

View File

@@ -17,11 +17,36 @@ class DeviceController extends mfBaseController
protected function indexAction()
{
$deviceManufacturers = array_map(function($manufacturer) {
return [
"text" => $manufacturer->name,
"value" => $manufacturer->name,
];
}, DevicemanufactorModel::getAll());
$this->layout()->setTemplate("Device/Index");
$devices = DeviceModel::getAll();
$this->layout()->set("devices", $devices);
$deviceTypes = array_map(function($deviceType) {
return [
"text" => $deviceType->name,
"value" => $deviceType->name,
];
}, DevicetypeModel::getAll());
$JSGlobals = ["BASE_URL" => self::getUrl("Device"),
"DASHBOARD_URL" => self::getUrl("Dashboard"),
"MFAPPNAME" => MFAPPNAME_SLUG,
"PAGE_TITLE" => "Devices",
"PATH" => [
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
["text" => "Devices", "href" => self::getUrl("Device")]
],
"DEVICE_MANUFACTURERS" => $deviceManufacturers,
"DEVICE_TYPES" => $deviceTypes,
"DEVICE_API_URL" => self::getUrl("Device/api"),
];
$this->layout()->set("vueViewName", "Device");
$this->layout()->set("JSGlobals", $JSGlobals);
$this->layout()->setTemplate("VueViews/Vue");
}
@@ -83,7 +108,7 @@ class DeviceController extends mfBaseController
}
$this->layout()->set("device", $device);
return $this->addAction();
$this->addAction();
}
protected function saveAction()
@@ -253,57 +278,25 @@ class DeviceController extends mfBaseController
switch ($do) {
case "getDevices":
$devices = DeviceModel::getAll();
foreach ($devices as $device) {
$locationText = "";
$locationUrl = "";
if (trim($device->pop->name)) {
$locationText = $device->pop->name;
$locationUrl = self::getUrl("Pop", "Detail", ["id" => $device->pop->id]);
} else if (trim($device->addr_street)) {
$locationText = $device->addr_street . " " . $device->addr_number . ", " . $device->addr_zip . " " . $device->addr_city;
$locationUrl = "http://maps.google.com/?q=" . $locationText;
} else if (trim($device->gps_lat)) {
$locationText = $device->gps_lat . " , " . $device->gps_long;
$locationUrl = "http://maps.google.com/?q=" . $locationText;
}
$data[] = [
"name" => $device->name,
"devicetype" => $device->devicetype->name,
"devicemanufactor" => $device->devicetype->devicemanufactor->name,
"locationText" => $locationText,
"locationUrl" => $locationUrl,
"ip" => $device->ip,
"mac" => $device->mac,
"serial" => $device->serial,
"price" => $device->price != "0.0" ? $device->price : $device->devicetype->price,
"power" => $device->power != "0.0" ? $device->power : $device->devicetype->power,
"backup" => $device->last_config_backup ? (time() - $device->last_config_backup <= 172800 ? 'ok' : 'aged') : 'na',
];
}
die(json_encode($data));
break;
header('Content-Type: application/json');
die(json_encode($this->getDevices()));
case "getconfig":
$return = $this->getConfig($id, $format, $filename);
$this->getConfig($id, $format, $filename);
break;
case "createconfig":
$return = $this->createConfig($ip);
$this->createConfig($ip);
break;
case "getoltinfo":
$return = $this->getoltInfo($ip, $portid, $adv);
$this->getoltInfo($ip, $portid, $adv);
break;
case "getontinfo":
$return = $this->getontInfo($ip, $portid, $ont);
$this->getontInfo($ip, $portid, $ont);
break;
case "getontinfomac":
$return = $this->getontInfoMac($ip, $portid, $ont);
$this->getontInfoMac($ip, $portid, $ont);
break;
case "changeoltsplitter":
$return = $this->changeoltSplitter($id, $portid, $ports);
$this->changeoltSplitter($id, $portid, $ports);
break;
default:
$return = false;
@@ -352,7 +345,7 @@ class DeviceController extends mfBaseController
$returnUrl = "Device";
$returnAction = "Detail";
$returnVariables['id'] = $id;
return $this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker);
$this->redirect($returnUrl, $returnAction, $returnVariables);
}
private function changeoltSplitter($id, $portid, $ports)
@@ -390,4 +383,54 @@ class DeviceController extends mfBaseController
exit;
}
private function getDevices()
{
$devices = DeviceModel::getAll();
foreach ($devices as $device) {
$locationText = "";
$locationUrl = "";
if (trim($device->pop->name)) {
$locationText = $device->pop->name;
$locationUrl = self::getUrl("Pop", "Detail", ["id" => $device->pop->id]);
} else if (trim($device->addr_street)) {
$locationText = $device->addr_street . " " . $device->addr_number . ", " . $device->addr_zip . " " . $device->addr_city;
$locationUrl = "http://maps.google.com/?q=" . $locationText;
} else if (trim($device->gps_lat)) {
$locationText = $device->gps_lat . " , " . $device->gps_long;
$locationUrl = "http://maps.google.com/?q=" . $locationText;
}
$backup = 'na';
if ($device->last_config_backup) {
if (time() - $device->last_config_backup <= 172800) {
$backup = 'ok';
if ($device->autobackup==1) {
$backup = 'auto';
}
} else {
$backup = 'aged';
}
}
$data[] = [
"id" => $device->id,
"name" => $device->name,
"devicetype" => $device->devicetype->name,
"devicemanufactor" => $device->devicetype->devicemanufactor->name,
"locationText" => $locationText,
"locationUrl" => $locationUrl,
"ip" => $device->ip,
"mac" => $device->mac,
"serial" => $device->serial,
"price" => $device->price != "0.00" ? $device->price : $device->devicetype->price,
"power" => $device->power != "0.00" ? intval($device->power) : intval($device->devicetype->power),
"backup" => $backup,
];
}
return $data ?? [];
}
}