Change all lists to use ajax data source and high perf datatable + improve all consuming listing queries + add indexes on numbers for perf improvment

This commit is contained in:
osaajani 2020-09-23 03:02:13 +02:00
parent 52ac5b459b
commit b98d5a22ef
34 changed files with 1238 additions and 767 deletions

View file

@ -42,8 +42,17 @@ namespace controllers\publics;
*/
public function list()
{
$commands = $this->internal_command->list_for_user($_SESSION['user']['id']);
$this->render('command/list', ['commands' => $commands]);
$this->render('command/list');
}
/**
* Return commands as json
*/
public function list_json()
{
$entities = $this->internal_command->list_for_user($_SESSION['user']['id']);
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**

View file

@ -48,9 +48,19 @@ namespace controllers\publics;
{
$page = (int) $page;
$groups = $this->internal_conditional_group->list_for_user($_SESSION['user']['id'], 25, $page);
$groups = $this->internal_conditional_group->list_for_user($_SESSION['user']['id']);
$this->render('conditional_group/list', ['groups' => $groups]);
}
/**
* Return conditionnals groups as json
*/
public function list_json()
{
$entities = $this->internal_conditional_group->list_for_user($_SESSION['user']['id']);
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**
* Cette fonction va supprimer une liste de groups.

View file

@ -40,9 +40,22 @@ namespace controllers\publics;
*/
public function list()
{
$contacts = $this->internal_contact->list_for_user($_SESSION['user']['id']);
return $this->render('contact/list');
}
/**
* Return contacts as json
*/
public function list_json()
{
$entities = $this->internal_contact->list_for_user($_SESSION['user']['id']);
foreach ($entities as &$entity)
{
$entity['number_formatted'] = \controllers\internals\Tool::phone_link($entity['number']);
}
return $this->render('contact/list', ['contacts' => $contacts]);
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**

View file

@ -46,21 +46,24 @@ namespace controllers\publics;
*/
public function list()
{
$discussions = $this->internal_received->get_discussions_for_user($_SESSION['user']['id']);
$this->render('discussion/list');
}
/**
* Return discussions as json
*/
public function list_json()
{
$entities = $this->internal_received->get_discussions_for_user($_SESSION['user']['id']);
foreach ($discussions as $key => $discussion)
foreach ($entities as &$entity)
{
if (!$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $discussion['number']))
{
continue;
}
$discussions[$key]['contact'] = $contact['name'];
$entity['number_formatted'] = \controllers\internals\Tool::phone_link($entity['number']);
$entity['link'] = \descartes\Router::url('Discussion', 'show', ['number' => $entity['number']]);
}
$this->render('discussion/list', [
'discussions' => $discussions,
]);
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**

View file

@ -40,8 +40,22 @@ namespace controllers\publics;
*/
public function list()
{
$events = $this->internal_event->list_for_user($_SESSION['user']['id']);
$this->render('event/list', ['events' => $events, 'nb_results' => \count($events)]);
$this->render('event/list');
}
/**
* Return events as json
*/
public function list_json()
{
$entities = $this->internal_event->list_for_user($_SESSION['user']['id']);
foreach ($entities as &$entity)
{
$entity['icon'] = \controllers\internals\Tool::event_type_to_icon($entity['type']);
}
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**
@ -60,6 +74,13 @@ namespace controllers\publics;
return $this->redirect(\descartes\Router::url('Event', 'list'));
}
if (!\controllers\internals\Tool::is_admin())
{
\FlashMessage\FlashMessage::push('danger', 'Vous devez être administrateur pour supprimer un event !');
return $this->redirect(\descartes\Router::url('Event', 'list'));
}
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)

View file

@ -42,15 +42,18 @@ namespace controllers\publics;
*/
public function list()
{
$groups = $this->internal_group->list_for_user($_SESSION['user']['id']);
foreach ($groups as $key => $group)
{
$contacts = $this->internal_group->get_contacts($group['id']);
$groups[$key]['nb_contacts'] = \count($contacts);
}
$this->render('group/list', ['groups' => $groups]);
$this->render('group/list');
}
/**
* Return groups as json
*/
public function list_json()
{
$entities = $this->internal_group->list_for_user($_SESSION['user']['id']);
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**

View file

@ -72,6 +72,51 @@ class Phone extends \descartes\Controller
$this->render('phone/list', ['phones' => $phones]);
}
/**
* Return phones as json with additionnals datas about callbacks
*/
public function list_json()
{
$id_user = $_SESSION['user']['id'];
$api_key = $_SESSION['user']['api_key'];
$phones = $this->internal_phone->list_for_user($id_user);
$adapters = [];
$adapters = $this->internal_adapter->list_adapters();
foreach ($adapters as $key => $adapter)
{
unset($adapters[$key]);
$adapters[$adapter['meta_classname']] = $adapter;
}
foreach ($phones as &$phone)
{
$adapter = $adapters[$phone['adapter']] ?? false;
if (!$adapter)
{
$phone['adapter'] = 'Inconnu';
continue;
}
$phone['adapter'] = $adapter['meta_name'];
if ($adapter['meta_support_reception'])
{
$phone['callback_reception'] = \descartes\Router::url('Callback', 'reception', ['adapter_uid' => $adapter['meta_uid'], 'id_phone' => $phone['id']], ['api_key' => $api_key]);
}
if ($adapter['meta_support_status_change'])
{
$phone['callback_status'] = \descartes\Router::url('Callback', 'update_sended_status', ['adapter_uid' => $adapter['meta_uid']], ['api_key' => $api_key]);
}
}
header('Content-Type: application/json');
echo json_encode(['data' => $phones]);
}
/**
* Cette fonction va supprimer une liste de phones.
*

View file

@ -41,32 +41,22 @@ namespace controllers\publics;
*/
public function list()
{
$receiveds = $this->internal_received->list_for_user($_SESSION['user']['id']);
foreach ($receiveds as $key => $received)
$this->render('received/list', ['is_unread' => false]);
}
/**
* Return received as json
*/
public function list_json()
{
$entities = $this->internal_received->list_for_user($_SESSION['user']['id']);
foreach ($entities as &$entity)
{
if ('read' !== $received['status'])
{
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
}
if (null !== $received['id_phone'])
{
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']);
if ($phone)
{
$receiveds[$key]['phone_name'] = $phone['name'];
}
}
$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $received['origin']);
if ($contact)
{
$receiveds[$key]['contact'] = $contact['name'];
}
$entity['origin_formatted'] = \controllers\internals\Tool::phone_link($entity['origin']);
}
$this->render('received/list', ['receiveds' => $receiveds, 'nb_results' => \count($receiveds)]);
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**
@ -74,29 +64,56 @@ namespace controllers\publics;
*/
public function list_unread()
{
$receiveds = $this->internal_received->list_unread_for_user($_SESSION['user']['id']);
foreach ($receiveds as $key => $received)
$this->render('received/list', ['is_unread' => true]);
}
/**
* Return unred received as json
*/
public function list_unread_json()
{
$entities = $this->internal_received->list_unread_for_user($_SESSION['user']['id']);
foreach ($entities as &$entity)
{
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $received['id']);
$entity['origin_formatted'] = \controllers\internals\Tool::phone_link($entity['origin']);
}
if (null !== $received['id_phone'])
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**
* Mark messages as
*
* @param string $status : New status of the message, read or unread
* @param array int $_GET['ids'] : Ids of receiveds to delete
* @param mixed $csrf
*
* @return boolean;
*/
public function mark_as ($status, $csrf)
{
if (!$this->verify_csrf($csrf))
{
\FlashMessage\FlashMessage::push('danger', 'Jeton CSRF invalid !');
return $this->redirect(\descartes\Router::url('Received', 'list'));
}
$ids = $_GET['ids'] ?? [];
foreach ($ids as $id)
{
if ($status === \models\Received::STATUS_UNREAD)
{
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $received['id_phone']);
if ($phone)
{
$receiveds[$key]['phone_name'] = $phone['name'];
}
$this->internal_received->mark_as_unread_for_user($_SESSION['user']['id'], $id);
}
$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $received['origin']);
if ($contact)
elseif ($status === \models\Received::STATUS_READ)
{
$receiveds[$key]['contact'] = $contact['name'];
$this->internal_received->mark_as_read_for_user($_SESSION['user']['id'], $id);
}
}
$this->render('received/list_unread', ['receiveds' => $receiveds, 'nb_results' => \count($receiveds)]);
return $this->redirect(\descartes\Router::url('Received', 'list'));
}
/**

View file

@ -47,8 +47,18 @@ namespace controllers\publics;
*/
public function list()
{
$scheduleds = $this->internal_scheduled->list_for_user($_SESSION['user']['id']);
$this->render('scheduled/list', ['scheduleds' => $scheduleds]);
$this->render('scheduled/list');
}
/**
* Return scheduleds as json
*/
public function list_json()
{
$entities = $this->internal_scheduled->list_for_user($_SESSION['user']['id']);
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**

View file

@ -42,28 +42,24 @@ namespace controllers\publics;
*/
public function list()
{
$sendeds = $this->internal_sended->list_for_user($_SESSION['user']['id']);
$this->render('sended/list');
}
foreach ($sendeds as $key => $sended)
/**
* Return sendeds as json
*/
public function list_json()
{
$entities = $this->internal_sended->list_for_user($_SESSION['user']['id']);
foreach ($entities as &$entity)
{
if (null !== $sended['id_phone'])
{
$phone = $this->internal_phone->get_for_user($_SESSION['user']['id'], $sended['id_phone']);
if ($phone)
{
$sendeds[$key]['phone_name'] = $phone['name'];
}
}
$contact = $this->internal_contact->get_by_number_and_user($_SESSION['user']['id'], $sended['destination']);
if ($contact)
{
$sendeds[$key]['contact'] = $contact['name'];
}
$entity['destination_formatted'] = \controllers\internals\Tool::phone_link($entity['destination']);
}
$this->render('sended/list', ['sendeds' => $sendeds, 'nb_results' => \count($sendeds)]);
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**
* Cette fonction va supprimer une liste de sendeds.

View file

@ -39,8 +39,22 @@ namespace controllers\publics;
*/
public function list()
{
$smsstops = $this->internal_sms_stop->list_for_user($_SESSION['user']['id']);
$this->render('smsstop/list', ['smsstops' => $smsstops, 'nb_results' => \count($smsstops)]);
$this->render('smsstop/list');
}
/**
* Return smsstops as json
*/
public function list_json()
{
$entities = $this->internal_sms_stop->list_for_user($_SESSION['user']['id']);
foreach ($entities as &$entity)
{
$entity['number_formatted'] = \controllers\internals\Tool::phone_link($entity['number']);
}
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**

View file

@ -42,8 +42,17 @@ class User extends \descartes\Controller
*/
public function list()
{
$users = $this->internal_user->list();
$this->render('user/list', ['users' => $users]);
$this->render('user/list');
}
/**
* Return users as json
*/
public function list_json()
{
$entities = $this->internal_user->list();
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**

View file

@ -36,8 +36,17 @@ namespace controllers\publics;
*/
public function list()
{
$webhooks = $this->internal_webhook->list_for_user($_SESSION['user']['id']);
$this->render('webhook/list', ['webhooks' => $webhooks]);
$this->render('webhook/list');
}
/**
* Return commands as json
*/
public function list_json()
{
$entities = $this->internal_webhook->list_for_user($_SESSION['user']['id']);
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);
}
/**