1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Working on search

This commit is contained in:
Hillel Coren 2013-12-25 19:36:34 -05:00
parent c6c837f4df
commit aa8151edaf
6 changed files with 93 additions and 5 deletions

View File

@ -1,7 +1,18 @@
<?php
use ninja\repositories\AccountRepository;
class AccountController extends \BaseController {
protected $accountRepo;
public function __construct(AccountRepository $accountRepo)
{
parent::__construct();
$this->accountRepo = $accountRepo;
}
public function getStarted()
{
if (Auth::check())
@ -45,6 +56,13 @@ class AccountController extends \BaseController {
return Redirect::to('invoices/create');
}
public function getSearchData()
{
$data = $this->accountRepo->getSearchData();
return Response::json($data);
}
public function showSection($section = ACCOUNT_DETAILS)
{
if ($section == ACCOUNT_DETAILS)

View File

@ -25,12 +25,12 @@ class InvoiceEventHandler
public function onViewed($invoice)
{
$this->sendNotifications($invoice, 'viewed');
}
public function onPaid($invoice)
{
$this->sendNotifications($invoice, 'paid');
}
private function sendNotifications($invoice, $type)

View File

@ -0,0 +1,43 @@
<?php namespace ninja\repositories;
use Client;
use Contact;
class AccountRepository
{
public function getSearchData()
{
$clients = \DB::table('clients')
->where('clients.deleted_at', '=', null)
->select(\DB::raw("'Clients' as type, clients.public_id, clients.name"));
$contacts = \DB::table('clients')
->join('contacts', 'contacts.client_id', '=', 'clients.id')
->where('clients.deleted_at', '=', null)
->select(\DB::raw("'Contacts' as type, clients.public_id, CONCAT(contacts.first_name, ' ', contacts.last_name) as name"));
$invoices = \DB::table('clients')
->join('invoices', 'invoices.client_id', '=', 'clients.id')
->where('clients.deleted_at', '=', null)
->where('invoices.deleted_at', '=', null)
->select(\DB::raw("'Invoices' as type, invoices.public_id, CONCAT(invoices.invoice_number, ': ', clients.name) as name"));
$data = [];
foreach ($clients->union($contacts)->union($invoices)->get() as $row)
{
if (!isset($data[$row->type]))
{
$data[$row->type] = [];
}
$data[$row->type][] = [
'value' => $row->name,
'public_id' => $row->public_id
];
}
return $data;
}
}

View File

@ -58,7 +58,8 @@ Route::filter('auth', function()
Route::group(array('before' => 'auth'), function()
{
Route::get('home', function() { return View::make('header'); });
Route::get('account/{section?}', 'AccountController@showSection');
Route::get('account/getSearchData', array('as' => 'getSearchData', 'uses' => 'AccountController@getSearchData'));
Route::get('account/{section?}', 'AccountController@showSection');
Route::post('account/{section?}', 'AccountController@doSection');
Route::post('user/setTheme', 'UserController@setTheme');

View File

@ -28,6 +28,10 @@
<script src="{{ asset('js/bootstrap-datepicker.js') }}" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="{{ asset('css/datepicker.css') }}"/>
<script src="{{ asset('js/typeahead.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/hogan-2.0.0.js') }}" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="{{ asset('css/typeahead.js-bootstrap.css') }}"/>
<script src="{{ asset('js/script.js') }}" type="text/javascript"></script>
@ -485,7 +489,30 @@
}
}
$(function() {
$(function()
{
$('#search').focus(function(){
if (!window.hasOwnProperty('searchData')) {
$.get('{{ URL::route('getSearchData') }}', function(data) {
window.searchData = true;
var datasets = [];
for (var type in data)
{
if (!data.hasOwnProperty(type)) continue;
datasets.push({
name: type,
header: '&nbsp;<b>' + type + '</b>',
local: data[type]
});
}
$('#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;
}).focus().typeahead('setQuery', $('#search').val());
});
}
});
if (isStorageSupported()) {
@if (Auth::check() && !Auth::user()->registered)

View File

@ -641,7 +641,6 @@ function wordWrapText(value, width)
return lines.slice(0, 6).join("\n");
}
var CONSTS = {};
CONSTS.INVOICE_STATUS_DRAFT = 1;
CONSTS.INVOICE_STATUS_SENT = 2;