Fixed problem with search when using foreign language

This commit is contained in:
Hillel Coren 2016-02-15 20:15:45 +02:00
parent 668eab0279
commit 0ea8461706
2 changed files with 6 additions and 5 deletions

View File

@ -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,
];
}

View File

@ -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());
});
}