mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-27 11:20:39 -06:00
First version of a search interface.
This commit is contained in:
parent
e892b69a96
commit
efcad0b935
@ -1,16 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Helper\Controllers\SearchInterface as SI;
|
||||
|
||||
/**
|
||||
* Class SearchController
|
||||
*/
|
||||
class SearchController extends BaseController
|
||||
{
|
||||
protected $_helper;
|
||||
|
||||
public function __construct(SI $helper)
|
||||
{
|
||||
$this->_helper = $helper;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Results always come in the form of an array [results, count, fullCount]
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$subTitle = null;
|
||||
if (!is_null(Input::get('q'))) {
|
||||
$rawQuery = trim(Input::get('q'));
|
||||
$words = explode(' ', $rawQuery);
|
||||
$subTitle = 'Results for "' . e($rawQuery) . '"';
|
||||
|
||||
/*
|
||||
* Search for transactions:
|
||||
*/
|
||||
$result = $this->_helper->transactions($words);
|
||||
|
||||
}
|
||||
|
||||
return View::make('search.index')->with('title', 'Search')->with('subTitle', $subTitle)->with(
|
||||
'mainTitleIcon', 'fa-search'
|
||||
);
|
||||
}
|
||||
}
|
43
app/lib/Firefly/Helper/Controllers/Search.php
Normal file
43
app/lib/Firefly/Helper/Controllers/Search.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 21/09/14
|
||||
* Time: 20:58
|
||||
*/
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
/**
|
||||
* Class Search
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
class Search implements SearchInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*/
|
||||
public function transactions(array $words)
|
||||
{
|
||||
$query = \TransactionJournal::withRelevantData();
|
||||
|
||||
$fullCount = $query->count();
|
||||
|
||||
$query->where(
|
||||
function ($q) use ($words) {
|
||||
foreach ($words as $word) {
|
||||
$q->orWhere('description', 'LIKE', '%' . e($word) . '%');
|
||||
}
|
||||
}
|
||||
);
|
||||
$count = $query->count();
|
||||
$set = $query->get();
|
||||
/*
|
||||
* Build something with JSON?
|
||||
*/
|
||||
return $set;
|
||||
}
|
||||
|
||||
}
|
22
app/lib/Firefly/Helper/Controllers/SearchInterface.php
Normal file
22
app/lib/Firefly/Helper/Controllers/SearchInterface.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sander
|
||||
* Date: 21/09/14
|
||||
* Time: 20:58
|
||||
*/
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
/**
|
||||
* Interface SearchInterface
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
interface SearchInterface
|
||||
{
|
||||
/**
|
||||
* @param array $words
|
||||
*/
|
||||
public function transactions(array $words);
|
||||
}
|
@ -27,6 +27,11 @@ class HelperServiceProvider extends ServiceProvider
|
||||
'Firefly\Helper\Controllers\Chart'
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Controllers\SearchInterface',
|
||||
'Firefly\Helper\Controllers\Search'
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Controllers\TransactionInterface',
|
||||
'Firefly\Helper\Controllers\Transaction'
|
||||
|
@ -73,14 +73,18 @@
|
||||
<div class="sidebar-nav navbar-collapse">
|
||||
<ul class="nav" id="side-menu">
|
||||
<li class="sidebar-search">
|
||||
<form action="{{route('search')}}" method="GET" class="form-inline">
|
||||
<div class="input-group custom-search-form">
|
||||
<input type="text" class="form-control" placeholder="Search...">
|
||||
|
||||
<input type="text" name="q" class="form-control" placeholder="Search...">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default" type="button">
|
||||
<button class="btn btn-default" type="submit">
|
||||
<i class="fa fa-search"></i>
|
||||
</button>
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
<!-- /input-group -->
|
||||
</li>
|
||||
<li>
|
||||
|
60
app/views/search/index.blade.php
Normal file
60
app/views/search/index.blade.php
Normal file
@ -0,0 +1,60 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<i class="fa fa-repeat"></i> Transactions
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>Bla bla</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<i class="fa fa-bar-chart"></i> Categories
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>Bla bla</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<i class="fa fa-bar-chart"></i> Tags
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>Bla bla</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-12 col-sm-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<i class="fa fa-credit-card"></i> Accounts
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>Bla bla</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<i class="fa fa-tasks"></i> Budgets
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>Bla bla</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<i class="fa fa-search-plus"></i> Other results
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>Bla bla</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@stop
|
Loading…
Reference in New Issue
Block a user