-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
308 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Entity; | ||
use App\Models\Group; | ||
use Illuminate\Http\Request; | ||
|
||
class EntityGroupController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
*/ | ||
public function index(Entity $entity) | ||
{ | ||
$this->authorize('do-everything'); | ||
|
||
$groups = $entity->groups() ? $entity->groups()->get() : collect(); | ||
$joinable = Group::orderBy('name') | ||
->whereNotIn('id', $groups->pluck('id')) | ||
->get(); | ||
|
||
return view('entities.groups', [ | ||
'entity' => $entity, | ||
'groups' => $groups, | ||
'joinable' => $joinable, | ||
]); | ||
|
||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
*/ | ||
public function store(Request $request, Entity $entity) | ||
{ | ||
$this->authorize('do-everything'); | ||
|
||
if (empty(request('group'))) { | ||
return back() | ||
->with('status', __('entities.join_empty_group')) | ||
->with('color', 'red'); | ||
} | ||
|
||
$entity->groups()->attach(request('group')); | ||
|
||
return redirect() | ||
->back() | ||
->with('status', __('entities.join_group')); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
*/ | ||
public function destroy(Entity $entity) | ||
{ | ||
$this->authorize('do-everything'); | ||
|
||
if (empty(request('groups'))) { | ||
return back() | ||
->with('status', __('entities.leave_empty_group')) | ||
->with('color', 'red'); | ||
} | ||
$entity | ||
->groups() | ||
->detach(request('groups')); | ||
|
||
return redirect() | ||
->back() | ||
->with('status', __('entities.leave_group')); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<form x-data="{ open: false }" id="add_members" action="{{ route('entities.group.join', $entity) }}" | ||
method="post"> | ||
@csrf | ||
<div class="overflow-x-auto bg-white border rounded-lg"> | ||
<table class="min-w-full border-b border-gray-300"> | ||
<thead> | ||
<tr> | ||
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b"> | ||
</th> | ||
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b"> | ||
{{ __('common.name') }}</th> | ||
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b"> | ||
{{ __('common.description') }}</th> | ||
</tr> | ||
</thead> | ||
<tbody class="divide-y divide-gray-200"> | ||
@forelse ($joinable as $group) | ||
<tr x-data class="hover:bg-blue-50" role="button" | ||
@click="checkbox = $el.querySelector('input[type=checkbox]'); checkbox.checked = !checkbox.checked"> | ||
<td class="px-6 py-3 text-sm"> | ||
<input @click.stop class="rounded" type="checkbox" name="group[]" | ||
value="{{ $group->id }}"> | ||
</td> | ||
<td class="whitespace-nowrap px-6 py-3 text-sm"> | ||
{{ $group->name }} | ||
</td> | ||
<td class="px-6 py-3 text-sm"> | ||
{{ $group->description }} | ||
</td> | ||
</tr> | ||
@empty | ||
<tr class="hover:bg-blue-50"> | ||
<td class="px-6 py-3 font-bold text-center"> | ||
{{ __('groups.empty') }} | ||
</td> | ||
</tr> | ||
@endforelse | ||
</tbody> | ||
</table> | ||
@if (count($joinable)) | ||
<div class="px-4 py-2 bg-gray-100"> | ||
<x-button @click.prevent="open = !open">{{ __('common.add_members') }}</x-button> | ||
|
||
<x-modal> | ||
<x-slot:title>{{ __('common.confirm_add_members') }}</x-slot:title> | ||
{{ __('common.confirm_add_members_body') }} | ||
</x-modal> | ||
</div> | ||
@endif | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<form x-data="{ open: false }" id="delete_members" action="{{ route('entities.group.leave', $entity) }}" | ||
method="post"> | ||
@csrf | ||
@method('DELETE') | ||
<div class="overflow-x-auto bg-white border rounded-lg"> | ||
<table class="min-w-full border-b border-gray-300"> | ||
<thead> | ||
<tr> | ||
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b"> </th> | ||
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b"> | ||
{{ __('common.name') }} | ||
</th> | ||
<th class="px-6 py-3 text-xs tracking-widest text-left uppercase bg-gray-100 border-b"> | ||
{{ __('common.description') }} | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody class="divide-y divide-gray-200"> | ||
@forelse ($groups as $group) | ||
<tr x-data class="hover:bg-blue-50" role="button" | ||
@click="checkbox = $el.querySelector('input[type=checkbox]'); checkbox.checked = !checkbox.checked"> | ||
<td class="px-6 py-3 text-sm"> | ||
<input @click.stop class="rounded" type="checkbox" name="groups[]" | ||
value="{{ $group->id }}"> | ||
</td> | ||
<td class="whitespace-nowrap px-6 py-3 text-sm"> | ||
{{ $group->name }} | ||
</td> | ||
<td class="px-6 py-3 text-sm"> | ||
{{ $group->description }} | ||
</td> | ||
</tr> | ||
@empty | ||
<tr class="hover:bg-blue-50"> | ||
<td class="px-6 py-3 font-bold text-center" colspan="4"> | ||
{{ __('groups.no_members') }} | ||
</td> | ||
</tr> | ||
@endforelse | ||
</tbody> | ||
</table> | ||
@if (count($groups)) | ||
<div class="px-4 py-2 bg-gray-100"> | ||
<x-button color="red" @click.prevent="open = !open">{{ __('common.delete_members') }}</x-button> | ||
|
||
<x-modal> | ||
<x-slot:title>{{ __('common.confirm_delete_members') }}</x-slot:title> | ||
{{ __('common.confirm_delete_members_body') }} | ||
</x-modal> | ||
</div> | ||
@endif | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@extends('layout') | ||
@section('title', __('entities.show', ['name' => $entity->{"name_$locale"}])) | ||
|
||
@section('content') | ||
|
||
@include('entities.navigation') | ||
|
||
@can('do-everything') | ||
|
||
<div class="mb-4"> | ||
<h3 class="text-lg font-semibold"> | ||
{{ __('common.delete_members') }} | ||
</h3> | ||
@include('entities.groupForm.delete') | ||
</div> | ||
|
||
<div> | ||
<h3 class="text-lg font-semibold"> | ||
{{ __('common.add_members') }} | ||
</h3> | ||
@include('entities.groupForm.add') | ||
</div> | ||
|
||
@endcan | ||
|
||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters