diff --git a/pom.xml b/pom.xml
index 51e84a3..0fe8ad5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
dev.fyloz.trial.colorrecipesexplorer
ColorRecipesExplorer
- 1.1.2
+ 1.1.3
Color Recipes Explorer
diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/io/response/ResponseBuilder.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/io/response/ResponseBuilder.java
index 87734db..61d50fd 100644
--- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/io/response/ResponseBuilder.java
+++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/io/response/ResponseBuilder.java
@@ -23,6 +23,7 @@ public abstract class ResponseBuilder {
// Ajoute l'URL de base à toutes les réponses
attributes.put("baseUrl", ControllerUtils.getCurrentBaseUrl());
+ attributes.put("referer", ControllerUtils.getLatestUrl());
}
protected abstract void addResponseCodeToAttribute(String responseCodeType, String responseMessagePath, String[] parameters);
diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Material.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Material.java
index a796832..a7eceb2 100644
--- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Material.java
+++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Material.java
@@ -104,11 +104,8 @@ public class Material extends BeanModel implements Serializable {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Material material = (Material) o;
- return Float.compare(material.inventoryQuantity, inventoryQuantity) == 0 &&
- isMixType == material.isMixType &&
- Objects.equals(materialID, material.materialID) &&
- Objects.equals(materialCode, material.materialCode) &&
- Objects.equals(materialType, material.materialType);
+ return Objects.equals(materialID, material.materialID) &&
+ Objects.equals(materialCode, material.materialCode);
}
@Override
diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MaterialType.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MaterialType.java
index e9140ce..b9e6807 100644
--- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MaterialType.java
+++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MaterialType.java
@@ -101,8 +101,7 @@ public class MaterialType extends BeanModel implements Serializable {
MaterialType that = (MaterialType) o;
return Objects.equals(materialTypeID, that.materialTypeID) &&
Objects.equals(materialTypeName, that.materialTypeName) &&
- Objects.equals(prefix, that.prefix) &&
- Objects.equals(usePercentages, that.usePercentages);
+ Objects.equals(prefix, that.prefix);
}
@Override
diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/InventoryService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/InventoryService.java
index f230ded..6f4b3c5 100644
--- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/InventoryService.java
+++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/InventoryService.java
@@ -6,7 +6,6 @@ import dev.fyloz.trial.colorrecipesexplorer.core.model.MixQuantity;
import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService;
import org.springframework.stereotype.Service;
-import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -22,7 +21,7 @@ public class InventoryService {
public String checkQuantities(Mix mix, Map quantities) {
for (Material material : mix.getMixQuantities().stream().map(MixQuantity::getMaterial).collect(Collectors.toList())) {
if (!material.isMixType()) {
- float quantity = quantities.get(material);
+ Float quantity = quantities.get(material);
if (quantity > material.getInventoryQuantity()) {
return String.format("%s-%s", mix.getMixID(), material.getMaterialID());
@@ -34,12 +33,11 @@ public class InventoryService {
}
public boolean useMix(Mix mix, Map quantities) {
- List materials = mix.getMixQuantities().stream().map(MixQuantity::getMaterial).collect(Collectors.toList());
- for (Material material : materials) {
- if (!material.isMixType()) {
- float quantity = quantities.get(material);
+ for (Map.Entry entry : quantities.entrySet()) {
+ Material material = entry.getKey();
- material.setInventoryQuantity(material.getInventoryQuantity() - quantity);
+ if (!material.isMixType()) {
+ material.setInventoryQuantity(material.getInventoryQuantity() - entry.getValue());
if (!materialService.update(material).isPresent()) return false;
}
}
diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MaterialService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MaterialService.java
index 5f81a5d..1085485 100644
--- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MaterialService.java
+++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MaterialService.java
@@ -12,6 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -37,6 +38,12 @@ public class MaterialService extends GenericService {
return dao.findAllByMaterialType(materialType);
}
+ public List getAllOrdered() {
+ return getAll().stream()
+ .sorted(Comparator.comparing(Material::getMaterialCode))
+ .collect(Collectors.toList());
+ }
+
/**
* Vérifie si un produit est lié à un ou plusieurs mélanges.
*
diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixService.java
index e83e7ba..f0989c1 100644
--- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixService.java
+++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixService.java
@@ -86,6 +86,8 @@ public class MixService extends GenericService {
materials.add(found.get());
}
+ mix.getMixType().setTypeName(formDto.getMixTypeName());
+
List mixQuantities = createMixQuantities(mix, materials, formDto.getQuantities());
// Supprime les anciens MixQuantity pour éviter les doublons et les entrées inutiles dans la base de données
diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/utils/ControllerUtils.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/utils/ControllerUtils.java
index 8685fd7..d627e1e 100644
--- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/utils/ControllerUtils.java
+++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/utils/ControllerUtils.java
@@ -5,6 +5,8 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
+import java.net.URI;
+import java.net.URISyntaxException;
public class ControllerUtils {
@@ -12,15 +14,44 @@ public class ControllerUtils {
return String.format("redirect:/%s", viewName);
}
+ public static URI getUri(HttpServletRequest request) throws URISyntaxException {
+ return new URI(request.getRequestURL().toString());
+ }
+
+ public static String getUrlFromURI(URI uri) {
+ String scheme = uri.getScheme();
+ String host = uri.getHost();
+ int port = uri.getPort();
+
+ return String.format("%s://%s:%s", scheme, host, port);
+ }
+
public static String getCurrentBaseUrl() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
- if (attributes == null) {
- return null;
- }
+ if (attributes == null) return "";
HttpServletRequest request = attributes.getRequest();
String port = ":" + (ColorRecipesExplorerApplication.USE_PORT ? request.getServerPort() : "");
return String.format("%s://%s%s%s", request.getScheme(), request.getServerName(), port, request.getContextPath());
}
+
+ public static String getLatestUrl() {
+ ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ if (attributes == null) return "";
+
+ HttpServletRequest request = attributes.getRequest();
+
+ try {
+ String currentDomainName = getUrlFromURI(getUri(request));
+ String referer = request.getHeader("referer");
+ if (referer == null) return currentDomainName;
+
+ String refererURL = getUrlFromURI(new URI(referer));
+
+ return refererURL.equals(currentDomainName) ? referer : currentDomainName;
+ } catch (URISyntaxException e) {
+ return "";
+ }
+ }
}
diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/StringBank.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/StringBank.java
index 598497d..46c4486 100644
--- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/StringBank.java
+++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/StringBank.java
@@ -2,27 +2,6 @@ package dev.fyloz.trial.colorrecipesexplorer.web;
public class StringBank {
- public static final String SUCCESS_USING_MATERIALS = "Les quantités de chaque produits utilisés ont été déduites de l'inventaire";
- public static final String SUCCESS_SAVING_RECIPE_INFORMATIONS = "Les informations de la recette ont été sauvegardées";
- public static final String ERROR_SAVING = "Une erreur est survenue lors de l'enregistrement";
- public static final String ERROR_SAVING_IMAGE = "Une erreur est survenue lors de l'enregistrement de l'image";
- public static final String ERROR_SAVING_SIMDUT = "Une erreur est survenue lors de l'enregistrement du fichier SIMDUT";
- public static final String AUTH_ERROR = "Votre mot de passe n'est pas valide";
-
- // À formatter
- public static final String RECIPE_NOT_FOUND = "Aucune recette ayant l'identifiant '%s' n'a été trouvée";
- public static final String MIX_NOT_FOUND = "Aucun mélange ayant l'identifiant '%s' n'a été trouvé";
- public static final String MATERIAL_NOT_FOUND = "Aucun produit ayant l'identifiant '%s' n'a été trouvé";
- public static final String MATERIAL_ALREADY_EXIST = "Il y a déjà un produit s'appellant '%s'";
- public static final String MATERIAL_TYPE_ALREADY_EXIST = "Il y a déjà un type de produit s'appellant '%s'";
- public static final String COMPANY_NOT_FOUND = "Aucune bannière ayant l'identifiant '%s' n'a été trouvée";
- public static final String COMPANY_ALREADY_EXIST = "Il y a déjà une bannière s'appellant '%s'";
- public static final String MATERIAL_LINKED = "Le produit '%s' est lié à une ou plusieurs recettes, veuillez les supprimer d'abord";
- public static final String COMPANY_LINKED = "La bannière '%s' est liée à une ou plusieurs recettes, veuillez les supprimer d'abord";
- public static final String MIX_NOT_ASSOCIATED_WITH_RECIPE = "Le mélange ayant l'identifiant '%s' n'est pas associé à la recette ayant l'identifiant '%s'";
- public static final String NOT_ENOUGH_MATERIAL = "Il n'y a pas assez de '%s' en inventaire pour cette recette";
- public static final String MIX_TYPE_ALREADY_USED = "Cette recette contient déjà un mélange du type '%s'";
-
// Types de réponse
public static final String RESPONSE_ERROR = "error";
public static final String RESPONSE_SUCCESS = "success";
diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/InventoryController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/InventoryController.java
index ed2ed89..154be15 100644
--- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/InventoryController.java
+++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/InventoryController.java
@@ -44,7 +44,7 @@ public class InventoryController {
public ModelAndView getInventory(ModelAndView model) {
return new ModelResponseBuilder(model)
.withView(INVENTORY)
- .addResponseData(ResponseDataType.MATERIALS, materialService.getAll().stream().filter(m -> !m.isMixType()).collect(Collectors.toList()))
+ .addResponseData(ResponseDataType.MATERIALS, materialService.getAllOrdered().stream().filter(m -> !m.isMixType()).collect(Collectors.toList()))
.addResponseData(ResponseDataType.MATERIAL_TYPES, materialTypeService.getAll())
.build();
}
@@ -76,7 +76,7 @@ public class InventoryController {
@PostMapping(value = USE_INVENTORY, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Transactional
- // TODO traduit les méthodes JSON
+ // TODO vers DTO
public Map consumeMaterials(@RequestBody Map form) {
JSONResponseBuilder responseBuilder = new JSONResponseBuilder();
diff --git a/src/main/resources/lang/messages_en.properties b/src/main/resources/lang/messages_en.properties
index f8205fc..4c132e0 100644
--- a/src/main/resources/lang/messages_en.properties
+++ b/src/main/resources/lang/messages_en.properties
@@ -27,7 +27,7 @@ mix.location=Location
material.code=Code
material.inventoryQuantity=Inventory quantity
material.type=Material type
-material.SIMDUTFile=SIMDUT File
+material.simdutFile=SIMDUT File
units.milliliters=Milliliters
units.liters=Liters
units.gallons=Gallons
@@ -94,3 +94,9 @@ recipe.error.anyFound=No recipes were found.
recipe.exportAllXLS=Export all colors (XLSX)
recipe.xlsVersion=XLSX version
keyword.updates=Updates history
+material.simdutFile.notFound=No SIMDUT file found
+recipe.warning.changesNotSaved=Changes are not saved
+recipe.warning.exportAll=Do you really want to export all the colors? This can take some times and slow down the application.
+warning.noResult=Nothing corresponding the the research was found
+inventory.askUseMix=Do you really want to deduct this mix from the inventory?
+inventory.askUseRecipe=Do you really want to deduct this recipe from the inventory?
diff --git a/src/main/resources/lang/messages_fr.properties b/src/main/resources/lang/messages_fr.properties
index 6288ab2..9c6128d 100644
--- a/src/main/resources/lang/messages_fr.properties
+++ b/src/main/resources/lang/messages_fr.properties
@@ -27,7 +27,7 @@ mix.location=Position
material.code=Code
material.inventoryQuantity=Quantité en inventaire
material.type=Type de produit
-material.SIMDUTFile=Fichier SIMDUT
+material.simdutFile=Fichier SIMDUT
units.milliliters=Millilitres
units.liters=Litres
units.gallons=Gallons
@@ -94,4 +94,10 @@ recipe.error.anyFound=Aucune recette n'a été trouvée.
recipe.exportAllXLS=Exporter toutes les couleurs (XLSX)
recipe.xlsVersion=Version XLSX
keyword.updates=Historique des mises à jour
+material.simdutFile.notFound=Aucun fichier SIMDUT trouvé
+recipe.warning.changesNotSaved=Des modifications ne sont pas sauvegardées
+recipe.warning.exportAll=Voulez-vous vraiment exporter toutes les couleurs? Cela peut prendre un certain temps et ralentir l'application.
+warning.noResult=Rien correspondant à la recherche n'a été trouvé
+inventory.askUseMix=Êtes-vous certain de vouloir déduire ce mélange de l'inventaire?
+inventory.askUseRecipe=Êtes-vous certain de vouloir déduire cette recette de l'inventaire?
diff --git a/src/main/resources/static/css/main.css b/src/main/resources/static/css/main.css
index 9c60191..142611e 100644
--- a/src/main/resources/static/css/main.css
+++ b/src/main/resources/static/css/main.css
@@ -119,6 +119,8 @@ textarea {
border-style: solid;
border-color: #7a7a7a;
border-width: 1px;
+ margin-left: 20px;
+ padding: 10px;
}
.dropdown {
@@ -201,12 +203,14 @@ nav a:hover, .dropdown:hover .dropbtn {
}
#researchBoxContainer {
- text-align: right;
+ float: right;
}
#researchBox {
margin-top: 10px;
margin-right: 50px;
+ margin-left: -200px;
+ width: 150px;
}
.errorBox {
diff --git a/src/main/resources/static/js/main.js b/src/main/resources/static/js/main.js
index 8d3c09c..e009861 100644
--- a/src/main/resources/static/js/main.js
+++ b/src/main/resources/static/js/main.js
@@ -21,7 +21,7 @@ const successMsgBoxText = successMsgBox.querySelector("p");
.catch(err => {
if (err.response.status === 404) {
e.parentElement.classList.add("nosimdut");
- e.parentElement.title = "Aucun fichier SIMDUT trouvé";
+ e.parentElement.title = simdutNotFoundText;
}
});
});
@@ -33,9 +33,9 @@ const successMsgBoxText = successMsgBox.querySelector("p");
window.addEventListener("load", () => {
- document.querySelectorAll(".returnIndex").forEach((e) => {
+ document.querySelectorAll(".returnButton").forEach((e) => {
e.addEventListener("click", () => {
- document.location.href = "/";
+ document.location.href = referer;
});
});
@@ -84,11 +84,10 @@ window.addEventListener("load", () => {
});
});
- window.addEventListener("change", e => {
+ window.addEventListener("keyup", e => {
if (e.target) {
if (e.target.classList.contains("toSave")) {
- // TODO traductions
- warningMsgBoxText.innerText = "Des modifications ne sont pas été sauvegardées";
+ warningMsgBoxText.innerText = changesNotSavedText;
showElement(warningMsgBox);
}
}
@@ -102,13 +101,13 @@ window.addEventListener("load", () => {
});
function askDatabaseExport() {
- return confirm("Voulez-vous vraiment exporter toutes les couleurs? Cela peut prendre un certain temps et ralentir l'application pendant un certain temps.");
+ return confirm(exportAllWarningText);
}
function checkPassword(form, callback) {
hideElement(errorMsgBox);
- const password = prompt("Quel est votre mot de passe?");
+ const password = prompt(askPasswordText);
let data = {};
data.password = password;
@@ -120,13 +119,13 @@ function checkPassword(form, callback) {
if (callback != null) callback();
return true;
} else {
- errorMsgBoxText.innerText = "Votre mot de passe n'est pas valide";
+ errorMsgBoxText.innerText = invalidPasswordText;
showElement(errorMsgBox);
return false;
}
})
.catch(e => {
- errorMsgBoxText.innerText = "Une erreur est survenue lors de l'envoie des informations vers le serveur.";
+ errorMsgBoxText.innerText = generalErrorText;
showElement(errorMsgBox);
console.log(e);
return false;
@@ -185,3 +184,7 @@ function round(x) {
function percentageOf(percentage, number) {
return (percentage / 100) * number;
}
+
+function searchIn(searchString, str) {
+ return str.toUpperCase().indexOf(searchString.toUpperCase()) > -1;
+}
diff --git a/src/main/resources/static/js/mix.js b/src/main/resources/static/js/mix.js
index 8acd44f..4585783 100644
--- a/src/main/resources/static/js/mix.js
+++ b/src/main/resources/static/js/mix.js
@@ -16,7 +16,7 @@ window.addEventListener("load", () => {
init();
})
.catch(e => {
- errorMsgBoxText.innerText = "Une erreur est survenue lors de la récupération des produits";
+ errorMsgBoxText.innerText = generalErrorText;
showElement(errorMsgBox);
console.log(e);
});
@@ -149,12 +149,10 @@ function searchMaterial(input) {
let filter, filterUpper, materials;
filter = input.value;
- filterUpper = filter.toUpperCase();
materials = input.parentElement.querySelectorAll(".materialList p");
materials.forEach(e => {
- if (e.innerText.toUpperCase().indexOf(filterUpper) > -1 ||
- e.dataset.materialtype.toUpperCase().indexOf(filterUpper) > -1) e.style.display = "";
+ if (searchIn(filter, e.textContent) || searchIn(filter, e.dataset.materialType)) e.style.display = "";
else e.style.display = "none";
});
diff --git a/src/main/resources/templates/company/created.html b/src/main/resources/templates/company/created.html
index beaa5fa..fe0ab69 100644
--- a/src/main/resources/templates/company/created.html
+++ b/src/main/resources/templates/company/created.html
@@ -13,12 +13,11 @@
-