mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-22 08:13:20 +00:00
[CLIENT] #11 : Implémentation d'un renderer pour l'écran des statistiques
This commit is contained in:
parent
a9c67f2abe
commit
e889b091cb
@ -2,13 +2,17 @@ package com.pqt.client.gui.modules.stat_screen;
|
|||||||
|
|
||||||
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
||||||
import com.pqt.client.gui.ressources.css.GUICssTool;
|
import com.pqt.client.gui.ressources.css.GUICssTool;
|
||||||
|
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||||
|
import com.pqt.core.common_resources.statistics.StatisticFields;
|
||||||
|
import com.pqt.core.communication.GSonMessageToolFactory;
|
||||||
|
import com.pqt.core.communication.IMessageToolFactory;
|
||||||
|
import com.pqt.core.communication.IObjectParser;
|
||||||
|
import com.pqt.core.entities.product.LightweightProduct;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
class StatScreenView implements IFXComponent {
|
class StatScreenView implements IFXComponent {
|
||||||
@ -36,15 +40,48 @@ class StatScreenView implements IFXComponent {
|
|||||||
void display(Map<String, String> statistics){
|
void display(Map<String, String> statistics){
|
||||||
List<String> lines = new ArrayList<>();
|
List<String> lines = new ArrayList<>();
|
||||||
|
|
||||||
if(statistics!=null)
|
if(statistics!=null) {
|
||||||
lines.addAll(statistics.keySet()
|
|
||||||
|
lines.addAll(EnumSet.allOf(StatisticFields.class)
|
||||||
.stream()
|
.stream()
|
||||||
.map(key->String.format(" * %s : %s", key, statistics.get(key)))
|
.map(field -> {
|
||||||
|
if(statistics.containsKey(field.getStr())){
|
||||||
|
switch (field.getType()){
|
||||||
|
case SIMPLE:
|
||||||
|
return String.format("%s : %s", GUIStringTool.getStatisticFieldsRenderer().render(field), statistics.get(field.getStr()));
|
||||||
|
default :
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
if(statistics.containsKey(StatisticFields.TOP_POPULAR_PRODUCTS.getStr())){
|
||||||
|
StringBuffer sb = new StringBuffer(GUIStringTool.getStatisticFieldsRenderer().render(StatisticFields.TOP_POPULAR_PRODUCTS)).append(" :");
|
||||||
|
|
||||||
|
//TODO centraliser la récupération de la message factory, pour éviter les erreurs de aprsing quand il y aura plusieurs impl. de factory différentes
|
||||||
|
IObjectParser<List<LightweightProduct>> parser =
|
||||||
|
new GSonMessageToolFactory().getListParser(LightweightProduct.class);
|
||||||
|
|
||||||
|
List<String> products = parser.parse(statistics.get(StatisticFields.TOP_POPULAR_PRODUCTS.getStr()))
|
||||||
|
.stream()
|
||||||
|
.map(LightweightProduct::getName)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for(int i = 1; i<products.size(); i++){
|
||||||
|
sb.append("\n").append(String.format("\t%d. %s", i, products.get(i-1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.add(sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Platform.runLater(()-> {
|
Platform.runLater(()-> {
|
||||||
statTextArea.setText("");
|
statTextArea.setText("");
|
||||||
lines.forEach(line -> statTextArea.appendText(line + "\n"));
|
lines.forEach(line -> {
|
||||||
|
if(line!=null) statTextArea.appendText(" * "+line + "\n");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.pqt.client.gui.modules.stat_screen;
|
||||||
|
|
||||||
|
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||||
|
import com.pqt.client.gui.ressources.strings.IObjectStringRenderer;
|
||||||
|
import com.pqt.core.common_resources.statistics.StatisticFields;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StatisticFieldRenderer implements IObjectStringRenderer<StatisticFields> {
|
||||||
|
|
||||||
|
private final Map<StatisticFields, String> strings;
|
||||||
|
|
||||||
|
public StatisticFieldRenderer() {
|
||||||
|
strings = new HashMap<>();
|
||||||
|
strings.put(StatisticFields.TOTAL_MONEY_MADE, GUIStringTool.getTotalMoneyMadeStatFieldString());
|
||||||
|
strings.put(StatisticFields.TOTAL_SALE_WORTH,GUIStringTool.getTotalSaleWorthStatFieldString());
|
||||||
|
strings.put(StatisticFields.TOTAL_SALE_AMOUNT,GUIStringTool.getTotalSaleAmountStatFieldString());
|
||||||
|
strings.put(StatisticFields.TOP_POPULAR_PRODUCTS,GUIStringTool.getTopPopularProductsStatFieldString());
|
||||||
|
strings.put(StatisticFields.STAFF_SALE_AMOUNT,GUIStringTool.getStaffSaleAmountStatFieldString());
|
||||||
|
strings.put(StatisticFields.STAFF_SALE_WORTH,GUIStringTool.getstaffSaleWorthStatFieldString());
|
||||||
|
strings.put(StatisticFields.GUEST_SALE_AMOUNT,GUIStringTool.getGuestSaleAmountStatFieldString());
|
||||||
|
strings.put(StatisticFields.GUEST_SALE_WORTH,GUIStringTool.getGuestSaleWorthStatFieldString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String render(StatisticFields field){
|
||||||
|
//TODO faire le renderer
|
||||||
|
if(strings.containsKey(field))
|
||||||
|
return strings.get(field);
|
||||||
|
return field.getStr();
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.pqt.client.gui.ressources.strings;
|
package com.pqt.client.gui.ressources.strings;
|
||||||
|
|
||||||
|
import com.pqt.client.gui.modules.stat_screen.StatisticFieldRenderer;
|
||||||
|
import com.pqt.core.common_resources.statistics.StatisticFields;
|
||||||
import com.pqt.core.entities.product.Category;
|
import com.pqt.core.entities.product.Category;
|
||||||
import com.pqt.core.entities.product.Product;
|
import com.pqt.core.entities.product.Product;
|
||||||
import com.pqt.core.entities.sale.SaleStatus;
|
import com.pqt.core.entities.sale.SaleStatus;
|
||||||
@ -360,6 +362,47 @@ public class GUIStringTool {
|
|||||||
return String.format("%s : %s", e.getClass().getName(), e.getMessage());
|
return String.format("%s : %s", e.getClass().getName(), e.getMessage());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IObjectStringRenderer<StatisticFields> statisticFieldsRenderer = null;
|
||||||
|
|
||||||
|
public static IObjectStringRenderer<StatisticFields> getStatisticFieldsRenderer(){
|
||||||
|
if(statisticFieldsRenderer==null)
|
||||||
|
statisticFieldsRenderer = new StatisticFieldRenderer();
|
||||||
|
|
||||||
|
return statisticFieldsRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTotalMoneyMadeStatFieldString() {
|
||||||
|
return "Recette totale brute";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTotalSaleWorthStatFieldString() {
|
||||||
|
return "Valeur marchande totale brute";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTotalSaleAmountStatFieldString() {
|
||||||
|
return "Nombre total de commandes";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTopPopularProductsStatFieldString() {
|
||||||
|
return "Produits les plus populaires";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getStaffSaleAmountStatFieldString() {
|
||||||
|
return "Nombre de commandes pour le staff";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getstaffSaleWorthStatFieldString() {
|
||||||
|
return "Valeur marchande brute des ventes pour le staff";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getGuestSaleAmountStatFieldString() {
|
||||||
|
return "Nombre de commandes pour les invités";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getGuestSaleWorthStatFieldString() {
|
||||||
|
return "Valeur marchande brute des ventes pour les invités";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user