diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/configuration/InitialDataLoader.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/configuration/InitialDataLoader.java index a2d5f66..2c2be3f 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/configuration/InitialDataLoader.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/configuration/InitialDataLoader.java @@ -25,17 +25,18 @@ public class InitialDataLoader implements ApplicationListener optionalSavedMaterialType = materialTypeService.save(defaultMaterialType); if (!optionalSavedMaterialType.isPresent()) { - ColorRecipesExplorerApplication.LOGGER.warn("Échec de la création du type de produit par défaut."); + ColorRecipesExplorerApplication.LOGGER.warn(String.format("Échec de la création du type de produit par défaut '%s'.", name)); } } } diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/io/response/ResponseCode.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/io/response/ResponseCode.java index fa8dda0..702eea5 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/io/response/ResponseCode.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/io/response/ResponseCode.java @@ -27,6 +27,7 @@ public enum ResponseCode { FILE_NOT_IMAGE(24, ResponseCodeType.ERROR, 0), RECIPE_NOT_FOUND_NO_PARAMS(25, ResponseCodeType.ERROR, 0), MATERIAL_NOT_FOUND_BY_NAME(26, ResponseCodeType.ERROR, 1), + SUCCESS_DELETING_COMPANY(27, ResponseCodeType.SUCCESS, 1), // HTTP Errors _500(100, ResponseCodeType.ERROR, 0), diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Company.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Company.java index a9650e1..2c138ad 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Company.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Company.java @@ -1,73 +1,32 @@ package dev.fyloz.trial.colorrecipesexplorer.core.model; +import lombok.*; import org.hibernate.validator.constraints.Length; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; -import java.util.Objects; @Entity @Table(name = "companies") +@Data +@EqualsAndHashCode(callSuper = false) +@RequiredArgsConstructor +@NoArgsConstructor public class Company extends BeanModel implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private int companyID; + @NonNull + @NotNull @Length(min = 2, max = 50) @Column(unique = true) - @NotNull private String companyName; - public Company() { - - } - - public Company(@Length(min = 2, max = 50) @NotNull String companyName) { - this.companyName = companyName; - } - - public int getCompanyID() { - return companyID; - } - - public void setCompanyID(int companyID) { - this.companyID = companyID; - } - - public String getCompanyName() { - return companyName; - } - - public void setCompanyName(String companyName) { - this.companyName = companyName; - } - @Override public Integer getID() { return companyID; } - - @Override - public String toString() { - return "Company{" + - "companyID=" + companyID + - ", companyName='" + companyName + '\'' + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Company company = (Company) o; - return companyID == company.companyID && - Objects.equals(companyName, company.companyName); - } - - @Override - public int hashCode() { - return Objects.hash(companyID, companyName); - } } 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 a7eceb2..2289522 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 @@ -1,115 +1,53 @@ package dev.fyloz.trial.colorrecipesexplorer.core.model; +import lombok.*; import org.hibernate.annotations.ColumnDefault; import javax.persistence.*; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.io.Serializable; -import java.util.Objects; @Entity @Table(name = "materials") +@Data +@RequiredArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = false) public class Material extends BeanModel implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Integer materialID = 0; + @NonNull @NotNull @NotEmpty @Column(unique = true) private String materialCode; + @NonNull @NotNull - private float inventoryQuantity = 0; + @ColumnDefault("0") + private float inventoryQuantity; + @NonNull @NotNull @ColumnDefault("false") - private boolean isMixType = false; + private boolean isMixType; + @NonNull @NotNull @ManyToOne private MaterialType materialType; - public Material() { - - } - - public Material(@NotNull String materialCode, @NotNull float inventoryQuantity, @NotNull boolean isMixType, MaterialType materialType) { - this.materialCode = materialCode; - this.inventoryQuantity = inventoryQuantity; - this.isMixType = isMixType; - this.materialType = materialType; - } - - public Integer getMaterialID() { - return materialID; - } - - public void setMaterialID(Integer materialID) { - this.materialID = materialID; - } - - public String getMaterialCode() { - return materialCode; - } - - public void setMaterialCode(String materialCode) { - this.materialCode = materialCode; - } - - public float getInventoryQuantity() { - return inventoryQuantity; - } - - public void setInventoryQuantity(float inventoryQuantity) { - this.inventoryQuantity = inventoryQuantity; - } - - public boolean isMixType() { - return isMixType; - } - - public void setMixType(boolean mixType) { - isMixType = mixType; - } - - public MaterialType getMaterialType() { - return materialType; - } - - public void setMaterialType(MaterialType materialType) { - this.materialType = materialType; - } - @Override public Integer getID() { return materialID; } - @Override - public String toString() { - return "Material{" + - "materialID=" + materialID + - ", materialCode='" + materialCode + '\'' + - ", inventoryQuantity=" + inventoryQuantity + - ", isMixType=" + isMixType + - ", materialType=" + materialType + - '}'; + public boolean isMixType() { + return isMixType; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Material material = (Material) o; - return Objects.equals(materialID, material.materialID) && - Objects.equals(materialCode, material.materialCode); - } - - @Override - public int hashCode() { - return Objects.hash(materialID, materialCode, inventoryQuantity, isMixType, materialType); - } } 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 b9e6807..8377236 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 @@ -1,111 +1,48 @@ package dev.fyloz.trial.colorrecipesexplorer.core.model; +import lombok.*; import org.hibernate.annotations.ColumnDefault; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.List; -import java.util.Objects; @Entity +@Data +@EqualsAndHashCode(callSuper = false) +@RequiredArgsConstructor +@NoArgsConstructor public class MaterialType extends BeanModel implements Serializable { public static final String DEFAULT_MATERIAL_TYPE_NAME = "Aucun"; + public static final String BASE_MATERIAL_TYPE_NAME = "Base"; @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Integer materialTypeID; - @Column(unique = true) + @NonNull @NotNull + @Column(unique = true) private String materialTypeName; - @Column(unique = true) + @NonNull @NotNull + @Column(unique = true) private String prefix; + @NonNull @NotNull @ColumnDefault("false") - private Boolean usePercentages = false; + private Boolean usePercentages; @OneToMany @JoinColumn(name = "material_type") private List materials; - public MaterialType() { - - } - - public MaterialType(@NotNull String materialTypeName, @NotNull String prefix, @NotNull Boolean usePercentages) { - this.materialTypeName = materialTypeName; - this.prefix = prefix.toUpperCase(); - this.usePercentages = usePercentages; - } - - public Integer getMaterialTypeID() { - return materialTypeID; - } - - public void setMaterialTypeID(Integer materialTypeID) { - this.materialTypeID = materialTypeID; - } - - public String getMaterialTypeName() { - return materialTypeName; - } - - public void setMaterialTypeName(String materialTypeName) { - this.materialTypeName = materialTypeName; - } - - public String getPrefix() { - return prefix; - } - - public void setPrefix(String prefix) { - this.prefix = prefix.toUpperCase(); - } - - public Boolean getUsePercentages() { - return usePercentages; - } - - public void setUsePercentages(Boolean usePercentages) { - this.usePercentages = usePercentages; - } - - public List getMaterials() { - return materials; - } - @Override public Integer getID() { return materialTypeID; } - - @Override - public String toString() { - return "MaterialType{" + - "materialTypeID=" + materialTypeID + - ", materialTypeName='" + materialTypeName + '\'' + - ", prefix='" + prefix + '\'' + - ", usePercentages=" + usePercentages + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MaterialType that = (MaterialType) o; - return Objects.equals(materialTypeID, that.materialTypeID) && - Objects.equals(materialTypeName, that.materialTypeName) && - Objects.equals(prefix, that.prefix); - } - - @Override - public int hashCode() { - return Objects.hash(materialTypeID, materialTypeName, prefix, usePercentages, materials); - } } diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Mix.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Mix.java index 3d79705..3194bc5 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Mix.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Mix.java @@ -1,13 +1,18 @@ package dev.fyloz.trial.colorrecipesexplorer.core.model; +import lombok.*; + import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.List; -import java.util.Objects; @Entity @Table(name = "mixes") +@Data +@EqualsAndHashCode(callSuper = false) +@RequiredArgsConstructor +@NoArgsConstructor public class Mix extends BeanModel implements Serializable { @Id @@ -15,10 +20,13 @@ public class Mix extends BeanModel implements Serializable { @Basic private Integer mixID = 0; + @NonNull + @ToString.Exclude @NotNull @ManyToOne private Recipe recipe; + @NonNull @NotNull @ManyToOne private MixType mixType; @@ -29,84 +37,9 @@ public class Mix extends BeanModel implements Serializable { // Casier private String location; - public Mix() { - - } - - public Mix(@NotNull Recipe recipe, @NotNull MixType mixType, List mixQuantities) { - this.recipe = recipe; - this.mixType = mixType; - this.mixQuantities = mixQuantities; - } - - public Recipe getRecipe() { - return recipe; - } - - public void setRecipe(Recipe recipe) { - this.recipe = recipe; - } - - public Integer getMixID() { - return mixID; - } - - public void setMixID(Integer mixID) { - this.mixID = mixID; - } - - public MixType getMixType() { - return mixType; - } - - public void setMixType(MixType mixType) { - this.mixType = mixType; - } - - public List getMixQuantities() { - return mixQuantities; - } - - public void setMixQuantities(List mixQuantities) { - this.mixQuantities = mixQuantities; - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } - @Override public Integer getID() { return mixID; } - @Override - public String toString() { - return "Mix{" + - "mixID=" + mixID + -// ", recipe=" + recipe + - ", mixType=" + mixType + -// ", mixQuantities=" + mixQuantities + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Mix mix = (Mix) o; - return mixID.equals(mix.mixID) && - Objects.equals(recipe, mix.recipe) && - Objects.equals(mixType, mix.mixType) && - Objects.equals(mixQuantities, mix.mixQuantities); - } - - @Override - public int hashCode() { - return Objects.hash(mixID, recipe, mixType, mixQuantities, location); - } } diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MixQuantity.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MixQuantity.java index 71694f1..dba6b64 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MixQuantity.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MixQuantity.java @@ -1,14 +1,18 @@ package dev.fyloz.trial.colorrecipesexplorer.core.model; import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.*; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; -import java.util.Objects; @Entity @Table(name = "mixQuantities") +@Data +@EqualsAndHashCode(callSuper = false) +@RequiredArgsConstructor +@NoArgsConstructor public class MixQuantity extends BeanModel implements Serializable { @Id @@ -16,86 +20,24 @@ public class MixQuantity extends BeanModel implements Serializable { @Basic private Integer mixQuantityID = 0; + @NonNull + @ToString.Exclude + @NotNull @JsonIgnore @ManyToOne private Mix mix; + @NonNull + @NotNull @ManyToOne private Material material; + @NonNull @NotNull private Float quantity; - public MixQuantity() { - - } - - public MixQuantity(Mix mix, Material material, @NotNull Float quantity) { - this.mix = mix; - this.material = material; - this.quantity = quantity; - } - - public Integer getMixQuantityID() { - return mixQuantityID; - } - - public void setMixQuantityID(Integer mixQuantityID) { - this.mixQuantityID = mixQuantityID; - } - - public Mix getMix() { - return mix; - } - - public void setMix(Mix mix) { - this.mix = mix; - } - - public Material getMaterial() { - return material; - } - - public void setMaterial(Material material) { - this.material = material; - } - - public Float getQuantity() { - return quantity; - } - - public void setQuantity(Float quantity) { - this.quantity = quantity; - } - @Override public Integer getID() { return mixQuantityID; } - - @Override - public String toString() { - return "MixQuantity{" + - "mixQuantityID=" + mixQuantityID + - ", mix=" + mix + - ", material=" + material + - ", quantity=" + quantity + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MixQuantity that = (MixQuantity) o; - return Objects.equals(mixQuantityID, that.mixQuantityID) && - Objects.equals(mix, that.mix) && - Objects.equals(material, that.material) && - Objects.equals(quantity, that.quantity); - } - - @Override - public int hashCode() { - return Objects.hash(mixQuantityID, mix, material, quantity); - } } diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MixType.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MixType.java index 6c223bd..2fb9e39 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MixType.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/MixType.java @@ -1,84 +1,35 @@ package dev.fyloz.trial.colorrecipesexplorer.core.model; +import lombok.*; + import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; -import java.util.Objects; @Entity -@Table(name = "mixTypes") // TODO retirer @Table +@Table(name = "mixTypes") +@Data +@EqualsAndHashCode(callSuper = false) +@RequiredArgsConstructor +@NoArgsConstructor public class MixType extends BeanModel implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private int typeID; + @NonNull @NotNull - @Column(unique = true) private String typeName; + @NonNull @NotNull @OneToOne(cascade = CascadeType.ALL) @JoinColumn(name = "materialid") private Material material; - public MixType() { - - } - - public MixType(@NotNull String typeName, @NotNull Material material) { - this.typeName = typeName; - this.material = material; - } - - public int getTypeID() { - return typeID; - } - - public void setTypeID(int typeID) { - this.typeID = typeID; - } - - public String getTypeName() { - return typeName; - } - - public void setTypeName(String typeName) { - this.typeName = typeName; - } - - public Material getMaterial() { - return material; - } - - public void setMaterial(Material material) { - this.material = material; - } - @Override public Integer getID() { return typeID; } - - @Override - public String toString() { - return "MixType{" + - "typeID=" + typeID + - ", typeName='" + typeName + '\'' + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MixType mixType = (MixType) o; - return typeID == mixType.typeID && - Objects.equals(typeName, mixType.typeName); - } - - @Override - public int hashCode() { - return Objects.hash(typeID, typeName, material); - } } diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Recipe.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Recipe.java index 3c83fcc..eed7c52 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Recipe.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/Recipe.java @@ -1,34 +1,41 @@ package dev.fyloz.trial.colorrecipesexplorer.core.model; import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.*; import org.hibernate.validator.constraints.Length; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; -import java.util.ArrayList; import java.util.List; -import java.util.Objects; @Entity @Table(name = "recipes") +@Data +@EqualsAndHashCode(callSuper = false) +@RequiredArgsConstructor +@NoArgsConstructor public class Recipe extends BeanModel implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Integer recipeID = 0; - @Length(min = 2) + @NonNull @NotNull + @Length(min = 2) private String recipeCode; - @ManyToOne + @NonNull @NotNull + @ManyToOne private Company company; + @NonNull @NotNull private String recipeDescription; + @NonNull @NotNull private int sample; @@ -45,138 +52,32 @@ public class Recipe extends BeanModel implements Serializable { @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List recipeSteps; - public Recipe() { - - } - - public Recipe(@Length(min = 2) String recipeCode, @NotNull Company company, String recipeDescription, @NotNull int sample, @NotNull String approbationDate, String remark, String note) { - this.recipeCode = recipeCode; - this.company = company; - this.recipeDescription = recipeDescription; - this.sample = sample; - this.approbationDate = approbationDate; - this.remark = remark; - this.note = note; - } - - public Integer getRecipeID() { - return recipeID; - } - - public void setRecipeID(Integer recipeID) { - this.recipeID = recipeID; - } - - public String getRecipeCode() { - return recipeCode; - } - - public void setRecipeCode(String recipeCode) { - this.recipeCode = recipeCode; - } - - public Company getCompany() { - return company; - } - - public void setCompany(Company company) { - this.company = company; - } - - public String getRecipeDescription() { - return recipeDescription; - } - - public void setRecipeDescription(String recipeDescription) { - this.recipeDescription = recipeDescription; - } - - public int getSample() { - return sample; - } - - public void setSample(int sample) { - this.sample = sample; - } - - public String getApprobationDate() { - return approbationDate; - } - - public void setApprobationDate(String approbationDate) { - this.approbationDate = approbationDate; - } - - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - public String getNote() { - return note; - } - - public void setNote(String note) { - this.note = note; - } - - public List getRecipeMixes() { - return recipeMixes; - } - - public void setRecipeMixes(List recipeMixes) { - this.recipeMixes = recipeMixes; - } - - public List getRecipeSteps() { - return recipeSteps == null ? new ArrayList<>() : recipeSteps; - } - - public void setRecipeSteps(List recipeSteps) { - this.recipeSteps = recipeSteps; - } - @Override public Integer getID() { return recipeID; } - @Override - public String toString() { - return "Recipe{" + - "recipeID=" + recipeID + - ", recipeCode=" + recipeCode + - ", company=" + company + - ", recipeDescription='" + recipeDescription + - ", sample=" + sample + - ", approbationDate=" + approbationDate + - ", remark='" + remark + - ", note='" + note + - '}'; - } + public Material getBase() { + if (recipeMixes.isEmpty() || recipeMixes.stream().allMatch(m -> m.getMixQuantities().isEmpty())) return null; - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Recipe recipe = (Recipe) o; - return recipeID.equals(recipe.recipeID) && - recipeCode.equals(recipe.recipeCode) && - sample == recipe.sample && - Objects.equals(company, recipe.company) && - Objects.equals(recipeDescription, recipe.recipeDescription) && - Objects.equals(approbationDate, recipe.approbationDate) && - Objects.equals(remark, recipe.remark) && - Objects.equals(note, recipe.note) && - Objects.equals(recipeMixes, recipe.recipeMixes) && - Objects.equals(recipeSteps, recipe.recipeSteps); - } + Material base = recipeMixes + .stream() + .map(mix -> mix + .getMixQuantities() + .stream() + .filter(mq -> mq.getMaterial().getMaterialType().getMaterialTypeName().equals(MaterialType.BASE_MATERIAL_TYPE_NAME)) + .findFirst().get() + ) + .findFirst().orElse(recipeMixes + .stream() + .filter(m -> !m.getMixQuantities().isEmpty()) + .findFirst() + .get() + .getMixQuantities() + .stream() + .findFirst() + .get()).getMaterial(); - @Override - public int hashCode() { - return Objects.hash(recipeID, recipeCode, company, recipeDescription, sample, approbationDate, remark, note, recipeMixes, recipeSteps); + return base; } } diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/RecipeStep.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/RecipeStep.java index 70117ce..4aa6ea4 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/RecipeStep.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/RecipeStep.java @@ -1,85 +1,36 @@ package dev.fyloz.trial.colorrecipesexplorer.core.model; import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.*; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; -import java.util.Objects; @Entity @Table(name = "steps") +@Data +@EqualsAndHashCode(callSuper = false) +@RequiredArgsConstructor +@NoArgsConstructor public class RecipeStep extends BeanModel implements Serializable { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private int stepID; + @NonNull + @ToString.Exclude @ManyToOne(fetch = FetchType.LAZY) @JsonIgnore private Recipe recipe; + @NonNull @NotNull private String stepMessage; - public RecipeStep() { - - } - - public RecipeStep(Recipe recipe, @NotNull String stepMessage) { - this.recipe = recipe; - this.stepMessage = stepMessage; - } - - public int getStepID() { - return stepID; - } - - public void setStepID(int stepID) { - this.stepID = stepID; - } - - public String getStepMessage() { - return stepMessage; - } - - public void setStepMessage(String stepMessage) { - this.stepMessage = stepMessage; - } - - public Recipe getRecipe() { - return recipe; - } - - public void setRecipe(Recipe recipe) { - this.recipe = recipe; - } - @Override public Integer getID() { return stepID; } - - @Override - public String toString() { - return "RecipeStep{" + - "stepID=" + stepID + - ", stepMessage='" + stepMessage + '\'' + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RecipeStep recipeStep = (RecipeStep) o; - return stepID == recipeStep.stepID && - Objects.equals(stepMessage, recipeStep.stepMessage) && - Objects.equals(recipe, recipeStep.recipe); - } - - @Override - public int hashCode() { - return Objects.hash(stepID, recipe, stepMessage); - } } diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/dto/MixCreationFormDto.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/dto/MixCreationFormDto.java index 10586fb..c8ae70d 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/dto/MixCreationFormDto.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/model/dto/MixCreationFormDto.java @@ -1,5 +1,6 @@ package dev.fyloz.trial.colorrecipesexplorer.core.model.dto; +import dev.fyloz.trial.colorrecipesexplorer.core.model.MaterialType; import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe; import lombok.Data; @@ -12,6 +13,8 @@ public class MixCreationFormDto { private String mixTypeName; + private MaterialType materialType; + private List materials; private List quantities; 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 f0989c1..09e05f6 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 @@ -46,7 +46,7 @@ public class MixService extends GenericService { materials.add(found.get()); } - Optional optionalMixType = mixTypeService.createByName(formDto.getMixTypeName()); + Optional optionalMixType = mixTypeService.createByName(formDto.getMixTypeName(), formDto.getMaterialType()); if (!optionalMixType.isPresent()) return modelResponseBuilder.addResponseCode(ResponseCode.ERROR_SAVING); MixType mixType = optionalMixType.get(); @@ -54,7 +54,7 @@ public class MixService extends GenericService { return modelResponseBuilder.addResponseCode(ResponseCode.MIX_TYPE_ALREADY_USED, mixType.getTypeName()); // 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); + Mix mix = new Mix(recipe, mixType); Optional savedMix = save(mix); if (savedMix.isPresent()) { @@ -75,6 +75,7 @@ public class MixService extends GenericService { @Transactional public ModelResponseBuilder edit(Mix mix, MixCreationFormDto formDto) { ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder(); + Material material = mix.getMixType().getMaterial(); List materials = new ArrayList<>(); for (String materialCode : formDto.getMaterials()) { @@ -86,7 +87,9 @@ public class MixService extends GenericService { materials.add(found.get()); } + mix.getMixType().getMaterial().setMaterialType(formDto.getMaterialType()); mix.getMixType().setTypeName(formDto.getMixTypeName()); + material.setMaterialCode(formDto.getMixTypeName()); List mixQuantities = createMixQuantities(mix, materials, formDto.getQuantities()); @@ -96,7 +99,7 @@ public class MixService extends GenericService { } mix.setMixQuantities(mixQuantities); - if (update(mix).isPresent()) return null; + if (materialService.update(material).isPresent() && update(mix).isPresent()) return null; else return modelResponseBuilder.addResponseCode(ResponseCode.ERROR_SAVING); } diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixTypeService.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixTypeService.java index dbd70c9..751018a 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixTypeService.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/core/services/model/MixTypeService.java @@ -29,16 +29,8 @@ public class MixTypeService extends GenericService { return dao.findByMaterial(material); } - public Optional createByName(String name) { - Optional defaultType = materialTypeService.getDefaultMaterialType(); - if (!defaultType.isPresent()) return Optional.empty(); - - Optional mixTypeByName = getByName(name); - if (mixTypeByName.isPresent()) { - return mixTypeByName; - } - - Material mixTypeMaterial = new Material(name, 0, true, defaultType.get()); + public Optional createByName(String name, MaterialType type) { + Material mixTypeMaterial = new Material(name, 0f, true, type); MixType mixType = new MixType(name, mixTypeMaterial); return save(mixType); diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/creators/CompanyCreatorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/creators/CompanyCreatorController.java index 69c5328..15a29ca 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/creators/CompanyCreatorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/creators/CompanyCreatorController.java @@ -17,7 +17,7 @@ import javax.validation.Valid; import java.util.Optional; import static dev.fyloz.trial.colorrecipesexplorer.web.PagesPaths.CREATOR_COMPANY; -import static dev.fyloz.trial.colorrecipesexplorer.web.PagesPaths.CREATOR_COMPANY_SUCCESS; +import static dev.fyloz.trial.colorrecipesexplorer.web.PagesPaths.INDEX; @Controller public class CompanyCreatorController { @@ -56,7 +56,7 @@ public class CompanyCreatorController { */ @PostMapping(value = CREATOR_COMPANY, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) public ModelAndView createCompany(@ModelAttribute @Valid Company company) { - ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder(CREATOR_COMPANY_SUCCESS); + ModelResponseBuilder modelResponseBuilder = new ModelResponseBuilder().withRedirect(INDEX); if (companyService.isValidForCreation(company)) { Optional savedCompany = companyService.save(company); diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/creators/MixCreatorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/creators/MixCreatorController.java index edfbee0..b62498a 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/creators/MixCreatorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/creators/MixCreatorController.java @@ -7,10 +7,7 @@ import dev.fyloz.trial.colorrecipesexplorer.core.model.Material; import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType; import dev.fyloz.trial.colorrecipesexplorer.core.model.Recipe; import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MixCreationFormDto; -import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService; -import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MixService; -import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MixTypeService; -import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService; +import dev.fyloz.trial.colorrecipesexplorer.core.services.model.*; import dev.fyloz.trial.colorrecipesexplorer.core.utils.ControllerUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -36,13 +33,15 @@ public class MixCreatorController { private RecipeService recipeService; private MaterialService materialService; private MixTypeService mixTypeService; + private MaterialTypeService materialTypeService; @Autowired - public MixCreatorController(MixService mixService, RecipeService recipeService, MaterialService materialService, MixTypeService mixTypeService) { + public MixCreatorController(MixService mixService, RecipeService recipeService, MaterialService materialService, MixTypeService mixTypeService, MaterialTypeService materialTypeService) { this.mixService = mixService; this.recipeService = recipeService; this.materialService = materialService; this.mixTypeService = mixTypeService; + this.materialTypeService = materialTypeService; } /** @@ -79,6 +78,7 @@ public class MixCreatorController { ModelResponseBuilder responseBuilder = modelResponseBuilder .addResponseData(ResponseDataType.RECIPE, recipe) + .addResponseData(ResponseDataType.MATERIAL_TYPES, materialTypeService.getAll()) .addAttribute("materialsJson", materialService.asJson(materials)); if (materialService.getAll().isEmpty()) { diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/editors/MixEditorController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/editors/MixEditorController.java index 387f16f..ce347a2 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/editors/MixEditorController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/editors/MixEditorController.java @@ -7,10 +7,7 @@ import dev.fyloz.trial.colorrecipesexplorer.core.model.Material; import dev.fyloz.trial.colorrecipesexplorer.core.model.Mix; import dev.fyloz.trial.colorrecipesexplorer.core.model.MixType; import dev.fyloz.trial.colorrecipesexplorer.core.model.dto.MixCreationFormDto; -import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MaterialService; -import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MixService; -import dev.fyloz.trial.colorrecipesexplorer.core.services.model.MixTypeService; -import dev.fyloz.trial.colorrecipesexplorer.core.services.model.RecipeService; +import dev.fyloz.trial.colorrecipesexplorer.core.services.model.*; import dev.fyloz.trial.colorrecipesexplorer.core.utils.ControllerUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -28,7 +25,7 @@ import java.util.Optional; import java.util.stream.Collectors; import static dev.fyloz.trial.colorrecipesexplorer.web.PagesPaths.*; -import static dev.fyloz.trial.colorrecipesexplorer.web.StringBank.MIX_ID; +import static dev.fyloz.trial.colorrecipesexplorer.web.StringBank.*; @Controller public class MixEditorController { @@ -37,13 +34,15 @@ public class MixEditorController { private MaterialService materialService; private RecipeService recipeService; private MixTypeService mixTypeService; + private MaterialTypeService materialTypeService; @Autowired - public MixEditorController(MixService mixService, MaterialService materialService, RecipeService recipeService, MixTypeService mixTypeService) { + public MixEditorController(MixService mixService, MaterialService materialService, RecipeService recipeService, MixTypeService mixTypeService, MaterialTypeService materialTypeService) { this.mixService = mixService; this.materialService = materialService; this.recipeService = recipeService; this.mixTypeService = mixTypeService; + this.materialTypeService = materialTypeService; } /** @@ -79,7 +78,9 @@ public class MixEditorController { return modelResponseBuilder .addResponseData(ResponseDataType.MIX, mix) - .addResponseData(ResponseDataType.RECIPE_CODE, mix.getRecipe().getRecipeCode()) + .addResponseData(ResponseDataType.RECIPE, mix.getRecipe()) + .addAttribute(MATERIAL_TYPE, mix.getMixType().getMaterial().getMaterialType()) + .addAttribute(MATERIAL_TYPES, materialTypeService.getAll()) .addAttribute("mixJson", materialService.asJson(mix)) .addAttribute("materialsJson", materialService.asJson(materials)) .build(); diff --git a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/removers/CompanyRemoverController.java b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/removers/CompanyRemoverController.java index 2d3212a..09bef80 100644 --- a/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/removers/CompanyRemoverController.java +++ b/src/main/java/dev/fyloz/trial/colorrecipesexplorer/web/controller/removers/CompanyRemoverController.java @@ -71,11 +71,9 @@ public class CompanyRemoverController { if (optionalCompany.isPresent()) { Company company = optionalCompany.get(); - if (companyService.deleteIfNotLinked(company)) { - modelResponseBuilder.addResponseData(ResponseDataType.COMPANY_NAME, company.getCompanyName()); - } else { - modelResponseBuilder.addResponseCode(ResponseCode.COMPANY_LINKED, company.getCompanyName()); - } + if (companyService.deleteIfNotLinked(company)) + modelResponseBuilder.addResponseCode(ResponseCode.SUCCESS_DELETING_COMPANY, company.getCompanyName()); + else modelResponseBuilder.addResponseCode(ResponseCode.COMPANY_LINKED, company.getCompanyName()); } else { modelResponseBuilder.addResponseCode(ResponseCode.COMPANY_NOT_FOUND, companyID); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d12f327..05c2ad6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -18,10 +18,14 @@ spring: h2: console: enabled: true + path: /dbconsole + settings: + trace: true + web-allow-others: true server: port: 9090 error: whitelabel: enabled: false response: - useport: true \ No newline at end of file + useport: true diff --git a/src/main/resources/lang/messages_en.properties b/src/main/resources/lang/messages_en.properties index 4c132e0..5aa7c36 100644 --- a/src/main/resources/lang/messages_en.properties +++ b/src/main/resources/lang/messages_en.properties @@ -1,5 +1,5 @@ company.form.companyName=Banner name -menu.list=List +menu.explore=Explore menu.add=Add menu.edit=Edit menu.delete=Delete @@ -100,3 +100,6 @@ recipe.warning.exportAll=Do you really want to export all the colors? This can t 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? +keyword.images=Images +warning.askChangePage=Are you sure you want to continue? Unsaved changes will be lost. +keyword.print=Print diff --git a/src/main/resources/lang/messages_fr.properties b/src/main/resources/lang/messages_fr.properties index 9c6128d..57f87e0 100644 --- a/src/main/resources/lang/messages_fr.properties +++ b/src/main/resources/lang/messages_fr.properties @@ -1,4 +1,4 @@ -menu.list=Listes +menu.explore=Explorer menu.add=Ajouter menu.edit=Modifier menu.delete=Supprimer @@ -100,4 +100,7 @@ recipe.warning.exportAll=Voulez-vous vraiment exporter toutes les couleurs? Cela 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? +keyword.images=Images +warning.askChangePage=Êtes-vous sûr de vouloir continuer? Les modifications non enregistrées seront perdues. +keyword.print=Imprimer diff --git a/src/main/resources/lang/responses_en.properties b/src/main/resources/lang/responses_en.properties index cf314b5..a3188aa 100644 --- a/src/main/resources/lang/responses_en.properties +++ b/src/main/resources/lang/responses_en.properties @@ -26,4 +26,5 @@ response.22=No companies were found response.23=No materials were found. response.24=This file need to be an image response.25=The recipe was not found -response.26=The material with the code {0} was not found \ No newline at end of file +response.26=The material with the code {0} was not found +response.27=The banner {0} has been delete diff --git a/src/main/resources/lang/responses_fr.properties b/src/main/resources/lang/responses_fr.properties index 978b402..dfa5e68 100644 --- a/src/main/resources/lang/responses_fr.properties +++ b/src/main/resources/lang/responses_fr.properties @@ -26,4 +26,5 @@ response.22=Aucune compagnie n'a été trouvée response.23=Aucun produit n'a été trouvée. response.24=Ce fichier doit être une image response.25=La recette n'a pas été trouvée -response.26=Le produit ayant le code {0} n''a pas été trouvé \ No newline at end of file +response.26=Le produit ayant le code {0} n''a pas été trouvé +response.27=La bannière {0} a bien été supprimée diff --git a/src/main/resources/static/css/explore.css b/src/main/resources/static/css/explore.css new file mode 100644 index 0000000..b2821f1 --- /dev/null +++ b/src/main/resources/static/css/explore.css @@ -0,0 +1,168 @@ +.mix { + width: 600px; +} + +p { + display: inline; +} + +.mixContainer { + display: flex; + padding: 20px 0; + border-style: solid; + border-width: 1px 0; + border-color: #555555; +} + +.mixContainer:first-child { + border-top-color: white; +} + +.mixContainer:last-child { + border-bottom-color: white; +} + +.mixContainer .mixInfo { + width: 130px; + text-align: left; +} + +.mixContainer .mix { + max-width: 600px; +} + +.mixContainer .mixActionsContainer { + margin-left: 15px; + display: flex; + flex-direction: column; +} + +.mix td, .mix th { + padding: 0 5px; +} + +.notEnough td { + background-color: #ffb3b3; +} + +.quantityColumn, .mix input { + width: 50px; +} + +.totalQuantityLabel { + padding-right: 10px; + text-align: right; + vertical-align: middle; +} + +.inventoryQuantity { + display: none; +} + +.inventoryQuantityColumn { + min-width: auto !important; + width: auto !important; +} + +.unitsColumn { + width: 25px !important; + min-width: 0 !important; + max-width: 25px !important; +} + +.calculationColumn { + max-width: 125px !important; + min-width: 100px; +} + +.calculation { + color: dimgrey; +} + +.calculation span { + color: darkgreen; +} + +.materialCodeColumn { + min-width: 100px; +} + +.recipeLocation { + width: 55px; +} + +.recipeDescription { + display: flex; + flex-direction: column; + text-align: left; +} + +.recipeDescription div { + border-color: #555555; + border-width: 1px 0; + border-style: solid; + padding: 10px 0; +} + +.recipeDescription div:first-child { + border-top-color: white; +} + +.recipeDescription div:nth-last-child(2) { + border-bottom-color: white; +} + +.recipeDescription div b { + float: left; +} + +.recipeDescription div :not(b) { + float: right; + margin: 0 0 0 20px; + max-width: 350px; +} + +.steps { + text-align: left; +} + +.steps li { + padding: 5px; +} + +.steps li:nth-child(even) { + background-color: #f5f5f5; + margin: 0; +} + +.steps li:nth-child(odd) { + background-color: #fafafa; +} + +.imagesContainer { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: center; + padding: 20px; +} + +.imagesContainer img { + margin: 10px; + border: 1px solid #7a7a7a; + transition: all 0.5s; +} + +.imagesContainer .recipeImage:hover { + width: 420px; +} + +.imagesContainer.hovering .recipeImage:not(:hover) { + opacity: 0.5; +} + +@media only screen and (max-width: 1900px) { + .imagesContainer { + width: 50%; + } +} diff --git a/src/main/resources/static/css/flex.css b/src/main/resources/static/css/flex.css new file mode 100644 index 0000000..5626e63 --- /dev/null +++ b/src/main/resources/static/css/flex.css @@ -0,0 +1,14 @@ +.content { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: center; + margin-left: 50px; + margin-right: 50px; +} + +.content .flexContent { + padding: 20px; +} + + diff --git a/src/main/resources/static/css/form.css b/src/main/resources/static/css/form.css new file mode 100644 index 0000000..dff7ea2 --- /dev/null +++ b/src/main/resources/static/css/form.css @@ -0,0 +1,57 @@ +label { + font-weight: bold; +} + +.content { + flex-direction: column; +} + +.formWrap, .formEndButtons { + display: flex; + flex-direction: row; + justify-content: center; +} + +.formEndButtons button[type="button"] { + margin-right: 75px; +} + +.formEndButtons button[type="submit"] { + margin-left: 75px; +} + +.formColumn { + display: flex; + flex-direction: column; + text-align: left; +} + +.formColumn div { + min-height: 25px; + line-height: 25px; +} + +.formColumn select, .formColumn input, .formColumn button { + float: right; +} + +.formColumn input[type="text"], .formColumn input[type="number"], .formColumn input[type="date"], .formColumn select { + width: 145px; +} + +.formColumn:first-child { + margin-right: 20px; +} + +.formColumn:last-child { + margin-left: 20px; +} + +.rawInput:not(textarea):not(.noStyle) { + border-bottom-color: #7a7a7a; + color: #454545; +} + +.rawInput:hover:not(textarea):not(.noStyle) { + border-bottom-color: #7a7a7a; +} diff --git a/src/main/resources/static/css/forms.css b/src/main/resources/static/css/forms.css deleted file mode 100644 index 137ae42..0000000 --- a/src/main/resources/static/css/forms.css +++ /dev/null @@ -1,8 +0,0 @@ -.form { - display: inline-block; - margin-top: 10px; -} - -td:not(.centerTd) { - text-align: right; -} \ No newline at end of file diff --git a/src/main/resources/static/css/main.css b/src/main/resources/static/css/main.css index 142611e..3b6f84c 100644 --- a/src/main/resources/static/css/main.css +++ b/src/main/resources/static/css/main.css @@ -1,61 +1,18 @@ body { margin: 0; font-family: 'Open Sans', sans-serif; -} - -td { - vertical-align: top; -} - -th { - background-color: black; - color: white; - font-weight: normal; - font-size: large; + overflow-x: hidden; } h1 { text-decoration: underline; } -header, footer { - background-color: black; - height: 70px; - text-align: center; - width: 100%; - color: white; -} - -footer { - position: fixed; - height: 5%; - bottom: 0; - padding-top: 10px; -} - -header img { - float: right; -} - section { text-align: center; margin-bottom: 50px; } -nav { - overflow: hidden; - background-color: black; -} - -nav a { - float: left; - font-size: 18px; - color: white; - text-align: center; - padding: 14px 16px; - text-decoration: none; -} - footer a { color: white; text-decoration: none; @@ -109,85 +66,44 @@ input[type=number] { -moz-appearance: textfield; } -table { - border-collapse: collapse; -} - textarea { - font-family: 'Open Sans', sans-serif; - background-color: #fafafa; - border-style: solid; - border-color: #7a7a7a; - border-width: 1px; + font-family: inherit; + border: 1px solid #7a7a7a; margin-left: 20px; padding: 10px; } -.dropdown { - margin-top: 22px; - float: left; - overflow: hidden; +/*.error {*/ +/* color: red;*/ +/*}*/ + +/*.success {*/ +/* color: green;*/ +/*}*/ + +/*.error, .success {*/ +/* font-weight: bold;*/ +/*}*/ + +table { + border-collapse: collapse; } -.dropdown .dropbtn { - font-size: 16px; - border: none; - color: white; - outline: none; - padding: 14px 16px; - background-color: inherit; - font-family: inherit; - margin: 0; -} - -nav a:hover, .dropdown:hover .dropbtn { - background-color: #0d0d0d; -} - -.dropdown-content { - display: none; - position: absolute; - background-color: #0d0d0d; - min-width: 160px; - box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); - z-index: 1; -} - -.dropdown-content a { - float: none; - color: white; - padding: 12px 16px; - text-decoration: none; - display: block; +table:not(.noStyle) { + background-color: #f5f5f5; + border: 1px solid #7a7a7a; text-align: left; } -.dropdown-content a:hover { - background-color: #1a1a1a; +table:not(.noStyle) th { + background-color: black; + color: white; + font-weight: normal; + font-size: large; } -.dropdown:hover .dropdown-content { - display: block; -} - -.error { - color: red; -} - -.success { - color: green; -} - -.error, .success { - font-weight: bold; -} - -.mainTable { - border-spacing: 30px; -} - -.mainTableEndButtons { - text-align: center; +table:not(.noStyle) tr:nth-child(odd) { + background-color: #fafafa; } .nosimdut td { @@ -199,7 +115,7 @@ nav a:hover, .dropdown:hover .dropbtn { } .unapproved { - background-color: #fff0b3; + background-color: #fff0b3 !important; } #researchBoxContainer { @@ -254,28 +170,38 @@ nav a:hover, .dropdown:hover .dropbtn { .messageBox p { display: inline-block; - /*padding: 3px 0;*/ margin: 0 0 0 16px; line-height: 24px; } -/*.errorBox div {*/ -/* height: 24px;*/ -/* !*padding: 20px;*!*/ -/* margin: auto;*/ -/* vertical-align: middle;*/ -/*}*/ +.subtitle { + padding: 0 !important; + text-align: center; +} -/*.errorBox img {*/ -/* display: inline-block;*/ -/* float: left;*/ -/* height: 25px;*/ -/*}*/ +.rawInput:not(.noStyle) { + border-color: white; + color: #7a7a7a; + text-align: right; +} -/*.errorBox p {*/ -/* !*float: left;*!*/ -/* display: inline-block;*/ -/* font-size: 18px;*/ -/* margin: auto;*/ -/* padding: 2px 0;*/ -/*}*/ +.rawInput:hover:not(.noStyle) { + border-color: #e6e6e6; +} + +.rawInput:focus:not(.noStyle) { + border-color: #7a7a7a; + color: black; +} + +.formEndButtons { + margin-top: 10px; +} + +.returnButton { + float: left; +} + +.submitButton { + float: right; +} diff --git a/src/main/resources/static/css/menu.css b/src/main/resources/static/css/menu.css new file mode 100644 index 0000000..c330a6d --- /dev/null +++ b/src/main/resources/static/css/menu.css @@ -0,0 +1,87 @@ +header, footer { + background-color: black; + height: 70px; + text-align: center; + width: 100%; + color: white; +} + +footer { + position: fixed; + height: 5%; + bottom: 0; + padding-top: 10px; +} + +nav img { + margin-left: auto; +} + +nav { + display: flex; + flex-wrap: wrap; + overflow: visible; + background-color: inherit; +} + +nav a { + float: left; + font-size: 18px; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +.dropdown { + margin-top: 22px; + float: left; + overflow: hidden; + background-color: inherit; +} + +.dropdown .dropbtn { + font-size: 16px; + border: none; + color: white; + outline: none; + padding: 14px 16px; + background-color: inherit; + margin: 0; +} + +nav a:hover, .dropdown:hover .dropbtn { + background-color: #0d0d0d; +} + +.dropdown-content { + display: none; + position: absolute; + background-color: #0d0d0d; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); + z-index: 1; +} + +.dropdown-content a { + float: none; + color: white; + padding: 12px 16px; + text-decoration: none; + display: block; + text-align: left; +} + +.dropdown-content a:hover { + background-color: #1a1a1a; +} + +.dropdown:hover .dropdown-content { + display: block; +} + +@media only screen and (max-width: 702px) { + nav img { + display: none; + } +} diff --git a/src/main/resources/static/css/mix.css b/src/main/resources/static/css/mix.css index ac7471f..974c960 100644 --- a/src/main/resources/static/css/mix.css +++ b/src/main/resources/static/css/mix.css @@ -4,6 +4,10 @@ width: 150px; } +.materialSelector { + position: relative; +} + .materialSelector .materialList { border-color: #7a7a7a; border-width: 1px; @@ -12,9 +16,10 @@ max-height: 300px; overflow: auto; overflow-x: hidden; - position: fixed; - width: 150px; - z-index: 99; + position: absolute; + top: 100%; + width: 200px; + z-index: 10; } .materialSelector .materialList.show { @@ -36,6 +41,70 @@ background-color: #e6e6e6; } -.unitsColumn { - vertical-align: middle; +.materialListWrap { + display: flex; + flex-direction: column; +} + +.mixMaterialListTitle { + background-color: black; + color: white; +} + +.mixMaterialListTitle div { + display: block !important; + margin: auto; +} + +.materialListWrap div { + display: flex; + flex-direction: row; +} + +.mixMaterialList { + flex-direction: column !important; + background-color: #f5f5f5; + border-style: solid; + border-width: 1px; + border-color: #7a7a7a; +} + +.materialListRow:nth-child(odd) { + background-color: #fafafa; +} + +.material, .material *, .quantity, .quantity * { + width: 200px; +} + +.material input { + text-align: left; + padding: 0 10px; +} + +.quantity input { + text-align: right; + padding: 0 10px; +} + +.units, .units * { + width: 40px; +} + +.removeButton, .removeButton * { + width: 100px; +} + +.positionButtons { + display: flex !important; + flex-direction: column !important; + width: 50px; + padding: 1px 3px 1px 1px; + /*border-bottom: solid 1px #7a7a7a;*/ +} + +.positionButtons button { + margin: 1px; + width: inherit; + height: 50%; } diff --git a/src/main/resources/static/css/recipesList.css b/src/main/resources/static/css/recipesList.css new file mode 100644 index 0000000..4faaa30 --- /dev/null +++ b/src/main/resources/static/css/recipesList.css @@ -0,0 +1,43 @@ +h1 { + margin-bottom: 0; +} + +.content { + flex-direction: column; +} + +.content .recipesList { + border-collapse: collapse; + margin: 0 auto; + text-align: center; +} + +h1, h2 { + margin: 0 0 10px; +} + +h1 { + margin-top: 10px; +} + +.recipesList th { + padding: 0 15px; +} + +.recipesList td { + padding: 0 20px; +} + +.recipeDescription { + max-width: 400px; +} + +.descriptionCell { + border-right-color: #e6e6e6; + border-right-style: solid; + border-right-width: 2px; +} + +.researchEnabled .companyTab:not(.researchResult), .researchEnabled .recipeRow:not(.researchResult) { + display: none; +} diff --git a/src/main/resources/static/js/main.js b/src/main/resources/static/js/main.js index e009861..990feeb 100644 --- a/src/main/resources/static/js/main.js +++ b/src/main/resources/static/js/main.js @@ -6,30 +6,24 @@ const warningMsgBoxText = warningMsgBox.querySelector("p"); const successMsgBox = document.querySelector(".successBox"); const successMsgBoxText = successMsgBox.querySelector("p"); -// Ne fonctionne pas dans window#load -(() => { - // Ajoute Axios - const axiosElement = document.createElement("script"); - axiosElement.src = "/js/libs/axios.min.js"; - body.appendChild(axiosElement); +$(() => { + $('.materialCode').each(function () { + const row = $(this); + const materialID = row.data("materialid"); - axiosElement.onload = () => { - // Vérifie si les SIMDUTs sont présents - document.querySelectorAll(".materialCode").forEach(e => { - const materialID = e.getAttribute("data-materialID"); - axios.post(`/simdut/${materialID}`) - .catch(err => { - if (err.response.status === 404) { - e.parentElement.classList.add("nosimdut"); - e.parentElement.title = simdutNotFoundText; - } - }); - }); - }; + axios.post(`/simdut/${materialID}`) + .catch(function (err) { + if (err.response.status === 404) { + row.parent().addClass("nosimdut"); + row.parent().title = simdutNotFoundText; + } + }); + }); - // Placé ici pour un chargement plus rapide - document.querySelectorAll(".messageBox").forEach(e => checkMessageBoxesDisplay(e)); -})(); + $(".messageBox").each(function () { + checkMessageBoxesDisplay($(this)[0]) + }); +}); window.addEventListener("load", () => { @@ -64,9 +58,7 @@ window.addEventListener("load", () => { e.querySelectorAll(".remover").forEach(elem => { elem.addEventListener("click", () => { e.action += elem.getAttribute("data-entityID"); - e.onsubmit = () => { - return checkPassword(e); - } + checkPassword(e); }); }); }); @@ -84,6 +76,10 @@ window.addEventListener("load", () => { }); }); + document.querySelectorAll('input[type="text"], input[type="number"], input[type="date"], textarea').forEach(e => e.classList.add("rawInput")) + + document.querySelectorAll(".rawInput").forEach(e => e.placeholder = "N/A"); + window.addEventListener("keyup", e => { if (e.target) { if (e.target.classList.contains("toSave")) { @@ -108,32 +104,33 @@ function checkPassword(form, callback) { hideElement(errorMsgBox); const password = prompt(askPasswordText); + if (!password) return false; let data = {}; data.password = password; axios.post("/password/valid", data) .then(r => { - if (r.data) { + if (r.data === true) { if (form != null) form.submit(); if (callback != null) callback(); return true; } else { errorMsgBoxText.innerText = invalidPasswordText; showElement(errorMsgBox); - return false; } }) .catch(e => { errorMsgBoxText.innerText = generalErrorText; showElement(errorMsgBox); console.log(e); - return false; }); + + return false; } function checkMessageBoxesDisplay(element) { - if (!element.querySelector("p").innerText) hideElement(element); + if (!element.querySelector("p").textContent) hideElement(element); else showElement(element); } @@ -142,7 +139,7 @@ function hideElement(element) { } function showElement(element) { - element.style.display = "inline-block"; + element.style.display = ""; } const lTomL = 1000; @@ -151,17 +148,19 @@ const galTomL = 3785.41; let currentUnit = "mL"; // Change les unités selon la sélection de l'utilisateur -function changeUnits(unitSelect, quantitiesSelector, unitsSelector) { +function changeUnits(unitSelect, quantitiesSelector, unitsDisplay) { currentUnit = unitSelect.value; - document.querySelectorAll(unitsSelector).forEach(e => { + document.querySelectorAll(unitsDisplay).forEach(e => { e.innerText = currentUnit; // Modifie la quantitée const quantityElem = e.parentElement.parentElement.querySelector(quantitiesSelector); - const originalQuantity = parseInt(quantityElem.dataset.quantityml); + if (quantityElem) { + const originalQuantity = parseInt(quantityElem.dataset.quantityml); - quantityElem.innerText = convertMlToUnit(originalQuantity); + quantityElem.innerText = convertMlToUnit(originalQuantity); + } }); } diff --git a/src/main/resources/static/js/mix.js b/src/main/resources/static/js/mix.js index 4585783..8aca781 100644 --- a/src/main/resources/static/js/mix.js +++ b/src/main/resources/static/js/mix.js @@ -7,7 +7,7 @@ let removeText; let materialSelectorHtml; let recipeID; -window.addEventListener("load", () => { +$(() => { recipeID = document.querySelector("#recipeID").value; axios.get(`/mix/selector/${recipeID}/-1`) @@ -16,65 +16,115 @@ window.addEventListener("load", () => { init(); }) .catch(e => { + console.log(e.status); errorMsgBoxText.innerText = generalErrorText; showElement(errorMsgBox); console.log(e); }); }); -window.addEventListener("click", e => { - if (e.target) { - if (e.target.classList.contains("rowRemover")) { - document.querySelector(`#row_${e.target.dataset.remove}`).remove(); - return; - } - - const materialSelector = e.target.parentElement; - if (materialSelector == null || materialSelector.parentElement == null) { - hideMaterialList(); - return; - } - if (!materialSelector.classList.contains("materialSelector") && !materialSelector.parentElement.classList.contains("materialSelector")) hideMaterialList(); - } +$(document).on("click", function () { + hideMaterialList(); }); -document.querySelector("#materials button").addEventListener("click", () => { +$(document).on("click", ".materialSelector", function (event) { + event.stopPropagation(); + showMaterialList($(this)[0]); +}); + +$(document).on("click", ".removeMaterial", function () { + const id = $(this).data("removerow"); + if ($(".materialListRow").length > 1) $(`#${id}`).remove(); +}); + +$(document).on("click", ".upRow", function () { + const row = $(this).parent().parent(); + row.insertBefore(row.prev()); +}); + +$(document).on("click", ".downRow", function () { + const row = $(this).parent().parent(); + row.insertBefore(row.next()); +}); + +document.querySelector(".mixMaterialListTitle button").addEventListener("click", () => { addMaterial(null, null); }); function addMaterial(materialCode, quantity) { - let row = addRow(); + const row = addRow(materialNbr); + const positionColumn = addColumn("positionButtons", row); + const materialColumn = addColumn("material", row); + const quantityColumn = addColumn("quantity", row); + const unitsColumn = addColumn("units", row); + const removeButtonColumn = addColumn("removeButton", row); - let materialSelectionColumn = addColumn(row, null); - let quantityInputColumn = addColumn(row, null); - let unitsColumn = addColumn(row, "unitsColumn"); - let removeButtonColumn = addColumn(row, null); + addPositionButtons(positionColumn); + addQuantityInput(quantity, quantityColumn); + addUnits(unitsColumn); + addRemoveButton(materialNbr, removeButtonColumn); - addInput(quantityInputColumn, quantity); - addSpan(unitsColumn); - addButton(removeButtonColumn); - - materialSelectionColumn.innerHTML = materialSelectorHtml; - const input = materialSelectionColumn.querySelector("input"); + materialColumn.innerHTML = materialSelectorHtml; + const materialSelector = materialColumn.querySelector("input"); if (materialCode) { - const material = materialSelectionColumn.querySelector(`.materialList p[data-materialcode="${materialCode}"]`); + const material = materialColumn.querySelector(`.materialList p[data-materialcode="${materialCode}"]`); if (material) { - input.value = material.dataset.materialcode; - input.dataset.usepercentages = material.dataset.usepercentages; + materialSelector.value = material.dataset.materialcode; + materialSelector.dataset.usepercentages = material.dataset.usepercentages; } } - document.querySelector("#materials tbody").appendChild(row); - materialNbr++; + row.appendChild(materialColumn); + row.appendChild(quantityColumn); + row.appendChild(unitsColumn); + row.appendChild(removeButtonColumn); - checkUnits(input, row); + document.querySelector(".mixMaterialList").appendChild(row); + + checkUnits(materialSelector, row); + materialNbr++; } -function addInput(parent, quantity) { +function addRow(index) { + const row = document.createElement("div"); + row.classList.add("materialListRow"); + row.id = `material_${index}`; + return row; +} + +function addColumn(type, parent) { + const column = document.createElement("div"); + column.classList.add(type); + + parent.appendChild(column); + return column; +} + +function addUnits(parent) { + const units = document.createElement("p"); + units.classList.add("quantityUnits"); + units.textContent = "mL"; + + parent.appendChild(units); + return units; +} + +function addRemoveButton(index, parent) { + const button = document.createElement("button"); + button.type = "button"; + button.textContent = removeText; + button.dataset.removerow = `material_${index}`; + button.classList.add("removeMaterial"); + + parent.appendChild(button); + return button; +} + +function addQuantityInput(quantity, parent) { let input = document.createElement("input"); - if (quantity === null) quantity = 1; + if (quantity === undefined || quantity === null) quantity = 1; input.type = "number"; input.name = "quantities"; @@ -87,41 +137,18 @@ function addInput(parent, quantity) { return input; } -function addSpan(parent) { - let span = document.createElement("span"); +function addPositionButtons(parent) { + const up = document.createElement("button"); + up.classList.add("upRow"); + up.type = "button"; + up.textContent = "↑"; + parent.appendChild(up); - span.className = "quantityUnit"; - span.innerText = "mL"; - - parent.appendChild(span); - return span; -} - -function addButton(parent) { - let button = document.createElement("button"); - - button.type = "button"; - button.dataset.remove = materialNbr; - button.className = "rowRemover"; - button.innerText = removeText; - - parent.appendChild(button); - return button; -} - -function addRow() { - let row = document.createElement("tr"); - row.id = `row_${materialNbr}`; - - return row; -} - -function addColumn(parent, className) { - let column = document.createElement("td"); - if (className != null) column.className = className; - - parent.appendChild(column); - return column; + const down = document.createElement("button"); + down.classList.add("downRow"); + down.type = "button"; + down.textContent = "↓"; + parent.appendChild(down); } function showMaterialList(input) { @@ -152,7 +179,7 @@ function searchMaterial(input) { materials = input.parentElement.querySelectorAll(".materialList p"); materials.forEach(e => { - if (searchIn(filter, e.textContent) || searchIn(filter, e.dataset.materialType)) e.style.display = ""; + if (searchIn(filter, e.textContent) || searchIn(filter, e.dataset.materialtype)) e.style.display = ""; else e.style.display = "none"; }); @@ -163,7 +190,7 @@ function searchMaterial(input) { } function checkUnits(materialSelector, row) { - const quantityUnits = row.querySelector(".quantityUnit"); + const quantityUnits = row.querySelector(".quantityUnits"); if (materialSelector.dataset.usepercentages === "true") quantityUnits.innerText = "%"; else quantityUnits.innerText = "mL"; } diff --git a/src/main/resources/static/js/recipeResearch.js b/src/main/resources/static/js/recipeResearch.js new file mode 100644 index 0000000..5bb866b --- /dev/null +++ b/src/main/resources/static/js/recipeResearch.js @@ -0,0 +1,72 @@ +(() => { + document.querySelectorAll(".recipeRow").forEach(e => { + if (e.dataset.approbationdate === undefined) { + e.classList.add("unapproved"); + e.title = recipeNotApproved; + } + }); +})(); + +function closeTabs() { + document.querySelectorAll(".recipesList").forEach(l => l.style.display = "none"); +} + +function openTabs() { + document.querySelectorAll(".recipesList").forEach(l => l.style.display = ""); +} + +const companyRows = document.querySelectorAll(".companyTab"); + +function performSearch(searchString) { + let found = false; + let emptySearch = false; + + const recipesContainer = document.querySelector(".recipesContainer:not(.researchEnabled)"); + if (recipesContainer !== undefined && recipesContainer !== null) { + recipesContainer.classList.add("researchEnabled"); + } + + document.querySelectorAll(".researchResult").forEach(t => { + t.classList.remove("researchResult"); + }); + + companyRows.forEach(c => { + const recipeRows = c.querySelectorAll(".recipeRow"); + + hideElement(warningMsgBox); + + if (!searchString || !searchString.replace(/\s/g, '').length) { + c.classList.add("researchResult"); + + recipeRows.forEach(r => { + r.classList.add("researchResult"); + }); + + found = true; + emptySearch = true; + } else if (searchIn(searchString, c.querySelector("h2").dataset.companyname)) { + c.classList.add("researchResult"); + recipeRows.forEach(r => r.classList.add("researchResult")); + found = true; + } else { + recipeRows.forEach(r => { + r.querySelectorAll(".descriptionCell").forEach(d => { + if (searchIn(searchString, d.textContent)) { + r.classList.add("researchResult"); + c.classList.add("researchResult"); + found = true; + } + }); + }); + } + + if (!found) { + warningMsgBoxText.innerText = researchNotFound; + showElement(warningMsgBox); + } + + if (emptySearch) closeTabs(); + else openTabs(); + } + ); +} diff --git a/src/main/resources/templates/company/created.html b/src/main/resources/templates/company/created.html deleted file mode 100644 index fe0ab69..0000000 --- a/src/main/resources/templates/company/created.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - -
- -
-

-

- -
- -
- - - - diff --git a/src/main/resources/templates/company/creator.html b/src/main/resources/templates/company/creator.html index a393d48..0c0a50f 100644 --- a/src/main/resources/templates/company/creator.html +++ b/src/main/resources/templates/company/creator.html @@ -1,10 +1,7 @@ - - - - + @@ -15,22 +12,29 @@

-
-
- - - - - - -
-
-
+
+
+
+
+ +
+
+ +
+
+
+
+
- diff --git a/src/main/resources/templates/company/remover.html b/src/main/resources/templates/company/remover.html index b0360e0..ef05ef3 100644 --- a/src/main/resources/templates/company/remover.html +++ b/src/main/resources/templates/company/remover.html @@ -1,9 +1,7 @@ - - - + + @@ -48,45 +9,49 @@
- +
-
+

+ +
-

+

- + -
- + +
- + diff --git a/src/main/resources/templates/inventory.html b/src/main/resources/templates/inventory.html index 418b018..07ca00a 100644 --- a/src/main/resources/templates/inventory.html +++ b/src/main/resources/templates/inventory.html @@ -2,7 +2,7 @@ - + @@ -59,36 +68,58 @@

- +
- +
+
+
+ + + + - - - - + + - - + + - - + - - + + + + + + + +
+ +
mL + +
+ + +
+
- +
-
-
+
+
-
-
+
+
- +
+
+ - - - - - - mL - - - - - - - -
@@ -135,6 +149,8 @@ + diff --git a/src/main/resources/templates/recipe/remover.html b/src/main/resources/templates/recipe/remover.html index eb8c979..ab4432e 100644 --- a/src/main/resources/templates/recipe/remover.html +++ b/src/main/resources/templates/recipe/remover.html @@ -1,42 +1,7 @@ - - - + @@ -44,43 +9,51 @@
+
+ +
+
-

-
- -

- - - - - - - - - - - - - -
- -
-
- -
+
+
+
+

+ + + + + + + + + + + + + + + +
+
+ + +
- + diff --git a/src/main/resources/templates/updates.html b/src/main/resources/templates/updates.html index b9b18d6..bb6f0f9 100644 --- a/src/main/resources/templates/updates.html +++ b/src/main/resources/templates/updates.html @@ -1,7 +1,7 @@ - +