From 4fd490d2e40527acc2d2064dd44e9c530067c00c Mon Sep 17 00:00:00 2001 From: Guilherme Capanema Date: Sun, 7 Jun 2020 21:20:11 -0300 Subject: [PATCH] =?UTF-8?q?Implementa=20listagem=20b=C3=A1sica=20dos=20ass?= =?UTF-8?q?ociados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Associate.php | 2 +- .../Collaborators/Associates/Index.php | 50 +++++ composer.json | 1 + composer.lock | 188 +++++++++++++++++- database/seeds/AssociateSeeder.php | 2 +- resources/lang/pt-BR/associate_categories.php | 3 + resources/lang/pt-BR/associates.php | 3 + .../views/layouts/collaborators.blade.php | 2 +- .../collaborators/associates/index.blade.php | 104 ++++++++++ routes/web.php | 6 + storage/debugbar/.gitignore | 2 + .../Collaborators/Associates/IndexTest.php | 25 +++ 12 files changed, 384 insertions(+), 4 deletions(-) create mode 100644 app/Http/Livewire/Collaborators/Associates/Index.php create mode 100644 resources/views/livewire/collaborators/associates/index.blade.php create mode 100644 storage/debugbar/.gitignore create mode 100644 tests/Feature/Collaborators/Associates/IndexTest.php diff --git a/app/Associate.php b/app/Associate.php index f918860..27427a9 100644 --- a/app/Associate.php +++ b/app/Associate.php @@ -60,7 +60,7 @@ class Associate extends Authenticatable */ public function category() { - return $this->belongsTo(UserCategory::class); + return $this->belongsTo(AssociateCategory::class, 'associate_category_id'); } // diff --git a/app/Http/Livewire/Collaborators/Associates/Index.php b/app/Http/Livewire/Collaborators/Associates/Index.php new file mode 100644 index 0000000..e0f3ca7 --- /dev/null +++ b/app/Http/Livewire/Collaborators/Associates/Index.php @@ -0,0 +1,50 @@ + ['except' => ''] + ]; + + /** @var string */ + public $orderColumn = 'created_at'; + + /** @var string */ + public $orderDirection = 'DESC'; + + /** @var int */ + public $perPage = 10; + + /** @var string */ + public $search; + + public function mount() + { + $this->search = request()->query('search', $this->search); + } + + public function updatingSearch() + { + $this->resetPage(); + } + + public function render() + { + return view('livewire.collaborators.associates.index', [ + 'associates' => Associate::with('category')->where('name', 'LIKE', '%' . $this->search . '%')->orderBy($this->orderColumn, $this->orderDirection)->paginate($this->perPage), + ]); + } +} diff --git a/composer.json b/composer.json index 091749d..dc1eb61 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "nothingworks/blade-svg": "^0.3.4" }, "require-dev": { + "barryvdh/laravel-debugbar": "^3.3", "facade/ignition": "^2.0", "fzaninotto/faker": "^1.9.1", "mockery/mockery": "^1.3.1", diff --git a/composer.lock b/composer.lock index aaab31b..8d01b80 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "31aff051abdf646ee48111e2bad56afe", + "content-hash": "d4e5a383efe41d6b65342734ac7a0dd9", "packages": [ { "name": "asm89/stack-cors", @@ -4028,6 +4028,74 @@ } ], "packages-dev": [ + { + "name": "barryvdh/laravel-debugbar", + "version": "v3.3.3", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-debugbar.git", + "reference": "57f2219f6d9efe41ed1bc880d86701c52f261bf5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/57f2219f6d9efe41ed1bc880d86701c52f261bf5", + "reference": "57f2219f6d9efe41ed1bc880d86701c52f261bf5", + "shasum": "" + }, + "require": { + "illuminate/routing": "^5.5|^6|^7", + "illuminate/session": "^5.5|^6|^7", + "illuminate/support": "^5.5|^6|^7", + "maximebf/debugbar": "^1.15.1", + "php": ">=7.0", + "symfony/debug": "^3|^4|^5", + "symfony/finder": "^3|^4|^5" + }, + "require-dev": { + "laravel/framework": "5.5.x" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Debugbar\\ServiceProvider" + ], + "aliases": { + "Debugbar": "Barryvdh\\Debugbar\\Facade" + } + } + }, + "autoload": { + "psr-4": { + "Barryvdh\\Debugbar\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "PHP Debugbar integration for Laravel", + "keywords": [ + "debug", + "debugbar", + "laravel", + "profiler", + "webprofiler" + ], + "time": "2020-05-05T10:53:32+00:00" + }, { "name": "doctrine/instantiator", "version": "1.3.1", @@ -4412,6 +4480,67 @@ ], "time": "2016-01-20T08:20:44+00:00" }, + { + "name": "maximebf/debugbar", + "version": "v1.16.3", + "source": { + "type": "git", + "url": "https://github.com/maximebf/php-debugbar.git", + "reference": "1a1605b8e9bacb34cc0c6278206d699772e1d372" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/1a1605b8e9bacb34cc0c6278206d699772e1d372", + "reference": "1a1605b8e9bacb34cc0c6278206d699772e1d372", + "shasum": "" + }, + "require": { + "php": "^7.1", + "psr/log": "^1.0", + "symfony/var-dumper": "^2.6|^3|^4|^5" + }, + "require-dev": { + "phpunit/phpunit": "^5" + }, + "suggest": { + "kriswallsmith/assetic": "The best way to manage assets", + "monolog/monolog": "Log using Monolog", + "predis/predis": "Redis storage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.16-dev" + } + }, + "autoload": { + "psr-4": { + "DebugBar\\": "src/DebugBar/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maxime Bouroumeau-Fuseau", + "email": "maxime.bouroumeau@gmail.com", + "homepage": "http://maximebf.com" + }, + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Debug bar in the browser for php application", + "homepage": "https://github.com/maximebf/php-debugbar", + "keywords": [ + "debug", + "debugbar" + ], + "time": "2020-05-06T07:06:27+00:00" + }, { "name": "mockery/mockery", "version": "1.4.0", @@ -5930,6 +6059,63 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03T07:35:21+00:00" }, + { + "name": "symfony/debug", + "version": "v4.4.9", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "28f92d08bb6d1fddf8158e02c194ad43870007e6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/28f92d08bb6d1fddf8158e02c194ad43870007e6", + "reference": "28f92d08bb6d1fddf8158e02c194ad43870007e6", + "shasum": "" + }, + "require": { + "php": ">=7.1.3", + "psr/log": "~1.0", + "symfony/polyfill-php80": "^1.15" + }, + "conflict": { + "symfony/http-kernel": "<3.4" + }, + "require-dev": { + "symfony/http-kernel": "^3.4|^4.0|^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2020-05-24T08:33:35+00:00" + }, { "name": "theseer/tokenizer", "version": "1.1.3", diff --git a/database/seeds/AssociateSeeder.php b/database/seeds/AssociateSeeder.php index f0bf0a1..83cd5c9 100644 --- a/database/seeds/AssociateSeeder.php +++ b/database/seeds/AssociateSeeder.php @@ -13,6 +13,6 @@ class AssociateSeeder extends Seeder public function run() { Associate::flushEventListeners(); - factory(Associate::class, 20)->create(); + factory(Associate::class, 130)->create(); } } diff --git a/resources/lang/pt-BR/associate_categories.php b/resources/lang/pt-BR/associate_categories.php index 4b69a42..5ac1664 100644 --- a/resources/lang/pt-BR/associate_categories.php +++ b/resources/lang/pt-BR/associate_categories.php @@ -2,4 +2,7 @@ return [ 'individual' => 'Associado Indivíduo', + 'supporting-institution' => 'Associada Instituição Apoiadora', + 'acting-institution' => 'Associada Instituição Atuante', + 'company' => 'Associada Empresa Apoiadora', ]; diff --git a/resources/lang/pt-BR/associates.php b/resources/lang/pt-BR/associates.php index 478b095..e6af50d 100644 --- a/resources/lang/pt-BR/associates.php +++ b/resources/lang/pt-BR/associates.php @@ -1,7 +1,9 @@ 'Associados', 'attributes' => [ + 'category' => 'Categoria', 'name' => 'Nome completo', 'birthday' => 'Data de nascimento', 'document' => [ @@ -37,5 +39,6 @@ return [ 'discussion' => 'Participação no grupo de comunicação', 'contribution' => 'Contribuição financeira', 'password' => 'Senha', + 'created_at' => 'Cadastro', ], ]; diff --git a/resources/views/layouts/collaborators.blade.php b/resources/views/layouts/collaborators.blade.php index ee25343..8161fe8 100644 --- a/resources/views/layouts/collaborators.blade.php +++ b/resources/views/layouts/collaborators.blade.php @@ -13,7 +13,7 @@ {{ __('sidebar.associates.title') }} - + @svg('database', 'fill-current') diff --git a/resources/views/livewire/collaborators/associates/index.blade.php b/resources/views/livewire/collaborators/associates/index.blade.php new file mode 100644 index 0000000..9f70566 --- /dev/null +++ b/resources/views/livewire/collaborators/associates/index.blade.php @@ -0,0 +1,104 @@ +
+ +

+ {{ __('associates.model') }} +

+ +
+ + + + + + + + + + +
+ +
+
+
+ + + + + + + + + + + + + + @foreach ($associates as $associate) + + + + + + + + + + + + + + @endforeach + +
+ {{ __('associates.attributes.name') }} + + {{ __('associates.attributes.category') }} + + {{ __('associates.attributes.address.city') }} + + {{ __('associates.attributes.created_at') }} +
+
+ +
+ +
+ +
+
+ {{ $associate->name }} +
+
+ {{ $associate->email }} +
+
+
+
+ + {{ __('associate_categories.' . $associate->category->key ) }} + + + +
+ {{ $associate->address['city'] }} +
+ +
+ {{ $associate->address['state'] }} +
+ +
+ {{ $associate->created_at->format('d/m/Y') }} + + Edit + +
+
+
+
+ +
+ {{ $associates->links() }} +
+ +
diff --git a/routes/web.php b/routes/web.php index 19ece9c..ede8fb2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -39,5 +39,11 @@ Route::prefix('admin')->name('collaborators.')->group(function () { Route::middleware('auth:collaborators')->group(function () { Route::view('/', 'collaborators.dashboard')->name('dashboard'); Route::post('logout', 'Collaborators\Auth\LogoutController')->name('logout'); + + Route::livewire('associates', 'collaborators.associates.index') + ->layout('layouts.collaborators') + ->name('associates.index'); }); }); + + diff --git a/storage/debugbar/.gitignore b/storage/debugbar/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/debugbar/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/Feature/Collaborators/Associates/IndexTest.php b/tests/Feature/Collaborators/Associates/IndexTest.php new file mode 100644 index 0000000..7ac043a --- /dev/null +++ b/tests/Feature/Collaborators/Associates/IndexTest.php @@ -0,0 +1,25 @@ +create(); + $this->be($collaborator, 'collaborators'); + + $this->get(route('collaborators.associates.index')) + ->assertSuccessful() + ->assertSeeLivewire('collaborators.associates.index'); + } +}