[Suiviobsmer-commits] r255 - in trunk: suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl suiviobsmer-business/src/main/xmi suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/base suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages sui
Author: fdesbois Date: 2010-01-21 12:23:50 +0000 (Thu, 21 Jan 2010) New Revision: 255 Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/SamplingFilterImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/base/AbstractFilteredPage.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/BusinessUtils.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties trunk/suiviobsmer-ui/src/main/webapp/Boats.tml trunk/suiviobsmer-ui/src/main/webapp/css/common.css trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css Log: Evol #2030 : Refactor boats using AbstractFilteredPage + improve and add javadoc Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/SamplingFilterImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/SamplingFilterImpl.java 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/SamplingFilterImpl.java 2010-01-21 12:23:50 UTC (rev 255) @@ -46,29 +46,34 @@ @Override public TopiaQuery prepareQueryForSampling(TopiaQuery query, String main) { - //query = super.prepareQuery(query); - //String sampleRow = main + ".sampleRow"; - + // SampleRow filter depends on SampleRow or sectorName or facadeName if (getSampleRow() != null) { query.add(main, getSampleRow()); - } else if (!StringUtils.isEmpty(getSectorName())) { + } else if (StringUtils.isNotEmpty(getSectorName())) { query.addFrom(FishingZone.class.getName() + " F"); query.add("F." + FishingZone.SECTOR_NAME, getSectorName()).add(main + " IN elements(F." + FishingZone.SAMPLE_ROW + ")"); - } else if (!StringUtils.isEmpty(getFacadeName())) { + } else if (StringUtils.isNotEmpty(getFacadeName())) { query.addFrom(FishingZone.class.getName() + " F"); query.add("F." + FishingZone.FACADE_NAME, getFacadeName()).add(main + " IN elements(F." + FishingZone.SAMPLE_ROW + ")"); } + // Profession filter + if (getProfession() != null) { + query.add(main + "." + SampleRow.PROFESSION, getProfession()); + } + + // Period filter on sampleRow dates if (getPeriod() != null) { getPeriod().initDayOfMonthExtremities(); query.add(main + "." + SampleRow.PERIOD_BEGIN, Op.LT, getPeriod().getThruDate()). add(main + "." + SampleRow.PERIOD_END, Op.GT, getPeriod().getFromDate()); } - if (getNbMonthFinishedFromToday() != null) { + /** Finished rows constraint only needed if an other filter is set **/ + if (isSamplingFiltered() && getNbMonthFinishedFromToday() != null) { // Only rows which are not finished will be kept - //Date current = SuiviObsmerContext.getCurrentDate(); + // Date current = SuiviObsmerContext.getCurrentDate(); Calendar calendar = new GregorianCalendar(); calendar.setTime(SuiviObsmerContext.getCurrentDate()); calendar.add(Calendar.MONTH, getNbMonthFinishedFromToday()); @@ -78,4 +83,10 @@ return query; } + @Override + public boolean isSamplingFiltered() { + return getSampleRow() != null || StringUtils.isNotEmpty(getSectorName()) || StringUtils.isNotEmpty(getFacadeName()) || + getPeriod() != null || getProfession() != null; + } + } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java 2010-01-21 12:23:50 UTC (rev 255) @@ -111,33 +111,35 @@ String main = query.getMainAlias(); query = filter.prepareQueryForBoat(query, main); - boolean sampleRowCodeFiltered = !StringUtils.isEmpty(filter.getSampleRowCode()); - boolean professionFiltered = filter.getProfession() != null; - boolean fishingZoneFiltered = filter.getFishingZone() != null; - boolean sampleRowFiltered = sampleRowCodeFiltered || professionFiltered || fishingZoneFiltered; +// boolean sampleRowCodeFiltered = !StringUtils.isEmpty(filter.getSampleRowCode()); +// boolean professionFiltered = filter.getProfession() != null; +// boolean fishingZoneFiltered = filter.getFishingZone() != null; +// boolean sampleRowFiltered = sampleRowCodeFiltered || professionFiltered || fishingZoneFiltered; - // Add join for ElligibleBoat - if (sampleRowFiltered) { + // Sampling filter + if (filter.isSamplingFiltered()) { + // Add join for ElligibleBoat String elligibleBoatClassName = ElligibleBoat.class.getName(); query.addFrom(elligibleBoatClassName + " E").add("E.boat = " + main); - } - // SampleRowCode - if (sampleRowCodeFiltered) { - query.add("E.sampleRow.code", filter.getSampleRowCode()); - } - // Profession - if (professionFiltered) { - query.add("E.sampleRow.profession", filter.getProfession()); - } + query = filter.prepareQueryForSampling(query, "E." + ElligibleBoat.SAMPLE_ROW); - // TODO FishingZone - - // Company : only if an other filter is set for the sampleRow - if (filter.getCompany() != null && sampleRowFiltered) { - query.add("E.sampleRow.company", filter.getCompany()); - query.add("E.companyActive = :booleanTrue OR (E.companyActive IS NULL AND E.globalActive = :booleanTrue)"). - addParam("booleanTrue", Boolean.TRUE); + // Company + if (filter.getCompany() != null) { + query.add("E." + ElligibleBoat.SAMPLE_ROW + "." + SampleRow.COMPANY, filter.getCompany()); + // Test only valid ElligibleBoat for that company + query.add("E." + ElligibleBoat.COMPANY_ACTIVE + " = :booleanTrue " + + "OR (E." + ElligibleBoat.COMPANY_ACTIVE + " IS NULL AND E." + ElligibleBoat.GLOBAL_ACTIVE + " = :booleanTrue)"); + query.addParam("booleanTrue", Boolean.TRUE); + } } +// // SampleRowCode +// if (sampleRowCodeFiltered) { +// query.add("E.sampleRow.code", filter.getSampleRowCode()); +// } +// // Profession +// if (professionFiltered) { +// query.add("E.sampleRow.profession", filter.getProfession()); +// } return query; } Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo =================================================================== (Binary files differ) Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java 2010-01-21 12:23:50 UTC (rev 255) @@ -152,7 +152,7 @@ // Exec with filter on SampleRowCode and company filter = new BoatFilterImpl(); - filter.setSampleRowCode("2009_03"); + filter.setSampleRow(rows.get(0)); // Code = 2009_03 filter.setCompany(company); boats = service.getBoatsByFilter(filter); assertEquals(2, boats.size()); Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/base/AbstractFilteredPage.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/base/AbstractFilteredPage.java 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/base/AbstractFilteredPage.java 2010-01-21 12:23:50 UTC (rev 255) @@ -67,6 +67,7 @@ * - Select change, use JavaScript : * <script type="text/javascript"> * Event.observe('facadeName', 'change', function() { $('filtersForm').submit(); } ); + * Event.observe('sectorName', 'change', function() { $('filtersForm').submit(); } ); * Event.observe('company', 'change', function() { $('filtersForm').submit(); } ); * </script> * </pre> @@ -124,7 +125,14 @@ @Property private String observerId; - protected void initFilter() throws SuiviObsmerException { + /** + * Initialize all select for filters. By default, only facade, sector and sampleRow selects will be initialized. + * + * @param companySelect if true, company select will be initialized + * @param observerSelect if true, observer select will be initialized + * @throws SuiviObsmerException + */ + protected void initSelectFilters(boolean companySelect, boolean observerSelect) throws SuiviObsmerException { facadeSelectModel = null; getFacadeSelectModel(); @@ -137,7 +145,7 @@ sampleRowId = getFilter().getSampleRow().getTopiaId(); } - if (user.getAdmin()) { + if (user.getAdmin() && companySelect) { companySelectModel = null; getCompanySelectModel(); if (getFilter().getCompany() != null) { @@ -150,11 +158,13 @@ getFilter().setCompany(user.getCompany()); } - observerSelectModel = null; - getObserverSelectModel(); + if (observerSelect) { + observerSelectModel = null; + getObserverSelectModel(); - if (getFilter().getObserver() != null) { - observerId = getFilter().getObserver().getTopiaId(); + if (getFilter().getObserver() != null) { + observerId = getFilter().getObserver().getTopiaId(); + } } } @@ -229,12 +239,15 @@ protected abstract BoatFilter getFilter() throws SuiviObsmerException; - protected abstract void resetFilter(); - // protected abstract Zone getSampleRowFilterZone(); // // protected abstract Zone getObserverFilterZone(); + /** + * Used to show only active company and observers. + * + * @return true if only active users will be showed, false either + */ protected abstract boolean getAvailableDataForFiltersOnly(); public String[] onProvideCompletionsFromBoatName(String input) throws SuiviObsmerException { Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/BusinessUtils.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/BusinessUtils.java 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/BusinessUtils.java 2010-01-21 12:23:50 UTC (rev 255) @@ -120,7 +120,7 @@ return result; } - public static String getCSSColorClassForContact(Contact contact, boolean admin) { + public static String getContactStyle(Contact contact, boolean admin) { String result = ""; ContactState state = ContactState.createContactStateEnum(contact.getState()); if (BooleanUtils.isFalse(contact.getValidationProgram()) || Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2010-01-21 12:23:50 UTC (rev 255) @@ -27,8 +27,6 @@ import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.bean.BoatFilter; import fr.ifremer.suiviobsmer.bean.CompanyBoatInfos; -import fr.ifremer.suiviobsmer.bean.SamplingFilter; -import fr.ifremer.suiviobsmer.bean.SamplingFilterImpl; import fr.ifremer.suiviobsmer.entity.BoatInfos; import fr.ifremer.suiviobsmer.entity.Company; import fr.ifremer.suiviobsmer.entity.Contact; @@ -41,6 +39,7 @@ import fr.ifremer.suiviobsmer.services.ServiceReferential; import fr.ifremer.suiviobsmer.services.ServiceSampling; import fr.ifremer.suiviobsmer.services.ServiceUser; +import fr.ifremer.suiviobsmer.ui.base.AbstractFilteredPage; import fr.ifremer.suiviobsmer.ui.data.BusinessUtils; import fr.ifremer.suiviobsmer.ui.base.GenericSelectModel; import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage; @@ -89,7 +88,7 @@ * par : $Author$ */ @IncludeStylesheet("context:css/boats.css") -public class Boats implements SuiviObsmerPage { +public class Boats extends AbstractFilteredPage implements SuiviObsmerPage { @Override public boolean isOnlyForAdmin() { @@ -119,7 +118,7 @@ private PropertyAccess propertyAccess; @Property - private String sampleRowCode; + private String sampleRowContextId; @InjectComponent private FeedBack filterFeedback; @@ -127,57 +126,45 @@ void setupRender() throws SuiviObsmerException { sampleRow = null; getSampleRow(); + // Profession select reset professionSelectModel = null; getProfessionSelectModel(); - fishingZoneSelectModel = null; - getFishingZoneSelectModel(); - sampleRowSelectModel = null; - getSampleRowSelectModel(); - // Suppress persistant boat informations for selected boat - //boatInfos = null; - companyBoatInfos = null; - boatSelectedImmatriculation = null; + // Manage sampleRow from context if (isSampleRowExists()) { + // Filters will be set and displayed + getFilter().setSampleRow(sampleRow); filtersHidden = false; boats = null; filterFeedback.addInfo("Vous êtes en cours de sélection d'un navire pour la ligne du plan " + sampleRow.getCode()); professionId = getSampleRow().getProfession().getTopiaId(); - // FIXME FD-20100121 Missing filter for fishingZone --> Need use of AbstratFilteredPage - //fishingZoneId = getSampleRow().getFirstFishingZone().getTopiaId(); - getBoatFilter().setSampleRowCode(getSampleRow().getCode()); } + + // Initialize filters using AbstractFilteredPage superclass + initSelectFilters(true, false); + // Only rows which are not finished nearly one month + getFilter().setNbMonthFinishedFromToday(-1); + + companyBoatInfos = null; + boatSelectedImmatriculation = null; } void onActivate(EventContext ec) { if (ec.getCount() > 0) { - sampleRowCode = ec.get(String.class, 0); + sampleRowContextId = ec.get(String.class, 0); } } String onPassivate() { - return sampleRowCode; + return sampleRowContextId; } /**************************** Import Forms ********************************/ - /** - * Fichier CSV contenant une liste de navires. - */ + /** Csv file for boats import */ @Property private UploadedFile boatsCsvFile; - @InjectComponent - private Form importBoatsForm; - - /** - * Récupération des exceptions du champs d'upload de fichier. - */ - /*Object onUploadException(FileUploadException ex) { - createListForm.recordError("Upload exception: " + ex.getMessage()); - return this; - }*/ - @Log void onSuccessFromImportBoatsForm() { //importBoatsForm.clearErrors(); @@ -189,9 +176,9 @@ } catch (SuiviObsmerException eee) { layout.getFeedBack().addError(eee.getMessage()); } - //return importBoatsForm.getHasErrors() ? importBoatsForm : this; } + /** Csv file for activityCalendar import, can be a Gzip file */ @Property private UploadedFile activityCalendarsCsvFile; @@ -258,55 +245,61 @@ /**************************** Filters Form *****************************************/ + /** Filters to apply on boats list */ @Persist private BoatFilter boatFilter; + /** Current sampleRow from context */ @Persist private SampleRow sampleRow; + /** Profession select */ @Persist - private GenericSelectModel<SampleRow> sampleRowSelectModel; - - @Persist private GenericSelectModel<Profession> professionSelectModel; @Property private String professionId; + /** Used to manage view of filters zone */ @Persist - private GenericSelectModel<FishingZone> fishingZoneSelectModel; - - @Property - private String fishingZoneId; - - @Persist private boolean filtersHidden; @InjectComponent private Zone filtersZone; - public BoatFilter getBoatFilter() throws SuiviObsmerException { + /** + * Filters to apply on boats list. Method used by AbstractFilteredPage superclass. + * + * @return the current BoatFilter to apply + * @throws SuiviObsmerException + * @see AbstractFilteredPage + */ + @Override + public BoatFilter getFilter() throws SuiviObsmerException { if (boatFilter == null) { boatFilter = new BoatFilterImpl(); - if (log.isDebugEnabled()) { - log.debug("new BoatFilter"); - } - if (!user.getAdmin()) { - if (log.isDebugEnabled()) { - log.debug("set company for boatFilter"); - } - boatFilter.setCompany(user.getCompany()); - } } return boatFilter; } + @Override + protected boolean getAvailableDataForFiltersOnly() { + return true; + } + + /** + * Retrieve sampleRow from business with id from url context. The sampleRowId from context is set by SamplingPlan page. + * When the sampleRow is not null, the filters are disabled to optimize searching boats for this row. + * + * @return the sampleRow from business + * @throws SuiviObsmerException + */ public SampleRow getSampleRow() throws SuiviObsmerException { - if (sampleRow == null && !StringUtils.isEmpty(sampleRowCode)) { + if (sampleRow == null && !StringUtils.isEmpty(sampleRowContextId)) { if (log.isInfoEnabled()) { log.info("BUSINESS REQUEST [getSampleRow]"); } - sampleRow = serviceSampling.getSampleRow(sampleRowCode); + sampleRow = serviceSampling.getSampleRow(sampleRowContextId); } return sampleRow; } @@ -315,25 +308,6 @@ return getSampleRow() != null; } - public GenericSelectModel<SampleRow> getSampleRowSelectModel() throws SuiviObsmerException { - if (sampleRowSelectModel == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getSampleRowsForUser]"); - } - // FIXME-FD20100118 Refactor filter system using AbstractFilteredPage - SamplingFilter filter = new SamplingFilterImpl(); - // Used to test if the rows are finished with a gap of 1 month (today - 1 month) - filter.setNbMonthFinishedFromToday(-1); - if (!user.getAdmin()) { - filter.setCompany(user.getCompany()); - } - List<SampleRow> sampleRows = serviceSampling.getSampleRowsByFilter(filter); - sampleRowSelectModel = new GenericSelectModel<SampleRow>(sampleRows, SampleRow.class, - "code", "code", propertyAccess); - } - return sampleRowSelectModel; - } - public GenericSelectModel<Profession> getProfessionSelectModel() throws SuiviObsmerException { if (professionSelectModel == null) { if (log.isInfoEnabled()) { @@ -346,28 +320,11 @@ return professionSelectModel; } - public GenericSelectModel<FishingZone> getFishingZoneSelectModel() throws SuiviObsmerException { - if (fishingZoneSelectModel == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getFishingZones]"); - } - List<FishingZone> fishingZones = null; - if (isSampleRowExists()) { - fishingZones = getSampleRow().getFishingZone(); - } else { - fishingZones = serviceReferential.getFishingZones(); - } - fishingZoneSelectModel = new GenericSelectModel<FishingZone>(fishingZones, FishingZone.class, - "code", "topiaId", propertyAccess); - } - return fishingZoneSelectModel; - } - public boolean isFiltersHidden() { return filtersHidden; } - public String getHiddenClass() { + public String getHiddenStyle() { return isFiltersHidden() ? "hidden" : ""; } @@ -380,18 +337,28 @@ filtersHidden = true; return filtersZone.getBody(); } - + + /** + * EVENT_SELECTED :: reset submit button for filtersForm. Reset filters and sampleRow from context. + */ void onSelectedFromReset() { - // Suppress persistant boat filter + // Suppress persistant boat filter and sampleRowId in url context. boatFilter = null; - sampleRowCode = null; + sampleRowContextId = null; } + /** + * EVENT_SELECTED :: search sumit button for filtersForm. Get profession from selectModel to add it in filters. + * Other filters are managed by AbstractFilteredPage superclass. + * + * @throws SuiviObsmerException for business errors + * @see AbstractFilteredPage + */ void onSelectedFromSearch() throws SuiviObsmerException { if (log.isDebugEnabled()) { - //log.debug("SUBMIT : facadeChange=" + facadeChangeSelected); - log.debug("FILTER : fishingZone=" + boatFilter.getFishingZone()); - log.debug("FILTER : sampleRowCode=" + boatFilter.getSampleRowCode()); + log.debug("FILTER : facadeName=" + boatFilter.getFacadeName()); + log.debug("FILTER : sectorName=" + boatFilter.getSectorName()); + log.debug("FILTER : sampleRow=" + boatFilter.getSampleRow()); log.debug("FILTER : profession=" + boatFilter.getProfession()); log.debug("FILTER : boatName=" + boatFilter.getBoatName()); log.debug("FILTER : boatImmatriculation=" + boatFilter.getBoatImmatriculation()); @@ -399,57 +366,66 @@ log.debug("FILTER : company=" + boatFilter.getCompany()); } Profession profession = getProfessionSelectModel().findObject(professionId); - FishingZone fishingZone = getFishingZoneSelectModel().findObject(fishingZoneId); boatFilter.setProfession(profession); - boatFilter.setFishingZone(fishingZone); } + /** + * EVENT_SUCCESS :: for filtersForm. Reset persitant data to have new data using filters selected. + * + * @throws SuiviObsmerException for business errors + */ void onSuccessFromFiltersForm() throws SuiviObsmerException { // Suppress persistant boats list to get new one with filter boats = null; // Suppress persistant immatriculation for boat selected boatSelectedImmatriculation = null; // Suppress persistant boat informations for boat selected - //boatInfos = null; companyBoatInfos = null; } /**************************** Boats List *****************************************/ - + + /** DataSource containing the boats */ @Persist -// private Map<Integer, Boat> boats; private BoatDataSource boats; + /** Selected boat immatriculation for showing boatInfos */ @Property @Persist private Integer boatSelectedImmatriculation; + /** Current boat in the Grid */ @Property private Boat boat; + /** Used to change style a line on two */ private boolean even = true; + /** Used to refresh boats Grid */ @InjectComponent private Zone boatsZone; + /** + * Get dataSource which contains current boats to show on the page. Depends on filters sets by user. + * BoatDataSource uses serviceBoat to retrieve boats with filters. + * + * @return the BoatDataSource which contains the boats map + * @throws SuiviObsmerException + * @see BoatDataSource + */ public BoatDataSource getBoats() throws SuiviObsmerException { if (boats == null) { - boats = new BoatDataSource(getBoatFilter(), serviceBoat); + boats = new BoatDataSource(getFilter(), serviceBoat); } return boats; } -// public Map<Integer, Boat> getBoats() throws SuiviObsmerException { -// if (boats == null) { -// if (log.isInfoEnabled()) { -// log.info("BUSINESS REQUEST [getBoatsByFilter]"); -// } -// boats = serviceBoat.getBoatsByFilter(boatFilter); -// } -// return boats; -// } - - public String getRowClass() { + /** + * Initialized row CSS style depends on selection in the list. The style is also changed a line on two. + * + * @return the CSS style class to used for the current row in the Grid + */ + public String getRowStyle() { String result = ""; even = !even; if (boatSelectedImmatriculation != null && @@ -469,9 +445,6 @@ public boolean canCreateNewContactFromList() throws SuiviObsmerException { if (!user.getAdmin() && isSampleRowExists()) { -// if (getSampleRow().isFinished()) { -// return false; -// } return boat.canCreateContact(user.getCompany()); } return false; @@ -480,15 +453,7 @@ Block onActionFromShowBoatInfos(Integer boatImma) { boatSelectedImmatriculation = boatImma; // Suppress persistant boat informations - //boatInfos = null; - companyBoatInfos = null; - //companyId = null; - - // Initialize from Date for boarding calcul in BoatInfos - Calendar calendar = new GregorianCalendar(); - calendar.add(Calendar.MONTH, -12); - boardingFromDate = calendar.getTime(); - + companyBoatInfos = null; return boatsZone.getBody(); } @@ -514,15 +479,6 @@ private boolean boatInfosEditable; - @Inject - private ServiceUser serviceUser; - - private GenericSelectModel<Company> companySelectModel; - - @Property - private String companyId; - - @Property private Date boardingFromDate; /*@Persist @@ -534,10 +490,6 @@ return SuiviObsmerContext.isActivityCalendarImportRun(); } - public boolean canShowActiveBoatInfos() { - return (user.getAdmin() && companyId != null) || !user.getAdmin(); - } - public Block getActiveBoatInfosBlock() { if (boatInfosEditable) { return editBoatInfos; @@ -545,52 +497,74 @@ return displayBoatInfos; } - public Company getCompany() throws SuiviObsmerException { - if (user.getAdmin() && companyId != null) { - return getCompanySelectModel().findObject(companyId); - } - return user.getCompany(); - } - - public GenericSelectModel<Company> getCompanySelectModel() throws SuiviObsmerException { - if (companySelectModel == null) { - if (log.isDebugEnabled()) { - log.debug("BUSINESS REQUEST [getCompanies]"); - } - List<Company> companies = serviceUser.getCompanies(true); - companySelectModel = new GenericSelectModel<Company>(companies,Company.class, - "name","topiaId",propertyAccess); - } - return companySelectModel; - } - public CompanyBoatInfos getCompanyBoatInfos() throws SuiviObsmerException { if (companyBoatInfos == null && boatSelectedImmatriculation != null) { if (log.isInfoEnabled()) { log.info("BUSINESS REQUEST [getElligibleBoats]"); } + // Use filter to retrieve company + Company company = getFilter().getCompany() != null ? getFilter().getCompany() : user.getCompany(); companyBoatInfos = - serviceBoat.getCompanyBoatInfos(boatSelectedImmatriculation, getCompany()); + serviceBoat.getCompanyBoatInfos(boatSelectedImmatriculation, company); } return companyBoatInfos; } + /** + * Used to get the selected boat name. This method is useful to avoid problems when using only boatInfos. + * Actually, the name is displayed when the boat is selected. + * + * @return + * @throws SuiviObsmerException + */ public String getBoatName() throws SuiviObsmerException { - Boat boat = null; + Boat selectedBoat = null; if (getBoatInfos() != null) { - boat = getBoatInfos().getBoat(); + selectedBoat = getBoatInfos().getBoat(); + } else { + selectedBoat = getBoats().get(boatSelectedImmatriculation); } - boat = getBoats().get(boatSelectedImmatriculation); - return boat.getName(); + return selectedBoat.getName(); } + /** + * Date for calculate boardings done for the selected boat. All boardings (number of contacts) will be calculated from this date. + * Initialized as 12 months from today, but can be set by user. + * + * @return the Date used to calculate boardings done on the selected boat + */ + public Date getBoardingFromDate() { + if (boardingFromDate == null) { + Calendar calendar = new GregorianCalendar(); + calendar.add(Calendar.MONTH, -12); + boardingFromDate = calendar.getTime(); + } + return boardingFromDate; + } + + /** + * Used by Tapestry to set the boardingFromDate from calculateBoardings form. + * + * @param boardingFromDate used to calculate boardings done on the selected boat + */ + public void setBoardingFromDate(Date boardingFromDate) { + this.boardingFromDate = boardingFromDate; + } + public BoatInfos getBoatInfos() throws SuiviObsmerException { return getCompanyBoatInfos().getBoatInfos(); } - public String getlastContactClass() throws SuiviObsmerException { + /** + * Get CSS style class to apply on lastContact depends on its state. + * + * @return the CSS style to apply on contact block + * @throws SuiviObsmerException + * @see BusinessUtils#getContactStyle(Contact, boolean) + */ + public String getlastContactStyle() throws SuiviObsmerException { Contact contact = getCompanyBoatInfos().getLastContact(); - return BusinessUtils.getCSSColorClassForContact(contact, user.getAdmin()); + return BusinessUtils.getContactStyle(contact, user.getAdmin()); } /** /////////////////////// FOR EACH ELLIGIBLEBOAT ROW ///////////////// **/ @@ -604,20 +578,15 @@ } public boolean canCreateNewContactFromElligibleBoat() throws SuiviObsmerException { - if (!user.getAdmin() && !isElligibleBoatCompanyActiveFalse()) { -// SampleRow row = elligibleBoat.getSampleRow(); -// if (row.isFinished()) { -// return false; -// } + if (!user.getAdmin() && !isElligibleBoatCompanyActiveFalse()) { Boat boat = getBoatInfos().getBoat(); return boat.canCreateContact(user.getCompany()); } return false; } - public String getElligibleRowClass() { + public String getElligibleRowStyle() { boolean condition1 = elligibleBoat.getCompanyActive() == null && !elligibleBoat.getGlobalActive(); - return condition1 || isElligibleBoatCompanyActiveFalse() ? "line-through" : ""; } @@ -677,10 +646,6 @@ } Block onSuccessFromCalculateBoardings() throws SuiviObsmerException { - // Reinitialiaze companyId for select (admin only) - if (user.getAdmin()) { - companyId = getCompanyBoatInfos().getCompany().getTopiaId(); - } return boatInfosZone.getBody(); } Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2010-01-21 12:23:50 UTC (rev 255) @@ -114,7 +114,7 @@ private String editableContactId; void setupRender() throws SuiviObsmerException { - initFilter(); + initSelectFilters(true ,true); contacts = null; getContacts(); contactsForm.clearErrors(); @@ -152,12 +152,6 @@ protected BoatFilter getFilter() throws SuiviObsmerException { return getContactFilter(); } - - @Override - protected void resetFilter() { - contactFilter = null; - filtersVisible = false; - } // @Override // protected Zone getSampleRowFilterZone() { @@ -347,7 +341,7 @@ } public String getRowClass() { - String result = BusinessUtils.getCSSColorClassForContact(contact, user.getAdmin()); + String result = BusinessUtils.getContactStyle(contact, user.getAdmin()); if (contact.getTopiaId().equals(contactSelectedId)) { result = "selected"; } Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java 2010-01-21 12:23:50 UTC (rev 255) @@ -77,7 +77,7 @@ private User user; void setupRender() throws SuiviObsmerException { - initFilter(); + initSelectFilters(true, false); //getFilter().setUnfinishedRowsOnly(false); } @@ -113,11 +113,6 @@ return dataSamplingFilter; } - @Override - protected void resetFilter() { - dataSamplingFilter = null; - } - // @Override // protected Zone getSampleRowFilterZone() { // return sampleRowZone; @@ -174,7 +169,7 @@ void onSuccessFromFiltersForm() { if (reset) { - resetFilter(); + dataSamplingFilter = null; } } Modified: trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties =================================================================== --- trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties 2010-01-21 12:23:50 UTC (rev 255) @@ -3,7 +3,7 @@ # FILTERS sampleRow-label: Ligne du plan -fishingZone-label: Zone de p\u00EAche +facadeName-label: Fa\u00E7ade profession-label: M\u00E9tier du plan boatName-label: Navire districtCode-label: Quartier Modified: trunk/suiviobsmer-ui/src/main/webapp/Boats.tml =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2010-01-21 12:23:50 UTC (rev 255) @@ -64,20 +64,22 @@ </t:if> </div> <t:feedback t:id="filterFeedback" /> - <div class="so-filters-form ${hiddenClass}"> + <div class="so-filters-form ${hiddenStyle}"> <form t:type="form" t:id="filtersForm"> <t:errors /> <div class="t-beaneditor"> - <t:beaneditor t:id="filtersEditor" t:object="boatFilter" - t:include="boatName" t:add="sampleRow, fishingZone, profession" t:reorder="sampleRow, fishingZone, profession, boatName"> + <t:beaneditor t:id="filtersEditor" t:object="filter" + t:include="boatName" t:add="facade, sampleRow, profession" t:reorder="facade, sampleRow, profession, boatName"> + <p:facade> + <t:label t:for="facadeName" /> + <select t:type="select" t:id="facadeName" t:model="facadeSelectModel" value="filter.facadeName" /> + <span> zone </span> + <select t:type="select" t:id="sectorName" t:model="sectorSelectModel" value="filter.sectorName" /> + </p:facade> <p:sampleRow> <t:label t:for="sampleRow" /> - <select t:type="select" t:id="sampleRow" t:disabled="sampleRowExists" t:model="sampleRowSelectModel" value="boatFilter.sampleRowCode" /> + <select t:type="select" t:id="sampleRow" t:disabled="sampleRowExists" t:model="sampleRowSelectModel" value="sampleRowId" /> </p:sampleRow> - <p:fishingZone> - <t:label t:for="fishingZone" /> - <select t:type="select" t:id="fishingZone" t:model="fishingZoneSelectModel" value="fishingZoneId" /> - </p:fishingZone> <p:profession> <t:label t:for="profession" /> <select t:type="select" t:id="profession" t:disabled="sampleRowExists" t:model="professionSelectModel" value="professionId" /> @@ -85,11 +87,11 @@ <p:boatName> <t:label t:for="boatName" /> <span> nom </span> - <input t:type="textfield" t:id="boatName" t:value="boatFilter.boatName" /> + <input t:type="textfield" t:id="boatName" t:value="filter.boatName" t:mixins="Autocomplete" /> <span> immatriculation </span> - <input t:type="textfield" t:id="boatImmatriculation" class="width50" t:value="boatFilter.boatImmatriculation" /> + <input t:type="textfield" t:id="boatImmatriculation" class="width50" t:value="filter.boatImmatriculation" /> <span> code quartier </span> - <input t:type="textfield" t:id="boatDistrictCode" class="width50" t:value="boatFilter.boatDistrictCode" /> + <input t:type="textfield" t:id="boatDistrictCode" class="width50" t:value="filter.boatDistrictCode" /> </p:boatName> </t:beaneditor> <div class="t-beaneditor-row aright"> @@ -108,7 +110,7 @@ <div class="fleft" id="so-boats-list"> <h1>Liste des navires</h1> <div t:type="grid" t:source="boats" t:row="boat" - t:include="name, immatriculation, districtCode, boatLength, buildYear" t:rowClass="prop:rowClass" t:rowsPerPage="20"> + t:include="name, immatriculation, districtCode, boatLength, buildYear" t:rowClass="prop:rowStyle" t:rowsPerPage="20"> <p:nameCell> <t:if t:test="canCreateNewContactFromList()"> <a t:type="actionlink" t:id="addNewContactFromBoat" t:context="boat.immatriculation"> @@ -137,7 +139,7 @@ </form> </t:if> <!-- BODY - delegator --> - <t:if t:test="canShowActiveBoatInfos()"> + <t:if t:test="filter.company"> <t:delegate to="activeBoatInfosBlock" /> </t:if> <!-- BODY - activity calendar --> @@ -194,7 +196,7 @@ <t:if t:test="companyBoatInfos.lastContact"> <fieldset id="so-boats-boat-infos-lastcontact"> <legend>Dernier contact avec le navire pour votre société</legend> - <div class="${lastContactClass}"> + <div class="${lastContactStyle}"> <dl t:type="beandisplay" t:id="boatInfosLastContact" t:object="companyBoatInfos.lastContact" t:include="referenceDate, state" t:add="createdBy, sampleRowCode"> <p:createdBy> @@ -233,7 +235,7 @@ </p> <p class="sep"> </p> <p> - <form t:type="form" t:id="CalculateBoardings" t:zone="so-boats-boat-infos"> + <form t:type="form" t:id="calculateBoardings" t:zone="so-boats-boat-infos"> <t:label t:for="fromDate"/> : <input t:type="datefield" t:id="fromDate" class="width70" value="boardingFromDate" /> <input t:type="submit" class="ico refresh" t:id="refreshBoardings" value="Refresh" title="Recalculer les embarquements"/> @@ -249,7 +251,7 @@ <ul> <li t:type="loop" t:source="companyBoatInfos.elligibleBoatsValues" t:value="elligibleBoat"> <span t:type="ck/Tooltip" title="Infos" t:value="prop:elligibleRowInfos" t:effect="appear"> - <span class="${elligibleRowClass}"> + <span class="${elligibleRowStyle}"> ${elligibleBoat.sampleRow.code} </span> </span> @@ -329,7 +331,7 @@ <ul> <li t:type="loop" t:source="companyBoatInfos.elligibleBoatsValues" volatile="true" t:value="elligibleBoat"> <span t:type="ck/Tooltip" title="Infos" t:value="prop:elligibleRowInfos" t:effect="appear"> - <span class="${elligibleRowClass}"> + <span class="${elligibleRowStyle}"> ${elligibleBoat.sampleRow.code} </span> </span> @@ -359,7 +361,9 @@ </t:if> </div> - - - + <!-- Script for filters change --> + <script type="text/javascript"> + Event.observe('facadeName', 'change', function() { $('filtersForm').submit(); } ); + Event.observe('sectorName', 'change', function() { $('filtersForm').submit(); } ); + </script> </t:layout> Modified: trunk/suiviobsmer-ui/src/main/webapp/css/common.css =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/css/common.css 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-ui/src/main/webapp/css/common.css 2010-01-21 12:23:50 UTC (rev 255) @@ -291,7 +291,11 @@ font-weight: bold; } +div.t-autocomplete-menu ul { + background-color: #19a28d; +} + /***** ZONE IMPORT *****/ div.so-import { width: 60%; Modified: trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css 2010-01-21 09:39:18 UTC (rev 254) +++ trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css 2010-01-21 12:23:50 UTC (rev 255) @@ -46,9 +46,9 @@ border: 1px outset black; } -div#so-contacts-search div.t-autocomplete-menu ul { +/*div#so-contacts-search div.t-autocomplete-menu ul { background-color: #19a28d; -} +}*/ div#so-contacts-search a { text-decoration: none;
participants (1)
-
fdesbois@users.labs.libre-entreprise.org