Skip to content

Commit

Permalink
[FEATURE] Add recursive folder filter option in admin module #1299
Browse files Browse the repository at this point in the history
  • Loading branch information
derhansen committed Nov 30, 2024
1 parent b987086 commit c659cbe
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 23 deletions.
58 changes: 50 additions & 8 deletions Classes/Controller/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use DERHANSEN\SfEventMgt\Service\ExportService;
use DERHANSEN\SfEventMgt\Service\MaintenanceService;
use DERHANSEN\SfEventMgt\Service\SettingsService;
use DERHANSEN\SfEventMgt\Utility\PageUtility;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
Expand Down Expand Up @@ -258,18 +259,19 @@ public function listAction(?SearchDemand $searchDemand = null, array $overwriteD
];
}

$eventDemand = GeneralUtility::makeInstance(EventDemand::class);
$eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
$eventDemand->setOrderFieldAllowed($this->settings['orderFieldAllowed'] ?? '');
$eventDemand->setSearchDemand($searchDemand);
$eventDemand->setStoragePage((string)$this->pid);
$eventDemand->setIgnoreEnableFields(true);

$events = [];
$pagination = null;
if ($this->getBackendUser()->isInWebMount($this->pid) &&
$pageUids = $this->resolveSearchPageUids((int)($overwriteDemand['recursive'] ?? 0));
if ($pageUids !== '' &&
$this->getBackendUser()->check('tables_select', 'tx_sfeventmgt_domain_model_event')
) {
$eventDemand = GeneralUtility::makeInstance(EventDemand::class);
$eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
$eventDemand->setOrderFieldAllowed($this->settings['orderFieldAllowed'] ?? '');
$eventDemand->setSearchDemand($searchDemand);
$eventDemand->setIgnoreEnableFields(true);
$eventDemand->setStoragePage($pageUids);

$events = $this->eventRepository->findDemanded($eventDemand);
$pagination = $this->getPagination($events, $this->settings['pagination'] ?? []);
}
Expand All @@ -281,6 +283,7 @@ public function listAction(?SearchDemand $searchDemand = null, array $overwriteD
'searchDemand' => $searchDemand,
'orderByFields' => $this->getOrderByFields(),
'orderDirections' => $this->getOrderDirections(),
'recursiveLevels' => $this->getRecursiveLevels(),
'overwriteDemand' => $overwriteDemand,
'pagination' => $pagination,
],
Expand All @@ -293,6 +296,30 @@ public function listAction(?SearchDemand $searchDemand = null, array $overwriteD
return $this->initModuleTemplateAndReturnResponse('Administration/List', $variables);
}

/**
* Resolves the page UIDs to search in respecting the given recursive option and additionally checking, if
* the current backend user is allowed to affected pages
*/
private function resolveSearchPageUids(int $recursive): string
{
$extendedPageUids = PageUtility::extendPidListByChildren(
(string)$this->pid,
$recursive
);
$extendedPageUids = GeneralUtility::intExplode(',', $extendedPageUids, true);

$pageUids = [];
foreach ($extendedPageUids as $extendedPageUid) {
if (!in_array($extendedPageUid, $pageUids, true) &&
$this->getBackendUser()->isInWebMount($extendedPageUid)
) {
$pageUids[] = $extendedPageUid;
}
}

return implode(',', $pageUids);
}

/**
* Returns, if reset filter operation has been used
*/
Expand Down Expand Up @@ -478,6 +505,21 @@ public function getOrderDirections(): array
];
}

/**
* Returns an array with possible recursive levels
*/
public function getRecursiveLevels(): array
{
return [
$this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.current'),
$this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level1'),
$this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level2'),
$this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level3'),
$this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level4'),
$this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level5'),
];
}

/**
* Returns an array with possible orderBy fields
*/
Expand Down
19 changes: 19 additions & 0 deletions Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,25 @@
<trans-unit id="administration.pagination.records">
<source>Records</source>
</trans-unit>
<trans-unit id="administration.recursiveLevel.current">
<source>Current folder</source>
</trans-unit>
<trans-unit id="administration.recursiveLevel.level1">
<source>1 level down</source>
</trans-unit>
<trans-unit id="administration.recursiveLevel.level2">
<source>2 levels down</source>
</trans-unit>
<trans-unit id="administration.recursiveLevel.level3">
<source>3 levels down</source>
</trans-unit>
<trans-unit id="administration.recursiveLevel.level4">
<source>4 levels down</source>
</trans-unit>
<trans-unit id="administration.recursiveLevel.level5">
<source>5 levels down</source>
</trans-unit>

<trans-unit id="evaluation.timeRestriction.header">
<source>Time Restriction</source>
</trans-unit>
Expand Down
30 changes: 15 additions & 15 deletions Resources/Private/Templates/Administration/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ <h1>
</h1>

<f:form name="searchDemand" object="{searchDemand}" action="list">
<div class="row row-cols-auto align-items-end g-3 mb-3">
<div class="col">
<div class="form-row g-3 mb-3">
<div class="form-group">
<label for="search" class="form-label">
<f:translate key="LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:search" />
</label>

<div class="input-group">
<f:form.textfield property="search" id="search" class="form-control t3js-clearable"/>

<label class="mb-0 btn btn-default" for="search">
<f:form.select id="recursiveLevel" name="overwriteDemand[recursive]" options="{recursiveLevels}" class="form-select recursiveLevel" value="{overwriteDemand.recursive}"/>
<button class="mb-0 btn btn-default" for="search">
<core:icon identifier="actions-search" />
</label>
</button>
</div>
</div>

<div class="col">
<div class="form-group">
<label for="startDate" class="form-label">
<f:translate key="tx_sfeventmgt_domain_model_event.startdate"/>
</label>
<div class="input-group">
<div class="input-group date-field">
<f:form.textfield
name="startDate"
value="{f:if(condition: searchDemand.startDate, then: \"{f:format.date(format:'{settings.search.dateFormat}', date: '{searchDemand.startDate}')}\")}"
Expand All @@ -50,12 +50,12 @@ <h1>
</div>
</div>

<div class="col">
<div class="form-group">
<label for="endDate" class="form-label">
<f:translate key="tx_sfeventmgt_domain_model_event.enddate"/>
</label>

<div class="input-group">
<div class="input-group date-field">
<f:form.textfield
name="endDate"
value="{f:if(condition: searchDemand.endDate, then: \"{f:format.date(format:'{settings.search.dateFormat}', date: '{searchDemand.endDate}')}\")}"
Expand All @@ -75,17 +75,17 @@ <h1>
</div>
</div>

<div class="col">
<div class="form-group">
<label for="orderField" class="form-label">
<f:translate key="admin.sorting"/>
</label>
<f:form.select id="orderField" name="overwriteDemand[orderField]" options="{orderByFields}" class="form-select" value="{overwriteDemand.orderField}"/>
</div>
<div class="col">
<f:form.select id="orderDirection" name="overwriteDemand[orderDirection]" options="{orderDirections}" class="form-select" value="{overwriteDemand.orderDirection}"/>
<div class="input-group">
<f:form.select id="orderField" name="overwriteDemand[orderField]" options="{orderByFields}" class="form-select" value="{overwriteDemand.orderField}"/>
<f:form.select id="orderDirection" name="overwriteDemand[orderDirection]" options="{orderDirections}" class="form-select" value="{overwriteDemand.orderDirection}"/>
</div>
</div>

<div class="col">
<div class="form-group align-self-end">
<f:form.button type="submit" name="operation" value="search" class="btn btn-default">{f:translate(key:'LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:search')}</f:form.button>
<f:form.button type="submit" name="operation" value="reset-filters" class="btn btn-link">Reset</f:form.button>
</div>
Expand Down
8 changes: 8 additions & 0 deletions Resources/Public/Css/administration.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ tr.db_list_normal td.logdate {
text-decoration: none;
}

select.recursiveLevel {
max-width: 140px;
}

.date-field {
max-width: 200px;
}

/**
* Action Buttons
*/
Expand Down

0 comments on commit c659cbe

Please sign in to comment.