Browse Source

Cambios

Mejora en la barra de busqueda y agregamos los iconos para convertir en archivos las tablas
main
TheSilva7 6 days ago
parent
commit
36aed2ee0f
  1. 33
      app/Exports/DocentesExport.php
  2. 40
      app/Http/Controllers/DocentesController.php
  3. 5
      composer.json
  4. 16
      composer.lock
  5. 43
      resources/views/docentes.blade.php
  6. 24
      resources/views/docentesCrearEditar.blade.php
  7. 47
      resources/views/exports/docentes.blade.php
  8. 2
      routes/web.php

33
app/Exports/DocentesExport.php

@ -0,0 +1,33 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class DocentesExport implements FromCollection, WithHeadings
{
protected $docentes;
public function __construct($docentes)
{
$this->docentes = $docentes;
}
public function collection()
{
return $this->docentes;
}
public function headings(): array
{
return [
'ID',
'Nombre',
'Teléfono',
'Correo',
'Tipo de Licencia',
'Materia'
];
}
}

40
app/Http/Controllers/DocentesController.php

@ -4,6 +4,9 @@ namespace App\Http\Controllers;
use App\Models\Docentes;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use Barryvdh\DomPDF\Facade\Pdf;
use App\Exports\DocentesExport;
class DocentesController extends Controller
{
@ -12,7 +15,25 @@ class DocentesController extends Controller
*/
public function index(Request $request)
{
$docentes = Docentes::all();
$busqueda = $request->busqueda;
if ($busqueda) {
// Busca docentes que coincidan con el término de búsqueda
$docentes = Docentes::where('nombre', 'LIKE', "%{$busqueda}%")
->orWhere('correo', 'LIKE', "%{$busqueda}%")
->orWhere('tipo_licencia', 'LIKE', "%{$busqueda}%")
->orWhere('materia', 'LIKE', "%{$busqueda}%")
->get();
if ($docentes->isEmpty()) {
return redirect()->route('docentes.index')
->with('error', 'No existe ningún docente con el término "' . $busqueda . '". Por favor, inténtalo de nuevo.');
}
} else {
// Si no hay búsqueda, mostrar todos los docentes
$docentes = Docentes::all();
}
return view('docentes', ['docentes' => $docentes]);
}
@ -71,4 +92,21 @@ class DocentesController extends Controller
$docente->delete();
return redirect()->route('docentes.index')->with('success', 'Docente eliminado correctamente');
}
public function export($format)
{
$docentes = Docentes::all();
switch($format) {
case 'csv':
return Excel::download(new DocentesExport($docentes), 'docentes.csv', \Maatwebsite\Excel\Excel::CSV);
case 'excel':
return Excel::download(new DocentesExport($docentes), 'docentes.xlsx');
case 'pdf':
return PDF::loadView('exports.docentes', ['docentes' => $docentes])
->download('docentes.pdf');
default:
return redirect()->back()->with('error', 'Formato no soportado');
}
}
}

5
composer.json

@ -12,8 +12,9 @@
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"laravel/ui": "^4.6",
"maatwebsite/excel": "^3.1",
"phpoffice/phpspreadsheet": "^4.1"
"maatwebsite/excel": "^1.1",
"phpoffice/phpspreadsheet": "^4.1",
"psr/simple-cache": "2.0"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",

16
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": "acb583cdead6464e77a88f1ff4c131d6",
"content-hash": "c0f0a026d64d98ad86849a80b4a5135b",
"packages": [
{
"name": "barryvdh/laravel-dompdf",
@ -3680,16 +3680,16 @@
},
{
"name": "psr/simple-cache",
"version": "3.0.0",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/simple-cache.git",
"reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865"
"reference": "8707bf3cea6f710bf6ef05491234e3ab06f6432a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865",
"reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865",
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/8707bf3cea6f710bf6ef05491234e3ab06f6432a",
"reference": "8707bf3cea6f710bf6ef05491234e3ab06f6432a",
"shasum": ""
},
"require": {
@ -3698,7 +3698,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
"dev-master": "2.0.x-dev"
}
},
"autoload": {
@ -3725,9 +3725,9 @@
"simple-cache"
],
"support": {
"source": "https://github.com/php-fig/simple-cache/tree/3.0.0"
"source": "https://github.com/php-fig/simple-cache/tree/2.0.0"
},
"time": "2021-10-29T13:26:27+00:00"
"time": "2021-10-29T13:22:09+00:00"
},
{
"name": "psy/psysh",

43
resources/views/docentes.blade.php

@ -30,7 +30,25 @@
</a>
</div>
<!-- Barra de búsqueda -->
<div class="flex gap-2 mb-4">
<button onclick="copyToClipboard()" class="text-gray-600 hover:text-blue-600 p-2" title="Copiar">
<i class="fas fa-copy"></i>
</button>
<a href="{{ route('docentes.export', ['format' => 'csv']) }}" class="text-gray-600 hover:text-green-600 p-2" title="Exportar a CSV">
<i class="fas fa-file-csv"></i>
</a>
<a href="{{ route('docentes.export', ['format' => 'excel']) }}" class="text-gray-600 hover:text-green-700 p-2" title="Exportar a Excel">
<i class="fas fa-file-excel"></i>
</a>
<a href="{{ route('docentes.export', ['format' => 'pdf']) }}" class="text-gray-600 hover:text-red-600 p-2" title="Exportar a PDF">
<i class="fas fa-file-pdf"></i>
</a>
<button onclick="window.print()" class="text-gray-600 hover:text-gray-800 p-2" title="Imprimir">
<i class="fas fa-print"></i>
</button>
</div>
<!-- Barra de búsqueda en su propia sección -->
<div class="p-4 border-b border-gray-200 bg-gray-50">
<form action="{{ route('docentes.index') }}" method="GET" class="flex gap-2">
<div class="relative w-full sm:w-64">
@ -44,7 +62,7 @@
</div>
</div>
<button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600">
Buscar/Actualizar
Buscar
</button>
@if(request('busqueda'))
<a href="{{ route('docentes.index') }}" class="px-4 py-2 bg-gray-500 text-white rounded-lg hover:bg-gray-600">
@ -172,10 +190,29 @@ document.addEventListener('DOMContentLoaded', function() {
new DataTable('#docentes-table', {
layout: {
topStart: {
buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
buttons: ['copy', 'csv', 'excel', 'pdf']
}
}
});
function copyToClipboard() {
const table = document.querySelector('table');
const range = document.createRange();
range.selectNode(table);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
// Mostrar mensaje de éxito
Swal.fire({
icon: 'success',
title: 'Copiado',
text: 'La tabla ha sido copiada al portapapeles',
timer: 1500,
showConfirmButton: false
});
}
</script>
@endsection

24
resources/views/docentesCrearEditar.blade.php

@ -25,9 +25,27 @@
<label for="correo" class="block text-sm font-medium text-gray-700">Correo</label>
<input type="email" name="correo" id="correo" value="{{ old('correo', $docente->correo ?? '') }}" class="mt-1 block w-full border border-gray-300 rounded-lg shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="tipo_licencia" class="block text-sm font-medium text-gray-700">Tipo de Licencia</label>
<input type="text" name="tipo_licencia" id="tipo_licencia" value="{{ old('tipo_licencia', $docente->tipo_licencia ?? '') }}" class="mt-1 block w-full border border-gray-300 rounded-lg shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
<div class="mb-4">
<label for="tipo_licencia" class="block text-sm font-medium text-gray-700 mb-2">
Tipo de Licencia
</label>
<div class="relative rounded-md shadow-sm">
<select name="tipo_licencia"
id="tipo_licencia"
class="block w-full pl-3 pr-10 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
required>
<option value="">Seleccione un tipo de licencia</option>
<option value="A" {{ isset($docente) && $docente->tipo_licencia == 'A' ? 'selected' : '' }}>Licencia A</option>
<option value="B" {{ isset($docente) && $docente->tipo_licencia == 'B' ? 'selected' : '' }}>Licencia B</option>
<option value="C" {{ isset($docente) && $docente->tipo_licencia == 'C' ? 'selected' : '' }}>Licencia C</option>
</select>
<div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
<i class="fas fa-id-card text-gray-400"></i>
</div>
</div>
@error('tipo_licencia')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<div>
<label for="materia" class="block text-sm font-medium text-gray-700">Materia</label>

47
resources/views/exports/docentes.blade.php

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>Docentes</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h2>Lista de Docentes</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Teléfono</th>
<th>Correo</th>
<th>Tipo de Licencia</th>
<th>Materia</th>
</tr>
</thead>
<tbody>
@foreach($docentes as $docente)
<tr>
<td>{{ $docente->id }}</td>
<td>{{ $docente->nombre }}</td>
<td>{{ $docente->telefono }}</td>
<td>{{ $docente->correo }}</td>
<td>{{ $docente->tipo_licencia }}</td>
<td>{{ $docente->materia }}</td>
</tr>
@endforeach
</tbody>
</table>
</body>
</html>

2
routes/web.php

@ -41,7 +41,7 @@ Route::resource('capacidades', CapacidadController::class);
Route::get('marcas/excel', [MarcaController::class, 'exportExcel'])->name('marcas.excel');
Route::get('marcas/pdf', [MarcaController::class, 'exportPDF'])->name('marcas.pdf');
Route::get('/docentes/export/{format}', [DocentesController::class, 'export'])->name('docentes.export');
// Rutas protegidas que requieren autenticación
Route::middleware(['auth'])->group(function () {

Loading…
Cancel
Save