feat: agregado subir archvios txt de resultados
parent
46545d44a8
commit
b1f36301bd
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Administracion;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ProcesoAdmisionResultadoArchivo;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProcesoAdmisionResultadoArchivoController extends Controller
|
||||
{
|
||||
public function index(int $procesoId)
|
||||
{
|
||||
$archivos = ProcesoAdmisionResultadoArchivo::where('proceso_admision_id', $procesoId)
|
||||
->orderBy('orden')
|
||||
->get();
|
||||
|
||||
return response()->json($archivos);
|
||||
}
|
||||
|
||||
public function store(Request $request, int $procesoId)
|
||||
{
|
||||
$request->validate([
|
||||
'orden' => 'required|integer|min:1|max:6',
|
||||
'nombre' => 'required|string|max:255',
|
||||
'archivo' => 'required|file|mimes:txt|max:10240',
|
||||
]);
|
||||
|
||||
// Máximo 6 archivos por proceso
|
||||
$count = ProcesoAdmisionResultadoArchivo::where('proceso_admision_id', $procesoId)->count();
|
||||
if ($count >= 6) {
|
||||
return response()->json(['message' => 'Máximo 6 archivos por proceso.'], 422);
|
||||
}
|
||||
|
||||
// No puede haber dos archivos con el mismo orden en el mismo proceso
|
||||
$existe = ProcesoAdmisionResultadoArchivo::where('proceso_admision_id', $procesoId)
|
||||
->where('orden', $request->orden)
|
||||
->exists();
|
||||
if ($existe) {
|
||||
return response()->json(['message' => 'Ya existe un archivo para ese slot.'], 422);
|
||||
}
|
||||
|
||||
$contenido = file_get_contents($request->file('archivo')->getRealPath());
|
||||
$encoding = mb_detect_encoding($contenido, ['UTF-8', 'Windows-1252', 'ISO-8859-1'], true);
|
||||
$contenidoUtf8 = ($encoding === 'UTF-8')
|
||||
? $contenido
|
||||
: mb_convert_encoding($contenido, 'UTF-8', $encoding ?: 'Windows-1252');
|
||||
$filename = uniqid() . '.txt';
|
||||
$path = "proceso-resultados/{$procesoId}/{$filename}";
|
||||
\Storage::disk('public')->put($path, $contenidoUtf8);
|
||||
|
||||
$archivo = ProcesoAdmisionResultadoArchivo::create([
|
||||
'proceso_admision_id' => $procesoId,
|
||||
'nombre' => $request->nombre,
|
||||
'file_path' => $path,
|
||||
'orden' => $request->orden,
|
||||
]);
|
||||
|
||||
return response()->json($archivo, 201);
|
||||
}
|
||||
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$archivo = ProcesoAdmisionResultadoArchivo::findOrFail($id);
|
||||
|
||||
Storage::disk('public')->delete($archivo->file_path);
|
||||
$archivo->delete();
|
||||
|
||||
return response()->json(['message' => 'Eliminado correctamente.']);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProcesoAdmisionResultadoArchivo extends Model
|
||||
{
|
||||
protected $table = 'proceso_admision_resultado_archivos';
|
||||
|
||||
protected $fillable = [
|
||||
'proceso_admision_id',
|
||||
'nombre',
|
||||
'file_path',
|
||||
'orden',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'orden' => 'integer',
|
||||
];
|
||||
|
||||
protected $appends = ['archivo_url'];
|
||||
|
||||
public function getArchivoUrlAttribute(): ?string
|
||||
{
|
||||
return $this->file_path
|
||||
? Storage::disk('public')->url($this->file_path)
|
||||
: null;
|
||||
}
|
||||
|
||||
public function proceso(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ProcesoAdmision::class, 'proceso_admision_id');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('proceso_admision_resultado_archivos', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('proceso_admision_id')
|
||||
->constrained('procesos_admision')
|
||||
->onDelete('cascade');
|
||||
$table->string('nombre');
|
||||
$table->string('file_path');
|
||||
$table->unsignedTinyInteger('orden');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['proceso_admision_id', 'orden'], 'uniq_proceso_orden');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('proceso_admision_resultado_archivos');
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,312 @@
|
||||
<script setup>
|
||||
import { onMounted } from "vue"
|
||||
import NavbarModerno from '../../nabvar.vue'
|
||||
import FooterModerno from '../../Footer.vue'
|
||||
import { FileSearchOutlined } from "@ant-design/icons-vue"
|
||||
import { useWebAdmisionStore } from '../../../store/web'
|
||||
import { useProcesoAdmisionResultadoStore } from '../../../store/procesoAdmisionResultado.store'
|
||||
|
||||
const webStore = useWebAdmisionStore()
|
||||
const resultadosStore = useProcesoAdmisionResultadoStore()
|
||||
|
||||
onMounted(async () => {
|
||||
if (!webStore.procesos.length) {
|
||||
await webStore.cargarProcesos()
|
||||
}
|
||||
const proceso = webStore.procesoPrincipal
|
||||
if (proceso?.id) {
|
||||
await resultadosStore.fetchArchivosPublico(proceso.id)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NavbarModerno />
|
||||
|
||||
<section id="proceso-resultado" class="convocatorias-modern">
|
||||
<div class="section-container">
|
||||
<div class="section-header">
|
||||
<div class="header-with-badge">
|
||||
<h2 class="section-title">
|
||||
RESULTADOS — {{ webStore.procesoPrincipal?.titulo ?? 'Proceso vigente' }}
|
||||
</h2>
|
||||
</div>
|
||||
<p class="section-subtitle">
|
||||
Resultados del proceso de admisión vigente.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Estado -->
|
||||
<a-card class="main-convocatoria-card" :loading="resultadosStore.loading">
|
||||
<div class="card-badge">Resultados</div>
|
||||
|
||||
<template v-if="resultadosStore.error">
|
||||
<div style="padding: 6px 2px; color: #dc2626; font-weight: 700;">
|
||||
{{ resultadosStore.error }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="!resultadosStore.archivos.length && !resultadosStore.loading">
|
||||
<div style="padding: 6px 2px; color: #666;">
|
||||
Resultados próximamente.
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div style="padding: 6px 2px; color:#666;">
|
||||
Resultados disponibles — {{ webStore.procesoPrincipal?.titulo }}
|
||||
</div>
|
||||
</template>
|
||||
</a-card>
|
||||
|
||||
<!-- Cards de archivos -->
|
||||
<a-card
|
||||
v-if="resultadosStore.archivos.length"
|
||||
class="year-section-card"
|
||||
>
|
||||
<div class="year-header">
|
||||
<div class="year-icon">
|
||||
<FileSearchOutlined />
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="year-title">{{ webStore.procesoPrincipal?.titulo }}</h3>
|
||||
<p class="year-subtitle">Selecciona el archivo que deseas consultar.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a-divider class="custom-divider" />
|
||||
|
||||
<div class="secondary-list one-col">
|
||||
<a-card
|
||||
v-for="archivo in resultadosStore.archivos"
|
||||
:key="archivo.id"
|
||||
class="secondary-convocatoria-card"
|
||||
>
|
||||
<div class="convocatoria-header">
|
||||
<div>
|
||||
<h4 class="secondary-title">{{ archivo.nombre }}</h4>
|
||||
</div>
|
||||
<a-tag class="status-tag" color="blue">DISPONIBLE</a-tag>
|
||||
</div>
|
||||
|
||||
<div class="card-footer">
|
||||
<a-button
|
||||
type="primary"
|
||||
ghost
|
||||
size="small"
|
||||
:href="archivo.archivo_url"
|
||||
target="_blank"
|
||||
>
|
||||
<template #icon><FileSearchOutlined /></template>
|
||||
Ver Resultados
|
||||
</a-button>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</a-card>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<FooterModerno />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.convocatorias-modern {
|
||||
position: relative;
|
||||
padding: 40px 0;
|
||||
font-family: "Times New Roman", Times, serif;
|
||||
background: #fbfcff;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.convocatorias-modern::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
z-index: 0;
|
||||
background-image:
|
||||
repeating-linear-gradient(
|
||||
to right,
|
||||
rgba(13, 27, 82, 0.06) 0,
|
||||
rgba(13, 27, 82, 0.06) 1px,
|
||||
transparent 1px,
|
||||
transparent 24px
|
||||
),
|
||||
repeating-linear-gradient(
|
||||
to bottom,
|
||||
rgba(13, 27, 82, 0.06) 0,
|
||||
rgba(13, 27, 82, 0.06) 1px,
|
||||
transparent 1px,
|
||||
transparent 24px
|
||||
);
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.section-container {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 24px;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
text-align: center;
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
|
||||
.header-with-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 2.6rem;
|
||||
font-weight: 700;
|
||||
color: #0d1b52;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.section-subtitle {
|
||||
font-size: 1.125rem;
|
||||
color: #666;
|
||||
max-width: 640px;
|
||||
margin: 14px auto 0;
|
||||
}
|
||||
|
||||
.main-convocatoria-card {
|
||||
position: relative;
|
||||
border: none;
|
||||
box-shadow: 0 10px 34px rgba(0, 0, 0, 0.08);
|
||||
border-radius: 16px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.main-convocatoria-card :deep(.ant-card-body) {
|
||||
padding: 28px;
|
||||
}
|
||||
|
||||
.card-badge {
|
||||
position: absolute;
|
||||
top: -12px;
|
||||
left: 24px;
|
||||
background: linear-gradient(45deg, #1890ff, #52c41a);
|
||||
color: white;
|
||||
padding: 6px 16px;
|
||||
border-radius: 999px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.year-section-card {
|
||||
border: none;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.07);
|
||||
border-radius: 16px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.year-section-card :deep(.ant-card-body) {
|
||||
padding: 22px;
|
||||
}
|
||||
|
||||
.year-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.year-icon {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 999px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: rgba(24, 144, 255, 0.12);
|
||||
color: #1890ff;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.year-title {
|
||||
margin: 0;
|
||||
font-size: 1.35rem;
|
||||
color: #1a237e;
|
||||
font-weight: 700;
|
||||
font-family: "Times New Roman", Times, serif;
|
||||
}
|
||||
|
||||
.year-subtitle {
|
||||
margin: 4px 0 0;
|
||||
color: #666;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.custom-divider {
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.secondary-convocatoria-card {
|
||||
border: none;
|
||||
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.secondary-convocatoria-card :deep(.ant-card-body) {
|
||||
padding: 18px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
min-height: 100px;
|
||||
}
|
||||
|
||||
.convocatoria-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
gap: 14px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.secondary-title {
|
||||
margin: 0;
|
||||
font-size: 1.05rem;
|
||||
color: #1a237e;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
font-family: "Times New Roman", Times, serif;
|
||||
}
|
||||
|
||||
.status-tag {
|
||||
font-weight: 700;
|
||||
padding: 4px 12px;
|
||||
border-radius: 999px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.card-footer > :last-child {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.secondary-list.one-col {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
@media (max-width: 992px) {
|
||||
.section-title { font-size: 2.1rem; }
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.convocatorias-modern { padding: 55px 0; }
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,113 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import api from '../axios'
|
||||
import apiPublico from '../axiosPostulante'
|
||||
|
||||
// Genera el nombre predeterminado para cada slot según las fechas del proceso.
|
||||
// El admin puede editarlo antes de subir, pero esto es el punto de partida.
|
||||
export function generarNombreSlot(orden, proceso) {
|
||||
const titulo = proceso?.titulo ?? 'Examen'
|
||||
|
||||
const formatDia = (isoStr, abrev = false) => {
|
||||
if (!isoStr) return ''
|
||||
const d = new Date(isoStr)
|
||||
if (Number.isNaN(d.getTime())) return ''
|
||||
const dias = ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado']
|
||||
const diasAbrev = ['Dom.', 'Lun.', 'Mar.', 'Mié.', 'Jue.', 'Vie.', 'Sáb.']
|
||||
const meses = ['enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre']
|
||||
const nombreDia = abrev ? diasAbrev[d.getDay()] : dias[d.getDay()]
|
||||
const dia = String(d.getDate()).padStart(2, '0')
|
||||
const mes = meses[d.getMonth()]
|
||||
const anio = d.getFullYear()
|
||||
return abrev
|
||||
? `${nombreDia} ${d.getDate()} ${mes.charAt(0).toUpperCase() + mes.slice(1)}`
|
||||
: `${nombreDia} ${dia} de ${mes}`
|
||||
}
|
||||
|
||||
const f1 = formatDia(proceso?.fecha_examen1)
|
||||
const f2 = formatDia(proceso?.fecha_examen2)
|
||||
const f2abrev = formatDia(proceso?.fecha_examen2, true)
|
||||
const anio2 = proceso?.fecha_examen2 ? new Date(proceso.fecha_examen2).getFullYear() : ''
|
||||
|
||||
const plantillas = {
|
||||
1: `Ingresantes ${titulo} ${f1}`,
|
||||
2: `Ingresantes ${titulo} ${f1} (CONADIS)`,
|
||||
3: `Clasificados para el examen del ${f2} del ${anio2}`,
|
||||
4: `Clasificados para la 2da etapa del ${f2} (CONADIS)`,
|
||||
5: `Ingresantes ${titulo} ${f2}`,
|
||||
6: `Ingresantes ${titulo} ${f2} (CONADIS)`,
|
||||
}
|
||||
|
||||
return plantillas[orden] ?? `Resultado ${orden}`
|
||||
}
|
||||
|
||||
export const useProcesoAdmisionResultadoStore = defineStore('procesoAdmisionResultado', {
|
||||
state: () => ({
|
||||
archivos: [],
|
||||
loading: false,
|
||||
error: null,
|
||||
}),
|
||||
|
||||
actions: {
|
||||
// Uso público: HeroSection + ProcesoResultado.vue
|
||||
async fetchArchivosPublico(procesoId) {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
try {
|
||||
const res = await apiPublico.get(`/proceso-resultado/${procesoId}/archivos`)
|
||||
this.archivos = res.data ?? []
|
||||
} catch (err) {
|
||||
this.error = err.response?.data?.message ?? 'Error al cargar archivos'
|
||||
this.archivos = []
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
// Uso admin: modal en ProcesosAdmisionList
|
||||
async fetchArchivosAdmin(procesoId) {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
try {
|
||||
const res = await api.get(`/admin/proceso-resultado/${procesoId}/archivos`)
|
||||
this.archivos = res.data ?? []
|
||||
} catch (err) {
|
||||
this.error = err.response?.data?.message ?? 'Error al cargar archivos'
|
||||
this.archivos = []
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
async subirArchivo(procesoId, formData) {
|
||||
this.error = null
|
||||
try {
|
||||
const res = await api.post(
|
||||
`/admin/proceso-resultado/${procesoId}/archivos`,
|
||||
formData,
|
||||
{ headers: { 'Content-Type': 'multipart/form-data' } }
|
||||
)
|
||||
this.archivos = [...this.archivos, res.data].sort((a, b) => a.orden - b.orden)
|
||||
return true
|
||||
} catch (err) {
|
||||
this.error = err.response?.data?.message ?? 'Error al subir archivo'
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
async eliminarArchivo(id) {
|
||||
try {
|
||||
await api.delete(`/admin/proceso-resultado/archivos/${id}`)
|
||||
this.archivos = this.archivos.filter((a) => a.id !== id)
|
||||
return true
|
||||
} catch (err) {
|
||||
this.error = err.response?.data?.message ?? 'Error al eliminar'
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
limpiar() {
|
||||
this.archivos = []
|
||||
this.error = null
|
||||
},
|
||||
},
|
||||
})
|
||||
Loading…
Reference in New Issue