Skip to content

Commit

Permalink
Ecoscore integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Goulven.Furet authored and Goulven.Furet committed Nov 27, 2023
1 parent 2014bc0 commit c35a100
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 3 deletions.
22 changes: 22 additions & 0 deletions commons/src/main/java/org/open4goods/model/data/Score.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@ public boolean is(Integer number) {
}
}




/**
* Generate the letter score
* @return
*/
public String letter() {
Long percent = percent();

if (percent <= 20.0) {
return "A";
} else if (percent <= 40.0) {
return "B";
}else if (percent <= 60.0) {
return "C";
}else if (percent <= 80.0) {
return "D";
} else {
return "E";
}
}

@JsonIgnore
public boolean is1() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ public List<Score> realScores() {
return ret;
}

/**
*
* @return the ecoscore or null
*/
public Score ecoscore() {
// TODO : const
return scores.get("ECOSCORE");
}

/**
*
Expand Down
Binary file added ui/src/main/resources/static/icons/ecoscore/A.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/src/main/resources/static/icons/ecoscore/B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/src/main/resources/static/icons/ecoscore/C.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/src/main/resources/static/icons/ecoscore/D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/src/main/resources/static/icons/ecoscore/E.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions ui/src/main/resources/templates/inc/product-ecoscore.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@
<!-- Score -->
<div class="tab-pane fade active show" id="panel-ecoscore" role="tabpanel" aria-labelledby="panel-ecoscore">
<div>
<div class="text-center">
<img class="mt-4" width="350px" src="/icons/ecoscore.png">
<div th:if="${product.ecoscore}" class="text-center">
<img class="mt-4" width="350px" th:alt="'Ecoscore : ' + ${product.ecoscore.letter()}" th:title="'éco-score : ' + ${product.ecoscore.letter()}" th:src="'/icons/ecoscore/scoring-'+${product.ecoscore.letter()}+'.png'">
</div>
<div class="m-5">
<div th:each="score : ${product.realScores()}" class="progress-wrapper">

<div class="progress-info">
<span><img height="50" th:src="'/icons/ecoscore/'+${score.letter()}+'.png'"></span>
<span class="h4 help-pointer progress-tooltip" data-bs-toggle="tooltip" data-bs-placement="top" th:title="#{'ecoscore.' +${score.name}+'.tooltip'(${score.absValue()}, ${score.relValue()}, ${product.attributes.aggregatedAttributes.get(score.name)})}" th:classappend="'bg-'+${score.colorClassName()}" th:text="#{'score-'+${score.name}}"></span>
<div class="progress-percentage">
<!--
Expand Down

0 comments on commit c35a100

Please sign in to comment.