Author: bleny Date: 2010-11-04 22:57:53 +0000 (Thu, 04 Nov 2010) New Revision: 740 Log: refactoring totals by columns in sampling plan ; start filter by multiple codes Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java trunk/wao-ui/src/main/webapp/SamplingPlan.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-11-04 22:55:02 UTC (rev 739) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-11-04 22:57:53 UTC (rev 740) @@ -225,8 +225,20 @@ // sectorName and facadeName are the two FishingZone filters known // FishingZone filter (sectorName OR facadeName) + + if (logger.isDebugEnabled()) { + logger.debug("CollectionUtils.isNotEmpty(filter.getSampleRows())" + + CollectionUtils.isNotEmpty(filter.getSampleRows())); + } + if (CollectionUtils.isNotEmpty(filter.getSampleRows())) { + if (logger.isDebugEnabled()) { + for (SampleRow row : filter.getSampleRows()) { + logger.debug("sampleRows contains row " + row); + } + } + query.addEquals(sampleRowProperty.$alias(), filter.getSampleRows().toArray( new SampleRow[filter.getSampleRows().size()])); Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-11-04 22:55:02 UTC (rev 739) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-11-04 22:57:53 UTC (rev 740) @@ -62,7 +62,9 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * SampingPlan @@ -239,6 +241,51 @@ return this; } + @Property + private boolean refreshSampleRowCodeZone; + + @Property + private String sampleRowCodeIndex; + + @Persist + @Property + private SampleRow selectedSampleRow; + + @InjectComponent + private Zone sampleRowZone; + + public void onChangeFromSelectedSampleRow(String sampleRowCode) { + selectedSampleRow = getSampleRowSelectModel().findObject(sampleRowCode); + + logger.debug("selectedSampleRow " + selectedSampleRow.getCode()); + } + + public Object onActionFromAddSampleRowCode() { + refreshSampleRowCodeZone = true; + if (logger.isDebugEnabled()) { + logger.debug("added filter on code " + selectedSampleRow.getCode()); + } + + if (getFilter().getSampleRows() == null) { + getFilter().setSampleRows(new ArrayList<SampleRow>()); + } + getFilter().addSampleRows(selectedSampleRow); + + selectedSampleRow = null; + + return sampleRowZone; + } + + public Object onActionFromRemoveSampleRowCode(String sampleRowCodeIndex) { + refreshSampleRowCodeZone = true; + + logger.debug("should remove" + sampleRowCodeIndex); + + getFilter().getSampleRows().remove(selectedSampleRow); + + return sampleRowZone; + } + /**************************** MAIN ACTIONS ********************************/ @Persist @@ -297,6 +344,11 @@ */ public List<SampleRow> getData() throws WaoException { if (data == null) { + if (logger.isDebugEnabled()) { + logger.debug("sampleRows filter sent to service : " + + getFilter().getSampleRows()); + } + FacadeRow facade = serviceSampling.getSampleRowsOrderedByFishingZone(getFilter()); data = facade.getValues(); @@ -401,19 +453,26 @@ return NumberFormat.getNumberInstance(); } - private List<String> totals; + private Map<Date, Integer> totalExpectedForMonths; + private Map<Date, Integer> totalRealForMonths; + private Integer highTotalExpected; + private Integer highTotalReal; - @Property - private String total; + /** Set totalExpectedForMonths, totalRealForMonths, highTotalExpected and + * highTotalReal values. + */ + protected void setTotalsForMonths() { - public List<String> getTotals() { + // to prevent a side-effect, keep month value + Date keptMonth = month; - List<String> totals = new ArrayList<String>(); + totalExpectedForMonths = new HashMap<Date, Integer>(); + totalRealForMonths = new HashMap<Date, Integer>(); - // high totals are the total... of the totals, it will appear + // high totals is the total... of the totals, it will appear // in the bottom right, as the last element of the "totals" line - Integer highTotalExpected = 0; - Integer highTotalReal = 0; + highTotalExpected = 0; + highTotalReal = 0; for (Date month : getMonths()) { this.month = month; @@ -423,37 +482,95 @@ for (SampleRow row : getData()) { this.row = row; - Integer expected = getNbTidesExpected(), real = getNbTidesReal(); if (logger.isDebugEnabled()) { - logger.debug(String.format("expected = %s, real = %s", expected, real)); + logger.debug( String.format("for month %s and row %s : expected = %s, real = %s", + getDateFormat().format(month), row.getCode(), expected, real)); } if (expected != null) { totalExpected += expected; } - if (real != null) { + if (real != null && canDisplayTidesReal()) { totalReal += real; } } - String total = totalExpected.toString(); - if (canDisplayTidesReal() && totalReal != 0) { - total += " (" + totalReal + ")"; + totalExpectedForMonths.put(month, totalExpected); + totalRealForMonths.put(month, totalReal); + + if (logger.isDebugEnabled()) { + logger.debug( String.format("totals for month %s : expected = %s, actual = %s", + getDateFormat().format(month), totalExpected, totalReal)); } - totals.add(total); - highTotalExpected += totalExpected; highTotalReal += totalReal; } + + if (logger.isDebugEnabled()) { + for (Map.Entry<Date, Integer> expected : totalExpectedForMonths.entrySet()) { + logger.debug( String.format("totals for month %s : expected = %s, actual = %s", + getDateFormat().format(expected.getKey()), expected.getValue(), + totalRealForMonths.get(expected.getKey()))); + } + } - totals.add(highTotalExpected + " (" + highTotalReal + ")"); + // to prevent side-effect, restore month value + month = keptMonth; + } - return totals; + public Integer getTotalExpectedForMonth() { + if (totalExpectedForMonths == null) { + setTotalsForMonths(); + } + Integer total = totalExpectedForMonths.get(month); + if (logger.isDebugEnabled()) { + logger.debug(String.format("total for month %s is %s", getDateFormat().format(month), total)); + } + return total; } + public Integer getTotalRealForMonth() { + if (totalExpectedForMonths == null) { + setTotalsForMonths(); + } + return totalRealForMonths.get(month); + } + + public String getRatioForMonth() { + String ratio = ""; + if (getTotalExpectedForMonth() > 0) { + double percent = ((double) getTotalRealForMonth() / getTotalExpectedForMonth()); + ratio = NumberFormat.getPercentInstance().format(percent); + } + return ratio; + } + + public Integer getHighTotalExpected() { + if (highTotalExpected == null) { + setTotalsForMonths(); + } + return highTotalExpected; + } + + public Integer getHighTotalReal() { + if (highTotalReal == null) { + setTotalsForMonths(); + } + return highTotalReal; + } + + public String getHighTotalRatio() { + String ratio = ""; + if (getHighTotalExpected() > 0) { + double percent = ((double) getHighTotalReal() / getHighTotalExpected()); + ratio = NumberFormat.getPercentInstance().format(percent); + } + return ratio; + } + /** ------------------------- HTML & STYLE ----------------------------- **/ @Property @@ -512,6 +629,16 @@ return result; } + public String getRealTidesClassForTotal() { + String result = "real-warning"; + if (getTotalRealForMonth() < getTotalExpectedForMonth()) { + result += "-inf"; + } else if (getTotalExpectedForMonth() > getTotalRealForMonth()) { + result += "-sup"; + } + return result; + } + public String getMonthCurrentClass() { return isCurrentMonth() ? "selected" : ""; } Modified: trunk/wao-ui/src/main/webapp/SamplingPlan.tml =================================================================== --- trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-11-04 22:55:02 UTC (rev 739) +++ trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-11-04 22:57:53 UTC (rev 740) @@ -128,8 +128,31 @@ <select t:type="select" t:id="sectorName" t:model="sectorSelectModel" t:value="filter.sectorName" /> <input t:type="submit" class="ico22px refresh" t:id="refreshBySector" value="Refresh" title="Rafraîchir les métiers en fonction de la zone sélectionnée"/> - <t:label t:for="sampleRow" />: - <input t:type="select" t:id="sampleRow" t:model="sampleRowSelectModel" value="sampleRowId" /> + <!--t:label t:for="sampleRow" />: + <input t:type="select" t:id="sampleRow" t:model="sampleRowSelectModel" value="sampleRowId" /--> + + + <t:zone id="so-sampling-sampleRowZone" t:id="sampleRowZone" t:update="show"> + <t:nuiton.subForm t:visible="refreshSampleRowCodeZone"> + <t:label t:for="selectedSampleRow" />: + <select t:type="select" t:id="selectedSampleRow" t:value="selectedSampleRow" t:model="sampleRowSelectModel" + t:mixins="ck/onEvent" t:event="change"/> + <a t:type="actionlink" t:id="addSampleRowCode" title="Ajouter un code de ligne" t:zone="so-sampling-sampleRowZone"> + <img src="${asset:context:img/add-16px.png}" /> + </a> + <!--ul> + <li t:type="loop" t:source="filter.sampleRows" t:value="row" t:index="sampleRowCodeIndex"> + ${row.code} + <a t:type="actionlink" t:id="removeSampleRowCode" t:context="sampleRowCodeIndex" title="Supprimer ce code de ligne" t:zone="so-sampling-sampleRowZone"> + <img src="${asset:context:img/remove-22px.png}" /> + </a> + </li> + </ul--> + </t:nuiton.subForm> + </t:zone> + + + </div> <div class="t-beaneditor-row aright"> <input t:type="submit" class="ico search-32px" t:id="search" value="Search" title="Rechercher les lignes du plan correspondants aux filtres saisies" /> @@ -303,11 +326,25 @@ </tr> <tr> <td colspan="${nbColumnsForProfession}" /> - <t:loop source="totals" value="total"> + + <t:loop source="months" value="month"> <td class="width50 acenter ${monthCurrentClass}"> - ${total} + ${totalExpectedForMonth} + <!--t:if t:test="canDisplayTidesReal()"--> + <span class="${realTidesClassForTotal}"><em>(${totalRealForMonth})</em></span> + <br /> + ${ratioForMonth} + <!--/t:if--> </td> </t:loop> + <td class="width50 acenter bright"> + <span t:type="ck/Tooltip" title="Infos" t:value="Total sur la période du mois ${dateFormat.format(month)}" t:effect="appear"> + ${highTotalExpected} + <t:unless t:test="user.guest"> + <em>(${highTotalReal})</em><br /><strong>${highTotalRatio}</strong> + </t:unless> + </span> + </td> <td colspan="${nbColumnsForOther}" /> </tr> </tbody>