mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-11-03 12:49:58 -06:00
Fix search.
This commit is contained in:
1 parent
7e944e6309
commit
e1c94aac75
4 files changed
+40
-47
No files matched your search
@@ -44,9 +44,9 @@ use Override;
|
||||
final class TransactionController extends Controller
|
||||
{
|
||||
#[Override]
|
||||
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
|
||||
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
|
||||
private TransactionGroupRepositoryInterface $groupRepository;
|
||||
private JournalRepositoryInterface $repository;
|
||||
private JournalRepositoryInterface $repository;
|
||||
|
||||
/**
|
||||
* TransactionController constructor.
|
||||
@@ -69,7 +69,7 @@ final class TransactionController extends Controller
|
||||
|
||||
public function transactions(AutocompleteTransactionApiRequest $request): JsonResponse
|
||||
{
|
||||
$result = $this->repository->searchJournalDescriptions($request->attributes->get('query'), $request->attributes->get('limit'));
|
||||
$result = $this->repository->searchJournalDescriptions($request->attributes->get('query'), $request->attributes->get('limit'));
|
||||
|
||||
// limit and unique
|
||||
$filtered = $result->unique('description');
|
||||
@@ -78,8 +78,8 @@ final class TransactionController extends Controller
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($filtered as $journal) {
|
||||
$array[] = [
|
||||
'id' => (string) $journal->id,
|
||||
'transaction_group_id' => (string) $journal->transaction_group_id,
|
||||
'id' => (string)$journal->id,
|
||||
'transaction_group_id' => (string)$journal->transaction_group_id,
|
||||
'name' => $journal->description,
|
||||
'description' => $journal->description,
|
||||
];
|
||||
@@ -90,10 +90,11 @@ final class TransactionController extends Controller
|
||||
|
||||
public function transactionsWithMeta(AutocompleteTransactionApiRequest $request): JsonResponse
|
||||
{
|
||||
$query = $request->attributes->get('query');
|
||||
$result = new Collection();
|
||||
if (is_numeric($request->attributes->get('query'))) {
|
||||
if (is_numeric($query)) {
|
||||
// search for group, not journal.
|
||||
$firstResult = $this->groupRepository->find((int) $request->attributes->get('query'));
|
||||
$firstResult = $this->groupRepository->find((int)$query);
|
||||
if ($firstResult instanceof TransactionGroup) {
|
||||
// group may contain multiple journals, each a result:
|
||||
foreach ($firstResult->transactionJournals as $journal) {
|
||||
@@ -101,19 +102,19 @@ final class TransactionController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!is_numeric($request->attributes->get('query'))) {
|
||||
$result = $this->repository->searchJournalDescriptions($request->attributes->get('query'), $request->attributes->get('limit'));
|
||||
if (!is_numeric($query)) {
|
||||
$result = $this->repository->searchJournalDescriptions($query, $request->attributes->get('limit'));
|
||||
}
|
||||
|
||||
// limit and unique
|
||||
$array = [];
|
||||
$array = [];
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($result as $journal) {
|
||||
$currency = Amount::getCurrencyFromJournal($journal);
|
||||
$array[] = [
|
||||
'id' => (string) $journal->id,
|
||||
'transaction_group_id' => (string) $journal->transaction_group_id,
|
||||
'id' => (string)$journal->id,
|
||||
'transaction_group_id' => (string)$journal->transaction_group_id,
|
||||
'name' => $journal->description,
|
||||
'description' => $journal->description,
|
||||
'date' => $journal->date,
|
||||
|
||||
@@ -62,7 +62,7 @@ abstract class AggregateFormRequest extends ApiRequest
|
||||
if (!is_a($requestClass, Request::class, true)) {
|
||||
throw new RuntimeException('getRequests() must return class-strings of subclasses of Request');
|
||||
}
|
||||
Log::debug(sprintf('Initializing subrequest %s', $requestClass));
|
||||
// Log::debug(sprintf('Initializing subrequest %s', $requestClass));
|
||||
|
||||
$instance = new $requestClass();
|
||||
$this->requests[] = $instance;
|
||||
@@ -97,7 +97,7 @@ abstract class AggregateFormRequest extends ApiRequest
|
||||
// register all subrequests' validators
|
||||
foreach ($this->requests as $request) {
|
||||
if (method_exists($request, 'withValidator')) {
|
||||
Log::debug(sprintf('Process withValidator from class %s', $request::class));
|
||||
// Log::debug(sprintf('Process withValidator from class %s', $request::class));
|
||||
$request->withValidator($validator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Override;
|
||||
|
||||
use function Safe\json_encode;
|
||||
|
||||
/**
|
||||
@@ -65,10 +65,9 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
public function countByMeta(string $field, string $value, bool $includeDeleted): int
|
||||
{
|
||||
$search = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
|
||||
->where('name', $field)
|
||||
->where('data', json_encode($value))
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
;
|
||||
->where('name', $field)
|
||||
->where('data', json_encode($value))
|
||||
->where('transaction_journals.user_id', $this->user->id);
|
||||
if ($includeDeleted) {
|
||||
$search->withTrashed();
|
||||
}
|
||||
@@ -80,11 +79,10 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
public function countByNotes(string $value, bool $includeDeleted): int
|
||||
{
|
||||
$search = Note::query()
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'notes.noteable_id')
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->where('text', 'LIKE', sprintf('%%%s%%', $value))
|
||||
;
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'notes.noteable_id')
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->where('text', 'LIKE', sprintf('%%%s%%', $value));
|
||||
if ($includeDeleted) {
|
||||
$search->withTrashed();
|
||||
}
|
||||
@@ -118,10 +116,9 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
public function findByType(array $types): Collection
|
||||
{
|
||||
return $this->user->transactionJournals()
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->whereIn('transaction_types.type', $types)
|
||||
->get(['transaction_journals.*'])
|
||||
;
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->whereIn('transaction_types.type', $types)
|
||||
->get(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +149,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
}
|
||||
|
||||
/** @var null|Account $res */
|
||||
$res = $transaction->account;
|
||||
$res = $transaction->account;
|
||||
if (null === $res) {
|
||||
throw new FireflyException('Account is unexpectedly NULL.');
|
||||
}
|
||||
@@ -165,7 +162,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
*/
|
||||
public function getJournalTotal(TransactionJournal $journal): string
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty('amount-positive');
|
||||
if ($cache->has()) {
|
||||
@@ -174,7 +171,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
|
||||
// saves on queries:
|
||||
$amount = $journal->transactions()->where('amount', '>', 0)->get()->sum('amount');
|
||||
$amount = (string) $amount;
|
||||
$amount = (string)$amount;
|
||||
$cache->store($amount);
|
||||
|
||||
return $amount;
|
||||
@@ -191,7 +188,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
/** @var null|Note $note */
|
||||
$note = $link->notes()->first();
|
||||
|
||||
return (string) $note?->text;
|
||||
return (string)$note?->text;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,7 +223,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
}
|
||||
|
||||
/** @var null|Account $res */
|
||||
$res = $transaction->account;
|
||||
$res = $transaction->account;
|
||||
if (null === $res) {
|
||||
throw new FireflyException('Account is unexpectedly NULL.');
|
||||
}
|
||||
|
||||
@@ -23,32 +23,27 @@ import formatMoney from "../../../util/format-money.js";
|
||||
import { format } from "date-fns";
|
||||
|
||||
export function createLinkAutocomplete(fieldIdentifier, url) {
|
||||
let token = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
|
||||
let locale = window.store.get("locale");
|
||||
const renderJournal = function (item) {
|
||||
return (
|
||||
item.description +
|
||||
'<br><small class="text-muted">' +
|
||||
formatMoney(item.amount, item.currency_code) +
|
||||
" @ " +
|
||||
format(new Date(item.date), window.i18next.t("config.date_time_fns", { lng: locale }), locale) +
|
||||
"</small>"
|
||||
);
|
||||
let locale = window.store.get("locale");
|
||||
// return item.description;
|
||||
return item.description + '<br><small class="text-muted">#' + item.transaction_group_id + ', ' + formatMoney(item.amount, item.currency_code) + " @ " + format(new Date(item.date), window.i18next.t("config.date_time_fns", { lng: locale }), locale) + "</small>";
|
||||
};
|
||||
console.log('Created link AC', fieldIdentifier);
|
||||
Autocomplete.init("#" + fieldIdentifier, {
|
||||
server: url + "?_token=" + token,
|
||||
server: url,
|
||||
labelField: "name",
|
||||
hiddenInput: true,
|
||||
valueField: "id",
|
||||
liveServer: true,
|
||||
onRenderItem: renderJournal.bind(this),
|
||||
// fixed: true,
|
||||
showAllSuggestions: true,
|
||||
onRenderItem: renderJournal,
|
||||
fetchOptions: {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"X-CSRF-TOKEN": token,
|
||||
"X-CSRF-TOKEN": document.head.querySelector('meta[name="csrf-token"]').content,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user