From e889b091cb980a1cb86026a5855d2222b5b1f141 Mon Sep 17 00:00:00 2001 From: "Notmoo-PC\\Notmoo" Date: Tue, 23 Jan 2018 17:24:26 +0100 Subject: [PATCH] =?UTF-8?q?[CLIENT]=20#11=20:=20Impl=C3=A9mentation=20d'un?= =?UTF-8?q?=20renderer=20pour=20l'=C3=A9cran=20des=20statistiques?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/stat_screen/StatScreenView.java | 55 ++++++++++++++++--- .../stat_screen/StatisticFieldRenderer.java | 33 +++++++++++ .../gui/ressources/strings/GUIStringTool.java | 43 +++++++++++++++ 3 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatisticFieldRenderer.java diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenView.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenView.java index f42fa43d..bff414bc 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenView.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenView.java @@ -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.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.scene.control.TextArea; import javafx.scene.layout.Pane; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; class StatScreenView implements IFXComponent { @@ -36,15 +40,48 @@ class StatScreenView implements IFXComponent { void display(Map statistics){ List lines = new ArrayList<>(); - if(statistics!=null) - lines.addAll(statistics.keySet() - .stream() - .map(key->String.format(" * %s : %s", key, statistics.get(key))) - .collect(Collectors.toList())); + if(statistics!=null) { + + lines.addAll(EnumSet.allOf(StatisticFields.class) + .stream() + .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())); + 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> parser = + new GSonMessageToolFactory().getListParser(LightweightProduct.class); + + List products = parser.parse(statistics.get(StatisticFields.TOP_POPULAR_PRODUCTS.getStr())) + .stream() + .map(LightweightProduct::getName) + .collect(Collectors.toList()); + + for(int i = 1; i { statTextArea.setText(""); - lines.forEach(line -> statTextArea.appendText(line + "\n")); + lines.forEach(line -> { + if(line!=null) statTextArea.appendText(" * "+line + "\n"); + }); }); } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatisticFieldRenderer.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatisticFieldRenderer.java new file mode 100644 index 00000000..37cb7fa5 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatisticFieldRenderer.java @@ -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 { + + private final Map 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(); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java index 25945093..f0dde994 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java @@ -1,5 +1,7 @@ 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.Product; import com.pqt.core.entities.sale.SaleStatus; @@ -360,6 +362,47 @@ public class GUIStringTool { return String.format("%s : %s", e.getClass().getName(), e.getMessage()); }; } + + private static IObjectStringRenderer statisticFieldsRenderer = null; + + public static IObjectStringRenderer 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"; + } }