From 0ea84617063b3c4ec51fb0419534adebda46ab66 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 15 Feb 2016 20:15:45 +0200 Subject: [PATCH] Fixed problem with search when using foreign language --- app/Ninja/Repositories/AccountRepository.php | 9 +++++---- resources/views/header.blade.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index 2170c34f25ad..2b469bf0fcf7 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -75,26 +75,26 @@ class AccountRepository ->where('clients.deleted_at', '=', null) ->where('clients.account_id', '=', \Auth::user()->account_id) ->whereRaw("clients.name <> ''") - ->select(\DB::raw("'" . trans('texts.clients') . "' as type, clients.public_id, clients.name, '' as token")); + ->select(\DB::raw("'clients' as type, '" . trans('texts.clients') . "' as trans_type, clients.public_id, clients.name, '' as token")); $contacts = \DB::table('clients') ->join('contacts', 'contacts.client_id', '=', 'clients.id') ->where('clients.deleted_at', '=', null) ->where('clients.account_id', '=', \Auth::user()->account_id) ->whereRaw("CONCAT(contacts.first_name, contacts.last_name, contacts.email) <> ''") - ->select(\DB::raw("'" . trans('texts.contacts') . "' as type, clients.public_id, CONCAT(contacts.first_name, ' ', contacts.last_name, ' ', contacts.email) as name, '' as token")); + ->select(\DB::raw("'clients' as type, '" . trans('texts.contacts') . "' as trans_type, clients.public_id, CONCAT(contacts.first_name, ' ', contacts.last_name, ' ', contacts.email) as name, '' as token")); $invoices = \DB::table('clients') ->join('invoices', 'invoices.client_id', '=', 'clients.id') ->where('clients.account_id', '=', \Auth::user()->account_id) ->where('clients.deleted_at', '=', null) ->where('invoices.deleted_at', '=', null) - ->select(\DB::raw("'" . trans('texts.invoices') . "' as type, invoices.public_id, CONCAT(invoices.invoice_number, ': ', clients.name) as name, invoices.invoice_number as token")); + ->select(\DB::raw("'invoices' as type, '" . trans('texts.invoices') . "' as trans_type, invoices.public_id, CONCAT(invoices.invoice_number, ': ', clients.name) as name, invoices.invoice_number as token")); $data = []; foreach ($clients->union($contacts)->union($invoices)->get() as $row) { - $type = $row->type; + $type = $row->trans_type; if (!isset($data[$type])) { $data[$type] = []; @@ -111,6 +111,7 @@ class AccountRepository 'value' => $row->name, 'public_id' => $row->public_id, 'tokens' => $tokens, + 'entity_type' => $row->type, ]; } diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index 74d293ed4232..a007d34328df 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -282,7 +282,7 @@ } $('#search').typeahead(datasets).on('typeahead:selected', function(element, datum, name) { var type = name == 'Contacts' ? 'clients' : name.toLowerCase(); - window.location = '{{ URL::to('/') }}' + '/' + type + '/' + datum.public_id; + window.location = '{{ URL::to('/') }}' + '/' + datum.entity_type + '/' + datum.public_id; }).focus().typeahead('setQuery', $('#search').val()); }); }