diff --git a/app/resources/routes/ventas/cierres.php b/app/resources/routes/ventas/cierres.php index bf57def..2320f3d 100644 --- a/app/resources/routes/ventas/cierres.php +++ b/app/resources/routes/ventas/cierres.php @@ -3,6 +3,7 @@ use Incoviba\Controller\Ventas\Reservations as Cierres; $app->group('/cierres', function($app) { + $app->get('/project/{project_id}', Cierres::class); $app->get('[/]', Cierres::class); }); $app->group('/cierre/{cierre_id}', function($app) { diff --git a/app/resources/views/ventas/reservations.blade.php b/app/resources/views/ventas/reservations.blade.php index 3319bfe..a5e52c6 100644 --- a/app/resources/views/ventas/reservations.blade.php +++ b/app/resources/views/ventas/reservations.blade.php @@ -1,7 +1,7 @@ @extends('layout.base') @section('page_title') - Cierres -Reservas + Cierres - Reservas @endsection @section('page_content') @@ -143,6 +143,7 @@ const project_id = event.currentTarget.dataset.id reservations.show.results() + reservations.update.url(project_id) if (project_id === this.current_project) { this.hide() @@ -167,6 +168,10 @@ }) } + load(project_id) { + this.component.querySelector(`.item.link[data-id="${project_id}"]`).click() + } + show() { this.component.style.display = this.display.projects this.title_component.style.display = 'none' @@ -462,6 +467,19 @@ return Promise.any(promises).then(() => { reservations.loading.hide() }) + }, + pathname: project_id => { + const current_url = new URL(window.location.href) + if (project_id === null) { + if (current_url.pathname.includes('project')) { + return current_url.pathname.replace(/\/project\/\d+/, '') + } + return current_url.pathname + } + if (current_url.pathname.includes('project')) { + return current_url.pathname.replace(/project\/\d+/, `project/${project_id}`) + } + return `${current_url.pathname}/project/${project_id}` } }, loading: { @@ -472,6 +490,11 @@ reservations.components.loader.style.display = 'none' } }, + update: { + url: project_id => { + window.history.pushState(null, '', reservations.get.pathname(project_id)) + } + }, action: { reset: event => { event.preventDefault() @@ -481,12 +504,14 @@ reservations.components.reservations[key].hide() }) reservations.show.projects() + reservations.update.url(null) return false }, up: event => { event.preventDefault() Object.values(reservations.components.reservations).forEach(reservations => reservations.hide()) reservations.show.projects() + reservations.update.url(null) return false }, add: event => { @@ -544,6 +569,11 @@ this.show.projects() this.components.modals.add = new AddReservationModal(configuration.ids.projects) + + const project_id = {{ $project_id ?? 'null' }}; + if (project_id !== null) { + reservations.components.projects.load(project_id) + } } } $(document).ready(() => { diff --git a/app/src/Controller/Ventas/Reservations.php b/app/src/Controller/Ventas/Reservations.php index 9ee1edc..bcdac5c 100644 --- a/app/src/Controller/Ventas/Reservations.php +++ b/app/src/Controller/Ventas/Reservations.php @@ -13,7 +13,7 @@ class Reservations { public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto $proyectoService, Repository\Region $regionRepository, - View $view): ResponseInterface + View $view, ?int $project_id = null): ResponseInterface { $projects = []; try { @@ -23,6 +23,6 @@ class Reservations try { $regions = $regionRepository->fetchAll(); } catch (EmptyResult) {} - return $view->render($response, 'ventas.reservations', compact('projects', 'regions')); + return $view->render($response, 'ventas.reservations', compact('projects', 'regions', 'project_id')); } }