Autocomplete items count.

This commit is contained in:
Alexey Skobkin 2016-12-11 03:54:01 +03:00
parent 28f3c14fa5
commit 4c3191aa86
2 changed files with 5 additions and 1 deletions

View file

@ -11,6 +11,8 @@ use Symfony\Component\HttpFoundation\Request;
class MainController extends Controller class MainController extends Controller
{ {
const AJAX_AUTOCOMPLETE_SIZE = 10;
public function indexAction(Request $request) public function indexAction(Request $request)
{ {
/** @var EntityManager $em */ /** @var EntityManager $em */
@ -39,6 +41,7 @@ class MainController extends Controller
return $this->render('SkobkinPointToolsBundle:Main:index.html.twig', [ return $this->render('SkobkinPointToolsBundle:Main:index.html.twig', [
'form' => $form->createView(), 'form' => $form->createView(),
'autocomplete_size' => self::AJAX_AUTOCOMPLETE_SIZE,
'users_count' => $em->getRepository('SkobkinPointToolsBundle:User')->getUsersCount(), 'users_count' => $em->getRepository('SkobkinPointToolsBundle:User')->getUsersCount(),
'subscribers_count' => $em->getRepository('SkobkinPointToolsBundle:Subscription')->getUserSubscribersCountById($this->container->getParameter('point_id')), 'subscribers_count' => $em->getRepository('SkobkinPointToolsBundle:Subscription')->getUserSubscribersCountById($this->container->getParameter('point_id')),
'events_count' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastDayEventsCount(), 'events_count' => $em->getRepository('SkobkinPointToolsBundle:SubscriptionEvent')->getLastDayEventsCount(),
@ -52,7 +55,7 @@ class MainController extends Controller
$result = []; $result = [];
foreach ($em->getRepository('SkobkinPointToolsBundle:User')->findUsersLikeLogin($login) as $user) { foreach ($em->getRepository('SkobkinPointToolsBundle:User')->findUsersLikeLogin($login, self::AJAX_AUTOCOMPLETE_SIZE) as $user) {
$result[] = [ $result[] = [
'login' => $user->getLogin(), 'login' => $user->getLogin(),
'name' => $user->getName(), 'name' => $user->getName(),

View file

@ -23,6 +23,7 @@
$field.typeahead({ $field.typeahead({
minLength: 2, minLength: 2,
items: {{ autocomplete_size|e('js') }},
delay: 500, delay: 500,
autoSelect: true, autoSelect: true,
source: function (query, processCallback) { source: function (query, processCallback) {