From 09fcac7cb5541d5393ec090c16a70997dd0ecb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Pocrnji=C4=8D?= Date: Thu, 21 Nov 2024 21:08:47 +0100 Subject: [PATCH] search fix --- app/Models/Client.php | 12 +- app/Models/ClientCase.php | 9 +- app/Models/Person/Person.php | 10 +- composer.json | 1 - composer.lock | 206 +----------------- config/scout.php | 4 +- ...4_11_09_213443_create_activities_table.php | 2 +- database/seeders/PersonSeeder.php | 4 +- resources/js/Layouts/AppLayout.vue | 74 +++++-- routes/web.php | 48 ++-- tests/Feature/StringNormalizerTest.php | 18 ++ 11 files changed, 126 insertions(+), 262 deletions(-) create mode 100644 tests/Feature/StringNormalizerTest.php diff --git a/app/Models/Client.php b/app/Models/Client.php index fb5e6e5..d0135f6 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -35,14 +35,10 @@ protected function makeAllSearchableUsing(Builder $query): Builder public function toSearchableArray(): array { - $array = $this->toArray(); - - $array['person'] = $this->person ? $this->person->only(['full_name', 'tax_number', 'social_security_number']): null; - $array['person_addresses'] = $this->person->addresses ? $this->person->addresses->only(['adddress'])->toArray() : []; - $array['person_phones'] = $this->person->phones ? $this->person->phones->only(['nu'])->toArray() : []; - - - return $array; + return [ + 'person.full_name' => '', + 'person_addresses.address' => '' + ]; } diff --git a/app/Models/ClientCase.php b/app/Models/ClientCase.php index 22252f1..0c4d3dc 100644 --- a/app/Models/ClientCase.php +++ b/app/Models/ClientCase.php @@ -34,13 +34,10 @@ protected function makeAllSearchableUsing(Builder $query): Builder public function toSearchableArray(): array { - $array = $this->toArray(); - $array['person'] = $this->person ? $this->person->only(['full_name', 'tax_number', 'social_security_number']): null; - $array['person_addresses'] = $this->person->addresses ? $this->person->addresses->only(['adddress'])->toArray() : []; - $array['person_phones'] = $this->person->phones ? $this->person->phones->only(['nu'])->toArray() : []; - - return $array; + return [ + 'person.full_name' => '' + ]; } public function client(): BelongsTo diff --git a/app/Models/Person/Person.php b/app/Models/Person/Person.php index ea93797..627e242 100644 --- a/app/Models/Person/Person.php +++ b/app/Models/Person/Person.php @@ -63,11 +63,11 @@ protected function makeAllSearchableUsing(Builder $query): Builder public function toSearchableArray(): array { return [ - 'first_name' => $this->first_name, - 'last_name' => $this->last_name, - 'full_name' => $this->full_name, - 'addresses' => $this->addresses, - 'phones' => $this->phones + 'first_name' => '', + 'last_name' => '', + 'full_name' => '', + 'person_addresses.address' => '', + 'person_phones.nu' => '' ]; } diff --git a/composer.json b/composer.json index dd7c2cd..a9053c0 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,6 @@ "license": "MIT", "require": { "php": "^8.2", - "algolia/scout-extended": "3.1", "arielmejiadev/larapex-charts": "^2.1", "diglactic/laravel-breadcrumbs": "^9.0", "http-interop/http-factory-guzzle": "^1.2", diff --git a/composer.lock b/composer.lock index cb3c88a..7814a91 100644 --- a/composer.lock +++ b/composer.lock @@ -4,163 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c042c0c871352d0b2fbd12893a3cb9ae", + "content-hash": "1125fcd2a303fd68a7e84ac445b3b914", "packages": [ - { - "name": "algolia/algoliasearch-client-php", - "version": "3.4.1", - "source": { - "type": "git", - "url": "https://github.com/algolia/algoliasearch-client-php.git", - "reference": "cf87b649f745479c0800299481d91dc303e23cea" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/algolia/algoliasearch-client-php/zipball/cf87b649f745479c0800299481d91dc303e23cea", - "reference": "cf87b649f745479c0800299481d91dc303e23cea", - "shasum": "" - }, - "require": { - "ext-curl": "*", - "ext-json": "*", - "ext-mbstring": "*", - "php": "^7.3 || ^8.0", - "psr/http-message": "^1.1 || ^2.0", - "psr/log": "^1.0 || ^2.0 || ^3.0", - "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.0", - "fzaninotto/faker": "^1.8", - "phpunit/phpunit": "^8.0 || ^9.0", - "symfony/yaml": "^2.0 || ^4.0" - }, - "suggest": { - "guzzlehttp/guzzle": "If you prefer to use Guzzle HTTP client instead of the Http Client implementation provided by the package" - }, - "bin": [ - "bin/algolia-doctor" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-2.0": "2.0.x-dev" - } - }, - "autoload": { - "files": [ - "src/Http/Psr7/functions.php", - "src/functions.php" - ], - "psr-4": { - "Algolia\\AlgoliaSearch\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Algolia Team", - "email": "contact@algolia.com" - } - ], - "description": "Algolia Search API Client for PHP", - "keywords": [ - "algolia", - "api", - "client", - "php", - "search" - ], - "support": { - "issues": "https://github.com/algolia/algoliasearch-client-php/issues", - "source": "https://github.com/algolia/algoliasearch-client-php/tree/3.4.1" - }, - "time": "2023-08-28T14:34:04+00:00" - }, - { - "name": "algolia/scout-extended", - "version": "v3.1.0", - "source": { - "type": "git", - "url": "https://github.com/algolia/scout-extended.git", - "reference": "74d8c73955c07ce52633f74005624545239a9522" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/algolia/scout-extended/zipball/74d8c73955c07ce52633f74005624545239a9522", - "reference": "74d8c73955c07ce52633f74005624545239a9522", - "shasum": "" - }, - "require": { - "algolia/algoliasearch-client-php": "^3.0.0", - "ext-json": "*", - "illuminate/console": "^9.0|^10.0|^11.0", - "illuminate/contracts": "^9.0|^10.0|^11.0", - "illuminate/database": "^9.0|^10.0|^11.0", - "illuminate/filesystem": "^9.0|^10.0|^11.0", - "illuminate/support": "^9.0|^10.0|^11.0", - "laravel/scout": "^9.0|^10.0", - "php": "^8.0", - "riimu/kit-phpencoder": "^2.4" - }, - "require-dev": { - "fakerphp/faker": "^1.13", - "laravel/legacy-factories": "^1.1", - "mockery/mockery": "^1.4", - "nunomaduro/larastan": "^1.0|^2.0", - "orchestra/testbench": "^4.9|^5.9|^6.6|^7.0|^8.0|^9.0", - "phpstan/phpstan": "^1.3", - "phpunit/phpunit": "^8.0|^9.0|^10.5" - }, - "suggest": { - "ext-dom": "Required to use the HTML Splitter." - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Algolia\\ScoutExtended\\ScoutExtendedServiceProvider" - ] - } - }, - "autoload": { - "psr-4": { - "Algolia\\ScoutExtended\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nuno Maduro", - "email": "enunomaduro@gmail.com" - }, - { - "name": "Algolia Team", - "email": "contact@algolia.com" - } - ], - "description": "Scout Extended extends Laravel Scout adding algolia-specific features", - "keywords": [ - "algolia", - "analytics", - "extended", - "laravel", - "places", - "scout", - "search" - ], - "support": { - "issues": "https://github.com/algolia/scout-extended/issues", - "source": "https://github.com/algolia/scout-extended/tree/v3.1.0" - }, - "time": "2024-03-21T14:34:08+00:00" - }, { "name": "arielmejiadev/larapex-charts", "version": "2.1.1", @@ -4294,55 +4139,6 @@ ], "time": "2024-04-27T21:32:50+00:00" }, - { - "name": "riimu/kit-phpencoder", - "version": "v2.4.2", - "source": { - "type": "git", - "url": "https://github.com/Riimu/Kit-PHPEncoder.git", - "reference": "72ff7825de193b272e17b228394819dbfc638e72" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Riimu/Kit-PHPEncoder/zipball/72ff7825de193b272e17b228394819dbfc638e72", - "reference": "72ff7825de193b272e17b228394819dbfc638e72", - "shasum": "" - }, - "require": { - "php": ">=5.6.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Riimu\\Kit\\PHPEncoder\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Riikka Kalliomäki", - "email": "riikka.kalliomaki@gmail.com", - "homepage": "http://riimu.net" - } - ], - "description": "Highly customizable alternative to var_export for PHP code generation", - "homepage": "http://kit.riimu.net", - "keywords": [ - "code", - "encoder", - "export", - "generator", - "variable" - ], - "support": { - "issues": "https://github.com/Riimu/Kit-PHPEncoder/issues", - "source": "https://github.com/Riimu/Kit-PHPEncoder/tree/v2.4.2" - }, - "time": "2022-12-10T18:12:25+00:00" - }, { "name": "robertboes/inertia-breadcrumbs", "version": "0.6.0", diff --git a/config/scout.php b/config/scout.php index 65b8229..c3f0f42 100644 --- a/config/scout.php +++ b/config/scout.php @@ -113,8 +113,8 @@ */ 'algolia' => [ - 'id' => env('ALGOLIA_APP_ID', 'ZDAXR87LZV'), - 'secret' => env('ALGOLIA_SECRET', '8797318d18e10541ad15d49ae1e64db2'), + 'id' => env('ALGOLIA_APP_ID', ''), + 'secret' => env('ALGOLIA_SECRET', ''), ], /* diff --git a/database/migrations/2024_11_09_213443_create_activities_table.php b/database/migrations/2024_11_09_213443_create_activities_table.php index ec677fc..5ec20c7 100644 --- a/database/migrations/2024_11_09_213443_create_activities_table.php +++ b/database/migrations/2024_11_09_213443_create_activities_table.php @@ -15,7 +15,7 @@ public function up(): void $table->id(); $table->date('due_date')->nullable(); $table->decimal('amount', 8, 4)->nullable(); - $table->text('note')->default(''); + $table->text('note')->nullable()->default(''); $table->foreignIdFor(\App\Models\Action::class); $table->foreignIdFor(\App\Models\Decision::class); $table->foreignIdFor(\App\Models\ClientCase::class); diff --git a/database/seeders/PersonSeeder.php b/database/seeders/PersonSeeder.php index ddff8fa..50f3475 100644 --- a/database/seeders/PersonSeeder.php +++ b/database/seeders/PersonSeeder.php @@ -147,7 +147,7 @@ public function run(): void 'user_id' => 1 ])->clientCase()->create( [ - 'client_id' => 4 + 'client_id' => 2 ] ); @@ -166,7 +166,7 @@ public function run(): void 'user_id' => 1 ])->clientCase()->create( [ - 'client_id' => 4 + 'client_id' => 2 ] ); diff --git a/resources/js/Layouts/AppLayout.vue b/resources/js/Layouts/AppLayout.vue index 4b1f885..156709b 100644 --- a/resources/js/Layouts/AppLayout.vue +++ b/resources/js/Layouts/AppLayout.vue @@ -40,7 +40,7 @@ const onSearchFocus = () => { } const onSearchBlue = () => { - setTimeout(() => querySearchList.value = true, 100) + setTimeout(() => querySearchList.value = true, 300) } watch(querySearch, debounce((value) => { @@ -129,25 +129,25 @@ watch(querySearch, debounce((value) => { - -
-

Naročniki:

- - - {{ client.person.full_name }} - - -
+ + +

Naročniki:

+ + + {{ client.full_name }} + + +
- -
-

Primeri:

- - - {{ clientCase.person.full_name }} - - -
+ + +

Primeri:

+ + + {{ clientCase.full_name }} + + +
@@ -313,6 +313,42 @@ watch(querySearch, debounce((value) => { +
+ + + + + + + +

Naročniki:

+ + + {{ client.full_name }} + + + +
+ + +

Primeri:

+ + + {{ clientCase.full_name }} + + + +
+
+
diff --git a/routes/web.php b/routes/web.php index dcb799b..a56fa6f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,11 +6,11 @@ use App\Http\Controllers\ContractController; use App\Http\Controllers\SettingController; use App\Models\Person\Person; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use ArielMejiaDev\LarapexCharts\LarapexChart; use Illuminate\Support\Facades\Route; use Inertia\Inertia; +use \Illuminate\Database\Eloquent\Builder; Route::redirect('/', 'login'); @@ -45,27 +45,49 @@ Route::get('search', function(Request $request) { if( !empty($request->input('query')) ) { + /*$clients = App\Models\Client::search($request->input('query')) - ->query(function($q) use($request) { - $q->with('person')->limit($request->input('limit')); + ->query( function($builder) use($request){ + $builder->leftJoin('person', 'clients.person_id', '=', 'person.id') + ->leftJoin('person_addresses', 'person_addresses.person_id', '=', 'person.id') + ->select('clients.*', 'person.full_name as person_fullname') + ->limit($request->input('limit')); }) - ->get();*/ - $clients = App\Models\Client::search($request->input('query')) - ->query( fn(Builder $builder) => - $builder->with('person:id,full_name')->limit($request->input('limit')) - ) ->get(); $clientCases = App\Models\ClientCase::search($request->input('query')) - ->query( fn(Builder $builder) => - $builder->with('person:id,full_name')->limit($request->input('limit')) - ) + ->query(function($builder) use($request){ + $builder->join('person', 'client_cases.person_id', '=', 'person.id') + ->select('client_cases.*', 'person.full_name as person_fullname') + ->limit($request->input('limit')); + }) + ->get();*/ + + + $clients = App\Models\Person\Person::search($request->input('query')) + ->query(function($builder) use($request): void { + $builder->join('clients', 'person.id', '=', 'clients.person_id') + ->leftJoin('person_addresses', 'person.id', '=', 'person_addresses.person_id') + ->leftJoin('person_phones', 'person.id', '=', 'person_phones.person_id') + ->select('person.*', 'clients.uuid as client_uuid') + ->limit($request->input('limit')); + }) + ->get(); + + $clientCases = App\Models\Person\Person::search($request->input('query')) + ->query(function($builder) use($request): void { + $builder->join('client_cases', 'person.id', '=', 'client_cases.person_id') + ->leftJoin('person_addresses', 'person.id', '=', 'person_addresses.person_id') + ->leftJoin('person_phones', 'person.id', '=', 'person_phones.person_id') + ->select('person.*', 'client_cases.uuid as case_uuid') + ->limit($request->input('limit')); + }) ->get(); - return [ 'clients' => $clients, - 'client_cases' => $clientCases + 'client_cases' => $clientCases, + 'query' => $request->input('query') ]; } diff --git a/tests/Feature/StringNormalizerTest.php b/tests/Feature/StringNormalizerTest.php new file mode 100644 index 0000000..544c0ff --- /dev/null +++ b/tests/Feature/StringNormalizerTest.php @@ -0,0 +1,18 @@ +assertTrue(\Normalizer::normalize('Naročnik')); + } +}