added new fcp filter

This commit is contained in:
2025-09-11 14:32:39 +02:00
parent 8a53e31fa3
commit e1bfb5e96d
3 changed files with 115 additions and 26 deletions

View File

@@ -171,7 +171,14 @@
<label class="form-label" for="filter_home_oaid_rimo_id">Home OAID / Rimo ID</label>
<input type="text" class="form-control" name="filter[home_oaid_rimo_id]" id="filter_home_oaid_rimo_id" value="<?=(array_key_exists("home_oaid_rimo_id", $filter)) ? $filter['home_oaid_rimo_id'] : ""?>" />
</div>
<div class="col-sm-12 col-md-1">
<label class="form-label" for="filter_fcp">FCP</label>
<select name="filter[rimo_fcp_name][]" id="filter_fcp" multiple class="form-control">
<option value="">Kein FCP gefunden</option>
</select>
</div>
</div>
<div class="row mt-2">
<div class="col">
@@ -225,6 +232,7 @@
<th>Straße</th>
<th>Hausnr.</th>
<th>Stiege</th>
<th>FCP</th>
<th>Homes/<wbr>Preorders</th>
<th>Rimo-ID</th>
<th>Rollout Jahr</th>
@@ -244,6 +252,7 @@
<td><?=$address->strasse->name?></td>
<td><?=$address->hausnummer?></td>
<td><?=$address->stiege?></td>
<td><?=$address->rimo_fcp_name ?? 'N/A'?></td>
<td><?=count($address->wohneinheiten)?>
<span class="text-secondary" title="<?=($address->tool_building_type == 0) ? "Unbekannt" : (($address->tool_building_type == 1) ? "EFH" : "MPH")?>">
<i class="fas fa-fw <?=($address->tool_building_type == 0) ? "fa-question" : (($address->tool_building_type == 1) ? "fa-home" : "fa-building")?>"></i>
@@ -276,29 +285,66 @@
</div>
</div>
<script>
$("#filter_status_id").select2({closeOnSelect: false});
$("#filter_status_flag").select2({closeOnSelect: false});
$("#filter_network_id").select2({closeOnSelect: false});
<script>
$(document).ready(function() {
$("#filter_status_id, #filter_status_flag, #filter_network_id").select2({ closeOnSelect: false });
$('#filter_network_id').change(function() {
if($('#filter_network_id').val() === "null") {
$('#filter-gemeinde-id').hide();
$('#filter-gemeinde-text').show();
$('#filter-ortschaft-id').hide();
$('#filter-ortschaft-text').show();
$('#filter-gemeinde-id option:first').prop("selected", "selected");
$('#filter-ortschaft-id option:first').prop("selected", "selected");
} else {
$('#filter-gemeinde-text').hide();
$('#filter-gemeinde-id').show();
$('#filter-ortschaft-text').hide();
$('#filter-ortschaft-id').show();
}
$('#filter_gemeinde').val("");
$('#filter_ortschaft').val("");
});
</script>
const fcpSelect = $("#filter_fcp");
const networkSelect = $("#filter_network_id");
const apiUrl = "<?=self::getUrl("AddressDB", "api")?>";
const updateFcpSelect = (placeholder, data = []) => {
fcpSelect.empty().select2({ data, placeholder, allowClear: true });
};
updateFcpSelect("Bitte ein Netzgebiet auswählen");
networkSelect.on('change', function() {
const selectedNets = $(this).val() || [];
const hasNull = Array.isArray(selectedNets) && selectedNets.includes("null");
$('#filter-gemeinde-text, #filter-ortschaft-text').toggle(hasNull);
$('#filter-gemeinde-id, #filter-ortschaft-id').toggle(!hasNull);
$('#filter_gemeinde, #filter_ortschaft').val("");
if (hasNull) {
$('#filter-gemeinde-id, #filter-ortschaft-id').find('option:first').prop("selected", "selected");
}
if (selectedNets.length !== 1) {
updateFcpSelect(selectedNets.length > 1 ? "Bitte genau ein Netzgebiet auswählen" : "Kein Netzgebiet ausgewählt");
return;
}
const networkId = selectedNets[0];
if (networkId === 'null') {
updateFcpSelect("Kein Netzgebiet ausgewählt");
return;
}
$.get(apiUrl, { do: "getFCPsForNetwork", network_id: networkId }, (response) => {
if (response?.status === "OK" && Array.isArray(response.result)) {
let fcpData = response.result;
fcpData.unshift({ id: "", text: "" });
fcpData.sort((a, b) => {
const aN = a.text.replace(/\D/g, ""), bN = b.text.replace(/\D/g, "");
return aN && bN ? parseInt(aN, 10) - parseInt(bN, 10) : a.text.localeCompare(b.text);
});
updateFcpSelect("FCP auswählen", fcpData);
const fcpValues = new URLSearchParams(window.location.search).getAll("filter[rimo_fcp_name][]");
if (fcpValues.length > 0) {
fcpSelect.val(fcpValues).trigger("change");
}
} else {
updateFcpSelect("Keine FCPs gefunden");
}
}, "json").fail(() => {
updateFcpSelect("Fehler beim Laden");
});
}).trigger('change');
});
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -533,6 +533,35 @@ class ADBHausnummerModel {
$where .= ")";
}
if (array_key_exists("rimo_fcp_name", $filter)) {
if (is_array($filter['rimo_fcp_name'])) {
$escapedNames = array_map(function($name) {
return "'" . FronkDB::singleton()->escape($name) . "'";
}, $filter['rimo_fcp_name']);
$where .= " AND Hausnummer.rimo_fcp_name IN (" . implode(", ", $escapedNames) . ")";
} else {
$rimo_fcp_name = FronkDB::singleton()->escape($filter['rimo_fcp_name']);
if ($rimo_fcp_name) {
$where .= " AND Hausnummer.rimo_fcp_name = '$rimo_fcp_name'";
}
}
}
if (array_key_exists("fcp_id", $filter)) {
if (is_array($filter['fcp_id'])) {
$escapedIds = array_map(function($id) {
return "'" . FronkDB::singleton()->escape($id) . "'";
}, $filter['fcp_id']);
$where .= " AND Hausnummer.fcp_id IN (" . implode(", ", $escapedIds) . ")";
} else {
$fcp_id = FronkDB::singleton()->escape($filter['fcp_id']);
if ($fcp_id) {
$where .= " AND Hausnummer.fcp_id = '$fcp_id'";
}
}
}
return $where;
}

View File

@@ -196,7 +196,8 @@ class AddressDBController extends mfBaseController {
if(is_array($filter) && count($filter)) {
foreach($filter as $name => $value) {
if(strlen($value) > 0) $new_filter[$name] = $value;
if (is_array($value) && count($value)) $new_filter[$name] = $value;
else if(strlen($value) > 0) $new_filter[$name] = $value;
}
}
@@ -821,6 +822,9 @@ class AddressDBController extends mfBaseController {
case 'getUnit':
$return = $this->getUnitApi();
break;
case 'getFCPsForNetwork':
$return = $this->getFCPsForNetworkApi();
break;
case "findUnit":
break;
default:
@@ -1364,4 +1368,14 @@ class AddressDBController extends mfBaseController {
return ["count" => count($buildings), "buildings" => $results];
}
protected function getFCPsForNetworkApi(): array {
if (!$this->request->network_id) return [];
return array_map(
fn($fcp) => ["id" => $fcp->name ?? null, "text" => $fcp->name ?? null, 'lat' => $fcp->gps_lat ?? null, 'lng' => $fcp->gps_long ?? null],
ADBRimoFcp::getAll(["netzgebiet_id" => intval($this->request->network_id)]) ?? []
);
}
}