Skip to content

Commit

Permalink
feature: add possibility to add filter string fixes Uberspace#15
Browse files Browse the repository at this point in the history
  • Loading branch information
joni1993 committed Oct 19, 2020
1 parent 5c4de90 commit 58be868
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion library/Netboximport/ProvidedHook/Director/ImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function flattenArray($prefix, $array, $autoflatten_elements = array(), $flatten
}

private function fetchObjects($ressource, $activeOnly, $autoflatten_elements, $additionalKeysCallback = null) {
$objects = $this->api->get($ressource);
$objects = $this->api->get($ressource,$this->getFilters());

//Filter only active objects if setting is set
$objects = array_filter($objects, function ($object) use ($activeOnly) {
Expand Down Expand Up @@ -201,6 +201,11 @@ public static function addSettingsFormFields(QuickForm $form) {
$form->addElement('YesNo', 'importvirtualmachines', array(
'label' => $form->translate('Import virtual machines'),
'description' => $form->translate('Import virtual machines (virtualization/virtual-machines in netbox).'),
));

$form->addElement('text', 'filters', array(
'label' => $form->translate("Filterstring"),
'description' => $form->translate("Filters to be applied in API request (e.g. role=Server"),
));

$form->addElement('YesNo', 'activeonly', array(
Expand Down Expand Up @@ -257,6 +262,11 @@ public function fetchData() {

}

private function getFilters() {
parse_str($this->getSetting('filters'),$filters_array);
return $filters_array;
}

public function listColumns() {
// return a list of all keys, which appeared in any of the objects
return array_keys(array_merge(...array_map('get_object_vars', $this->fetchData())));
Expand Down

0 comments on commit 58be868

Please sign in to comment.