Skip to content

Commit

Permalink
FETAURE: add dimensions filter for nodeevents
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehoffmann30 committed Feb 1, 2021
1 parent a0cd97b commit 94d9081
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 10 deletions.
43 changes: 37 additions & 6 deletions Classes/Controller/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Neos\Neos\Controller\Module\AbstractModuleController;
use Neos\Neos\Domain\Repository\DomainRepository;
use Neos\Neos\Domain\Repository\SiteRepository;
use Neos\Neos\Domain\Service\ConfigurationContentDimensionPresetSource;
use Neos\Neos\Domain\Service\UserService;
use Neos\Neos\EventLog\Domain\Model\EventsOnDate;
use Neos\Neos\EventLog\Domain\Model\NodeEvent;
Expand Down Expand Up @@ -56,6 +57,12 @@ class HistoryController extends AbstractModuleController
*/
protected $userService;

/**
* @Flow\Inject
* @var ConfigurationContentDimensionPresetSource
*/
protected $configurationContentDimensionPresetSource;

/**
* Show event overview.
*
Expand All @@ -64,15 +71,19 @@ class HistoryController extends AbstractModuleController
* @param string|null $siteIdentifier
* @param string|null $nodeIdentifier
* @param string|null $accountIdentifier
*
* @param string|null $dimensionsHash
* @return void
* @throws \Neos\Flow\Http\Exception
* @throws \Neos\Flow\Mvc\Routing\Exception\MissingActionNameException
* @throws \Neos\Neos\Domain\Exception
*/
public function indexAction(
int $offset = 0,
int $limit = 25,
string $siteIdentifier = null,
string $nodeIdentifier = null,
string $accountIdentifier = null
string $accountIdentifier = null,
string $dimensionsHash = null
) {
if ($nodeIdentifier === '') {
$nodeIdentifier = null;
Expand All @@ -99,6 +110,25 @@ public function indexAction(
$accounts[$identifier] = $user ? $user->getName()->getFullName() : $identifier;
}

$dimensions = [];

$savedDimensions = $this->nodeEventRepository->findUniqueDimensions();

if (!empty($savedDimensions)) {
$dimensionPresets = $this->configurationContentDimensionPresetSource->getAllPresets();

foreach ($savedDimensions as $savedDimensionData) {
$label = '';
foreach ($savedDimensionData['dimension'] as $dimension => $value) {
$presetLabel = str_replace(' ', '-', $dimensionPresets[$dimension]['presets'][$value[0]]['label']);
$label .= $presetLabel . '_';
}

$dimensions[$savedDimensionData['dimensionsHash']] = rtrim($label, '_');
}

}

/** @var NodeEvent[] $events */
$events = $this->nodeEventRepository
->findRelevantEventsByWorkspace(
Expand All @@ -107,7 +137,8 @@ public function indexAction(
'live',
$siteIdentifier ?: null,
$nodeIdentifier,
$accountIdentifier ?: null
$accountIdentifier ?: null,
$dimensionsHash ?: null
)
->toArray()
;
Expand All @@ -126,9 +157,7 @@ public function indexAction(
'nodeIdentifier' => $nodeIdentifier,
'offset' => $offset + $limit,
'siteIdentifier' => $siteIdentifier,
],
'History',
'Neos.Neos'
]
)
;
}
Expand Down Expand Up @@ -166,13 +195,15 @@ public function indexAction(

$this->view->assignMultiple([
'accountIdentifier' => $accountIdentifier,
'dimensionsHash' => $dimensionsHash,
'eventsByDate' => $eventsByDate,
'firstEvent' => $firstEvent,
'nextPage' => $nextPage,
'nodeIdentifier' => $nodeIdentifier,
'siteIdentifier' => $siteIdentifier,
'sites' => $sites,
'accounts' => $accounts,
'dimensions' => $dimensions,
]);
}

Expand Down
24 changes: 21 additions & 3 deletions Classes/Domain/Repository/NodeEventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class NodeEventRepository extends EventRepository
* @param string|null $siteIdentifier
* @param string|null $nodeIdentifier
* @param string|null $accountIdentifier
*
* @param string|null $dimensionsHash
* @return QueryResultInterface
*/
public function findRelevantEventsByWorkspace(
Expand All @@ -33,7 +33,8 @@ public function findRelevantEventsByWorkspace(
$workspaceName,
string $siteIdentifier = null,
string $nodeIdentifier = null,
string $accountIdentifier = null
string $accountIdentifier = null,
string $dimensionsHash = null
) : QueryResultInterface {
$query = $this->prepareRelevantEventsQuery();
$queryBuilder = $query->getQueryBuilder();
Expand Down Expand Up @@ -61,6 +62,12 @@ public function findRelevantEventsByWorkspace(
->setParameter('accountIdentifier', $accountIdentifier)
;
}
if ($dimensionsHash !== null) {
$queryBuilder
->andWhere('e.dimensionsHash = :dimensionsHash')
->setParameter('dimensionsHash', $dimensionsHash)
;
}
$queryBuilder->setFirstResult($offset);
$queryBuilder->setMaxResults($limit);

Expand Down Expand Up @@ -110,8 +117,19 @@ public function findAccountIdentifiers(
$dqlQuery = $this->createDqlQuery($dql);
$dqlQuery->setParameters($query->getParameters());

return array_map(function($result) {
return array_map(static function ($result) {
return $result['accountIdentifier'];
}, $dqlQuery->execute());
}

public function findUniqueDimensions(): array
{
$queryBuilder = $this->createQueryBuilder('event');
$queryBuilder
->select('event.dimension')
->addSelect('event.dimensionsHash')
->where($queryBuilder->expr()->isNotNull('event.dimension'));
$queryBuilder->groupBy('event.dimensionsHash');
return $queryBuilder->getQuery()->getArrayResult();
}
}
2 changes: 2 additions & 0 deletions Resources/Private/Fusion/Root.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ include: resource://Neos.Neos/Private/Fusion/Backend/History/Root.fusion

AE.History.HistoryController.index = AE.History:Template {
accountIdentifier = ${accountIdentifier}
dimensionsHash = ${dimensionsHash}
eventsByDate = ${eventsByDate}
firstEvent = ${firstEvent}
nextPage = ${nextPage}
nodeIdentifier = ${nodeIdentifier}
siteIdentifier = ${siteIdentifier}
sites = ${sites}
accounts = ${accounts}
dimensions = ${dimensions}

eventRenderer = Neos.Neos:History.EventRenderer
}
Expand Down
20 changes: 19 additions & 1 deletion Resources/Private/Templates/History/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@
<br/>
</f:if>

<f:if condition="{dimensions -> f:count()} > 1">
<label for="dimensionsHash"><b>{neos:backend.translate(
id: 'contentDimensions',
package: 'Neos.Neos',
source: 'Main'
)}</b></label>
<f:form.select
id="dimensionsHash"
name="moduleArguments[dimensionsHash]"
options="{dimensions}"
prependOptionLabel="All"
sortByOptionLabel="true"
value="{dimensionsHash}"
/>
<br/>
<br/>
</f:if>

<f:if condition="{nodeIdentifier}">
<label>
<b>{neos:backend.translate(id: 'page', package: 'Neos.Neos')}</b>
Expand Down Expand Up @@ -360,7 +378,7 @@ <h3 class="neos-history-event-title">
nextPage
;

$('#siteIdentifier, #accountIdentifier').change(function () {
$('#siteIdentifier, #accountIdentifier, #dimensionsHash').change(function () {
this.form.submit();
});

Expand Down

0 comments on commit 94d9081

Please sign in to comment.