Skip to content

Commit

Permalink
Add graphs and draggable ui (#10)
Browse files Browse the repository at this point in the history
* Add a query page so people can discover their own query url. And add some base things for the graph.

* Add a working metrics system, and failed jobs viewer.

* Remove code that caused a bug

* Address PR feedback

* Refactor the tests, and clean up the filiters so they use Arrayable

* Refactor the ugly chart controller some by adding a repository method for getting the transactions by dates...

* Add transaction repositorycontract

* Add metric and value changes. And update the ugly chart controller some more.

* Update the graph/metrics

* Update ugly controller more, and update the settings with toasted

* Fix the bugon the metrics
  • Loading branch information
Austin Kregel authored Jun 29, 2020
1 parent 625815d commit 52ac0d3
Show file tree
Hide file tree
Showing 75 changed files with 1,469 additions and 11,975 deletions.
4 changes: 2 additions & 2 deletions app/Console/Commands/GenerateChannelsAndAlertsFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public function handle()
'name' => 'transaction.category.name'
],
[
'value' => 'tag.name',
'name' => 'transaction.tag.name'
'value' => 'tag.name.en',
'name' => 'transaction.tag.name.en'
],
]);

Expand Down
4 changes: 3 additions & 1 deletion app/Contracts/ConditionContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Contracts\Models;

use Illuminate\Contracts\Support\Arrayable;

interface ConditionContract
{
public function __invoke($item, ConditionalsContract $condition): bool;
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool;
}
13 changes: 0 additions & 13 deletions app/Contracts/Repositories/TransactionRepository.php

This file was deleted.

17 changes: 17 additions & 0 deletions app/Contracts/Repositories/TransactionRepositoryContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Contracts\Repositories;

use App\User;
use Carbon\Carbon;
use Illuminate\Support\Collection;

/**
* Interface TransactionRepository.
*
* @package namespace App\Contracts\Repositories;
*/
interface TransactionRepositoryContract extends AbstractRepositoryInterface
{
public function findAllBetweenDateForUserInScope(User $user, Carbon $startDate, Carbon $endDate, string $scope): Collection;
}
6 changes: 4 additions & 2 deletions app/Filters/Conditions/EndsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

class EndsWith implements ConditionContract
{
public function __invoke($item, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return Str::endsWith($item[$condition->getComparatorField()], $condition->getComparatorValue()) ;
return Str::endsWith(Arr::get($item->toArray(), $condition->getComparatorField()), $condition->getComparatorValue()) ;
}
}
6 changes: 4 additions & 2 deletions app/Filters/Conditions/EqualFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class EqualFilter implements ConditionContract
{
public function __invoke($item, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return $condition->getComparatorValue() == $item[$condition->getComparatorField()];
return $condition->getComparatorValue() == Arr::get($item->toArray(), $condition->getComparatorField());
}
}
6 changes: 4 additions & 2 deletions app/Filters/Conditions/GreaterThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class GreaterThan implements ConditionContract
{
public function __invoke($items, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return $items[$condition->getComparatorField()] > $condition->getComparatorValue();
return Arr::get($item->toArray(), $condition->getComparatorField()) > $condition->getComparatorValue();
}
}
6 changes: 4 additions & 2 deletions app/Filters/Conditions/GreaterThanEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class GreaterThanEqual implements ConditionContract
{
public function __invoke($items, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return $items[$condition->getComparatorField()] >= $condition->getComparatorValue();
return Arr::get($item->toArray(), $condition->getComparatorField()) >= $condition->getComparatorValue();
}
}
6 changes: 4 additions & 2 deletions app/Filters/Conditions/InFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class InFilter implements ConditionContract
{
public function __invoke($items, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return in_array($condition->getComparatorValue(), $items[$condition->getComparatorField()]);
return in_array($condition->getComparatorValue(), Arr::get($item->toArray(), $condition->getComparatorField()));
}
}
5 changes: 3 additions & 2 deletions app/Filters/Conditions/InLikeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;

class InLikeFilter implements ConditionContract
{
public function __invoke($items, ConditionalsContract $condition): bool
public function __invoke(Arrayable $items, ConditionalsContract $condition): bool
{
foreach ($items as $value) {
foreach ($items->toArray() as $value) {
if (stripos($value[$condition->getComparatorField()], $condition->getComparatorValue()) !== false) {
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions app/Filters/Conditions/LessThanEqualFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class LessThanEqualFilter implements ConditionContract
{
public function __invoke($items, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return $items[$condition->getComparatorField()] <= $condition->getComparatorValue();
return Arr::get($item->toArray(), $condition->getComparatorField()) <= $condition->getComparatorValue();
}
}
6 changes: 4 additions & 2 deletions app/Filters/Conditions/LessThanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class LessThanFilter implements ConditionContract
{
public function __invoke($items, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return $items[$condition->getComparatorField()] < $condition->getComparatorValue();
return Arr::get($item->toArray(), $condition->getComparatorField()) < $condition->getComparatorValue();
}
}
5 changes: 3 additions & 2 deletions app/Filters/Conditions/LikeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class LikeFilter implements ConditionContract
{
public function __invoke($item, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return stripos(
Arr::get($item, $condition->getComparatorField()),
Arr::get($item->toArray(), $condition->getComparatorField()),
$condition->getComparatorValue()
) !== false;
}
Expand Down
6 changes: 4 additions & 2 deletions app/Filters/Conditions/NotEqualFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class NotEqualFilter implements ConditionContract
{
public function __invoke($item, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return $condition->getComparatorValue() != $item[$condition->getComparatorField()];
return $condition->getComparatorValue() != Arr::get($item->toArray(), $condition->getComparatorField());
}
}
6 changes: 4 additions & 2 deletions app/Filters/Conditions/NotInFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class NotInFilter implements ConditionContract
{
public function __invoke($items, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return !in_array($condition->getComparatorValue(), $items[$condition->getComparatorField()]);
return !in_array($condition->getComparatorValue(), Arr::get($item->toArray(), $condition->getComparatorField()));
}
}
5 changes: 3 additions & 2 deletions app/Filters/Conditions/NotInLikeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;

class NotInLikeFilter implements ConditionContract
{
public function __invoke($items, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
foreach ($items as $value) {
foreach ($item->toArray() as $value) {
if (stripos($value[$condition->getComparatorField()], $condition->getComparatorValue()) === false) {
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions app/Filters/Conditions/NotLikeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;

class NotLikeFilter implements ConditionContract
{
public function __invoke($item, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return stripos($item[$condition->getComparatorField()], $condition->getComparatorValue()) === false;
return stripos(Arr::get($item->toArray(), $condition->getComparatorField()), $condition->getComparatorValue()) === false;
}
}
6 changes: 4 additions & 2 deletions app/Filters/Conditions/StartsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

use App\Contracts\Models\ConditionalsContract;
use App\Contracts\Models\ConditionContract;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

class StartsWith implements ConditionContract
{
public function __invoke($item, ConditionalsContract $condition): bool
public function __invoke(Arrayable $item, ConditionalsContract $condition): bool
{
return Str::startsWith($item[$condition->getComparatorField()], $condition->getComparatorValue()) ;
return Str::startsWith(Arr::get($item->toArray(), $condition->getComparatorField()), $condition->getComparatorValue()) ;
}
}
35 changes: 35 additions & 0 deletions app/Filters/Metrics/TrendFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Filters\Metrics;

use App\Models\Transaction;
use Illuminate\Support\Collection;

class TrendFilter
{
public function handle(array $duration, Collection $data): array
{
[$durationStart, $durationEnd] = $duration;

$numericalDuration = $durationStart->diffInDays($durationEnd);

if ($numericalDuration > 31) {
$numericalDuration = $durationStart->diffInMonths($durationEnd);
}
$returnedData = [];

for ($i = 0; $i < $numericalDuration; $i++) {
$returnedData[$durationStart->copy()->addDay($i)->format('m/d')] = 0;
}

$data->each(function (Transaction $transaction) use (&$returnedData) {
if (!array_key_exists($transaction->date->format('m/d'), $returnedData)) {
$returnedData[$transaction->date->format('m/d')] = 0;
}

$returnedData[$transaction->date->format('m/d')] += $transaction->amount;
});

return $returnedData;
}
}
14 changes: 14 additions & 0 deletions app/Http/Controllers/Api/CacheController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;

class CacheController
{
public function __invoke(Request $request)
{
cache()->tags([$request->user()->email])->flush();
return response('', 200);
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public function conditionals(ConditionalsRequest $request, Tag $tag)
{
try {
$tag->transactions()->sync([]);
$response = $this->json(
$tag->conditionals()->create($request->json()->all() + ['type' => 'automatic'])
return $this->json(
$tag->conditionals()->create($request->json()->all())
);
} finally {
$this->dispatch(new SyncTagsWithTransactionsInDatabase($request->user()));
Expand Down
Loading

0 comments on commit 52ac0d3

Please sign in to comment.