Langues back-end

This commit is contained in:
FyloZ 2019-08-26 07:26:07 -04:00
parent b2fbb6411f
commit dc1c0b8585
32 changed files with 656 additions and 317 deletions

View File

@ -0,0 +1,112 @@
package fyloz.trial.ColorRecipesExplorer.core;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ModelBuilder {
private static String RESPONSE_PREFIX = "response.";
private static String ERROR_ATTRIBUTE_NAME = "error";
private static String SUCCESS_ATTRIBUTE_NAME = "success";
private ModelAndView model;
private Map<String, Object> modelAttributes;
public ModelBuilder(String view) {
this(new ModelAndView(view));
}
public ModelBuilder(ModelAndView model) {
this.model = model == null ? new ModelAndView() : model;
modelAttributes = new HashMap<>();
}
public ModelBuilder setView(String view) {
model.setViewName(view);
return this;
}
public ModelBuilder addAttribute(String attributeName, Object content) {
modelAttributes.put(attributeName, content);
return this;
}
public ModelBuilder addResponseCode(ResponseCode responseCode, String... parameters) {
int requiredParametersNumber = responseCode.getParametersNumber();
int givenParametersNumber = parameters.length;
StringBuilder builder = new StringBuilder();
if (requiredParametersNumber != givenParametersNumber) {
throw new IllegalArgumentException(String.format("Mauvais nombre de paramètre dans un réponse de modèle: %s requis, %s fournis", requiredParametersNumber, givenParametersNumber));
}
// Construit le code de réponse
builder.append(RESPONSE_PREFIX);
builder.append(responseCode.getCode());
// Ajoute les paramètres, si nécessaire
if (requiredParametersNumber > 0) {
builder.append("('");
for (int i = 0; i < givenParametersNumber; i++) {
builder.append(parameters[i]);
if (i < givenParametersNumber - 1) {
builder.append("','");
}
}
builder.append("')");
}
// Ajoute l'attribut dans le Map
addAttribute(responseCode.getType() == ResponseCode.ResponseCodeType.ERROR ? ERROR_ATTRIBUTE_NAME : SUCCESS_ATTRIBUTE_NAME, builder.toString());
addAttribute("arg1", "Bathia");
addAttribute("arg2", "test");
return this;
}
public ModelBuilder addData(ModelDataType modelDataType, @NotNull Object data) {
Class modelDataTypeClass = modelDataType.getDataType();
Class modelListDataTypeClass = modelDataType.getListDataType();
Class givenDataTypeClass = data.getClass();
// Vérifie le type de l'objet
if (!modelDataTypeClass.equals(givenDataTypeClass)) {
throw new IllegalArgumentException(String.format("L'objet passé en paramètre n'est pas du bon type. Requis: %s, fournis: %s", modelDataTypeClass.getName(), givenDataTypeClass.getName()));
}
// Si l'objet est une liste, vérifie qu'elle n'est pas vide et qu'elle est du bon type
if (modelDataTypeClass.equals(List.class) && modelListDataTypeClass != null) {
List listData = (List) data;
if (listData.size() < 1) {
throw new IllegalArgumentException("La liste passée en paramètre ne contient aucun élément");
}
Class givenListDataTypeClass = listData.get(0).getClass();
if (givenDataTypeClass.equals(modelListDataTypeClass)) {
throw new IllegalArgumentException(String.format("La liste passée en paramètre contient des éléments du mauvais type. Requis: %s, fournis: %s", modelListDataTypeClass.getName(), givenListDataTypeClass.getName()));
}
}
// Ajoute l'attribut dans le Map
addAttribute(modelDataType.getDataTypeName(), data);
return this;
}
public ModelAndView build() {
model.addAllObjects(modelAttributes);
return model;
}
}

View File

@ -0,0 +1,82 @@
package fyloz.trial.ColorRecipesExplorer.core;
import fyloz.trial.ColorRecipesExplorer.model.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.stream.Stream;
public enum ModelDataType {
MATERIAL("material", Material.class),
MATERIALS("materials", ArrayList.class, MATERIAL),
MATERIAL_ID("materialID", Integer.class),
MATERIAL_CODE("materialCode", String.class),
MATERIAL_TYPE("materialType", MaterialType.class),
MATERIAL_TYPES("materialTypes", ArrayList.class, MATERIAL_TYPE),
RECIPE("recipe", Recipe.class),
RECIPES("recipes", ArrayList.class, RECIPE),
RECIPE_ID("recipeID", Integer.class),
RECIPE_CODE("recipeCode", String.class),
RECIPE_MAP("recipeMap", HashMap.class),
RECIPE_STEP("recipeStep", RecipeStep.class),
RECIPE_STEPS("recipeSteps", ArrayList.class, RECIPE_STEP),
MIX("mix", Mix.class),
MIXES("mixes", ArrayList.class, MIX),
MIX_ID("mixID", Integer.class),
MIX_TYPE("mixType", MixType.class),
MIX_TYPES("mixTypes", ArrayList.class, MIX_TYPE),
MIX_QUANTITY("mixQuantity", MixQuantity.class),
MIX_QUANTITIES("mixQuantities", ArrayList.class, MIX_QUANTITY),
COMPANY("company", Company.class),
COMPANIES("companies", ArrayList.class, COMPANY),
COMPANY_ID("companyID", Integer.class),
COMPANY_NAME("companyName", String.class),
IMAGE("image", String.class),
IMAGES("images", ArrayList.class, IMAGE);
private String dataTypeName;
private Class dataType;
private Class listDataType;
ModelDataType(String dataTypeName, Class dataType) {
this(dataTypeName, dataType, null);
}
ModelDataType(String dataTypeName, Class dataType, ModelDataType listDataType) {
this.dataTypeName = dataTypeName;
this.dataType = dataType;
if (listDataType != null) {
this.listDataType = listDataType.getDataType();
}
}
public String getDataTypeName() {
return dataTypeName;
}
public Class getDataType() {
return dataType;
}
public Class getListDataType() {
return listDataType;
}
@Override
public String toString() {
return getDataTypeName();
}
public static ModelDataType getModelDataTypeFromDataType(Class dataType) {
return Stream.of(values()).filter(r -> r.getDataType().equals(dataType)).findFirst().orElse(null);
}
}

View File

@ -0,0 +1,51 @@
package fyloz.trial.ColorRecipesExplorer.core;
public enum ResponseCode {
SUCCESS_USING_MATERIALS(1, ResponseCodeType.SUCCESS, 0),
SUCCESS_SAVING_RECIPE_INFORMATIONS(2, ResponseCodeType.SUCCESS, 0),
ERROR_SAVING(3, ResponseCodeType.ERROR, 0),
ERROR_SAVING_IMAGE(4, ResponseCodeType.ERROR, 0),
ERROR_SAVING_SIMDUT(5, ResponseCodeType.ERROR, 0),
AUTH_ERROR(6, ResponseCodeType.ERROR, 0),
RECIPE_NOT_FOUND(7, ResponseCodeType.ERROR, 1),
MIX_NOT_FOUND(8, ResponseCodeType.ERROR, 1),
MATERIAL_NOT_FOUND(9, ResponseCodeType.ERROR, 1),
MATERIAL_ALREADY_EXIST(10, ResponseCodeType.ERROR, 1),
MATERIAL_TYPE_ALREADY_EXIST(11, ResponseCodeType.ERROR, 1),
COMPANY_NOT_FOUND(12, ResponseCodeType.ERROR, 1),
COMPANY_ALREADY_EXIST(13, ResponseCodeType.ERROR, 1),
MATERIAL_LINKED(14, ResponseCodeType.ERROR, 1),
COMPANY_LINKED(15, ResponseCodeType.ERROR, 1),
MIX_NOT_ASSOCIATED_WITH_RECIPE(16, ResponseCodeType.ERROR, 2),
NOT_ENOUGH_MATERIAL(17, ResponseCodeType.ERROR, 1),
MIX_TYPE_ALREADY_USED(18, ResponseCodeType.ERROR, 1);
public static final int MAX_PARAMETERS_NUMBER = 2;
private int code;
private ResponseCodeType type;
private int parametersNumber;
ResponseCode(int code, ResponseCodeType type, int parametersNumber) {
this.code = code;
this.type = type;
this.parametersNumber = parametersNumber;
}
public int getCode() {
return code;
}
public ResponseCodeType getType() {
return type;
}
public int getParametersNumber() {
return parametersNumber;
}
public enum ResponseCodeType {
ERROR,
SUCCESS
}
}

View File

@ -1,50 +0,0 @@
package fyloz.trial.ColorRecipesExplorer.core;
public enum ResponseCodes {
SUCCESS_USING_MATERIALS(100, ResponseCodeType.SUCCESS, false),
SUCCESS_SAVING_RECIPE_INFORMATIONS(2, ResponseCodeType.SUCCESS, false),
ERROR_SAVING(3, ResponseCodeType.ERROR, false),
ERROR_SAVING_IMAGE(4, ResponseCodeType.ERROR, false),
ERROR_SAVING_SIMDUT(5, ResponseCodeType.ERROR, false),
AUTH_ERROR(6, ResponseCodeType.ERROR, false),
RECIPE_NOT_FOUND(7, ResponseCodeType.ERROR, true),
MIX_NOT_FOUND(8, ResponseCodeType.ERROR, true),
MATERIAL_NOT_FOUND(9, ResponseCodeType.ERROR, true),
MATERIAL_ALREADY_EXIST(10, ResponseCodeType.ERROR, true),
MATERIAL_TYPE_ALREADY_EXIST(11, ResponseCodeType.ERROR, true),
COMPANY_NOT_FOUND(12, ResponseCodeType.ERROR, true),
COMPANY_ALREADY_EXIST(13, ResponseCodeType.ERROR, true),
MATERIAL_LINKED(14, ResponseCodeType.ERROR, true),
COMPANY_LINKED(15, ResponseCodeType.ERROR, true),
MIX_NOT_ASSOCIATED_WITH_RECIPE(16, ResponseCodeType.ERROR, true),
NOT_ENOUGH_MATERIAL(17, ResponseCodeType.ERROR, true),
MIX_TYPE_ALREADY_USED(18, ResponseCodeType.ERROR, true);
private int code;
private ResponseCodeType type;
private boolean needAdditionalContent;
ResponseCodes(int code, ResponseCodeType type, boolean needAdditionalContent) {
this.code = code;
this.type = type;
this.needAdditionalContent = needAdditionalContent;
}
public int getCode() {
return code;
}
public ResponseCodeType getType() {
return type;
}
public boolean needAdditionalContent() {
return needAdditionalContent;
}
public enum ResponseCodeType {
ERROR,
SUCCESS
}
}

View File

@ -18,11 +18,19 @@ public class LocaleConfiguration implements WebMvcConfigurer {
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:lang/messages", "classpath:lang/errors");
// messageSource.setBasenames("classpath:lang/messages", "classpath:lang/responses");
messageSource.setBasename("classpath:lang/responses");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
// @Bean
// public MessageSource responsesMessageSource() {
// ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
// messageSource.setBasename("classpath:lang/responses");
// return messageSource;
// }
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver localeResolver = new SessionLocaleResolver();

View File

@ -0,0 +1,8 @@
package fyloz.trial.ColorRecipesExplorer.core.utils;
public class ControllerUtils {
public static String redirect(String viewName) {
return String.format("redirect:/%s", viewName);
}
}

View File

@ -1,5 +1,7 @@
package fyloz.trial.ColorRecipesExplorer.services;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.dao.MixDao;
import fyloz.trial.ColorRecipesExplorer.model.*;
import org.springframework.beans.factory.annotation.Autowired;
@ -9,9 +11,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.ERROR_SAVING;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.MATERIAL_NOT_FOUND;
@Service
public class MixService extends GenericService<Mix> {
@ -37,18 +36,20 @@ public class MixService extends GenericService<Mix> {
* @return Le message d'erreur, s'il y a lieu
*/
@Transactional
public String create(List<Integer> materials, List<Float> quantities, Recipe recipe, MixType mixType) {
public ModelBuilder create(ModelBuilder modelBuilder, List<Integer> materials, List<Float> quantities, Recipe recipe, MixType mixType) {
// Crée le mélange en premier pour avoir accès à son ID pour les autres éléments
Mix mix = new Mix(recipe, mixType, null);
if ((mix = save(mix)) != null) {
List<MixQuantity> mixQuantities = createMixQuantities(mix, materials, quantities);
if (mixQuantities == null) return MATERIAL_NOT_FOUND;
if (mixQuantities == null) {
return modelBuilder.addResponseCode(ResponseCode.MATERIAL_NOT_FOUND);
}
if (mixQuantityService.saveAll(mixQuantities)) return null;
}
return ERROR_SAVING;
return modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING);
}
/**

View File

@ -1,6 +1,9 @@
package fyloz.trial.ColorRecipesExplorer.web.controller;
import fyloz.trial.ColorRecipesExplorer.ColorRecipesExplorerApplication;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.core.io.ImageHandler;
import fyloz.trial.ColorRecipesExplorer.model.Recipe;
import fyloz.trial.ColorRecipesExplorer.services.RecipeService;
@ -10,17 +13,19 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static fyloz.trial.ColorRecipesExplorer.core.utils.ControllerUtils.redirect;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.*;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.ERROR_SAVING_IMAGE;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.RESPONSE_ERROR;
@Controller
public class ImageFilesController {
@ -62,9 +67,11 @@ public class ImageFilesController {
* @return La page à afficher.
*/
@GetMapping(ADD_IMAGE_SPECIFIC)
public String showPage(Model model, @PathVariable int recipeID) {
model.addAttribute(RECIPE_ID, recipeID);
return ADD_IMAGE;
public ModelAndView showPage(ModelAndView model, @PathVariable int recipeID) {
return new ModelBuilder(model)
.setView(ADD_IMAGE)
.addData(ModelDataType.RECIPE_ID, recipeID)
.build();
}
/**
@ -83,37 +90,42 @@ public class ImageFilesController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param recipeID L'identifiant de la recette
* @param image L'image uploadée
* @return La page à afficher.
*/
@PostMapping(ADD_IMAGE)
public String addImage(Model model, int recipeID, MultipartFile image) {
public ModelAndView addImage(int recipeID, MultipartFile image) {
ModelBuilder modelBuilder = new ModelBuilder(redirect(EDITOR_RECIPE_SPECIFIC.replace("{recipeID}", String.valueOf(recipeID))));
Recipe recipe = recipeService.getByID(recipeID);
if (recipe == null) {
model.addAttribute(RESPONSE_ERROR, RECIPE_NOT_FOUND);
return showPage(model, recipeID);
modelBuilder.addResponseCode(ResponseCode.RECIPE_NOT_FOUND, String.valueOf(recipeID));
return showPage(modelBuilder.build(), recipeID);
}
ImageHandler imageHandler = new ImageHandler(recipe, recipeService);
if (!imageHandler.createFile()) {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING_IMAGE);
return showPage(model, recipeID);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING_IMAGE);
return showPage(modelBuilder.build(), recipeID);
}
model.addAttribute(RECIPE_CODE, recipe.getRecipeCode());
model.addAttribute(RECIPE_ID, recipe.getRecipeID());
modelBuilder
.addData(ModelDataType.RECIPE_CODE, recipe.getRecipeCode())
.addData(ModelDataType.RECIPE_ID, recipe.getRecipeID());
try {
// Si je n'utilise pas le path, il cherche un fichier dans les tmp ?
image.transferTo(new File(imageHandler.getFile().getAbsolutePath()));
return "redirect:/" + EDITOR_RECIPE_SPECIFIC.replace("{recipeID}", String.valueOf(recipeID));
return modelBuilder.build();
} catch (IOException e) {
ColorRecipesExplorerApplication.logger.error("Erreur inconnue lors de la création d'une image", e);
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING_IMAGE);
return showPage(model, recipeID);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING_IMAGE);
return showPage(modelBuilder.build(), recipeID);
}
}

View File

@ -1,6 +1,8 @@
package fyloz.trial.ColorRecipesExplorer.web.controller;
import fyloz.trial.ColorRecipesExplorer.PasswordValidator;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.model.Company;
import fyloz.trial.ColorRecipesExplorer.model.Recipe;
import fyloz.trial.ColorRecipesExplorer.services.CompanyService;
@ -8,11 +10,11 @@ import fyloz.trial.ColorRecipesExplorer.services.RecipeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.List;
@ -20,7 +22,6 @@ import java.util.Map;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.INDEX;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.PASSWORD_VALIDATION;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.RECIPES;
@Controller
public class IndexController {
@ -41,7 +42,7 @@ public class IndexController {
* @return La page à afficher.
*/
@GetMapping({INDEX, "/"})
public String showPage(Model model) {
public ModelAndView showPage() {
List<Company> companies = companyService.getAll();
Map<Company, List<Recipe>> recipes = new HashMap<>();
@ -49,9 +50,9 @@ public class IndexController {
recipes.put(company, recipeService.getByCompany(company));
}
model.addAttribute(RECIPES, recipes);
return INDEX;
return new ModelBuilder(INDEX)
.addData(ModelDataType.RECIPE_MAP, recipes)
.build();
}
/**
@ -65,8 +66,4 @@ public class IndexController {
public boolean validatePassword(@RequestBody Map<String, Object> data) {
return PasswordValidator.isValid((String) data.get("password"));
}
/**
* Donne acc
*/
}

View File

@ -1,5 +1,7 @@
package fyloz.trial.ColorRecipesExplorer.web.controller;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.model.Material;
import fyloz.trial.ColorRecipesExplorer.model.Mix;
import fyloz.trial.ColorRecipesExplorer.model.MixQuantity;
@ -11,11 +13,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.HashMap;
@ -49,15 +51,14 @@ public class InventoryController {
* Modèle de la page:
* - materials: Contient la liste de tous les matériaux
*
* @param model Le Model injecté par Thymeleaf
* @return La page à afficher.
*/
@GetMapping(INVENTORY)
public String getInventory(Model model) {
model.addAttribute(MATERIALS, materialService.getAll().stream().filter(m -> !m.isMixType()).collect(Collectors.toList()));
model.addAttribute(MATERIAL_TYPES, materialTypeService.getAll());
return INVENTORY;
public ModelAndView getInventory(ModelAndView model) {
return new ModelBuilder(INVENTORY)
.addData(ModelDataType.MATERIALS, materialService.getAll().stream().filter(m -> !m.isMixType()).collect(Collectors.toList()))
.addData(ModelDataType.MATERIAL_TYPES, materialTypeService.getAll())
.build();
}
/**
@ -87,6 +88,7 @@ public class InventoryController {
@PostMapping(value = USE_INVENTORY, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Transactional
// TODO traduits les méthodes JSON
public Map<String, String> consumeMaterials(@RequestBody Map<String, Object> form) {
Map<String, String> response = new HashMap<>();

View File

@ -1,14 +1,17 @@
package fyloz.trial.ColorRecipesExplorer.web.controller;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import static fyloz.trial.ColorRecipesExplorer.core.utils.ControllerUtils.redirect;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.TOUCHUP;
@Controller
public class OthersController {
@GetMapping(TOUCHUP)
public String getTouchUpPdf() {
return "redirect:/pdf/touchup.pdf";
public ModelAndView getTouchUpPdf() {
return new ModelBuilder(redirect("pdf/touchup.pdf")).build();
}
}

View File

@ -1,5 +1,8 @@
package fyloz.trial.ColorRecipesExplorer.web.controller;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Mix;
import fyloz.trial.ColorRecipesExplorer.model.Recipe;
import fyloz.trial.ColorRecipesExplorer.services.MixService;
@ -7,13 +10,10 @@ import fyloz.trial.ColorRecipesExplorer.services.RecipeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.*;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@ -40,27 +40,29 @@ public class RecipeExplorerController {
* - mixes: Contient les mélanges associées à la recette
* - images: Contient la liste des noms des images associées à la recette
*
* @param model Le Model injecté par Thymeleaf
* @param recipeID L'identifiant de la recette
* @return La page à afficher.
*/
@GetMapping(EXPLORER_RECIPE_SPECIFIC)
public String showRecipe(Model model, @PathVariable int recipeID) {
public ModelAndView showRecipe(@PathVariable int recipeID) {
ModelBuilder modelBuilder = new ModelBuilder(EXPLORER_RECIPE);
Recipe recipe = recipeService.getByID(recipeID);
if (recipe == null) {
model.addAttribute(RESPONSE_ERROR, String.format(RECIPE_NOT_FOUND, recipeID));
return INDEX;
return modelBuilder
.setView(INDEX)
.addResponseCode(ResponseCode.RECIPE_NOT_FOUND, String.valueOf(recipeID))
.build();
}
List<Mix> mixes = recipe.getRecipeMixes();
List<Mix> mixes = new ArrayList<>(recipe.getRecipeMixes()); // Convertit le PersistentBag en ArrayList
mixes.sort(Comparator.comparing(Mix::getMixID));
model.addAttribute(RECIPE, recipe);
model.addAttribute(MIXES, mixes);
model.addAttribute("images", recipeService.getImageFiles(recipe));
return EXPLORER_RECIPE;
return modelBuilder
.addData(ModelDataType.RECIPE, recipe)
.addData(ModelDataType.MIXES, mixes)
.addData(ModelDataType.IMAGES, recipeService.getImageFiles(recipe))
.build();
}
/**

View File

@ -1,20 +1,22 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.creators;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Company;
import fyloz.trial.ColorRecipesExplorer.services.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.CREATOR_COMPANY;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.CREATOR_COMPANY_SUCCESS;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@Controller
public class CompanyCreatorController {
@ -32,9 +34,11 @@ public class CompanyCreatorController {
* @return La page à afficher.
*/
@GetMapping(CREATOR_COMPANY)
public String showCreationPage(Model model, Company company) {
model.addAttribute("company", company);
return CREATOR_COMPANY;
public ModelAndView showCreationPage(ModelAndView model, Company company) {
return new ModelBuilder(model)
.setView(CREATOR_COMPANY)
.addData(ModelDataType.COMPANY, company)
.build();
}
/**
@ -55,18 +59,21 @@ public class CompanyCreatorController {
* @return La page à afficher.
*/
@PostMapping(value = CREATOR_COMPANY, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String createCompany(Model model, @ModelAttribute @Valid Company company) {
public ModelAndView createCompany(@ModelAttribute @Valid Company company) {
ModelBuilder modelBuilder = new ModelBuilder(CREATOR_COMPANY_SUCCESS);
if (companyService.isValidForCreation(company)) {
if ((company = companyService.save(company)) != null) {
model.addAttribute("companyName", company.getCompanyName());
return CREATOR_COMPANY_SUCCESS;
return modelBuilder
.addData(ModelDataType.COMPANY_NAME, company.getCompanyName())
.build();
} else {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING);
}
} else {
model.addAttribute(RESPONSE_ERROR, String.format(COMPANY_ALREADY_EXIST, company.getCompanyName()));
modelBuilder.addResponseCode(ResponseCode.MIX_NOT_ASSOCIATED_WITH_RECIPE, company.getCompanyName(), null);
}
return showCreationPage(model, company);
return showCreationPage(modelBuilder.build(), company);
}
}

View File

@ -1,21 +1,23 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.creators;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Material;
import fyloz.trial.ColorRecipesExplorer.services.MaterialService;
import fyloz.trial.ColorRecipesExplorer.services.MaterialTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.CREATOR_MATERIAL;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.CREATOR_MATERIAL_SUCCESS;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@Controller
public class MaterialCreatorController {
@ -35,10 +37,12 @@ public class MaterialCreatorController {
* @return La page à afficher.
*/
@GetMapping(CREATOR_MATERIAL)
public String showCreationPage(Model model, Material material) {
model.addAttribute(MATERIAL, material == null ? new Material() : material);
model.addAttribute(MATERIAL_TYPES, materialTypeService.getAll());
return CREATOR_MATERIAL;
public ModelAndView showCreationPage(ModelAndView model, Material material) {
return new ModelBuilder(model)
.setView(CREATOR_MATERIAL)
.addData(ModelDataType.MATERIAL, material != null ? material : new Material())
.addData(ModelDataType.MATERIAL_TYPES, materialTypeService.getAll())
.build();
}
/**
@ -55,29 +59,30 @@ public class MaterialCreatorController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le modèle injecté par Thymeleaf
* @param material Le produit à créer
* @param simdut Le fichier SIMDUT du produit (optionnel)
* @return La page à afficher.
*/
@PostMapping(value = CREATOR_MATERIAL, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String create(Model model, @Valid Material material, MultipartFile simdut) {
public ModelAndView create(@Valid Material material, MultipartFile simdut) {
ModelBuilder modelBuilder = new ModelBuilder(CREATOR_MATERIAL_SUCCESS);
if (!materialService.exists(material)) {
if ((material = materialService.save(material)) != null) {
model.addAttribute(MATERIAL_CODE, material.getMaterialCode());
modelBuilder.addData(ModelDataType.MATERIAL_CODE, material.getMaterialCode());
if (!materialService.addSimdut(simdut, material)) {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING_SIMDUT);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING_SIMDUT);
}
return CREATOR_MATERIAL_SUCCESS;
return modelBuilder.build();
} else {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING);
}
} else {
model.addAttribute(RESPONSE_ERROR, String.format(MATERIAL_ALREADY_EXIST, material.getMaterialCode()));
modelBuilder.addResponseCode(ResponseCode.MATERIAL_ALREADY_EXIST, material.getMaterialCode());
}
return showCreationPage(model, material);
return showCreationPage(modelBuilder.build(), material);
}
}

View File

@ -1,18 +1,21 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.creators;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.MaterialType;
import fyloz.trial.ColorRecipesExplorer.services.MaterialTypeService;
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.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
import static fyloz.trial.ColorRecipesExplorer.core.utils.ControllerUtils.redirect;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.CREATOR_MATERIAL_TYPE;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.INDEX;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@Controller
public class MaterialTypeCreatorController {
@ -25,23 +28,27 @@ public class MaterialTypeCreatorController {
}
@GetMapping(CREATOR_MATERIAL_TYPE)
public String showPage(Model model, MaterialType materialType) {
model.addAttribute(MATERIAL_TYPE, materialType == null ? new MaterialType() : materialType);
return CREATOR_MATERIAL_TYPE;
public ModelAndView showPage(ModelAndView model, MaterialType materialType) {
return new ModelBuilder(model)
.setView(CREATOR_MATERIAL_TYPE)
.addData(ModelDataType.MATERIAL_TYPE, materialType == null ? new MaterialType() : materialType)
.build();
}
@PostMapping(CREATOR_MATERIAL_TYPE)
public String create(Model model, @Valid MaterialType materialType) {
public ModelAndView create(@Valid MaterialType materialType) {
ModelBuilder modelBuilder = new ModelBuilder(redirect(INDEX));
if (materialTypeService.isValidForCreation(materialType)) {
if (materialTypeService.save(materialType) != null) {
return "redirect:/" + INDEX;
return modelBuilder.build();
} else {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING);
}
} else {
model.addAttribute(RESPONSE_ERROR, String.format(MIX_TYPE_ALREADY_USED, materialType.getMaterialTypeName()));
modelBuilder.addResponseCode(ResponseCode.MIX_TYPE_ALREADY_USED, materialType.getMaterialTypeName());
}
return showPage(model, materialType);
return showPage(modelBuilder.build(), materialType);
}
}

View File

@ -1,5 +1,8 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.creators;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Material;
import fyloz.trial.ColorRecipesExplorer.model.MixType;
import fyloz.trial.ColorRecipesExplorer.model.Recipe;
@ -10,20 +13,22 @@ import fyloz.trial.ColorRecipesExplorer.services.RecipeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import static fyloz.trial.ColorRecipesExplorer.core.utils.ControllerUtils.redirect;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.*;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.MIX_TYPE;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.RECIPE_ID;
@Controller
public class MixCreatorController {
@ -50,21 +55,26 @@ public class MixCreatorController {
* @return La page à afficher.
*/
@GetMapping(CREATOR_MIX_SPECIFIC)
public String showCreationPage(Model model, @PathVariable int recipeID) {
public ModelAndView showCreationPage(ModelAndView model, @PathVariable int recipeID) {
ModelBuilder modelBuilder = new ModelBuilder(model)
.setView(CREATOR_MIX);
Recipe recipe = recipeService.getByID(recipeID);
if (recipe == null) {
return "redirect:/" + EDITOR_RECIPE;
return modelBuilder
.setView(redirect(EDITOR_RECIPE))
.build();
}
List<MixType> associatedMixTypes = recipeService.getAssociatedMixesTypes(recipe);
// Récupère seulement les produits qui ne sont pas des types de mélange OU que ce type existe dans la recette
List<Material> materials = materialService.getAll().stream().filter(m -> !m.isMixType() || associatedMixTypes.contains(mixTypeService.getByMaterial(m))).collect(Collectors.toList());
model.addAttribute(RECIPE, recipe);
model.addAttribute(MATERIALS, materials);
model.addAttribute("materialsJson", materialService.asJson(materials)); // Ajoute les matériaux sous forme de JSON pour utiliser la liste en Javascript
return CREATOR_MIX;
return modelBuilder
.addData(ModelDataType.RECIPE, recipe)
.addData(ModelDataType.MATERIALS, materials)
.addAttribute("materialsJson", materialService.asJson(materials))
.build();
}
/**
@ -82,12 +92,11 @@ public class MixCreatorController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param form La formulaire du mélange entré par l'utilisateur
* @param form La formulaire du mélange entré par l'utilisateur
* @return La page à afficher.
*/
@PostMapping(value = CREATOR_MIX, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String createMix(Model model, @RequestBody LinkedMultiValueMap<String, String> form) {
public ModelAndView createMix(@RequestBody LinkedMultiValueMap<String, String> form) {
String mixTypeName = form.get(MIX_TYPE).get(0);
int recipeID = Integer.parseInt(form.get(RECIPE_ID).get(0));
@ -104,27 +113,33 @@ public class MixCreatorController {
}
}
ModelBuilder modelBuilder = new ModelBuilder(redirect(EDITOR_RECIPE_SPECIFIC.replaceAll("\\{" + RECIPE_ID + "}", String.valueOf(recipeID))));
Recipe recipe = recipeService.getByID(recipeID);
if (recipe == null) {
model.addAttribute(RESPONSE_ERROR, String.format(RECIPE_NOT_FOUND, recipeID));
return EDITOR_RECIPE;
return modelBuilder
.addResponseCode(ResponseCode.RECIPE_NOT_FOUND, String.valueOf(recipeID))
.build();
}
MixType mixType = mixTypeService.createByName(mixTypeName);
if (mixType == null) {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING);
return EDITOR_RECIPE;
return modelBuilder
.setView(EDITOR_RECIPE)
.addResponseCode(ResponseCode.ERROR_SAVING)
.build();
} else if (recipeService.getAssociatedMixesTypes(recipe).contains(mixType)) {
model.addAttribute(RESPONSE_ERROR, MIX_TYPE_ALREADY_USED);
return EDITOR_RECIPE;
return modelBuilder
.setView(EDITOR_RECIPE)
.addResponseCode(ResponseCode.MIX_TYPE_ALREADY_USED)
.build();
}
String errorMessage = mixService.create(materials, quantities, recipe, mixType);
if (errorMessage != null) {
model.addAttribute(RESPONSE_ERROR, errorMessage);
return showCreationPage(model, recipeID);
ModelBuilder creationResult = mixService.create(modelBuilder, materials, quantities, recipe, mixType);
if (creationResult != null) {
return showCreationPage(modelBuilder.build(), recipeID);
}
return "redirect:/" + EDITOR_RECIPE_SPECIFIC.replaceAll("\\{" + RECIPE_ID + "}", String.valueOf(recipeID));
return modelBuilder.build();
}
}

View File

@ -1,19 +1,21 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.creators;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Recipe;
import fyloz.trial.ColorRecipesExplorer.services.CompanyService;
import fyloz.trial.ColorRecipesExplorer.services.RecipeService;
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.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.CREATOR_RECIPE;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.CREATOR_RECIPE_SUCCESS;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@Controller
public class RecipeCreatorController {
@ -34,10 +36,12 @@ public class RecipeCreatorController {
* @return La page à afficher.
*/
@GetMapping(CREATOR_RECIPE)
public String showCreationPage(Model model, Recipe recipe) {
model.addAttribute(COMPANIES, companyService.getAll());
model.addAttribute(RECIPE, recipe == null ? new Recipe() : recipe);
return CREATOR_RECIPE;
public ModelAndView showCreationPage(ModelAndView model, Recipe recipe) {
return new ModelBuilder(model)
.setView(CREATOR_RECIPE)
.addData(ModelDataType.COMPANIES, companyService.getAll())
.addData(ModelDataType.RECIPE, recipe == null ? new Recipe() : recipe)
.build();
}
/**
@ -52,19 +56,20 @@ public class RecipeCreatorController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param recipe La recette à créer
* @return La page à afficher.
*/
@PostMapping(value = CREATOR_RECIPE)
public String createRecipe(Model model, @Valid Recipe recipe) {
public ModelAndView createRecipe(@Valid Recipe recipe) {
ModelBuilder modelBuilder = new ModelBuilder(CREATOR_RECIPE_SUCCESS);
if ((recipe = recipeService.save(recipe)) != null) {
model.addAttribute(RECIPE_CODE, recipe.getRecipeCode());
model.addAttribute(RECIPE_ID, recipe.getRecipeID());
return CREATOR_RECIPE_SUCCESS;
} else {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING);
return showCreationPage(model, recipe);
return modelBuilder
.addData(ModelDataType.RECIPE, recipe)
.build();
}
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING);
return showCreationPage(modelBuilder.build(), recipe);
}
}

View File

@ -1,21 +1,24 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.editors;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Material;
import fyloz.trial.ColorRecipesExplorer.services.MaterialService;
import fyloz.trial.ColorRecipesExplorer.services.MaterialTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import java.util.stream.Collectors;
import static fyloz.trial.ColorRecipesExplorer.core.utils.ControllerUtils.redirect;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.*;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@Controller
public class MaterialEditorController {
@ -39,10 +42,11 @@ public class MaterialEditorController {
* @return La page à afficher.
*/
@GetMapping(EDITOR_MATERIAL)
public String listMaterials(Model model) {
model.addAttribute(MATERIALS, materialService.getAll().stream().filter(m -> !m.isMixType()).collect(Collectors.toList()));
return EDITOR_MATERIAL;
public ModelAndView listMaterials(ModelAndView model) {
return new ModelBuilder(model)
.setView(EDITOR_MATERIAL)
.addData(ModelDataType.MATERIALS, materialService.getAll().stream().filter(m -> !m.isMixType()).collect(Collectors.toList()))
.build();
}
/**
@ -54,18 +58,21 @@ public class MaterialEditorController {
* @return La page à afficher.
*/
@GetMapping(EDITOR_MATERIAL_SPECIFIC)
public String showEditPage(Model model, @PathVariable int materialID) {
public ModelAndView showEditPage(ModelAndView model, @PathVariable int materialID) {
ModelBuilder modelBuilder = new ModelBuilder(model)
.setView(EDITOR_MATERIAL_EDITOR);
Material material = materialService.getByID(materialID);
if (material == null) {
model.addAttribute(RESPONSE_ERROR, String.format(MATERIAL_NOT_FOUND, materialID));
modelBuilder.addResponseCode(ResponseCode.MATERIAL_NOT_FOUND, String.valueOf(materialID));
return listMaterials(model);
return listMaterials(modelBuilder.build());
}
model.addAttribute(MATERIAL, material);
model.addAttribute(MATERIAL_TYPES, materialTypeService.getAll());
return EDITOR_MATERIAL_EDITOR;
return modelBuilder
.addData(ModelDataType.MATERIAL, material)
.addData(ModelDataType.MATERIAL_TYPES, materialTypeService.getAll())
.build();
}
/**
@ -80,10 +87,11 @@ public class MaterialEditorController {
* @return La page à afficher.
*/
@GetMapping(value = EDIT_MATERIAL_SIMDUT_SPECIFIC)
public String chooseSIMDUTFile(Model model, @PathVariable int materialID) {
model.addAttribute(MATERIAL_ID, materialID);
return EDIT_MATERIAL_SIMDUT;
public ModelAndView chooseSIMDUTFile(ModelAndView model, @PathVariable int materialID) {
return new ModelBuilder(model)
.setView(EDIT_MATERIAL_SIMDUT)
.addData(ModelDataType.MATERIAL_ID, materialID)
.build();
}
/**
@ -94,25 +102,28 @@ public class MaterialEditorController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param materialID L'identifiant du produit
* @param simdut Le fichier SIMDUT uploadé
* @return La page à afficher.
*/
@PostMapping(value = EDIT_MATERIAL_SIMDUT, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String saveSIMDUT(Model model, int materialID, MultipartFile simdut) {
public ModelAndView saveSIMDUT(int materialID, MultipartFile simdut) {
ModelBuilder modelBuilder = new ModelBuilder(redirect("material/editor/" + materialID));
Material material = materialService.getByID(materialID);
if (material == null) {
model.addAttribute(RESPONSE_ERROR, MATERIAL_NOT_FOUND);
return chooseSIMDUTFile(model, materialID);
modelBuilder.addResponseCode(ResponseCode.MATERIAL_NOT_FOUND, String.valueOf(materialID));
return chooseSIMDUTFile(modelBuilder.build(), materialID);
}
if (!materialService.removeSimdut(material) || !materialService.addSimdut(simdut, material)) {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING_SIMDUT);
return chooseSIMDUTFile(model, materialID);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING_SIMDUT);
return chooseSIMDUTFile(modelBuilder.build(), materialID);
}
return "redirect:/material/editor/" + materialID;
return modelBuilder.build();
}
/**
@ -129,25 +140,26 @@ public class MaterialEditorController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param material Le produit à mettre à jour
* @return La page à afficher.
*/
@PostMapping(value = EDITOR_MATERIAL, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String saveEditedMaterial(Model model, Material material) {
public ModelAndView saveEditedMaterial(Material material) {
ModelBuilder modelBuilder = new ModelBuilder("");
int materialID = material.getMaterialID();
if (materialService.getByID(materialID) == null) {
model.addAttribute(RESPONSE_ERROR, String.format(MATERIAL_NOT_FOUND, materialID));
modelBuilder.addResponseCode(ResponseCode.MATERIAL_NOT_FOUND, String.valueOf(materialID));
}
if ((material = materialService.update(material)) != null) {
model.addAttribute(MATERIAL_CODE, material.getMaterialCode());
modelBuilder.addData(ModelDataType.MATERIAL_CODE, material.getMaterialCode());
} else {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING);
return showEditPage(model, materialID);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING);
return showEditPage(modelBuilder.build(), materialID);
}
return listMaterials(model);
return listMaterials(modelBuilder.build());
}
}

View File

@ -1,5 +1,8 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.editors;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Material;
import fyloz.trial.ColorRecipesExplorer.model.Mix;
import fyloz.trial.ColorRecipesExplorer.model.MixType;
@ -10,19 +13,20 @@ import fyloz.trial.ColorRecipesExplorer.services.RecipeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import static fyloz.trial.ColorRecipesExplorer.core.utils.ControllerUtils.redirect;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.*;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.MIX_ID;
@Controller
public class MixEditorController {
@ -49,12 +53,16 @@ public class MixEditorController {
* @return La page à afficher.
*/
@GetMapping(EDITOR_MIX_SPECIFIC)
public String showPage(Model model, @PathVariable int mixID) {
public ModelAndView showPage(ModelAndView model, @PathVariable int mixID) {
ModelBuilder modelBuilder = new ModelBuilder(model)
.setView(EDITOR_MIX_SPECIFIC.replaceAll("/\\{" + MIX_ID + "}", ""));
Mix mix = mixService.getByID(mixID);
// Renvoie l'utilisateur à la page d'édition des recettes si le mélange n'est pas trouvé
if (mix == null) {
return "redirect:/" + EDITOR_RECIPE;
return modelBuilder
.setView(redirect(EDITOR_RECIPE))
.build();
}
List<Material> materials = new ArrayList<>();
@ -65,12 +73,12 @@ public class MixEditorController {
}
}
model.addAttribute(MIX, mix);
model.addAttribute("mixJson", mixService.asJson(mix));
model.addAttribute(RECIPE_CODE, mix.getRecipe().getRecipeCode());
model.addAttribute("materialsJson", materialService.asJson(materials));
return EDITOR_MIX_SPECIFIC.replaceAll("/\\{" + MIX_ID + "}", "");
return modelBuilder
.addData(ModelDataType.MIX, mix)
.addData(ModelDataType.RECIPE_CODE, mix.getRecipe().getRecipeCode())
.addAttribute("mixJson", materialService.asJson(mix))
.addAttribute("materialsJson", materialService.asJson(materials))
.build();
}
/**
@ -87,25 +95,29 @@ public class MixEditorController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param form Le formulaire du mélange entré par l'utilisateur
* @return La page à afficher.
*/
@PostMapping(value = EDITOR_MIX, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String saveMix(Model model, @RequestBody LinkedMultiValueMap<String, Object> form) {
public ModelAndView saveMix(@RequestBody LinkedMultiValueMap<String, Object> form) {
ModelBuilder modelBuilder = new ModelBuilder("");
int mixID = Integer.parseInt((String) form.get(MIX_ID).get(0));
Mix mix = mixService.getByID(mixID);
if (mix == null) {
model.addAttribute(RESPONSE_ERROR, String.format(MIX_NOT_FOUND, mixID));
return showPage(model, mixID);
modelBuilder.addResponseCode(ResponseCode.MIX_NOT_FOUND, String.valueOf(mixID));
return showPage(modelBuilder.build(), mixID);
}
modelBuilder.setView(redirect(EDITOR_RECIPE_SPECIFIC.replace("{recipeID}", String.valueOf(mix.getRecipe().getRecipeID()))));
List<Integer> materials = new ArrayList<>();
List<Float> quantities = new ArrayList<>();
for (String key : form.keySet()) {
LinkedList<String> value = (LinkedList) form.get(key);
// TODO Laisser ?
assert value != null : "Une valeur du formulaire d'édition d'un mélange est nulle.";
if (key.equals("product")) {
@ -116,26 +128,33 @@ public class MixEditorController {
}
if (!mixService.edit(mix, materials, quantities)) {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING);
return showPage(model, mixID);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING);
return showPage(modelBuilder.build(), mixID);
}
return "redirect:/" + EDITOR_RECIPE_SPECIFIC.replace("{recipeID}", String.valueOf(mix.getRecipe().getRecipeID()));
return modelBuilder.build();
}
@GetMapping(REMOVER_MIX_SPECIFIC)
public String deleteMix(Model model, @PathVariable int mixID) {
public ModelAndView deleteMix(@PathVariable int mixID) {
ModelBuilder modelBuilder = new ModelBuilder("");
Mix mix = mixService.getByID(mixID);
if (mix == null) {
model.addAttribute(RESPONSE_ERROR, MIX_NOT_FOUND);
return showPage(model, mixID);
modelBuilder.addResponseCode(ResponseCode.MIX_NOT_FOUND, String.valueOf(mixID));
return showPage(modelBuilder.build(), mixID);
}
modelBuilder.setView(redirect(EDITOR_RECIPE_SPECIFIC.replace("{recipeID}", String.valueOf(mix.getRecipe().getRecipeID()))));
if (!mixService.deleteMix(mix)) {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING);
return showPage(model, mixID);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING);
return showPage(modelBuilder.build(), mixID);
}
return "redirect:/" + EDITOR_RECIPE_SPECIFIC.replace("{recipeID}", String.valueOf(mix.getRecipe().getRecipeID()));
return modelBuilder.build();
}
}

View File

@ -1,22 +1,25 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.editors;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Recipe;
import fyloz.trial.ColorRecipesExplorer.services.CompanyService;
import fyloz.trial.ColorRecipesExplorer.services.RecipeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
import java.util.ArrayList;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.*;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@Controller
public class RecipeEditorController {
@ -40,10 +43,10 @@ public class RecipeEditorController {
* @return La page à afficher.
*/
@GetMapping(EDITOR_RECIPE)
public String listRecipes(Model model) {
model.addAttribute(RECIPES, recipeService.getRecipesByCompany());
return EDITOR_RECIPE;
public ModelAndView listRecipes(ModelAndView model) {
return new ModelBuilder(model)
.addData(ModelDataType.RECIPE_MAP, recipeService.getRecipesByCompany())
.build();
}
/**
@ -63,21 +66,24 @@ public class RecipeEditorController {
* @return La page à afficher.
*/
@GetMapping(EDITOR_RECIPE_SPECIFIC)
public String showEditPage(Model model, @PathVariable int recipeID) {
public ModelAndView showEditPage(ModelAndView model, @PathVariable int recipeID) {
ModelBuilder modelBuilder = new ModelBuilder(model)
.setView(EDITOR_RECIPE_EDITOR);
Recipe recipe = recipeService.getByID(recipeID);
if (recipe == null) {
model.addAttribute(RESPONSE_ERROR, String.format(RECIPE_NOT_FOUND, recipeID));
return listRecipes(model);
modelBuilder.addResponseCode(ResponseCode.RECIPE_NOT_FOUND, String.valueOf(recipeID));
return listRecipes(modelBuilder.build());
}
model.addAttribute(RECIPE, recipe);
model.addAttribute("recipeJSON", recipeService.asJson(recipe));
model.addAttribute(COMPANIES, companyService.getAll());
model.addAttribute(MIXES, recipeService.getSortedMixes(recipe));
model.addAttribute("images", recipeService.getImageFiles(recipe));
return EDITOR_RECIPE_EDITOR;
return modelBuilder
.addData(ModelDataType.RECIPE, recipe)
.addData(ModelDataType.COMPANIES, companyService.getAll())
.addData(ModelDataType.MIXES, new ArrayList<>(recipeService.getSortedMixes(recipe))) // Convertit le PersistentBag en ArrayList
.addData(ModelDataType.IMAGES, recipeService.getImageFiles(recipe))
.addAttribute("recipeJSON", recipeService.asJson(recipe))
.build();
}
/**
@ -94,23 +100,24 @@ public class RecipeEditorController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param recipe La recette à modifier
* @param form Le formulaire entré par l'utilisateur
* @return La page à afficher.
*/
@PostMapping(value = EDITOR_RECIPE, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String saveRecipe(Model model, @Valid Recipe recipe, @RequestBody MultiValueMap<String, Object> form) {
public ModelAndView saveRecipe(@Valid Recipe recipe, @RequestBody MultiValueMap<String, Object> form) {
ModelBuilder modelBuilder = new ModelBuilder("");
int recipeID = recipe.getRecipeID();
if (recipeService.getByID(recipeID) == null) {
model.addAttribute(RESPONSE_ERROR, String.format(RECIPE_NOT_FOUND, recipeID));
return listRecipes(model);
modelBuilder.addResponseCode(ResponseCode.RECIPE_NOT_FOUND, String.valueOf(recipeID));
return listRecipes(modelBuilder.build());
}
recipe = recipeService.createAndSetSteps(recipe, form);
model.addAttribute(RECIPE_CODE, recipe.getRecipeCode());
return listRecipes(model);
modelBuilder.addData(ModelDataType.RECIPE_CODE, recipe.getRecipeCode());
return listRecipes(modelBuilder.build());
}
}

View File

@ -1,17 +1,19 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.removers;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Company;
import fyloz.trial.ColorRecipesExplorer.services.CompanyService;
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.REMOVER_COMPANY;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.REMOVER_COMPANY_SPECIFIC;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@Controller
public class CompanyRemoverController {
@ -33,10 +35,11 @@ public class CompanyRemoverController {
* @return La page à afficher
*/
@GetMapping(REMOVER_COMPANY)
public String showPage(Model model) {
model.addAttribute(COMPANIES, companyService.getAll());
return REMOVER_COMPANY;
public ModelAndView showPage(ModelAndView model) {
return new ModelBuilder(model)
.setView(REMOVER_COMPANY)
.addData(ModelDataType.COMPANIES, companyService.getAll())
.build();
}
/**
@ -54,24 +57,25 @@ public class CompanyRemoverController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param companyID L'identifiant de la bannière
* @return La page à afficher
*/
@PostMapping(REMOVER_COMPANY_SPECIFIC)
public String removeCompany(Model model, @PathVariable int companyID) {
public ModelAndView removeCompany(@PathVariable int companyID) {
ModelBuilder modelBuilder = new ModelBuilder("");
Company company = companyService.getByID(companyID);
if (companyService.exists(company)) {
if (companyService.deleteIfNotLinked(company)) {
model.addAttribute("successCompanyName", company.getCompanyName());
modelBuilder.addData(ModelDataType.COMPANY_NAME, company.getCompanyName());
} else {
model.addAttribute(RESPONSE_ERROR, String.format(COMPANY_LINKED, company.getCompanyName()));
modelBuilder.addResponseCode(ResponseCode.COMPANY_LINKED, company.getCompanyName());
}
} else {
model.addAttribute(RESPONSE_ERROR, String.format(COMPANY_NOT_FOUND, companyID));
modelBuilder.addResponseCode(ResponseCode.COMPANY_NOT_FOUND, String.valueOf(companyID));
}
return showPage(model);
return showPage(modelBuilder.build());
}
}

View File

@ -1,19 +1,21 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.removers;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Material;
import fyloz.trial.ColorRecipesExplorer.services.MaterialService;
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.stream.Collectors;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.REMOVER_MATERIAL;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.REMOVER_MATERIAL_SPECIFIC;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@Controller
public class MaterialRemoverController {
@ -32,10 +34,11 @@ public class MaterialRemoverController {
* @return La page à afficher.
*/
@GetMapping(REMOVER_MATERIAL)
public String showPage(Model model) {
model.addAttribute(MATERIALS, materialService.getAll().stream().filter(m -> !m.isMixType()).collect(Collectors.toList()));
return REMOVER_MATERIAL;
public ModelAndView showPage(ModelAndView model) {
return new ModelBuilder(model)
.setView(REMOVER_MATERIAL)
.addData(ModelDataType.MATERIALS, materialService.getAll().stream().filter(m -> !m.isMixType()).collect(Collectors.toList()))
.build();
}
/**
@ -53,28 +56,28 @@ public class MaterialRemoverController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param materialID L'identifiant du produit à supprimer
* @return La page à afficher.
*/
@PostMapping(REMOVER_MATERIAL_SPECIFIC)
public String removeMaterial(Model model, @PathVariable int materialID) {
public ModelAndView removeMaterial(@PathVariable int materialID) {
ModelBuilder modelBuilder = new ModelBuilder("");
Material material = materialService.getByID(materialID);
if (material == null) {
model.addAttribute(RESPONSE_ERROR, String.format(MATERIAL_NOT_FOUND, materialID));
modelBuilder.addResponseCode(ResponseCode.MIX_NOT_FOUND, String.valueOf(materialID));
} else {
if (materialService.deleteIfNotLinked(material)) {
model.addAttribute(MATERIAL_CODE, material.getMaterialCode());
modelBuilder.addData(ModelDataType.MATERIAL_CODE, material.getMaterialCode());
if (!materialService.removeSimdut(material)) {
model.addAttribute(RESPONSE_ERROR, ERROR_SAVING_SIMDUT);
modelBuilder.addResponseCode(ResponseCode.ERROR_SAVING_SIMDUT);
}
} else {
model.addAttribute(RESPONSE_ERROR, String.format(MATERIAL_LINKED, material.getMaterialCode()));
modelBuilder.addResponseCode(ResponseCode.MATERIAL_LINKED, material.getMaterialCode());
}
}
return showPage(model);
return showPage(modelBuilder.build());
}
}

View File

@ -1,16 +1,18 @@
package fyloz.trial.ColorRecipesExplorer.web.controller.removers;
import fyloz.trial.ColorRecipesExplorer.core.ModelBuilder;
import fyloz.trial.ColorRecipesExplorer.core.ModelDataType;
import fyloz.trial.ColorRecipesExplorer.core.ResponseCode;
import fyloz.trial.ColorRecipesExplorer.model.Recipe;
import fyloz.trial.ColorRecipesExplorer.services.RecipeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.REMOVER_RECIPE;
import static fyloz.trial.ColorRecipesExplorer.web.PagesPaths.REMOVER_RECIPE_SPECIFIC;
import static fyloz.trial.ColorRecipesExplorer.web.StringBank.*;
@Controller
public class RecipeRemoverController {
@ -28,10 +30,11 @@ public class RecipeRemoverController {
* @return La page à afficher.
*/
@GetMapping(REMOVER_RECIPE)
public String listRecipes(Model model) {
model.addAttribute(RECIPES, recipeService.getRecipesByCompany());
return REMOVER_RECIPE;
public ModelAndView listRecipes(ModelAndView model) {
return new ModelBuilder(model)
.setView(REMOVER_RECIPE)
.addData(ModelDataType.RECIPES, recipeService.getRecipesByCompany())
.build();
}
/**
@ -49,23 +52,25 @@ public class RecipeRemoverController {
* <p>
* REQUIERT UNE AUTORISATION
*
* @param model Le Model injecté par Thymeleaf
* @param recipeID L'identifiant de la recette
* @return La page à afficher.
*/
@PostMapping(REMOVER_RECIPE_SPECIFIC)
public String removeRecipe(Model model, @PathVariable int recipeID) {
public ModelAndView removeRecipe(@PathVariable int recipeID) {
ModelBuilder modelBuilder = new ModelBuilder("");
Recipe recipe = recipeService.getByID(recipeID);
// Affiche un erreur si le recette n'est pas trouvée
if (recipe == null) {
model.addAttribute(RESPONSE_ERROR, String.format(RECIPE_NOT_FOUND, recipeID));
return listRecipes(model);
modelBuilder.addResponseCode(ResponseCode.RECIPE_NOT_FOUND, String.valueOf(recipeID));
return listRecipes(modelBuilder.build());
}
// TODO erreur dans cette méthode
recipeService.deleteRecipe(recipe);
model.addAttribute(RECIPE_CODE, recipe.getRecipeCode());
return listRecipes(model);
modelBuilder.addData(ModelDataType.RECIPE_CODE, recipe.getRecipeCode());
return listRecipes(modelBuilder.build());
}
}

View File

@ -1,5 +1,14 @@
response.1=The quantities of each material used have been deducted from the inventory
response.2=The recipe's informations have been saved
response.10=There is already a material with the code {0}
response.11=There is already a material type named {0}
response.12=Any banner with the identifier {0} has been found
response.13=There is already a banner named {0}
response.14=The material {0} is linked to one or more recipes, delete them first
response.15=The banner {0} is linked to one or more recipes, delete them first
response.16=The mix with the identifier {0} is not linked to the recipe with the identifier {1}
response.17=There is not enough {0} in inventory for this recipe
response.18=This recipe already contains a mix of the type {0}
response.2=The recipe''s informations have been saved
response.3=An error has occurred while saving
response.4=An error has occurred while saving the image
response.5=An error has occurred while saving the SIMDUT file

View File

@ -1,9 +1,18 @@
response.1=Les quantités de chaque produits utilisés ont été déduites de l'inventaire
response.1=Les quantités de chaque produits utilisés ont été déduites de l''inventaire
response.10=Il y a déjà un produit ayant le code {0}
response.11=Il y a déjà un type de produit s''appellant {0}
response.12=Aucune bannière ayant l'identifiant {0} n''a été trouvée
response.13=Il y a déjà une bannière s''appellant {0}
response.14=Le produit {0} est lié à une ou plusieurs recettes, veuillez les supprimer d'abord
response.15=La bannière {0} est liée à une ou plusieurs recettes, veuillez les supprimer d'abord
response.16=Le mélange ayant l''identifiant {0} n''est pas associé à la recette ayant l''identifiant {1}
response.17=Il n''y a pas assez de {0} en inventaire pour cette recette
response.18=Cette recette contient déjà un mélange du type {0}
response.2=Les informations de la recette ont été sauvegardées
response.3=Une erreur est survenue lors de l'enregistrement
response.4=Une erreur est survenue lors de l'enregistrement de l'image
response.5=Une erreur est survenue lors de l'enregistrement du fichier SIMDUT
response.3=Une erreur est survenue lors de l''enregistrement
response.4=Une erreur est survenue lors de l''enregistrement de l''image
response.5=Une erreur est survenue lors de l''enregistrement du fichier SIMDUT
response.6=Votre mot de passe n'est pas valide
response.7=Aucune recette ayant l'identifiant {0} n'a été trouvée
response.8=Aucun mélange ayant l'identifiant {0} n'a été trouvé
response.9=Aucun produit ayant l'identifiant {0} n'a été trouvé
response.7=Aucune recette ayant l''identifiant {0} n''a été trouvée
response.8=Aucun mélange ayant l''identifiant {0} n''a été trouvé
response.9=Aucun produit ayant l''identifiant {0} n''a été trouvé

View File

@ -12,7 +12,8 @@
<header th:include="fragments.html :: header"></header>
<!-- Corps de la page -->
<section>
<p class="error" th:text="${error}"></p>
<!-- <p class="error" th:text="${error}"></p>-->
<p th:include="fragments.html :: error"></p>
<h1 th:text="#{company.add.title}"></h1>
<div class="form">

View File

@ -26,8 +26,8 @@
<!-- Corps de la page -->
<section>
<p class="error" th:text="${error}"></p>
<p class="success" th:if="${successCompanyName != null}"
th:text="#{company.success.deleted(${successCompanyName})}"></b>
<p class="success" th:if="${companyName != null}"
th:text="#{company.success.deleted(${companyName})}"></b>
</p>
<h1 th:text="#{company.delete.title}"></h1>

View File

@ -50,6 +50,10 @@
</nav>
</div>
<div th:fragment="error">
<p th:if="${error != null && !error.isEmpty()}" class="error" th:text="#{${error}(${arg1}, ${arg2})}"></p>
</div>
<div th:fragment="separator">
<td colspan="2">
<hr/>

View File

@ -49,19 +49,19 @@
<p class="error" th:text="${error}"></p>
<div>
<th:block th:if="${!recipes.empty}">
<th:block th:each="company : ${recipes.keySet()}">
<th:block th:if="${!recipeMap.empty}">
<th:block th:each="company : ${recipeMap.keySet()}">
<h1 class="companyTabTitle" th:data-companyName="${company.companyName}"
th:text="${company.companyName}"></h1>
<th:block th:if="${!recipes.get(company).empty}">
<th:block th:if="${!recipeMap.get(company).empty}">
<table style="display:none" th:id="'recipes_' + ${company.companyName}">
<tr>
<th th:text="#{recipe.color}"></th>
<th th:text="#{recipe.description}"></th>
<th th:text="#{recipe.sample}"></th>
</tr>
<th:block th:each="recipe : ${recipes.get(company)}">
<th:block th:each="recipe : ${recipeMap.get(company)}">
<tr class="recipeRow" th:data-approbationDate="${recipe.approbationDate}">
<td th:text="${recipe.recipeCode}"></td>
<td class="centerCell recipeDescription" th:text="${recipe.recipeDescription}"></td>
@ -75,7 +75,7 @@
</th:block>
</th:block>
</th:block>
<th:block th:if="${recipes.empty}">
<th:block th:if="${recipeMap.empty}">
<b class="error" th:text="#{company.error.anyFound}"></b>
</th:block>
</div>

View File

@ -1,10 +1,7 @@
<!DOCTYPE html>
<html lang="fr" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="fragments.html :: head(#{app.title})"></th:block>
<title th:text="#{recipe.add.title}"></title>
<link href="/css/main.css" rel="stylesheet"/>
<th:block th:include="fragments.html :: head(#{recipe.add.title})"></th:block>
</head>
<body>
@ -15,8 +12,9 @@
<p class="error" th:text="${error}"></p>
<h1 th:text="#{recipe.add.title}"></h1>
<p th:text="#{recipe.sucess.saved(${recipeCode})}"></p>
<button th:onclick="'document.location.href=\'/recipe/editor/' + ${recipeID} + '\''" th:text="#{keyword.continue}"></button>
<p th:text="#{recipe.sucess.saved(${recipe.recipeCode})}"></p>
<button th:onclick="'document.location.href=\'/recipe/editor/' + ${recipe.recipeID} + '\''"
th:text="#{keyword.continue}"></button>
</section>
<!-- Fragment du pied de page -->
<footer th:include="fragments.html :: footer(null)"></footer>

View File

@ -29,17 +29,18 @@
th:text="#{recipe.success.edit(${recipeCode})}"></p>
<h1 th:text="#{recipe.edit.title}"></h1>
<th:block th:if="${!recipes.empty}" th:each="company : ${recipes.keySet()}">
<th:block th:if="${!recipeMap.empty}" th:each="company : ${recipeMap.keySet()}">
<h2 class="companyTabTitle" th:data-companyName="${company.companyName}"
th:text="${company.companyName}"></h2>
<table style="display:none" th:id="'recipes_' + ${company.companyName}" th:if="${!recipes.get(company).empty}">
<table style="display:none" th:id="'recipes_' + ${company.companyName}"
th:if="${!recipeMap.get(company).empty}">
<tr>
<th th:text="#{recipe.color}"></th>
<th th:text="#{recipe.description}"></th>
<th th:text="#{recipe.sample}"></th>
</tr>
<tr class="recipeRow" th:each="recipe : ${recipes.get(company)}"
<tr class="recipeRow" th:each="recipe : ${recipeMap.get(company)}"
th:data-approbationDate="${recipe.approbationDate}">
<td th:text="${recipe.recipeCode}"></td>
<td class="centerCell recipeDescription" th:text="${recipe.recipeDescription}"></td>
@ -51,7 +52,7 @@
</tr>
</table>
</th:block>
<b th:if="${recipes.empty}" class="error" th:text="#{company.error.anyFound}"></b>
<b th:if="${recipeMap.empty}" class="error" th:text="#{company.error.anyFound}"></b>
</section>
<!-- Fragment du pied de page -->
<footer th:include="fragments.html :: footer(null)"></footer>

Binary file not shown.