Fixed the charts, added some todo items.

This commit is contained in:
James Cole 2014-11-13 21:11:00 +01:00
parent 953d68c3a2
commit 58d8b6f95b
7 changed files with 125 additions and 11 deletions

View File

@ -464,8 +464,8 @@ class GoogleChartController extends BaseController
$chart->addColumn('Name', 'string');
$chart->addColumn('Amount', 'number');
/** @var \FireflyIII\Database\RecurringTransaction $rcr */
$rcr = App::make('FireflyIII\Database\RecurringTransaction');
/** @var \FireflyIII\Database\Recurring $rcr */
$rcr = App::make('FireflyIII\Database\Recurring');
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
$dateKit = App::make('FireflyIII\Shared\Toolkit\Date');

View File

@ -1,5 +1,4 @@
<?php
use FireflyIII\Exception\NotImplementedException;
/**
* Class SearchController
@ -11,7 +10,10 @@ class SearchController extends BaseController
*/
public function index()
{
throw new NotImplementedException;
/** @var \FireflyIII\Search\Search $searcher */
$searcher = App::make('FireflyIII\Search\Search');
$subTitle = null;
$rawQuery = null;
$result = [];
@ -20,11 +22,11 @@ class SearchController extends BaseController
$words = explode(' ', $rawQuery);
$subTitle = 'Results for "' . e($rawQuery) . '"';
$transactions = $this->_helper->searchTransactions($words);
$accounts = $this->_helper->searchAccounts($words);
$categories = $this->_helper->searchCategories($words);
$budgets = $this->_helper->searchBudgets($words);
$tags = $this->_helper->searchTags($words);
$transactions = $searcher->searchTransactions($words);
$accounts = $searcher->searchAccounts($words);
$categories = $searcher->searchCategories($words);
$budgets = $searcher->searchBudgets($words);
$tags = $searcher->searchTags($words);
$result = ['transactions' => $transactions, 'accounts' => $accounts, 'categories' => $categories, 'budgets' => $budgets, 'tags' => $tags];
}

View File

@ -330,7 +330,6 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface
* @param \RecurringTransaction $recurring
*
* @return bool
* @throws NotImplementedException
*/
public function scanEverything(\RecurringTransaction $recurring)
{

View File

@ -0,0 +1,107 @@
<?php
/**
* Created by PhpStorm.
* User: sander
* Date: 13/11/14
* Time: 21:01
*/
namespace FireflyIII\Search;
use Illuminate\Support\Collection;
class Search
{
/**
* @param array $words
*
* @return Collection
*/
public function searchAccounts(array $words)
{
return \Auth::user()->accounts()->with('accounttype')->where(
function ($q) use ($words) {
foreach ($words as $word) {
$q->orWhere('name', 'LIKE', '%' . e($word) . '%');
}
}
)->get();
}
/**
* @param array $words
*
* @return Collection
*/
public function searchBudgets(array $words)
{
/** @var Collection $set */
$set = \Auth::user()->budgets()->get();
$newSet = $set->filter(
function (\Budget $b) use ($words) {
$found = 0;
foreach ($words as $word) {
if (!(strpos(strtolower($b->name), strtolower($word)) === false)) {
$found++;
}
}
return $found > 0;
}
);
return $newSet;
}
/**
* @param array $words
*
* @return Collection
*/
public function searchCategories(array $words)
{
/** @var Collection $set */
$set = \Auth::user()->categories()->get();
$newSet = $set->filter(
function (\Category $c) use ($words) {
$found = 0;
foreach ($words as $word) {
if (!(strpos(strtolower($c->name), strtolower($word)) === false)) {
$found++;
}
}
return $found > 0;
}
);
return $newSet;
}
/**
* @param array $words
*
* @return Collection
*/
public function searchTags(array $words)
{
return new Collection;
}
/**
* @param array $words
*
* @return Collection
*/
public function searchTransactions(array $words)
{
return \Auth::user()->transactionjournals()->withRelevantData()->where(
function ($q) use ($words) {
foreach ($words as $word) {
$q->orWhere('description', 'LIKE', '%' . e($word) . '%');
}
}
)->get();
}
}

View File

@ -85,6 +85,7 @@ class Transaction extends Ardent
*/
public function connectPiggybank(\Piggybank $piggybank = null)
{
// TODO connect a piggy bank to a transaction.
throw new NotImplementedException;
// if (is_null($piggybank)) {
// return true;

View File

@ -41,7 +41,7 @@
<li class="sidebar-search">
<form action="{{route('search')}}" method="GET" class="form-inline">
<div class="input-group custom-search-form">
<input type="text" name="q" class="form-control" placeholder="Search...">
<input type="text" name="q" class="form-control" value="@if(Input::get('q')){{{Input::get('q')}}}@endif" placeholder="Search...">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="fa fa-search"></i>

View File

@ -228,6 +228,11 @@ function googleSankeyChart(URL, container) {
}
}
/**
* TODO fix this method so the layout is nice and dandy.
* @param URL
* @param container
*/
function googleTable(URL, container) {
if ($('#' + container).length == 1) {
$.getJSON(URL).success(function (data) {