Browse Source

commit2

master
Juanjo 1 year ago
parent
commit
ec2b375a8e
26 changed files with 685 additions and 0 deletions
  1. +21
    -0
      .idea/compiler.xml
  2. +1
    -0
      hola.txt
  3. +13
    -0
      src/main/java/com/example/demo/DemoApplication.java
  4. +111
    -0
      src/main/java/com/example/demo/Dominio.java
  5. +46
    -0
      src/main/java/com/example/demo/controllers/EmpleadoController.java
  6. +54
    -0
      src/main/java/com/example/demo/models/Director.java
  7. +74
    -0
      src/main/java/com/example/demo/models/Empleado.java
  8. +54
    -0
      src/main/java/com/example/demo/models/Genre.java
  9. +36
    -0
      src/main/java/com/example/demo/services/EmpleadoServicio.java
  10. +10
    -0
      src/main/resources/META-INF/resources/hola2.html
  11. +10
    -0
      src/main/resources/resources/hola.html
  12. +4
    -0
      src/main/resources/static/css/claro.css
  13. +8
    -0
      src/main/resources/static/css/estilo.css
  14. BIN
      src/main/resources/static/img/enterthevoid.png
  15. BIN
      src/main/resources/static/img/la_filmoteca_wordmark.png
  16. +42
    -0
      src/main/resources/templates/empleado/form.html
  17. +13
    -0
      src/main/resources/templates/error/error.html
  18. +60
    -0
      src/main/resources/templates/foot/footer.html
  19. +0
    -0
      src/main/resources/templates/formularios/formulario.html
  20. +10
    -0
      src/main/resources/templates/head/head.html
  21. +14
    -0
      src/main/resources/templates/hora.html
  22. +27
    -0
      src/main/resources/templates/index.html
  23. +27
    -0
      src/main/resources/templates/sections/escribir_resenya.html
  24. +10
    -0
      src/main/resources/templates/sections/genero_elegido.html
  25. +27
    -0
      src/main/resources/templates/sections/generos.html
  26. +13
    -0
      src/test/java/com/example/demo/DemoApplicationTests.java

+ 21
- 0
.idea/compiler.xml View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="alejandro-prueba" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="alejandro-prueba" target="17" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="alejandro-prueba" options="-parameters" />
</option>
</component>
</project>

+ 1
- 0
hola.txt View File

@ -0,0 +1 @@
dss

+ 13
- 0
src/main/java/com/example/demo/DemoApplication.java View File

@ -0,0 +1,13 @@
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/* Equivalente a : @Configuration + @EnableAutoConfiguration + @ComponentScan = @SpringBootApplication */
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

+ 111
- 0
src/main/java/com/example/demo/Dominio.java View File

@ -0,0 +1,111 @@
package com.example.demo;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import static java.net.IDN.toASCII;
import static java.net.IDN.toUnicode;
public class Dominio {
String host;
String protocolo;
String dominio;
String tld;
int puerto;
String addr;
byte[] address;
String canonnical;
String hostname;
String url;
String path;
String error;
String query;
public Dominio() throws MalformedURLException {
final String currentURL = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString();
URL requestURL = new URL(currentURL);
this.puerto = requestURL.getPort();
this.host = requestURL.getHost();
this.protocolo = requestURL.getProtocol();
this.path = requestURL.getPath();
this.query = requestURL.getQuery();
/* información del servidor */
InetAddress iaddr=null;
String hostnameCanonical=null;
String hostname=null;
byte[] address=null;
try {
iaddr = InetAddress.getByName(InetAddress.getLocalHost().getHostName());
this.addr = iaddr.toString();
this.canonnical = iaddr.getCanonicalHostName();
this.address = iaddr.getAddress();
this.hostname = iaddr.getHostName();
} catch (UnknownHostException e) {
this.error="UnknownHostException";
}
this.url = currentURL;
//Eliminamos www si existen
this.url = url.replace("www.","");
//Buscamos el primer . (http://eldominio.******
int y=url.indexOf('.');
if (y==-1) {
this.dominio= "sin-dominio";
this.tld = "sin-tld";
}
else {
this.dominio = toUnicode(url.substring(url.indexOf("://")+3,y));
this.tld = url.substring(y).replace(":"+this.puerto,"");
}
}
public String getError() {
return error;
}
public String getAddr() {
return addr;
}
public byte[] getAddress() {
return address;
}
public String getCanonnical() {
return canonnical;
}
public String getHostname() {
return hostname;
}
public String getHost() {
return host;
}
public String getUrl() {
return url;
}
public String getPath() {
return path;
}
public String getQuery() {
return query;
}
public String getProtocolo() {
return protocolo;
}
public String getDominio() {
return dominio;
}
public String getTld() {
return tld;
}
public int getPuerto() {
return puerto;
}
}

+ 46
- 0
src/main/java/com/example/demo/controllers/EmpleadoController.java View File

@ -0,0 +1,46 @@
package com.example.demo.controllers;
import com.example.demo.models.Empleado;
import com.example.demo.services.EmpleadoServicio;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class EmpleadoController {
@Autowired
private EmpleadoServicio servicio;
@GetMapping({"empleado/list"})
public String listado (Model model) {
model.addAttribute("mensaje","Ramoncín esto es una prueba");
model.addAttribute("dominio","dom.getDominio()");
model.addAttribute("tld","dom.getTld()");
model.addAttribute("pagina","list");
model.addAttribute("listaEmpleados",servicio.findAll());
return "index";
}
@GetMapping({"empleado/alta"})
public String alta (Model model) {
model.addAttribute("mensaje","Ramoncín esto es una prueba");
model.addAttribute("dominio","dom.getDominio()");
model.addAttribute("tld","dom.getTld()");
model.addAttribute("empleadoForm", new Empleado());
model.addAttribute("pagina","alta");
return "index";
}
@PostMapping("/empleado/new/submit")
public String nuevoEmpleadoSubmit(@ModelAttribute("empleadoForm") Empleado nuevoEmpleado) {
servicio.add(nuevoEmpleado);
return "redirect:/empleado/list";
}
}

+ 54
- 0
src/main/java/com/example/demo/models/Director.java View File

@ -0,0 +1,54 @@
package com.example.demo.models;
import java.util.Objects;
public class Director {
private long id;
private String name;
public Director() {}
public Director(long id, String name) {
this.id = id;
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Director director = (Director) o;
return id == director.id && Objects.equals(name, director.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
@Override
public String toString() {
return "Director{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}

+ 74
- 0
src/main/java/com/example/demo/models/Empleado.java View File

@ -0,0 +1,74 @@
package com.example.demo.models;
import java.util.Objects;
public class Empleado {
private long id;
private String nombre;
private String email;
private String telefono;
public Empleado(){}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Empleado empleado = (Empleado) o;
return getId() == empleado.getId() && getNombre().equals(empleado.getNombre()) && getEmail().equals(empleado.getEmail()) && getTelefono().equals(empleado.getTelefono());
}
@Override
public int hashCode() {
return Objects.hash(getId(), getNombre(), getEmail(), getTelefono());
}
public Empleado (long id, String nombre, String email, String telefono){
this.id = id;
this.nombre = nombre;
this.email = email;
this.telefono = telefono;
}
@Override
public String toString() {
return "Empleado{" +
"id=" + id +
", nombre='" + nombre + '\'' +
", email='" + email + '\'' +
", telefono='" + telefono + '\'' +
'}';
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTelefono() {
return telefono;
}
public void setTelefono(String telefono) {
this.telefono = telefono;
}
}

+ 54
- 0
src/main/java/com/example/demo/models/Genre.java View File

@ -0,0 +1,54 @@
package com.example.demo.models;
import java.util.Objects;
public class Genre {
private long id;
private String name;
public Genre(){}
public Genre(long id, String name) {
this.id = id;
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Genre genre = (Genre) o;
return id == genre.id && Objects.equals(name, genre.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
@Override
public String toString() {
return "Genre{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}

+ 36
- 0
src/main/java/com/example/demo/services/EmpleadoServicio.java View File

@ -0,0 +1,36 @@
package com.example.demo.services;
import com.example.demo.models.Empleado;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
public class EmpleadoServicio {
private List<Empleado> repositorio = new ArrayList<>();
public EmpleadoServicio() {
}
public Empleado add(Empleado e){
repositorio.add(e);
return e;
}
public List<Empleado> findAll() {
return repositorio;
}
@PostConstruct
public void init() {
repositorio.addAll(
Arrays.asList(new Empleado(1,"Juan","[email protected]","1111111111"),
new Empleado(2,"Perico","[email protected]","2222222222"),
new Empleado(3,"Andrés","[email protected]","3333333333"))
);
}
}

+ 10
- 0
src/main/resources/META-INF/resources/hola2.html View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hola 2
</body>
</html>

+ 10
- 0
src/main/resources/resources/hola.html View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hola
</body>
</html>

+ 4
- 0
src/main/resources/static/css/claro.css View File

@ -0,0 +1,4 @@
@charset "UTF-8";
body {
background-color: white;
}

+ 8
- 0
src/main/resources/static/css/estilo.css View File

@ -0,0 +1,8 @@
@charset "UTF-8";
body {
padding-bottom: 20px;
}
.navbar {
margin-bottom: 20px;
}

BIN
src/main/resources/static/img/enterthevoid.png View File

Before After
Width: 1000  |  Height: 330  |  Size: 521 KiB

BIN
src/main/resources/static/img/la_filmoteca_wordmark.png View File

Before After
Width: 432  |  Height: 123  |  Size: 15 KiB

+ 42
- 0
src/main/resources/templates/empleado/form.html View File

@ -0,0 +1,42 @@
<div th:fragment="alta" class="flex-shrink-0">
<h1>Alta de empleados de la empresa</h1>
<div class="container">
<div class="row">
<div class="col-md-offset-2 col-md-8">
<form method="post" action="#" th:action="${empleadoForm.id != 0} ? @{/empleado/edit/submit} : @{/empleado/new/submit}"
th:object="${empleadoForm}">
<h1 th:text="${empleadoForm.id != 0} ? 'Editar empleado' : 'Nuevo empleado'">Nuevo empleado</h1>
<div class="form-group"
th:classappend="${#fields.hasErrors('id')} ? 'has-error'">
<label for="id">ID</label> <input type="text"
class="form-control" id="id" placeholder="1"
th:field="*{id}"
th:attrappend="readonly=${empleadoForm.id != 0} ? 'readonly' : null">
<span th:if="${#fields.hasErrors('id')}" th:errors="*{id}"
class="help-block" id="id-error">Errores</span>
</div>
<div class="form-group">
<label for="nombre">Nombre</label> <input type="text"
class="form-control" id="nombre" placeholder="Nombre"
th:field="*{nombre}" />
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email"
placeholder="[email protected]" th:field="*{email}" />
</div>
<div class="form-group">
<label for="telefono">Teléfono</label> <input type="tel"
class="form-control" id="telefono" placeholder="954000000" th:field="*{telefono}" />
</div>
<button type="submit" class="btn btn-default">Enviar</button>
</form>
</div>
</div>
</div>
<!-- /.container -->
</div>

+ 13
- 0
src/main/resources/templates/error/error.html View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Error page</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/main.css" th:href="@{/css/main.css}" />
</head>
<body th:with="httpStatus=${T(org.springframework.http.HttpStatus).valueOf(#response.status)}">
<h1 th:text="|${httpStatus} - ${httpStatus.reasonPhrase}|"> Ha habido un error... </h1>
<p th:utext="${errorMessage}">Error java.lang.NullPointerException</p>
<a href="index.html" th:href="@{/index.html}">Volver al inicio</a>
</body>
</html>

+ 60
- 0
src/main/resources/templates/foot/footer.html View File

@ -0,0 +1,60 @@
<div th:fragment="main_footer" class="text-center text-lg-start bg-light text-muted">
<style>
@media print {
@page {
margin: 0 0.8in;
}
}
</style>
<section>
<div class="container text-center text-md-start mt-5">
<div class="row mt-3">
<div class="col-md-3 col-lg-4 col-xl-3 mx-auto mb-4">
<h6 class="text-uppercase fw-bold mb-4">
<p style = "margin-top: 10%"> <i class="fas fa-gem me-3"> </i>La Filmoteca</p>
</h6>
<p style="text-align: justify" >
Acercamos de una manera intuitiva las mejores películas de la historia según nuestros expertos y las más
prestigiosas publicaciones de este arte.
</p>
</div>
<div class="col-md-4 col-lg-3 col-xl-3 mx-auto mb-md-0 mb-4">
<h6 class="text-uppercase fw-bold mb-4" style = "margin-top: 10%">Contacta con nosotros</h6>
<p><i class="fas fa-home me-3"></i>Gata de Gorgos</p>
<p><i class="fas fa-envelope me-3"></i>[email protected]</p>
<p><i class="fas fa-phone me-3"></i> + 96 234 567 88</p>
</div>
</div>
</div>
</section>
<div class="text-center p-4" style="background-color: rgba(0, 0, 0, 0.05); line-height: 90%;">
<p> 2023 © <b>La Filmoteca</b> </p>
<p style = "font-size: smaller;"> Con la tecnologia de
<a href="https://mdbootstrap.com/"style="text-decoration: none; color: black"> MDBootstrap.com </a> </p>
<a type="button" class="btn btn-success mb-3" style="background-color: black;" id="crearpdf">Crear PDF</a>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
let boton = document.getElementById("crearpdf");
let container = document.getElementById("contenedor");
boton.addEventListener("click", event => {
event.preventDefault();
window.print();
}, false);
container.addEventListener("click", event => {
boton.style.display = "initial";
}, false);
}, false);
</script>
</div>

+ 0
- 0
src/main/resources/templates/formularios/formulario.html View File


+ 10
- 0
src/main/resources/templates/head/head.html View File

@ -0,0 +1,10 @@
<head th:fragment="main_head">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title th:text="${dominio}">Título de la página</title>
<meta name="description" content="">
<link href="/webjars/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="/webjars/font-awesome/css/all.css" rel="stylesheet">
<link href="/css/estilo.css" rel="stylesheet">
</head>

+ 14
- 0
src/main/resources/templates/hora.html View File

@ -0,0 +1,14 @@
<!doctype html>
<html lang="es" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" media="all"
th:href="'/css/' + ${background} + '.css'">
<title th:text="${fechahora}">Hora</title>
</head>
<body>
<h1>Hola thymeleaf hoy es ...</h1>
<h1 th:text="${fechahora}"> </h1>
</body>
</html>

+ 27
- 0
src/main/resources/templates/index.html View File

@ -0,0 +1,27 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="es" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:replace="head/head :: main_head">
<title th:text="${title}">Título de la página</title>
</head>
<body onload="mueveReloj()">
<header th:replace="header/nav :: main_menu"></header>
<div th:switch="${pagina}">
<div th:case="list">
<main th:replace="empleado/list :: listado"></main>
</div>
<div th:case="alta">
<main th:replace="empleado/form :: alta"></main>
</div>
<div th:case="*">
<main th:replace="main/main_content :: index"></main>
</div>
</div>
<footer th:replace="foot/footer :: main_footer"></footer>
<script src="/webjars/jsquery/jquery.min.js"></script>
<script src="/webjars/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="/js/reloj.js"></script>
</body>
</html>

+ 27
- 0
src/main/resources/templates/sections/escribir_resenya.html View File

@ -0,0 +1,27 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="es" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:replace="head/head :: main_head">
<title th:text="${title}">Título de la página</title>
</head>
<body onload="mueveReloj()">
<header th:replace="header/nav/nav_header :: main_nav_header"></header>
<div th:switch="${pagina}">
<div th:case="list">
<main th:replace="empleado/list :: listado"></main>
</div>
<div th:case="alta">
<main th:replace="empleado/form :: alta"></main>
</div>
<div th:case="*">
<main th:replace="main/main_content :: escribir_resenya"></main>
</div>
</div>
<footer th:replace="foot/footer :: main_footer"></footer>
<script src="/webjars/jsquery/jquery.min.js"></script>
<script src="/webjars/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="/js/reloj.js"></script>
</body>
</html>

+ 10
- 0
src/main/resources/templates/sections/genero_elegido.html View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

+ 27
- 0
src/main/resources/templates/sections/generos.html View File

@ -0,0 +1,27 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="es" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:replace="head/head :: main_head">
<title th:text="${title}">Título de la página</title>
</head>
<body onload="mueveReloj()">
<header th:replace="header/nav/nav_header :: main_nav_header"></header>
<div th:switch="${pagina}">
<div th:case="list">
<main th:replace="empleado/list :: listado"></main>
</div>
<div th:case="alta">
<main th:replace="empleado/form :: alta"></main>
</div>
<div th:case="*">
<main th:replace="main/main_content :: generos"></main>
</div>
</div>
<footer th:replace="foot/footer :: main_footer"></footer>
<script src="/webjars/jsquery/jquery.min.js"></script>
<script src="/webjars/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="/js/reloj.js"></script>
</body>
</html>

+ 13
- 0
src/test/java/com/example/demo/DemoApplicationTests.java View File

@ -0,0 +1,13 @@
package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DemoApplicationTests {
@Test
void contextLoads() {
}
}

Loading…
Cancel
Save