From a39d06a405d16481fdbc6e01cb9447741cd74582 Mon Sep 17 00:00:00 2001 From: gdamms Date: Wed, 1 Jun 2022 15:05:12 +0200 Subject: [PATCH] feat: colorpicker --- src/main/java/com/pixels/services/PixelService.java | 6 ++++-- src/main/webapp/index.html | 4 ++++ src/main/webapp/js/loaded.js | 12 +++++++++++- src/main/webapp/js/pixels.js | 3 +++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/pixels/services/PixelService.java b/src/main/java/com/pixels/services/PixelService.java index b768e97..db7f12f 100644 --- a/src/main/java/com/pixels/services/PixelService.java +++ b/src/main/java/com/pixels/services/PixelService.java @@ -92,7 +92,7 @@ public class PixelService { @Path("{id}/modify/") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public void modify(@PathParam("id") Long id, @CookieParam("JSESSIONID") Cookie cookie, - @FormParam("red") int red, @FormParam("green") int green, @FormParam("blue") int blue, + @FormParam("red") int red, @FormParam("green") int green, @FormParam("blue") int blue,@FormParam("color") String color, @FormParam("price") int price, @FormParam("description") String description) { // on récupère le pixel de la db via son id Pixel pixel = em.find(Pixel.class, id); @@ -103,7 +103,9 @@ public class PixelService { if (user.equals(pixel.getOwner())) { pixel.setPrice(price); pixel.setDescription(description); - pixel.setColor(String.format("%02X%02X%02X", red, green, blue)); + //pixel.setColor(String.format("%02X%02X%02X", red, green, blue)); + String colorDisplay = color.substring(1,color.length()); + pixel.setColor(colorDisplay); // on ajoute la transaction Date now = new Date(System.currentTimeMillis()); diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index bfab3e9..7de0f11 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -10,6 +10,8 @@ + + @@ -179,6 +181,8 @@ /> + +
{ + // console.log('New color', event.detail.color); + // }); + + document.forms["pay-form"].addEventListener("submit", (event) => { event.preventDefault(); fetch(event.target.action, { @@ -74,4 +84,4 @@ function pageLoaded() { } else { localStorage.setItem("logged", "false"); } -} +} \ No newline at end of file diff --git a/src/main/webapp/js/pixels.js b/src/main/webapp/js/pixels.js index 91db4e4..fc8c0b5 100644 --- a/src/main/webapp/js/pixels.js +++ b/src/main/webapp/js/pixels.js @@ -80,6 +80,9 @@ function updateModifyForm(pixel) { let price = document.getElementById("modify-price"); price.value = pixel.price; + let colorpicker = document.getElementById("colorpicker") + colorpicker.value = "#" + pixel.color + let color = hexToRgb(pixel.color); let red = document.getElementById("modify-red");