Compare commits
2 Commits
319cd5e44e
...
90c5d9dcd6
Author | SHA1 | Date | |
---|---|---|---|
90c5d9dcd6 | |||
7a0ec94abe |
@ -4,9 +4,31 @@ namespace ProVM\NotariaRaby\Common\Controller\Web\Admin;
|
|||||||
use Psr\Container\ContainerInterface as Container;
|
use Psr\Container\ContainerInterface as Container;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
use Slim\Views\Blade as View;
|
||||||
|
use Carbon\Carbon;
|
||||||
use ProVM\Common\Service\Filemanager;
|
use ProVM\Common\Service\Filemanager;
|
||||||
|
|
||||||
class Documentos {
|
class Documentos {
|
||||||
|
public function __invoke(Request $request, Response $response, Container $container, View $view, $tipo): Response {
|
||||||
|
$glob = implode(DIRECTORY_SEPARATOR, [
|
||||||
|
$container->get('folders.upload'),
|
||||||
|
$tipo . '*.pdf'
|
||||||
|
]);
|
||||||
|
$files = glob($glob);
|
||||||
|
$archivos = [];
|
||||||
|
foreach ($files as $filename) {
|
||||||
|
$file = new \SplFileInfo($filename);
|
||||||
|
$archivos []= $file;
|
||||||
|
}
|
||||||
|
$titulo = $tipo;
|
||||||
|
$months = (object) ['full' => [], 'short' => []];
|
||||||
|
$m = Carbon::createFromDate(0, 1, 1);
|
||||||
|
for ($i = 0; $i < 12; $i ++) {
|
||||||
|
$months->full []= ucwords($m->copy()->addMonths($i)->locale('es_ES')->isoFormat('MMMM'));
|
||||||
|
$months->short []= ucwords($m->copy()->addMonths($i)->locale('es_ES')->isoFormat('MMM'));
|
||||||
|
}
|
||||||
|
return $view->render($response, 'admin.archivos.list', compact('titulo', 'archivos', 'months'));
|
||||||
|
}
|
||||||
public function upload(Request $request, Response $response, Filemanager $filemanager, Container $container): Response {
|
public function upload(Request $request, Response $response, Filemanager $filemanager, Container $container): Response {
|
||||||
$post = $request->getParsedBody();
|
$post = $request->getParsedBody();
|
||||||
$files = $request->getUploadedFiles();
|
$files = $request->getUploadedFiles();
|
||||||
@ -33,4 +55,21 @@ class Documentos {
|
|||||||
->withHeader('Content-Type', 'application/json')
|
->withHeader('Content-Type', 'application/json')
|
||||||
->withStatus(201);
|
->withStatus(201);
|
||||||
}
|
}
|
||||||
|
public function delete(Request $request, Response $response, Container $container): Response {
|
||||||
|
$post = $request->getParsedBody();
|
||||||
|
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||||
|
$container->get('folders.upload'),
|
||||||
|
$post['archivo'] . '.pdf'
|
||||||
|
]);
|
||||||
|
$status = unlink($filename);
|
||||||
|
$output = [
|
||||||
|
'informacion' => $post,
|
||||||
|
'estado' => $status,
|
||||||
|
'archivo' => $filename
|
||||||
|
];
|
||||||
|
$response->getBody()->write(json_encode($output));
|
||||||
|
return $response
|
||||||
|
->withHeader('Content-Type', 'application/json')
|
||||||
|
->withStatus(201);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
|
|||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
|
||||||
class Documentos {
|
class Documentos {
|
||||||
public function existe(Request $request, Response $response, Container $container, $documento) {
|
public function existe(Request $request, Response $response, Container $container, $documento): Response {
|
||||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||||
$container->get('folders.upload'),
|
$container->get('folders.upload'),
|
||||||
$documento . '.pdf'
|
$documento . '.pdf'
|
||||||
|
@ -2,5 +2,7 @@
|
|||||||
use ProVM\NotariaRaby\Common\Controller\Web\Admin\Documentos;
|
use ProVM\NotariaRaby\Common\Controller\Web\Admin\Documentos;
|
||||||
|
|
||||||
$app->group('/documentos', function($app) {
|
$app->group('/documentos', function($app) {
|
||||||
|
$app->post('/delete', [Documentos::class, 'delete']);
|
||||||
|
$app->get('/{tipo}', Documentos::class);
|
||||||
$app->post('[/]', [Documentos::class, 'upload']);
|
$app->post('[/]', [Documentos::class, 'upload']);
|
||||||
});
|
});
|
||||||
|
142
resources/views/admin/archivos/list.blade.php
Normal file
142
resources/views/admin/archivos/list.blade.php
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
@extends('admin.layout.base')
|
||||||
|
|
||||||
|
@section('page_content')
|
||||||
|
<div class="ui container">
|
||||||
|
<h1 class="ui header">
|
||||||
|
{{str_replace('_', ' ', mb_strtoupper($titulo))}}
|
||||||
|
</h1>
|
||||||
|
<div class="ui grid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="nine wide column">
|
||||||
|
<div class="ui top attached right aligned segment">
|
||||||
|
<button class="ui inverted dark-blue button form_link">
|
||||||
|
NUEVO
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<table class="ui bottom attached celled table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Documento</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($archivos as $archivo)
|
||||||
|
<tr>
|
||||||
|
<td>{{str_replace([$titulo, '_'], ['', ' '], $archivo->getBasename('.' . $archivo->getExtension()))}}</td>
|
||||||
|
<td class="center aligned">
|
||||||
|
<i class="trash alternate outline icon" data-file="{{$archivo->getBasename('.' . $archivo->getExtension())}}"></i>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ui basic modal" id="doc_form">
|
||||||
|
<i class="close icon"></i>
|
||||||
|
<div class="inverted dark-blue header">
|
||||||
|
</div>
|
||||||
|
<div class="inverted dark-blue content">
|
||||||
|
<form class="ui form" method="post" action="#">
|
||||||
|
<input type="hidden" name="filename" />
|
||||||
|
<div class="field">
|
||||||
|
<input type="file" name="archivo" placeholder="Archivo" />
|
||||||
|
</div>
|
||||||
|
<div id="mod" class="field"></div>
|
||||||
|
<button class="ui button">Subir</button>
|
||||||
|
<div id="documento_message"></div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
<script type="text/javascript">
|
||||||
|
function formulario(link, title, mod) {
|
||||||
|
$('#doc_form').find('.header').html(title)
|
||||||
|
$('#doc_form').find('form').find("[name='filename']").val(link)
|
||||||
|
if (mod == 'fecha') {
|
||||||
|
fecha()
|
||||||
|
}
|
||||||
|
$('#doc_form').modal('show')
|
||||||
|
$('#doc_form').find('form').submit(function(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
var form_data = new FormData(this)
|
||||||
|
$.ajax({
|
||||||
|
url: '{{$urls->base}}/admin/documentos',
|
||||||
|
type: 'post',
|
||||||
|
data: form_data,
|
||||||
|
contentType: false,
|
||||||
|
cache: false,
|
||||||
|
processData: false,
|
||||||
|
success: function(data) {
|
||||||
|
if (data.estado == true) {
|
||||||
|
$('#doc_form').find('.header').html('')
|
||||||
|
$('#doc_form').find('form').find("[name='filename']").val('')
|
||||||
|
$('#doc_form').modal('hide')
|
||||||
|
$('#documento_message').html('')
|
||||||
|
$('#documento_message').hide()
|
||||||
|
location.reload()
|
||||||
|
} else {
|
||||||
|
$('#documento_message').html('Error al subir el archivo.')
|
||||||
|
$('#documento_message').show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
function fecha() {
|
||||||
|
var fecha = $('<div></div>').attr('class', 'ui calendar').append(
|
||||||
|
$('<div></div>').attr('class', 'ui input left icon').append(
|
||||||
|
$('<i></i>').attr('class', 'calendar icon')
|
||||||
|
).append(
|
||||||
|
$('<input />').attr('type', 'text').attr('name', 'month').attr('placeholder', 'Mex / Año')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
$('#mod').append(fecha)
|
||||||
|
$('#mod').find('.ui.calendar').calendar({
|
||||||
|
type: 'month',
|
||||||
|
text: {
|
||||||
|
months: [
|
||||||
|
'{!!implode("', '", $months->full)!!}'
|
||||||
|
],
|
||||||
|
monthsShort: [
|
||||||
|
'{!!implode("', '", $months->short)!!}'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('.trash').css('cursor', 'pointer').click(function() {
|
||||||
|
var file = $(this).attr('data-file')
|
||||||
|
$.post('{{$urls->admin}}/documentos/delete', {archivo: file}, function(data) {
|
||||||
|
if (data.estado) {
|
||||||
|
location.reload()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
alert('No se pudo borrar el archivo.')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
$('#doc_form').modal({
|
||||||
|
onHidden: function() {
|
||||||
|
$('#mod').html('')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
$('#documento_message').hide()
|
||||||
|
$('.form_link').click(function() {
|
||||||
|
var link = '{{$titulo}}'
|
||||||
|
var title = '{{mb_strtoupper($titulo)}}'
|
||||||
|
var mod = 'fecha'
|
||||||
|
if (link == 'valores') {
|
||||||
|
mod = ''
|
||||||
|
}
|
||||||
|
formulario(link, title, mod)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
@ -4,11 +4,7 @@
|
|||||||
{{$descripcion}}
|
{{$descripcion}}
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<a href="#" data-link="{{$link}}" data-title="{{$descripcion}}"
|
<a href="{{$urls->admin}}/documentos/{{$link}}">
|
||||||
@if (isset($mod))
|
|
||||||
data-mod="{{$mod}}"
|
|
||||||
@endif
|
|
||||||
class="form_link">
|
|
||||||
@include('admin.uicon')
|
@include('admin.uicon')
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,80 +22,9 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div id="transparencia_message" class="ui message transition hidden"></div>
|
<div id="transparencia_message" class="ui message transition hidden"></div>
|
||||||
<div class="ui basic modal" id="doc_form">
|
|
||||||
<i class="close icon"></i>
|
|
||||||
<div class="inverted dark-blue header">
|
|
||||||
</div>
|
|
||||||
<div class="inverted dark-blue content">
|
|
||||||
<form class="ui form" method="post" action="#">
|
|
||||||
<input type="hidden" name="filename" />
|
|
||||||
<div class="field">
|
|
||||||
<input type="file" name="archivo" placeholder="Archivo" />
|
|
||||||
</div>
|
|
||||||
<div id="mod" class="field"></div>
|
|
||||||
<button class="ui button">Subir</button>
|
|
||||||
<div id="documento_message"></div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@push('scripts')
|
@push('scripts')
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function formulario(link, title, mod) {
|
|
||||||
$('#doc_form').find('.header').html(title)
|
|
||||||
$('#doc_form').find('form').find("[name='filename']").val(link)
|
|
||||||
if (mod == 'fecha') {
|
|
||||||
fecha()
|
|
||||||
}
|
|
||||||
$('#doc_form').modal('show')
|
|
||||||
$('#doc_form').find('form').submit(function(e) {
|
|
||||||
e.preventDefault()
|
|
||||||
var form_data = new FormData(this)
|
|
||||||
$.ajax({
|
|
||||||
url: '{{$urls->base}}/admin/documentos',
|
|
||||||
type: 'post',
|
|
||||||
data: form_data,
|
|
||||||
contentType: false,
|
|
||||||
cache: false,
|
|
||||||
processData: false,
|
|
||||||
success: function(data) {
|
|
||||||
if (data.estado == true) {
|
|
||||||
$('#doc_form').find('.header').html('')
|
|
||||||
$('#doc_form').find('form').find("[name='filename']").val('')
|
|
||||||
$('#doc_form').modal('hide')
|
|
||||||
$('#documento_message').html('')
|
|
||||||
$('#documento_message').hide()
|
|
||||||
} else {
|
|
||||||
$('#documento_message').html('Error al subir el archivo.')
|
|
||||||
$('#documento_message').show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
function fecha() {
|
|
||||||
var fecha = $('<div></div>').attr('class', 'ui calendar').append(
|
|
||||||
$('<div></div>').attr('class', 'ui input left icon').append(
|
|
||||||
$('<i></i>').attr('class', 'calendar icon')
|
|
||||||
).append(
|
|
||||||
$('<input />').attr('type', 'text').attr('name', 'month').attr('placeholder', 'Mex / Año')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
$('#mod').append(fecha)
|
|
||||||
$('#mod').find('.ui.calendar').calendar({
|
|
||||||
type: 'month',
|
|
||||||
text: {
|
|
||||||
months: [
|
|
||||||
'{!!implode("', '", $months->full)!!}'
|
|
||||||
],
|
|
||||||
monthsShort: [
|
|
||||||
'{!!implode("', '", $months->short)!!}'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#transparencia_message').hide()
|
$('#transparencia_message').hide()
|
||||||
$('#transparencia').checkbox()
|
$('#transparencia').checkbox()
|
||||||
@ -131,19 +60,6 @@
|
|||||||
})
|
})
|
||||||
}, 'json')
|
}, 'json')
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#doc_form').modal({
|
|
||||||
onHidden: function() {
|
|
||||||
$('#mod').html('')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
$('#documento_message').hide()
|
|
||||||
$('.form_link').click(function() {
|
|
||||||
var link = $(this).attr('data-link')
|
|
||||||
var title = $(this).attr('data-title')
|
|
||||||
var mod = $(this).attr('data-mod')
|
|
||||||
formulario(link, title, mod)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
Reference in New Issue
Block a user