Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdianS18 committed Jul 16, 2024
2 parents 0a41b7f + c8d6323 commit 8bf6d46
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 37 deletions.
3 changes: 2 additions & 1 deletion app/Contracts/Interfaces/EmployeeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
use App\Contracts\Interfaces\Eloquent\StoreInterface;
use App\Contracts\Interfaces\Eloquent\UpdateInterface;
use App\Contracts\Interfaces\Eloquent\WhereInterface;
use Illuminate\Http\Request;

interface EmployeeInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, WhereInterface, ShowWithSlugInterface
{
public function paginate($query): mixed;
public function whereSchool(mixed $id, $query): mixed;
public function whereSchool(mixed $id, $query, Request $request): mixed;
public function getTeacherBySchool(mixed $id): mixed;
public function getCountEmployee(mixed $query) : mixed;
public function getSchool(mixed $id): mixed;
Expand Down
18 changes: 16 additions & 2 deletions app/Contracts/Repositories/EmployeeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contracts\Interfaces\EmployeeInterface;
use App\Enums\RoleEnum;
use App\Models\Employee;
use Illuminate\Http\Request;

class EmployeeRepository extends BaseRepository implements EmployeeInterface
{
Expand Down Expand Up @@ -63,9 +64,22 @@ public function getTeacherBySchool(mixed $id): mixed
return $this->model->query()->whereRelation('user.roles', 'name', RoleEnum::TEACHER->value)->where('school_id', $id)->get();
}

public function whereSchool(mixed $id, $query): mixed
public function whereSchool(mixed $id, $query, Request $request): mixed
{
return $this->model->query()->whereRelation('user.roles', 'name', $query)->where('school_id', $id)->latest()->paginate(10);
return $this->model->query()->whereRelation('user.roles', 'name', $query)
->where('school_id', $id)
->when($request->search, function ($query) use ($request) {
$query->whereHas('user', function($q) use ($request){
$q->where('name', 'LIKE', '%' . $request->search . '%');
});
})->when($request->filter === "terbaru", function($query) {
$query->latest();
})
->when($request->filter === "terlama", function($query) {
$query->oldest();
})
->latest()
->paginate(10);
}

public function showWithSlug(string $slug): mixed
Expand Down
23 changes: 21 additions & 2 deletions app/Http/Controllers/ClassroomStudentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,28 @@ public function edit(ClassroomStudent $classroomStudent)
/**
* Update the specified resource in storage.
*/
public function update(UpdateClassroomStudentRequest $request, ClassroomStudent $classroomStudent)
public function update(UpdateClassroomStudentRequest $request, Classroom $classroom)
{
//
// Convert comma-separated IDs to array
$addStudents = $request->input('add_students') ? explode(',', $request->input('add_students')) : [];
$removeStudents = $request->input('remove_students') ? explode(',', $request->input('remove_students')) : [];

// Add students to classroom
foreach ($addStudents as $studentId) {
ClassroomStudent::firstOrCreate([
'classroom_id' => $classroom->id,
'student_id' => $studentId,
]);
}

// Remove students from classroom
foreach ($removeStudents as $studentId) {
ClassroomStudent::where('classroom_id', $classroom->id)
->where('student_id', $studentId)
->delete();
}

return to_route('class.show', $classroom->id)->with('success', 'Berhasil meyimpan perubahan siswa');
}

/**
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Teacher/StaffController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Http\Requests\UpdateEmployeeRequest;
use App\Contracts\Interfaces\EmployeeInterface;
use App\Contracts\Interfaces\ReligionInterface;
use Illuminate\Http\Request;

class StaffController extends Controller
{
Expand All @@ -31,9 +32,9 @@ public function __construct(UserInterface $user, EmployeeInterface $employee, St
/**
* Display a listing of the resource.
*/
public function index()
public function index(Request $request)
{
$staffs = $this->employee->whereSchool(auth()->user()->school->id, RoleEnum::STAFF->value);
$staffs = $this->employee->whereSchool(auth()->user()->school->id, RoleEnum::STAFF->value, $request);
$religions = $this->religion->get();
return view('school.pages.employe.index', compact('staffs', 'religions'));
}
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Requests/UpdateClassroomStudentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UpdateClassroomStudentRequest extends FormRequest
*/
public function authorize(): bool
{
return false;
return true;
}

/**
Expand All @@ -22,7 +22,8 @@ public function authorize(): bool
public function rules(): array
{
return [
//
'add_students' => 'nullable|string',
'remove_students' => 'nullable|string',
];
}
}
96 changes: 72 additions & 24 deletions resources/views/school/pages/class/detail-class.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,43 @@
</div>
</div>
<div>
<button class="btn btn-primary px-4">Simpan</button>
<button id="save-button" class="btn btn-primary px-4">Simpan</button>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="d-flex flex-wrap mb-3">
<form action="" class="position-relative">
<input type="text" class="form-control product-search ps-5" id="input-search" placeholder="Cari...">
<input type="text" class="form-control product-search ps-5" id="input-search-left" placeholder="Cari...">
<i class="ti ti-search position-absolute top-50 start-0 translate-middle-y fs-6 text-dark ms-3"></i>
</form>
</div>

<div class="table-responsive rounded-2">
<table class="table border text-nowrap customize-table mb-0 align-middle text-center">
<table id="left-table" class="table border text-nowrap customize-table mb-0 align-middle text-center">
<thead>
<tr>
<th>Siswa</th>
<th>NISN</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@forelse ($students as $student)
<tr>
@foreach ($students as $student)
<tr data-id="{{ $student->id }}">
<td>{{ $student->user->name }}</td>
<td>{{ $student->nisn }}</td>
<td>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckChecked" checked>
<input class="form-check-input" type="checkbox">
</div>
</td>
</tr>
@empty
<tr>
<td colspan="3">Semua siswa sudah memiliki kelas</td>
</tr>
@endforelse
@endforeach
</tbody>
</table>
<div class="text-end mt-3 mb-3">
<button class="btn btn-success">
<button id="move-to-right" class="btn btn-success">
Masukan
</button>
</div>
Expand All @@ -71,39 +68,36 @@
<div class="col-md-6">
<div class="d-flex flex-wrap mb-3">
<form action="" class="position-relative">
<input type="text" class="form-control product-search ps-5" id="input-search" placeholder="Cari...">
<input type="text" class="form-control product-search ps-5" id="input-search-right" placeholder="Cari...">
<i class="ti ti-search position-absolute top-50 start-0 translate-middle-y fs-6 text-dark ms-3"></i>
</form>
</div>

<div class="table-responsive rounded-2">
<table class="table border text-nowrap customize-table mb-0 align-middle text-center">
<table id="right-table" class="table border text-nowrap customize-table mb-0 align-middle text-center">
<thead>
<tr>
<th>Siswa</th>
<th>NISN</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@forelse ($classroomStudents as $classroomStudent)
<tr>
@foreach ($classroomStudents as $classroomStudent)
<tr data-id="{{ $classroomStudent->student->id }}">
<td>{{ $classroomStudent->student->user->name }}</td>
<td>{{ $classroomStudent->student->nisn }}</td>
<td>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckChecked">
<input class="form-check-input" type="checkbox">
</div>
</td>
</tr>
@empty
<tr>
<td colspan="3">Kelas ini kosong</td>
</tr>
@endforelse
@endforeach
</tbody>
</table>
<div class="text-end mt-3 mb-3">
<button class="btn btn-danger">
<button id="move-to-left" class="btn btn-danger">
Keluarkan
</button>
</div>
Expand All @@ -112,6 +106,15 @@
</div>
</div>

<!-- Hidden fields to store changes -->
<form id="save-form" action="{{ route('classroom.update', $classroom->id) }}" method="POST">
@csrf
@method('PUT')
<input type="hidden" name="add_students" id="add-students">
<input type="hidden" name="remove_students" id="remove-students">
</form>


<div class="table-responsive rounded-2">
<table class="table border text-nowrap customize-table mb-0 align-middle text-center">
<thead>
Expand All @@ -137,7 +140,7 @@
</tr>
@empty
<tr>
<td colspan="3">Kelas ini kosong</td>
<td colspan="4">Kelas ini kosong</td>
</tr>
@endforelse
</tbody>
Expand All @@ -164,3 +167,48 @@
</ul>
</div>
@endsection
@section('script')
<script>
$(document).ready(function() {
// Handle move to right
$('#move-to-right').click(function() {
$('#left-table tbody tr').each(function() {
if ($(this).find('.form-check-input').is(':checked')) {
$(this).find('.form-check-input').prop('checked', false);
$('#right-table tbody').append($(this));
}
});
});
// Handle move to left
$('#move-to-left').click(function() {
$('#right-table tbody tr').each(function() {
if ($(this).find('.form-check-input').is(':checked')) {
$(this).find('.form-check-input').prop('checked', false);
$('#left-table tbody').append($(this));
}
});
});
// Handle save button
$('#save-button').click(function() {
var addStudents = [];
var removeStudents = [];
$('#right-table tbody tr').each(function() {
addStudents.push($(this).data('id'));
});
$('#left-table tbody tr').each(function() {
removeStudents.push($(this).data('id'));
});
$('#add-students').val(addStudents.join(','));
$('#remove-students').val(removeStudents.join(','));
$('#save-form').submit();
});
});
</script>
@endsection
11 changes: 7 additions & 4 deletions resources/views/school/pages/employe/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
<div class="position-relative">
<div class="">
<input type="text" name="search" class="form-control search-chat py-2 px-5 ps-5" id="search-name"
placeholder="Cari">
placeholder="Cari" value="{{ old('search', request('search')) }}">
<i class="ti ti-search position-absolute top-50 translate-middle-y fs-6 text-dark ms-3"></i>
</div>
</div>

<div class="d-flex gap-2">
<select name="" class="form-select" id="search-status">
<select name="filter" class="form-select" id="search-status">
<option value="">Tampilkan semua</option>
<option value="">Terbaru</option>
<option value="">Terlama</option>
<option value="terbaru">Terbaru</option>
<option value="terlama">Terlama</option>
</select>
</div>
<div>
<button type="submit" class="btn btn-primary btn-md">filter</button>
</div>
</form>
</div>
<div class="col-lg-6 mb-3">
Expand Down
2 changes: 2 additions & 0 deletions routes/role/school.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Http\Controllers\AttendanceController;
use App\Http\Controllers\AttendanceRuleController;
use App\Http\Controllers\ClassroomController;
use App\Http\Controllers\ClassroomStudentController;
use App\Http\Controllers\ExtracurricularController;
use App\Http\Controllers\LessonHourController;
use App\Http\Controllers\LevelClassController;
Expand Down Expand Up @@ -147,3 +148,4 @@
Route::delete('school/delete-class/{classroom}', [ClassroomController::class, 'destroy'])->name('class.delete');
// detail kelas
Route::get('school/{classroom}', [ClassroomController::class, 'show'])->name('class.show');
Route::put('school/{classroom}', [ClassroomStudentController::class, 'update'])->name('classroom.update');

0 comments on commit 8bf6d46

Please sign in to comment.