Unverified Commit 069def71 authored by Jerome Boucher's avatar Jerome Boucher
Browse files

fix/14312 : add count on audit search page

parent c4c48dc1
Pipeline #8908 canceled with stage
......@@ -206,17 +206,88 @@ class event
/**
* Get result of search form
* @param timestamp $toDate
*
* @param timestamp $fromDate
* @param timestamp $toDate
* @param string $event
* @param string $accountId
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
* @param string $term Term to search
* @param string $wording Wording to search
* @param integer $maxResults Max results to display
*
* @return audit/event[] Array of audit/event object
*/
public function search($toDate = null, $fromDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null)
public function search($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null, $maxResults = null)
{
list($queryString, $queryParams) = $this->queryBuilder($fromDate, $toDate, $event, $accountId, $status, $term, $wording);
$events = $this->sdoFactory->find("audit/event", $queryString, $queryParams, ">eventDate", 0, $maxResults);
$userAccountController = \laabs::newController('auth/userAccount');
$users = $userAccountController->index();
foreach ($users as $i => $user) {
$users[(string) $user->accountId] = $user;
unset($users[$i]);
}
$serviceAccountController = \laabs::newController('auth/serviceAccount');
$services = $serviceAccountController->index();
foreach ($services as $i => $service) {
$services[(string) $service->accountId] = $service;
unset($services[$i]);
}
foreach ($events as $i => $event) {
if (isset($event->accountId) && isset($users[(string) $event->accountId])) {
$event->accountName = $users[(string) $event->accountId]->accountName;
} elseif (isset($event->accountId) && isset($services[(string) $event->accountId])) {
$event->accountName = $services[(string) $event->accountId]->accountName;
} else {
$event->accountName = "__system__";
}
$event->origin = strtok($event->path, LAABS_URI_SEPARATOR);
$event->typeCode = strtok(LAABS_URI_SEPARATOR);
}
return $events;
}
/**
* Get count result of search form
*
* @param timestamp $fromDate
* @param timestamp $toDate
* @param string $event
* @param string $accountId
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
*
* @return integer Count of max results from query
*/
public function count($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null)
{
list($queryString, $queryParams) = $this->queryBuilder($fromDate, $toDate, $event, $accountId, $status, $term, $wording);
$count = $this->sdoFactory->count("audit/event", $queryString, $queryParams, ">eventDate");
return $count;
}
/**
* Build query
*
* @param timestamp $fromDate
* @param timestamp $toDate
* @param string $event
* @param string $accountId
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
*/
private function queryBuilder($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null)
{
$queryParts = array();
$queryParams = array();
......@@ -246,7 +317,7 @@ class event
if ($term) {
$wordings = explode(",", $wording);
$queryParts['term'] = null;
foreach ($wordings as $wording) {
if($wording == 'all') {
$queryParts['term'] = "(info ='*".$term."*' OR input = '*".$term."*' OR variables = '*".$term."*')";
......@@ -258,7 +329,7 @@ class event
}
}
}
if ($wording != 'all') {
$queryParts['term'] .= ")";
}
......@@ -268,57 +339,20 @@ class event
}
$queryString = implode(' AND ', $queryParts );
//$length = \laabs::getRequestMaxCount();
$length = 400;
$events = $this->sdoFactory->find("audit/event", $queryString, $queryParams, ">eventDate", 0, $length);
$userAccountController = \laabs::newController('auth/userAccount');
$users = $userAccountController->index();
foreach ($users as $i => $user) {
$users[(string) $user->accountId] = $user;
unset($users[$i]);
}
$serviceAccountController = \laabs::newController('auth/serviceAccount');
$services = $serviceAccountController->index();
foreach ($services as $i => $service) {
$services[(string) $service->accountId] = $service;
unset($services[$i]);
}
foreach ($events as $i => $event) {
if (isset($event->accountId) && isset($users[(string) $event->accountId])) {
$event->accountName = $users[(string) $event->accountId]->accountName;
} elseif (isset($event->accountId) && isset($services[(string) $event->accountId])) {
$event->accountName = $services[(string) $event->accountId]->accountName;
} else {
$event->accountName = "__system__";
}
$event->origin = strtok($event->path, LAABS_URI_SEPARATOR);
$event->typeCode = strtok(LAABS_URI_SEPARATOR);
}
/*if (count($events) >= $length) {
$count = $this->sdoFactory->count("audit/event", $queryString, $queryParams);
\laabs::setResponseCode(206);
\laabs::setResponseCount($count);
}*/
return $events;
return [$queryString, $queryParams];
}
/**
* Get event
* @param string $eventId
*
*
* @return audit/event Object
*/
public function getEvent($eventId)
{
$event = $this->sdoFactory->read("audit/event", $eventId);
return $event;
}
}
......@@ -39,17 +39,34 @@ interface eventInterface
/**
* Get search form for entries
* @param string $eventType Type of event
* @param timestamp $fromDate Start date
* @param timestamp $toDate End date
* @param string $accountId Id of account
* @param string $event Variables
* @param string $term Term to search
* @param string $wording Wording to search
*
* @param timestamp $fromDate Start date
* @param timestamp $toDate End date
* @param string $event Variables
* @param string $accountId Id of account
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
* @param integer $maxResults Max results to display
*
* @action audit/event/search
*/
public function readSearch($eventType = null, $fromDate = null, $toDate = null, $accountId = null, $event = null, $status = null, $term = null, $wording = null);
public function readSearch($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null, $maxResults = null);
/**
* Get count search for entries
*
* @param timestamp $fromDate Start date
* @param timestamp $toDate End date
* @param string $event Variables
* @param string $accountId Id of account
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
*
* @action audit/event/count
*/
public function readCount($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null);
/**
* Get search form for entries
......
......@@ -40,12 +40,15 @@ class event
* @param \dependency\json\JsonObject $json A new ready-to-use empty json
*
*/
public function __construct(\dependency\html\Document $view, \dependency\json\JsonObject $json)
public function __construct(\dependency\html\Document $view, \dependency\json\JsonObject $json, \dependency\localisation\TranslatorInterface $translator)
{
$this->view = $view;
$this->json = $json;
$this->json->status = true;
$this->translator = $translator;
$this->translator->setCatalog('recordsManagement/messages');
}
/**
......@@ -87,7 +90,7 @@ class event
$events = array();
$routes = array();
$translator = $this->view->translator;
$bundles = \laabs::bundles();
foreach ($bundles as $bundle) {
$apis = $bundle->getApis();
......@@ -108,31 +111,30 @@ class event
$event->label = $translator->getText($event->path, false, "audit/messages");
$events[] = $event;
}
$maxResults = null;
if (isset(\laabs::configuration('presentation.maarchRM')['maxResults'])) {
$maxResults = \laabs::configuration('presentation.maarchRM')['maxResults'];
}
$this->view->addContentFile("audit/search.html");
$this->view->setSource("maxResults", $maxResults);
$this->view->setSource("events", $events);
$this->view->translate();
$this->view->merge();
$this->view->addScriptSrc(
<<<EOD
$.ajaxSetup({
headers: { 'X-Laabs-Max-Count': 300}
});
EOD
);
return $this->view->saveHtml();
}
/**
* Get result
*
* @param Array $events Array of audit/event object
* @param Array $events Array of audit/event object
* @param integer $totalResults Max number of total results from query
*
* @return string view
*/
public function search($events)
public function search($events, $totalResults)
{
$this->view->addContentFile("audit/result.html");
......@@ -142,7 +144,16 @@ EOD
} else {
$multipleInstance = false;
}
$hasReachMaxResults = false;
if (isset(\laabs::configuration('presentation.maarchRM')['maxResults'])
&& $totalResults >= \laabs::configuration('presentation.maarchRM')['maxResults']) {
$hasReachMaxResults = true;
}
$this->view->setSource('hasReachMaxResults', $hasReachMaxResults);
$this->view->setSource('totalResults', $totalResults);
$this->view->setSource('multipleInstance', $multipleInstance);
$this->view->setSource("events", $events);
$this->view->merge();
......
......@@ -1865,3 +1865,6 @@ msgstr "Coffre fort numérique : Valider l'intégrité d'un objet numérique"
msgid "digitalSafe/digitalSafe/create_originatorOwnerOrgRegNumber__originatorOrgRegNumber_"
msgstr "Coffre fort numérique : Création d'un objet numérique"
msgid "result(s) on"
msgstr "résultat(s) sur"
......@@ -741,4 +741,7 @@ msgctxt "recordsManagement/destruction"
msgid "Organization"
msgstr "Organisation"
\ No newline at end of file
msgstr "Organisation"
msgid "result(s) on"
msgstr "résultat(s) sur"
......@@ -3,7 +3,10 @@
<div class="panel panel-primary">
<div class="panel-heading clearfix">
<div class="pull-left">
<?merge hasReachMaxResults.not() ?>
<h4><?merge events.count() ?> result(s)</h4>
<?merge hasReachMaxResults ?>
<h4><?merge events.count() ?> result(s) on <?merge totalResults ?> total</h4>
</div>
</div>
<div class="panel-body" style="padding: 0;">
......
......@@ -18,6 +18,7 @@
</div>
<div id="collapseOne" class="well panel-collapse collapse in" style="margin-bottom: 0px">
<form class="form-horizontal" id="eventSearchForm">
<input type="hidden" id="maxResults" value="[?merge maxResults ?]">
<div class="row">
<div class="col-md-6">
<div class="form-group">
......@@ -128,8 +129,9 @@
event: $('#eventName').data('event-path'),
accountId: $.trim($('#accountTypeahead').val()),
term: $('#term').val(),
maxResults: $('#maxResults').val()
};
if ($('#accountTypeahead').data('accountid')) {
serializedObject.accountId = $('#accountTypeahead').data('accountid') ;
}
......
......@@ -34,19 +34,22 @@ interface auditInterface
/**
* Get search form for entries
*@param string $eventType Type of event
*@param Date $fromDate Start date
*@param Date $toDate End date
*@param string $accountId Id of account
*@param string $event Variables
*@param string $term Term to search
*@param string $wording Wording to search
*
* @param Date $fromDate Start date
* @param Date $toDate End date
* @param string $accountId Id of account
* @param string $event Variables
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
* @param integer $maxResults Max results to display
*
* @uses audit/event/readSearch
* @uses audit/event/readCount
*
* @return audit/event/search
*/
public function readEvents($eventType = null, $fromDate = null, $toDate = null, $accountId = null, $event = null, $status = null, $term = null, $wording = null);
public function readEvents($fromDate = null, $toDate = null, $accountId = null, $event = null, $status = null, $term = null, $wording = null, $maxResults = null);
/**
* Get event
......@@ -56,11 +59,11 @@ interface auditInterface
*/
public function readEvent_eventId_();
/**
* List all users to display
*
* @uses auth/userAccount/readUserlist
*/
public function readUserTodisplay();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment