From 2af021040f9eec2bcf03b7f5e360fadc2b90bb16 Mon Sep 17 00:00:00 2001 From: Spitzer_Daniel Date: Mon, 20 Feb 2023 14:04:07 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Vlans-Pops=20auf=20Order=20Pills=20ge=C3=A4?= =?UTF-8?q?ndert.=20IPv6=20Anzeige=20hinzugef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Layout/default/Devicemanufactor/Index.php | 4 +-- Layout/default/Pop/Index.php | 30 ++++++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Layout/default/Devicemanufactor/Index.php b/Layout/default/Devicemanufactor/Index.php index 2eb12c5f3..82ac82ef2 100644 --- a/Layout/default/Devicemanufactor/Index.php +++ b/Layout/default/Devicemanufactor/Index.php @@ -36,7 +36,7 @@ $pagination_entity_name = "Devicemanufactor"; margin-top: -5px; } - .edit-weight { + .edit-width { width: 50px; } @@ -81,7 +81,7 @@ $pagination_entity_name = "Devicemanufactor"; Name Erstellt von - + diff --git a/Layout/default/Pop/Index.php b/Layout/default/Pop/Index.php index 01b475c6f..415ab89c2 100644 --- a/Layout/default/Pop/Index.php +++ b/Layout/default/Pop/Index.php @@ -36,6 +36,19 @@ $pagination_entity_name = "Pops"; margin-left: 30px !important; margin-top: -5px; } + + .edit-width { + width: 50px; + } + .font-weight-500 + { + font-weight: 500; + } + .order-date-pill + { + margin: 2px; + white-space: nowrap; + }
@@ -78,9 +91,9 @@ $pagination_entity_name = "Pops"; Name Netgebiet Zutritt - Vlan Public/Nat + Vlan Public/Nat/IPv6 Koordinaten - + @@ -94,13 +107,22 @@ $pagination_entity_name = "Pops"; - + vlan_public))) + $vlans .= 'Public: ' . $pop->vlan_public . ''; + if (!empty(trim($pop->vlan_nat))) + $vlans .= 'Nat: ' . $pop->vlan_nat . ''; + if (!empty(trim($pop->vlan_ipv6))) + $vlans .= 'IPv6: ' . $pop->vlan_ipv6 . ''; + ?> name ?> network->name ?> location ?> - vlan_public ?> / vlan_nat ?> + Date: Mon, 20 Feb 2023 22:15:36 +0100 Subject: [PATCH 2/3] =?UTF-8?q?datatables-std.css=20f=C3=BCr=20Standard=20?= =?UTF-8?q?DT=20erstellt=20datatables-std.js=20f=C3=BCr=20Standard=20DT=20?= =?UTF-8?q?erstellt=20zugewiesen=20an:=20Device,Devicetype,Devicemanufacto?= =?UTF-8?q?r,Pop,Filestore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pop Detail Ansicht erstellt Filestore auf DT umgebaut Bugfixing: * Bearbeiten aus verschiedenen Ansichten werden nun richtig zurückgeleitet (Devices/Pops) * Sortierung Devicetype in Devices wurde nun per Arraysort durchgeführt --- Layout/default/Device/Detail.php | 34 +++- Layout/default/Device/Form.php | 22 ++- Layout/default/Device/Index.php | 96 +--------- Layout/default/Devicemanufactor/Index.php | 98 +---------- Layout/default/Devicetype/Form.php | 2 +- Layout/default/Devicetype/Index.php | 98 +---------- Layout/default/Filestore/Index.php | 30 ++-- Layout/default/Pop/Detail.php | 166 +++++++++--------- Layout/default/Pop/Index.php | 120 +------------ application/Device/DeviceController.php | 33 +++- application/Device/DeviceModel.php | 11 +- .../Devicetype/DevicetypeController.php | 10 +- application/Devicetype/DevicetypeModel.php | 58 +++--- application/Pop/PopController.php | 35 +++- public/assets/css/datatables-std.css | 42 +++++ public/assets/css/select2-cstm.css | 11 ++ public/assets/js/datatables-std.js | 74 ++++++++ public/datatables/json/german.json | 25 +++ 18 files changed, 427 insertions(+), 538 deletions(-) create mode 100644 public/assets/css/datatables-std.css create mode 100644 public/assets/css/select2-cstm.css create mode 100644 public/assets/js/datatables-std.js create mode 100644 public/datatables/json/german.json diff --git a/Layout/default/Device/Detail.php b/Layout/default/Device/Detail.php index 3a075c56d..6a161376d 100644 --- a/Layout/default/Device/Detail.php +++ b/Layout/default/Device/Detail.php @@ -2,7 +2,7 @@ ?> - +
@@ -74,7 +46,7 @@ $pagination_entity_name = "Device"; - + @@ -83,7 +55,7 @@ $pagination_entity_name = "Device"; - + @@ -111,7 +83,7 @@ $pagination_entity_name = "Device"; @@ -152,69 +124,13 @@ $pagination_entity_name = "Device"; + \ No newline at end of file diff --git a/Layout/default/Devicemanufactor/Index.php b/Layout/default/Devicemanufactor/Index.php index 82ac82ef2..ce8eb742c 100644 --- a/Layout/default/Devicemanufactor/Index.php +++ b/Layout/default/Devicemanufactor/Index.php @@ -4,43 +4,7 @@ $pagination_baseurl_params = ["filter" => $filter]; $pagination_entity_name = "Devicemanufactor"; ?> - - - +
@@ -118,69 +82,13 @@ $pagination_entity_name = "Devicemanufactor"; + \ No newline at end of file diff --git a/Layout/default/Devicetype/Form.php b/Layout/default/Devicetype/Form.php index a0924f17f..ac4f20d18 100644 --- a/Layout/default/Devicetype/Form.php +++ b/Layout/default/Devicetype/Form.php @@ -1,5 +1,5 @@ - +
diff --git a/Layout/default/Devicetype/Index.php b/Layout/default/Devicetype/Index.php index 7830f643d..f09a21d50 100644 --- a/Layout/default/Devicetype/Index.php +++ b/Layout/default/Devicetype/Index.php @@ -4,42 +4,7 @@ $pagination_baseurl_params = ["filter" => $filter]; $pagination_entity_name = "Devicetype"; ?> - - - +
@@ -133,70 +98,15 @@ $pagination_entity_name = "Devicetype";
+ + \ No newline at end of file diff --git a/Layout/default/Filestore/Index.php b/Layout/default/Filestore/Index.php index e2e52cbb7..36395207d 100644 --- a/Layout/default/Filestore/Index.php +++ b/Layout/default/Filestore/Index.php @@ -1,10 +1,5 @@ -getUrl($Mod, "Index"); -$pagination_baseurl_params = ["filter" => $filter]; -$pagination_entity_name = "Dateien"; -?> - +
@@ -41,14 +36,24 @@ $pagination_entity_name = "Dateien"; -
Geräte NameDevice Name Geräte Typ Hersteller PopSeriennummer Preis max. Leistung
- $device->id]) ?>">name ?> + $device->id]) ?>">name ?> devicetype->name ?> devicetype->devicemanufactor->name ?>
+
+ + + + + + + + + + @@ -63,10 +68,9 @@ $pagination_entity_name = "Dateien"; +
Name Beschreibung Ersteller Bearbeiter
name ?>
- -
@@ -77,9 +81,15 @@ $pagination_entity_name = "Dateien"; + + - \ No newline at end of file diff --git a/Layout/default/Pop/Detail.php b/Layout/default/Pop/Detail.php index 3a075c56d..6cfd89bb6 100644 --- a/Layout/default/Pop/Detail.php +++ b/Layout/default/Pop/Detail.php @@ -2,7 +2,7 @@ ?> - +
@@ -20,13 +28,13 @@
-

Device data->name ?> - $devices->id]) ?>"> +

Pop: data->name ?> + $pops->id, 'returnto' => "pop-detail"]) ?>">

@@ -36,11 +44,14 @@ price)) { - $price = $devices->price; -} else { - $price = $devices->devicetype->price; -} +$vlans = ""; + +if (!empty(trim($pops->vlan_public))) + $vlans .= 'Public: ' . $pops->vlan_public . ''; +if (!empty(trim($pops->vlan_nat))) + $vlans .= 'Nat: ' . $pops->vlan_nat . ''; +if (!empty(trim($pops->vlan_ipv6))) + $vlans .= 'IPv6: ' . $pops->vlan_ipv6 . ''; ?>
@@ -56,113 +67,110 @@ if (!empty($devices->price)) { - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - + + +
Device Namename ?> Netzgebietnetwork->name ?>
IP-Adresseip ?> Namename ?>
Geräte Typdevicetype->name ?> Standort + gps_lat, '0') ?> + , gps_long, 0) ?>
Geräte Herstellerdevicetype->devicemanufactor->name ?> Standort Infolocation) ?>
Mac Adressemac ?> Access VLANs
Seriennummerserial ?>
Preis
Bemerkungcomment) ?> Interne Notiznote) ?>
-
+
-

Standort Informationen

+

Pop Devices

pop->name))) { + if (!empty($devices)) { ?>
- - - - - - - - - - - - -
Pop Namepop->name ?>
Adresse - pop->gps_lat, '0') ?> - , pop->gps_long, 0) ?>
-
- -
Keine Standort Informationen vorhanden
- - - - -
-
-
-

Config Backups

-
- -
- +
- + + + + + + + + + + + + + + + - - - - + price)) { + $price = $device->price; + } else { + $price = $device->devicetype->price; + } + ?> + + + + + + + + + + + + +
Datum/UhrzeitGeräte NameGeräte TypHerstellerIP-AdresseSeriennummerPreismax. Leistung
+ $device->id]) ?>">name ?> + devicetype->name ?>devicetype->devicemanufactor->name ?>ip ?>serial ?>devicetype->power ?> Watt
-
Keine Configs vorhanden
+
Keine Devices vorhanden
+ +
+

@@ -177,6 +185,6 @@ if (!empty($devices->price)) { - + \ No newline at end of file diff --git a/Layout/default/Pop/Index.php b/Layout/default/Pop/Index.php index 415ab89c2..4f20cdddd 100644 --- a/Layout/default/Pop/Index.php +++ b/Layout/default/Pop/Index.php @@ -4,52 +4,7 @@ $pagination_baseurl_params = ["filter" => $filter]; $pagination_entity_name = "Pops"; ?> - - - +
@@ -111,18 +66,19 @@ $pagination_entity_name = "Pops"; $vlans = ""; if (!empty(trim($pop->vlan_public))) - $vlans .= 'Public: ' . $pop->vlan_public . ''; + $vlans .= ' Public: ' . $pop->vlan_public . ''; if (!empty(trim($pop->vlan_nat))) - $vlans .= 'Nat: ' . $pop->vlan_nat . ''; + $vlans .= ' Nat: ' . $pop->vlan_nat . ''; if (!empty(trim($pop->vlan_ipv6))) - $vlans .= 'IPv6: ' . $pop->vlan_ipv6 . ''; + $vlans .= ' IPv6: ' . $pop->vlan_ipv6 . ''; ?> - name ?> + $pop->id]) ?>">name ?> + network->name ?> location ?> - + //refreshMap(); - let table; - $('#filterrow th').each(function (i) { - let title = $('#datatable thead th').eq($(this).index()).text(); - - if ($(this).index() == "5") { - - } else { - $(this).html(''); - } - }); - - table = $('#datatable').DataTable({ - buttons: [ - { - extend: 'excelHtml5', - text: 'XLSX Export', - className: 'btn-success margina' - - } - ], - orderCellsTop: true, - stateSave: true, - "initComplete": function () { - $('#datatable_filter').append(''); - $('#clear_cookie').click(function () { - $('input').val(''); - - table.search('').columns().search('').draw(); - }); - }, - "dom": 'flBrtip' - - }); - - $('#filterrow').on('keyup', 'input', function () { - - table - .column($(this).data('index')) - .search(this.value) - .draw(); - - - }); - var state = table.state.loaded(); - if (state) { - table.columns().eq(0).each(function (colIdx) { - var colSearch = state.columns[colIdx].search; - - if (colSearch.search) { - - - $('#filterrow').find("[data-index='" + colIdx + "']").val(colSearch.search); - - - } - }); - - table.draw(); - } + var hidesearch = [5]; $(document).ready(function () { }); - + \ No newline at end of file diff --git a/application/Device/DeviceController.php b/application/Device/DeviceController.php index 4ff29c800..328dae192 100644 --- a/application/Device/DeviceController.php +++ b/application/Device/DeviceController.php @@ -93,13 +93,11 @@ class DeviceController extends mfBaseController $data = []; $data['name'] = trim($r->name); $data['devicetype_id'] = $r->devicetype_id; - - if (empty(trim($r->pop_id))) { + if (trim($r->pop_id)=="0") { $data['pop_id'] = NULL; } else { $data['pop_id'] = $r->pop_id; } - $data['ip'] = $r->ip; $data['mac'] = $r->mac; $data['serial'] = $r->serial; @@ -139,11 +137,38 @@ class DeviceController extends mfBaseController $this->layout()->setFlash("Device konnte nicht angelegt werden", "error"); $this->redirect("Device"); } + $returnUrl="Device"; + $returnAction = "Index"; + $returnVariables = array(); + $returnAnker = ""; + if ($this->request->returnto) { + + if (strpos($this->request->returnto, "-") !== false) { + $urls = explode('-', $this->request->returnto); + $urlCounter = 0; + $returnUrlGen = ""; + foreach ($urls as $url) { + if ($urlCounter > 0) { + $returnUrlGen .= "/"; + } + $returnUrlGen .= ucfirst($url); + $urlCounter++; + } + $returnAction = ""; + $returnVariables['id'] = $id; + $returnUrl = $returnUrlGen; + } else { + $returnUrl = ucfirst($this->request->returnto); + + } + } + + if ($mode == "edit") { $this->layout()->setFlash("Device erfolgreich geändert", "success"); } else if ($mode = "add") { $this->layout()->setFlash("Device erfolgreich angelegt", "success"); } - $this->redirect("Device"); + $this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker); } } \ No newline at end of file diff --git a/application/Device/DeviceModel.php b/application/Device/DeviceModel.php index cd231746d..cd7bfb807 100644 --- a/application/Device/DeviceModel.php +++ b/application/Device/DeviceModel.php @@ -100,9 +100,8 @@ class DeviceModel public static function search($filter) { $items = []; $db = FronkDB::singleton(); - $where = self::getSqlFilter($filter); - $res = $db->select("Device", "*", "$where ORDER BY name, network_id"); + $res = $db->select("Device", "*", "$where ORDER BY name"); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { $items[] = new Device($data); @@ -115,10 +114,10 @@ class DeviceModel $where = "1=1 "; //var_dump($filter);exit; - if(array_key_exists("network_id", $filter)) { - $networkid = $filter['network_id']; - if(is_numeric($networkid)) { - $where .= " AND network_id=$networkid"; + if(array_key_exists("pop_id", $filter)) { + $popid = $filter['pop_id']; + if(is_numeric($popid)) { + $where .= " AND pop_id=$popid"; } } diff --git a/application/Devicetype/DevicetypeController.php b/application/Devicetype/DevicetypeController.php index cf5fd500d..3fbe660d6 100644 --- a/application/Devicetype/DevicetypeController.php +++ b/application/Devicetype/DevicetypeController.php @@ -60,7 +60,7 @@ class DevicetypeController extends mfBaseController $mode = "edit"; $devicetype = new Devicetype($id); if (!$devicetype->id) { - $this->layout()->setFlash("Gerätehersteller nicht gefunden", "error"); + $this->layout()->setFlash("Gerätetyp nicht gefunden", "error"); $this->redirect("Devicetype"); } } else { @@ -109,14 +109,14 @@ class DevicetypeController extends mfBaseController $id = $devicetype->save(); if (!$id) { - $this->layout()->setFlash("Gerätehersteller konnte nicht angelegt werden", "error"); + $this->layout()->setFlash("Gerätetyp konnte nicht angelegt werden", "error"); $this->redirect("Devicetype"); } if ($mode == "edit") { - $this->layout()->setFlash("Gerätehersteller erfolgreich geändert", "success"); + $this->layout()->setFlash("Gerätetyp erfolgreich geändert", "success"); } else if ($mode = "add") { - $this->layout()->setFlash("Gerätehersteller erfolgreich angelegt", "success"); + $this->layout()->setFlash("Gerätetyp erfolgreich angelegt", "success"); } $this->redirect("Devicetype"); } @@ -127,7 +127,7 @@ class DevicetypeController extends mfBaseController $id = $this->request->id; $devicetype = new Devicetype($id); if (!$devicetype->id || $devicetype->id != $id) { - $this->layout()->setFlash("Gerätehersteller nicht gefunden.", "error"); + $this->layout()->setFlash("Gerätetyp nicht gefunden.", "error"); $this->redirect("Devicetype"); } diff --git a/application/Devicetype/DevicetypeModel.php b/application/Devicetype/DevicetypeModel.php index f52f7f82f..dfa849cbf 100644 --- a/application/Devicetype/DevicetypeModel.php +++ b/application/Devicetype/DevicetypeModel.php @@ -1,6 +1,7 @@ $value) { - if(property_exists(get_called_class(), $field)) { - if(substr($field, 0, 5) == "vlan_" && !$value) { + foreach ($data as $field => $value) { + if (property_exists(get_called_class(), $field)) { + if (substr($field, 0, 5) == "vlan_" && !$value) { $model->$field = null; continue; } @@ -30,45 +33,47 @@ class DevicetypeModel { } $me = mfValuecache::singleton()->get("me"); - if(!$me) { + if (!$me) { $me = new User(); $me->loadMe(); mfValuecache::singleton()->set("me", $me); } - if($model->create_by === null) { + if ($model->create_by === null) { $model->create_by = $me->id; } - if($model->edit_by === null) { + if ($model->edit_by === null) { $model->edit_by = $me->id; } return $model; } - public static function getOne($id) { - if(!is_numeric($id) || !$id) { + public static function getOne($id) + { + if (!is_numeric($id) || !$id) { throw new Exception("Invalid number", 400); } $item = []; $db = FronkDB::singleton(); $res = $db->select("Devicetype", "*", "id=$id LIMIT 1"); - if($db->num_rows($res)) { + if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Devicetype($data); } return $item; } - public static function getAll() { + public static function getAll() + { $items = []; $db = FronkDB::singleton(); - $res = $db->select("Devicetype", "*"); - if($db->num_rows($res)) { - while($data = $db->fetch_object($res)) { + $res = $db->select("Devicetype", "*", "1=1 ORDER BY name"); + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { $items[] = new Devicetype($data); } } @@ -76,15 +81,16 @@ class DevicetypeModel { } - public static function getFirst() { + public static function getFirst() + { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $res = $db->select("Devicetype", "*", "$where ORDER BY name, network_id"); - if($db->num_rows($res)) { + if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Devicetype($data); - if($item->id) { + if ($item->id) { return $item; } else { return null; @@ -93,27 +99,29 @@ class DevicetypeModel { return null; } - public static function search($filter) { + public static function search($filter) + { $items = []; $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $res = $db->select("Devicetype", "*", "$where ORDER BY name, network_id"); - if($db->num_rows($res)) { - while($data = $db->fetch_object($res)) { + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { $items[] = new Devicetype($data); } } return $items; } - private static function getSqlFilter($filter) { + private static function getSqlFilter($filter) + { $where = "1=1 "; //var_dump($filter);exit; - if(array_key_exists("network_id", $filter)) { + if (array_key_exists("network_id", $filter)) { $networkid = $filter['network_id']; - if(is_numeric($networkid)) { + if (is_numeric($networkid)) { $where .= " AND network_id=$networkid"; } } diff --git a/application/Pop/PopController.php b/application/Pop/PopController.php index bc4a7c40c..b4a9c6f74 100644 --- a/application/Pop/PopController.php +++ b/application/Pop/PopController.php @@ -35,13 +35,15 @@ class PopController extends mfBaseController $this->redirect("Pop"); } - $device = new Device($id); - if ($device->id != $id) { + $pop = new Pop($id); + if ($pop->id != $id) { $this->layout()->setFlash("Pop nicht gefunden", "error"); $this->redirect("Pop"); } $this->layout()->setTemplate("Pop/Detail"); + $filter['pop_id'] = $id; + $this->layout()->set("devices", DeviceModel::search($filter)); $pops = PopModel::getOne($id); $this->layout()->set("pops", $pops); @@ -130,11 +132,36 @@ class PopController extends mfBaseController return $this->addAction(); } if ($this->request->returnto) { - $this->returUrl = ucfirst($this->request->returnto); + $returnAction = "Index"; + $returnVariables = array(); + $returnAnker = ""; + + + if (strpos($this->request->returnto, "-") !== false) { + $urls = explode('-', $this->request->returnto); + $urlCounter = 0; + $returnUrl = ""; + foreach ($urls as $url) { + if ($urlCounter > 0) { + $returnUrl .= "/"; + } + $returnUrl .= ucfirst($url); + $urlCounter++; + } + $returnAction = ""; + $returnVariables['id'] = $id; + $this->returUrl = $returnUrl; + var_dump($returnUrl); + } else { + $this->returUrl = ucfirst($this->request->returnto); + + } + } else { + $returnAnker = "view=pops&net=" . $pop->network_id; } $this->layout()->setFlash("Pop erfolgreich gespeichert.", "success"); - $this->redirect($this->returUrl, "Index", [], "view=pops&net=" . $pop->network_id); + $this->redirect($this->returUrl, $returnAction, $returnVariables, $returnAnker); } diff --git a/public/assets/css/datatables-std.css b/public/assets/css/datatables-std.css new file mode 100644 index 000000000..64953aef9 --- /dev/null +++ b/public/assets/css/datatables-std.css @@ -0,0 +1,42 @@ +#filterrow input { + width: 100%; + padding: 3px; + box-sizing: border-box; + display: table-header-group; + height: unset; +} + +.dataTables_wrapper .dataTables_filter { + float: left; + text-align: left; +} + +.dataTables_wrapper .dataTables_length { + float: right; +} + +.clear-fa { + margin-left: 5px; + font-size: 23px; + vertical-align: middle; + color: #cb2929; + cursor: pointer; +} + +.margina { + margin-left: 30px !important; + margin-top: -5px; +} + +.edit-width { + width: 50px; +} + +.order-date-pill { + margin: 2px; + white-space: nowrap; +} + +.font-weight-500 { + font-weight: 500; +} diff --git a/public/assets/css/select2-cstm.css b/public/assets/css/select2-cstm.css new file mode 100644 index 000000000..f9258132e --- /dev/null +++ b/public/assets/css/select2-cstm.css @@ -0,0 +1,11 @@ +.select2-container .select2-selection--single { + height: calc(1.5em + 0.9rem + 2px); +} + +.select2-container--default .select2-selection--single .select2-selection__rendered { + + line-height: calc(1.5em + 0.9rem + 2px); +} +.select2-container--default .select2-selection--single { + border: 1px solid #ced4da; +} \ No newline at end of file diff --git a/public/assets/js/datatables-std.js b/public/assets/js/datatables-std.js new file mode 100644 index 000000000..ef9f7875c --- /dev/null +++ b/public/assets/js/datatables-std.js @@ -0,0 +1,74 @@ +let table; +if (typeof hidesearch === "undefined") { + var hidesearch; + hidesearch = [100]; + console.log(hidesearch); +} + +if (typeof cstmdom === "undefined") { + var cstmdom; + cstmdom = "flBrtip"; + +} + +$('#filterrow th').each(function (i) { + let title = $('#datatable thead th').eq($(this).index()).text(); + + if (hidesearch.includes($(this).index())) { + + } else { + $(this).html(''); + } +}); + +table = $('#datatable').DataTable({ + buttons: [ + { + extend: 'excelHtml5', + text: 'XLSX Export', + className: 'btn-success margina' + + } + ], + "language": { + "url": "/datatables/json/german.json" + }, + orderCellsTop: true, + stateSave: true, + "initComplete": function () { + $('#datatable_filter').append(''); + $('#clear_cookie').click(function () { + $('input').val(''); + + table.search('').columns().search('').draw(); + }); + }, + "dom": cstmdom + +}); + +$('#filterrow').on('keyup', 'input', function () { + + table + .column($(this).data('index')) + .search(this.value) + .draw(); + + +}); +let state = table.state.loaded(); +if (state) { + table.columns().eq(0).each(function (colIdx) { + var colSearch = state.columns[colIdx].search; + + if (colSearch.search) { + + + $('#filterrow').find("[data-index='" + colIdx + "']").val(colSearch.search); + + + } + }); + + table.draw(); +} \ No newline at end of file diff --git a/public/datatables/json/german.json b/public/datatables/json/german.json new file mode 100644 index 000000000..5e3753a41 --- /dev/null +++ b/public/datatables/json/german.json @@ -0,0 +1,25 @@ + + +{ + "sEmptyTable": "Keine Daten in der Tabelle vorhanden", + "sInfo": "_START_ bis _END_ von _TOTAL_ Einträgen", + "sInfoEmpty": "0 bis 0 von 0 Einträgen", + "sInfoFiltered": "(gefiltert von _MAX_ Einträgen)", + "sInfoPostFix": "", + "sInfoThousands": ".", + "sLengthMenu": "_MENU_ Einträge anzeigen", + "sLoadingRecords": "Wird geladen...", + "sProcessing": "Bitte warten...", + "sSearch": "Suchen", + "sZeroRecords": "Keine Einträge vorhanden.", + "oPaginate": { + "sFirst": "Erste", + "sPrevious": "Zurück", + "sNext": "Nächste", + "sLast": "Letzte" + }, + "oAria": { + "sSortAscending": ": aktivieren, um Spalte aufsteigend zu sortieren", + "sSortDescending": ": aktivieren, um Spalte absteigend zu sortieren" + } +} From 0ce064b56bdd6943a2f0badb1e02601fd8641f10 Mon Sep 17 00:00:00 2001 From: Spitzer_Daniel Date: Wed, 22 Mar 2023 15:23:35 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Ger=C3=A4tehersteller,=20Devices,=20API=20E?= =?UTF-8?q?rweiterungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Layout/default/Device/Detail.php | 95 +++++++++++-- Layout/default/Device/Form.php | 39 +++++- Layout/default/Device/Index.php | 15 +- Layout/default/Devicemanufactor/Form.php | 7 + application/Api/v1/DeviceApicontroller.php | 25 ++++ application/Device/DeviceController.php | 93 +++++++++++-- application/Device/DeviceModel.php | 131 ++++++++++++++---- .../DevicemanufactorController.php | 1 + public/assets/css/datatables-std.css | 41 ++++++ 9 files changed, 395 insertions(+), 52 deletions(-) create mode 100644 application/Api/v1/DeviceApicontroller.php diff --git a/Layout/default/Device/Detail.php b/Layout/default/Device/Detail.php index 6a161376d..c8d9ca4c6 100644 --- a/Layout/default/Device/Detail.php +++ b/Layout/default/Device/Detail.php @@ -25,7 +25,8 @@
-

Device: data->name ?> +

Device: data->name ?> + $devices->id, 'returnto' => "device-detail"]) ?>"> @@ -36,11 +37,17 @@ price)) { +if ($devices->price != "0.00") { $price = $devices->price; } else { $price = $devices->devicetype->price; } +if ($devices->power != "0.0") { + $power = $devices->power; +} else { + $power = $devices->devicetype->power; +} + ?>
@@ -83,6 +90,10 @@ if (!empty($devices->price)) { Preis € + + Leistung + Watt + Bemerkung comment) ?> @@ -152,11 +163,21 @@ if (!empty($devices->price)) {
-
-

Config Backups

+
+

Config Backups

+ devicetype->devicemanufactor->config_backup > count()): ?> + + +
success == "true" && $devicesconfig->data > count()) { ?>
@@ -164,21 +185,35 @@ if (!empty($devices->price)) { + - - - - + data as $config) : + $configfileCleartext = $config->config_cleartext; + $configfileCompressed = $config->config_compressed; + $configid = $config->id; + ?> + + + + + + +
Datum/Uhrzeit
config_timestamp); ?> + + TXT / + XML
-
Keine Configs vorhanden
- +
+
Keine Configs vorhanden
+
@@ -191,10 +226,48 @@ if (!empty($devices->price)) {
+devicetype->devicemanufactor->config_backup > count()): + $year = date("Y", time()); + $month = date("n", time()); + $day = date("d", time()); + $config = $devices->devicetype->devicemanufactor->config_backup; + $config = str_replace("&&YEAR&&", $year, $config); + $config = str_replace("&&MONTH&&", $month, $config); + $config = str_replace("&&DAY&&", $day, $config); + + ?> + + + + diff --git a/Layout/default/Device/Form.php b/Layout/default/Device/Form.php index 3da64e550..3714e7b24 100644 --- a/Layout/default/Device/Form.php +++ b/Layout/default/Device/Form.php @@ -1,11 +1,25 @@ id]=$devicetype->devicemanufactor->name . " " . $devicetype->name; + $deviceTypes[$devicetype->id] = $devicetype->devicemanufactor->name . " " . $devicetype->name; } asort($deviceTypes); - +if ($device->price == "0.00") { + $price = ""; +} else { + $price = $device->price; +} +if ($device->power == "0.0") { + $power = ""; +} else { + $power = $device->power; +} +if (isset($_GET['returnto']) && $_GET['returnto'] == "device-detail") { + $cancelUrl = self::getUrl("Device", "Detail", ["id" => $device->id]); +} else { + $cancelUrl = self::getUrl("Device"); +} ?> @@ -34,7 +48,6 @@ asort($deviceTypes);

id) ? "Device bearbeiten" : "Neues Gerät" ?>

-
$_GET["returnto"]]) ?>">
@@ -93,6 +106,22 @@ asort($deviceTypes); value="serial ?>">
+
+ +
+ +
+
+
+ +
+ +
+
@@ -109,6 +138,10 @@ asort($deviceTypes);
+ + + +
diff --git a/Layout/default/Device/Index.php b/Layout/default/Device/Index.php index 04b81e309..b506d76e0 100644 --- a/Layout/default/Device/Index.php +++ b/Layout/default/Device/Index.php @@ -4,7 +4,7 @@ $pagination_baseurl_params = ["filter" => $filter]; $pagination_entity_name = "Device"; ?> - + @@ -74,11 +74,16 @@ $pagination_entity_name = "Device"; price)) { + if ($device->price != "0.00") { $price = $device->price; } else { $price = $device->devicetype->price; } + if ($device->power != "0.0") { + $power = $device->power; + } else { + $power = $device->devicetype->power; + } ?> @@ -94,7 +99,7 @@ $pagination_entity_name = "Device"; mac ?> serial ?> € - devicetype->power ?> Watt + Watt @@ -124,13 +129,13 @@ $pagination_entity_name = "Device"; - + \ No newline at end of file diff --git a/Layout/default/Devicemanufactor/Form.php b/Layout/default/Devicemanufactor/Form.php index a524cc9fc..0d2b6100e 100644 --- a/Layout/default/Devicemanufactor/Form.php +++ b/Layout/default/Devicemanufactor/Form.php @@ -42,6 +42,13 @@ value="name ?>">
+
+ +
+ +
+

diff --git a/application/Api/v1/DeviceApicontroller.php b/application/Api/v1/DeviceApicontroller.php new file mode 100644 index 000000000..2d2b760fb --- /dev/null +++ b/application/Api/v1/DeviceApicontroller.php @@ -0,0 +1,25 @@ +db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); + $this->addRoute("/device/getDevices", "getDevices", "GET"); + + } + + protected function getDevices() + { + $devices = DeviceModel::getAll(); + foreach ($devices as $key => $device) { + $deviceReturn[$key]['id'] = $device->id; + $deviceReturn[$key]['name'] = $device->name; + $deviceReturn[$key]['ip'] = $device->ip; + $deviceReturn[$key]['serial'] = $device->serial; + } + + return mfResponse::Ok($deviceReturn); + + } +} \ No newline at end of file diff --git a/application/Device/DeviceController.php b/application/Device/DeviceController.php index 328dae192..37c9b49c6 100644 --- a/application/Device/DeviceController.php +++ b/application/Device/DeviceController.php @@ -42,7 +42,9 @@ class DeviceController extends mfBaseController } $this->layout()->setTemplate("Device/Detail"); + $devicesconfig = DeviceModel::getconifg($id); $devices = DeviceModel::getOne($id); + $this->layout()->set("devicesconfig", $devicesconfig); $this->layout()->set("devices", $devices); } @@ -60,13 +62,13 @@ class DeviceController extends mfBaseController $id = $this->request->id; if (!is_numeric($id) || !$id) { - $this->layout()->setFlash("Gerät nicht gefunden", "error"); + $this->layout()->setFlash("Device nicht gefunden", "error"); $this->redirect("Device"); } $device = new Device($id); if ($device->id != $id) { - $this->layout()->setFlash("Gerät nicht gefunden", "error"); + $this->layout()->setFlash("Device nicht gefunden", "error"); $this->redirect("Device"); } @@ -93,7 +95,7 @@ class DeviceController extends mfBaseController $data = []; $data['name'] = trim($r->name); $data['devicetype_id'] = $r->devicetype_id; - if (trim($r->pop_id)=="0") { + if (trim($r->pop_id) == "0") { $data['pop_id'] = NULL; } else { $data['pop_id'] = $r->pop_id; @@ -101,6 +103,16 @@ class DeviceController extends mfBaseController $data['ip'] = $r->ip; $data['mac'] = $r->mac; $data['serial'] = $r->serial; + if (empty(trim($r->price))) { + $data['price'] = "0.00"; + } else { + $data['price'] = $r->price; + } + if (empty(trim($r->power))) { + $data['power'] = "0.0"; + } else { + $data['power'] = $r->power; + } $data['comment'] = $r->comment; $ipv4_validation_regex = "/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/"; @@ -133,11 +145,8 @@ class DeviceController extends mfBaseController // exit; $id = $device->save(); - if (!$id) { - $this->layout()->setFlash("Device konnte nicht angelegt werden", "error"); - $this->redirect("Device"); - } - $returnUrl="Device"; + + $returnUrl = "Device"; $returnAction = "Index"; $returnVariables = array(); $returnAnker = ""; @@ -163,6 +172,15 @@ class DeviceController extends mfBaseController } } + if (!$id) { + $returnVariables['id'] = $r->id; + if ($mode == "edit") { + $this->layout()->setFlash("Device konnte nicht gespeichert werden", "error"); + } else if ($mode = "add") { + $this->layout()->setFlash("Device konnte nicht angelegt werden", "error"); + } + $this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker); + } if ($mode == "edit") { $this->layout()->setFlash("Device erfolgreich geändert", "success"); @@ -171,4 +189,63 @@ class DeviceController extends mfBaseController } $this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker); } + + protected function apiAction() + { + if (!$this->me->is(["Admin"])) { + $this->redirect("Dashboard"); + } + $do = $this->request->do; + $format = $this->request->format; + $filename = $this->request->filename; + $id = $this->request->id; + $ip = $this->request->ip; + + $data = []; + + switch ($do) { + case "getconfig": + $return = $this->getConfig($id, $format, $filename); + break; + case "createconfig": + $return = $this->createConfig($ip); + break; + default: + $return = false; + } + + } + + private function getConfig($id, $format, $filename) + { + $configDownload = DeviceModel::getconifgdownload($id, $format); +// + +// header('Content-Type: application/octet-stream'); + header('Content-Type: text/plain'); + header('Content-disposition: attachment; filename="' . $filename . '"'); + echo $configDownload; + + exit; + } + + private function createConfig($ip) + { + $r = $this->request; + $id = $r->id; + $createConfig = DeviceModel::configcreate($ip); + if ($createConfig->success==="true") + { + $this->layout()->setFlash("Backup wurde erfolgreich erstellt", "success"); + } + else + { + $this->layout()->setFlash("Backup konnte nicht erstellt werden. Fehler: ".$createConfig->error, "error"); + } + $returnUrl = "Device"; + $returnAction = "Detail"; + $returnVariables['id'] = $id; + return $this->redirect($returnUrl, $returnAction, $returnVariables, $returnAnker); + } + } \ No newline at end of file diff --git a/application/Device/DeviceModel.php b/application/Device/DeviceModel.php index cd7bfb807..b5df9bdcc 100644 --- a/application/Device/DeviceModel.php +++ b/application/Device/DeviceModel.php @@ -5,8 +5,8 @@ class DeviceModel public $name = null; public $ip = null; public $mac = null; - public $serial= null; - public $comment= null; + public $serial = null; + public $comment = null; public $devicetype_id = null; public $pop_id = null; @@ -16,16 +16,18 @@ class DeviceModel public $create = null; public $edit = null; - public static function find($data) { + public static function find($data) + { } - public static function create(Array $data) { + public static function create(array $data) + { $model = new Device(); - foreach($data as $field => $value) { - if(property_exists(get_called_class(), $field)) { - if(substr($field, 0, 5) == "vlan_" && !$value) { + foreach ($data as $field => $value) { + if (property_exists(get_called_class(), $field)) { + if (substr($field, 0, 5) == "vlan_" && !$value) { $model->$field = null; continue; } @@ -34,45 +36,47 @@ class DeviceModel } $me = mfValuecache::singleton()->get("me"); - if(!$me) { + if (!$me) { $me = new User(); $me->loadMe(); mfValuecache::singleton()->set("me", $me); } - if($model->create_by === null) { + if ($model->create_by === null) { $model->create_by = $me->id; } - if($model->edit_by === null) { + if ($model->edit_by === null) { $model->edit_by = $me->id; } return $model; } - public static function getOne($id) { - if(!is_numeric($id) || !$id) { + public static function getOne($id) + { + if (!is_numeric($id) || !$id) { throw new Exception("Invalid number", 400); } $item = []; $db = FronkDB::singleton(); $res = $db->select("Device", "*", "id=$id LIMIT 1"); - if($db->num_rows($res)) { + if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Device($data); } return $item; } - public static function getAll() { + public static function getAll() + { $items = []; $db = FronkDB::singleton(); $res = $db->select("Device", "*"); - if($db->num_rows($res)) { - while($data = $db->fetch_object($res)) { + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { $items[] = new Device($data); } } @@ -80,15 +84,16 @@ class DeviceModel } - public static function getFirst() { + public static function getFirst() + { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $res = $db->select("Device", "*", "$where ORDER BY name, network_id"); - if($db->num_rows($res)) { + if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Device($data); - if($item->id) { + if ($item->id) { return $item; } else { return null; @@ -97,26 +102,28 @@ class DeviceModel return null; } - public static function search($filter) { + public static function search($filter) + { $items = []; $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); $res = $db->select("Device", "*", "$where ORDER BY name"); - if($db->num_rows($res)) { - while($data = $db->fetch_object($res)) { + if ($db->num_rows($res)) { + while ($data = $db->fetch_object($res)) { $items[] = new Device($data); } } return $items; } - private static function getSqlFilter($filter) { + private static function getSqlFilter($filter) + { $where = "1=1 "; //var_dump($filter);exit; - if(array_key_exists("pop_id", $filter)) { + if (array_key_exists("pop_id", $filter)) { $popid = $filter['pop_id']; - if(is_numeric($popid)) { + if (is_numeric($popid)) { $where .= " AND pop_id=$popid"; } } @@ -124,4 +131,78 @@ class DeviceModel //var_dump($filter, $where);exit; return $where; } + + public static function getconifg($id) + { + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => 'https://172.16.5.56/api/deviceconfigs/' . $id, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer 4|6l5ixx3CYBP7xClqEfVAC3zrBbQlxusAtu4zNwQp'), + )); + $response = curl_exec($curl); + curl_close($curl); + return json_decode($response); + } + + public static function getconifgdownload($id, $format) + { + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => 'https://172.16.5.56/api/deviceconfigsdownload/' . $id . '/' . $format, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer 5|3QyhSkLgzrHwdVt05wQFUp2sFciiFhhGzucJirnI'), + )); + + $response = curl_exec($curl); + + curl_close($curl); +// echo $response; +// var_dump($response); + return ($response); + } + + + public static function configcreate($ip) + { + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => 'https://172.16.5.56/api/deviceconfigscreate/' . $ip , + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Authorization: Bearer 5|3QyhSkLgzrHwdVt05wQFUp2sFciiFhhGzucJirnI'), + )); + $response = curl_exec($curl); + + return json_decode($response); + } } \ No newline at end of file diff --git a/application/Devicemanufactor/DevicemanufactorController.php b/application/Devicemanufactor/DevicemanufactorController.php index 2b57e377a..cc535e56d 100644 --- a/application/Devicemanufactor/DevicemanufactorController.php +++ b/application/Devicemanufactor/DevicemanufactorController.php @@ -68,6 +68,7 @@ class DevicemanufactorController extends mfBaseController $data = []; $data['name'] = trim($r->name); + $data['config_backup'] = trim($r->config_backup); if (!$data['name']) { diff --git a/public/assets/css/datatables-std.css b/public/assets/css/datatables-std.css index 64953aef9..b0e233eb8 100644 --- a/public/assets/css/datatables-std.css +++ b/public/assets/css/datatables-std.css @@ -32,6 +32,10 @@ width: 50px; } +.edit-width-large { + width: 100px; +} + .order-date-pill { margin: 2px; white-space: nowrap; @@ -40,3 +44,40 @@ .font-weight-500 { font-weight: 500; } + +.history-ico { + color: #007bff; + cursor: pointer; +} + +.history-ico:hover { + color: #006875; + +} + +.code-ico { + cursor: pointer; + font-size: 25px; + margin-top: 7px; + margin-left: 10px; +} + +.spinner-ico { + margin-left: 5px; +} + +.filestore-history { + background-color: #33ff0021 !important; +} + +.filestore-history-td { + padding: 0 0px 0 10px !important; + box-shadow: unset; +} +.filestore-history-td:hover { + box-shadow: unset !important; +} +.filestore-history-tr:hover{ + color: unset !important; + background-color: #fff !important; +} \ No newline at end of file