Browse Source

Implementa listagem básica dos associados

master
Guilherme Capanema 6 years ago
parent
commit
4fd490d2e4
12 changed files with 384 additions and 4 deletions
  1. +1
    -1
      app/Associate.php
  2. +50
    -0
      app/Http/Livewire/Collaborators/Associates/Index.php
  3. +1
    -0
      composer.json
  4. +187
    -1
      composer.lock
  5. +1
    -1
      database/seeds/AssociateSeeder.php
  6. +3
    -0
      resources/lang/pt-BR/associate_categories.php
  7. +3
    -0
      resources/lang/pt-BR/associates.php
  8. +1
    -1
      resources/views/layouts/collaborators.blade.php
  9. +104
    -0
      resources/views/livewire/collaborators/associates/index.blade.php
  10. +6
    -0
      routes/web.php
  11. +2
    -0
      storage/debugbar/.gitignore
  12. +25
    -0
      tests/Feature/Collaborators/Associates/IndexTest.php

+ 1
- 1
app/Associate.php View File

@ -60,7 +60,7 @@ class Associate extends Authenticatable
*/ */
public function category() public function category()
{ {
return $this->belongsTo(UserCategory::class);
return $this->belongsTo(AssociateCategory::class, 'associate_category_id');
} }
// //


+ 50
- 0
app/Http/Livewire/Collaborators/Associates/Index.php View File

@ -0,0 +1,50 @@
<?php
namespace App\Http\Livewire\Collaborators\Associates;
use App\Associate;
use Livewire\Component;
use Livewire\WithPagination;
class Index extends Component
{
use WithPagination;
/**
* The parameters that should sync with the URL query string
*
* @var array
*/
protected $updatesQueryString = [
'search' => ['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),
]);
}
}

+ 1
- 0
composer.json View File

@ -20,6 +20,7 @@
"nothingworks/blade-svg": "^0.3.4" "nothingworks/blade-svg": "^0.3.4"
}, },
"require-dev": { "require-dev": {
"barryvdh/laravel-debugbar": "^3.3",
"facade/ignition": "^2.0", "facade/ignition": "^2.0",
"fzaninotto/faker": "^1.9.1", "fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1", "mockery/mockery": "^1.3.1",


+ 187
- 1
composer.lock View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "31aff051abdf646ee48111e2bad56afe",
"content-hash": "d4e5a383efe41d6b65342734ac7a0dd9",
"packages": [ "packages": [
{ {
"name": "asm89/stack-cors", "name": "asm89/stack-cors",
@ -4028,6 +4028,74 @@
} }
], ],
"packages-dev": [ "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", "name": "doctrine/instantiator",
"version": "1.3.1", "version": "1.3.1",
@ -4412,6 +4480,67 @@
], ],
"time": "2016-01-20T08:20:44+00:00" "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", "name": "mockery/mockery",
"version": "1.4.0", "version": "1.4.0",
@ -5930,6 +6059,63 @@
"homepage": "https://github.com/sebastianbergmann/version", "homepage": "https://github.com/sebastianbergmann/version",
"time": "2016-10-03T07:35:21+00:00" "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", "name": "theseer/tokenizer",
"version": "1.1.3", "version": "1.1.3",


+ 1
- 1
database/seeds/AssociateSeeder.php View File

@ -13,6 +13,6 @@ class AssociateSeeder extends Seeder
public function run() public function run()
{ {
Associate::flushEventListeners(); Associate::flushEventListeners();
factory(Associate::class, 20)->create();
factory(Associate::class, 130)->create();
} }
} }

+ 3
- 0
resources/lang/pt-BR/associate_categories.php View File

@ -2,4 +2,7 @@
return [ return [
'individual' => 'Associado Indivíduo', 'individual' => 'Associado Indivíduo',
'supporting-institution' => 'Associada Instituição Apoiadora',
'acting-institution' => 'Associada Instituição Atuante',
'company' => 'Associada Empresa Apoiadora',
]; ];

+ 3
- 0
resources/lang/pt-BR/associates.php View File

@ -1,7 +1,9 @@
<?php <?php
return [ return [
'model' => 'Associados',
'attributes' => [ 'attributes' => [
'category' => 'Categoria',
'name' => 'Nome completo', 'name' => 'Nome completo',
'birthday' => 'Data de nascimento', 'birthday' => 'Data de nascimento',
'document' => [ 'document' => [
@ -37,5 +39,6 @@ return [
'discussion' => 'Participação no grupo de comunicação', 'discussion' => 'Participação no grupo de comunicação',
'contribution' => 'Contribuição financeira', 'contribution' => 'Contribuição financeira',
'password' => 'Senha', 'password' => 'Senha',
'created_at' => 'Cadastro',
], ],
]; ];

+ 1
- 1
resources/views/layouts/collaborators.blade.php View File

@ -13,7 +13,7 @@
{{ __('sidebar.associates.title') }} {{ __('sidebar.associates.title') }}
</x-sidebar.title> </x-sidebar.title>
<x-sidebar.item href="{{ route('collaborators.dashboard') }}">
<x-sidebar.item href="{{ route('collaborators.associates.index') }}" :current="request()->route()->named('collaborators.associates.index')">
<x-slot name="icon"> <x-slot name="icon">
@svg('database', 'fill-current') @svg('database', 'fill-current')
</x-slot> </x-slot>


+ 104
- 0
resources/views/livewire/collaborators/associates/index.blade.php View File

@ -0,0 +1,104 @@
<div>
<h1 class="text-3xl font-bold">
{{ __('associates.model') }}
</h1>
<div class="flex items-center justify-between px-4 py-3 sm:px-6">
<x-input.select wire:model="perPage">
<option>10</option>
<option>25</option>
<option>50</option>
<option>100</option>
</x-input.select>
<x-input.text wire:model.debounce.300ms="search" />
</div>
<div class="flex flex-col">
<div class="-my-2 py-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
<div class="align-middle inline-block min-w-full shadow overflow-hidden sm:rounded-lg border-b border-gray-200">
<table class="min-w-full">
<thead>
<tr>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
{{ __('associates.attributes.name') }}
</th>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
{{ __('associates.attributes.category') }}
</th>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
{{ __('associates.attributes.address.city') }}
</th>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
{{ __('associates.attributes.created_at') }}
</th>
<th class="px-6 py-3 border-b border-gray-200 bg-gray-50"></th>
</tr>
</thead>
<tbody class="bg-white">
@foreach ($associates as $associate)
<tr>
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10">
<img class="h-10 w-10 rounded-full" src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" alt="" />
</div>
<div class="ml-4">
<div class="text-sm leading-5 font-medium text-gray-900">
{{ $associate->name }}
</div>
<div class="text-sm leading-5 text-gray-500">
{{ $associate->email }}
</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
{{ __('associate_categories.' . $associate->category->key ) }}
</span>
</td>
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200">
<div class="text-sm leading-5 text-gray-900">
{{ $associate->address['city'] }}
</div>
<div class="text-sm leading-5 text-gray-500">
{{ $associate->address['state'] }}
</div>
</td>
<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200 text-sm leading-5 text-gray-500">
{{ $associate->created_at->format('d/m/Y') }}
</td>
<td class="px-6 py-4 whitespace-no-wrap text-right border-b border-gray-200 text-sm leading-5 font-medium">
<a href="#" class="text-indigo-600 hover:text-indigo-900">Edit
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
<div class="mt-4">
{{ $associates->links() }}
</div>
</div>

+ 6
- 0
routes/web.php View File

@ -39,5 +39,11 @@ Route::prefix('admin')->name('collaborators.')->group(function () {
Route::middleware('auth:collaborators')->group(function () { Route::middleware('auth:collaborators')->group(function () {
Route::view('/', 'collaborators.dashboard')->name('dashboard'); Route::view('/', 'collaborators.dashboard')->name('dashboard');
Route::post('logout', 'Collaborators\Auth\LogoutController')->name('logout'); Route::post('logout', 'Collaborators\Auth\LogoutController')->name('logout');
Route::livewire('associates', 'collaborators.associates.index')
->layout('layouts.collaborators')
->name('associates.index');
}); });
}); });

+ 2
- 0
storage/debugbar/.gitignore View File

@ -0,0 +1,2 @@
*
!.gitignore

+ 25
- 0
tests/Feature/Collaborators/Associates/IndexTest.php View File

@ -0,0 +1,25 @@
<?php
namespace Tests\Feature\Collaborators\Associates;
use App\Collaborator;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Livewire\Livewire;
use Tests\TestCase;
class IndexTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function a_collaborator_can_view_index_page()
{
$collaborator = factory(Collaborator::class)->create();
$this->be($collaborator, 'collaborators');
$this->get(route('collaborators.associates.index'))
->assertSuccessful()
->assertSeeLivewire('collaborators.associates.index');
}
}