Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Feature Suggestion: Configurable Quick Fill in DateRangeItem and MiniDateRangeItem

    Hi Isomorphic,

    when revisiting old code I found a feature I build a few years ago, but that I could not use because of this now long fixed bug.
    What I'm doing is adding a CanvasItem after my MiniDateRangeItem, that consists of some Labels that quick-fill the Item for filtering on click.
    As this is after my normal item I have to change the DynamicForms numCols to 3 and the colSpan of other items to 2. This would not be necessary if this was built-in.

    This is what it looks like:

    Click image for larger version  Name:	MiniDateRangeItem.PNG Views:	0 Size:	1.6 KB ID:	270507

    After click on Q2:
    Click image for larger version

Name:	After Click.PNG
Views:	81
Size:	1.7 KB
ID:	270508

    My suggestion is that you add options to MiniDateRangeItem and DateRangeItem to enable either predefined or custom "quick fillers".
    • Predefined could be: YTD, QTD, MTD, WTD, Last year, Last quater, Last Month, Last Week, Next year, Next quater, Next Month, Next Week.
      I don't have the future options there, as this is a creation date (=in the past). But generally, past and future are useful of course.
    • Manually they'd consist of an array of entries consisting of a title and a from/to-Date or RelativeDateString.

    This is what I did in SmartGWT:
    Code:
    MiniDateRangeItem createdAtDRI = new MiniDateRangeItem("CREATED_AT", I18nEdited.creationDateRange());
    createdAtDRI.setType("datetime");
    createdAtDRI.setAllowRelativeDates(true);
    createdAtDRI.setWidth("*");
    availableFields.add(createdAtDRI);
    availableFields.add(new MDRIConfiguer("MDRIConfiguer", createdAtDRI));
    
    setFields(availableFields.toArray(new FormItem[availableFields.size()]));
    
    MDRIConfiguer.java:
    public class MDRIConfiguer extends CanvasItem {
        private MiniDateRangeItem createdAtDRI;
    
        public MDRIConfiguer(String name, final MiniDateRangeItem createdAtDRI) {
            super(name);
            this.createdAtDRI = createdAtDRI;
            setShouldSaveValue(false);
            setStartRow(false);
            setShowTitle(false);
            setWidth("*");
            setHeight(1);
    
            HStack al = new HStack(5);
            {
                al.addMember(new DateShortcut("YTD", new RelativeDate("-0Y[-0Y]"), null));
                al.addMember(new DateShortcut("QTD", new RelativeDate("-0Q[-0Q]"), null));
                al.addMember(new DateShortcut("MTD", new RelativeDate("-0M[-0M]"), null));
    
                Date d = new Date();
                DateTimeFormatInfo ddtfi = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo();
                CalendarUtil.addMonthsToDate(d, -12);
                String lastYear = DateTimeFormat.getFormat(ddtfi.formatYear()).format(d);
    
                d = new Date();
                CalendarUtil.addMonthsToDate(d, -3);
                int month0aligned = (new Integer(DateTimeFormat.getFormat("M").format(d)) / 3) + 1;
                String lastQuarter = "Q" + (month0aligned == 0 ? 4 : month0aligned);
    
                d = new Date();
                CalendarUtil.addMonthsToDate(d, -1);
                String lastMonth = DateTimeFormat.getFormat(ddtfi.formatMonthFull()).format(d);
    
                al.addMember(new DateShortcut(lastYear, new RelativeDate("-1Y[-0Y]"), new RelativeDate("-1Y[+0Y]")));
                al.addMember(new DateShortcut(lastQuarter, new RelativeDate("-1Q[-0Q]"), new RelativeDate("-1Q[+0Q]")));
                al.addMember(new DateShortcut(lastMonth, new RelativeDate("-1M[-0M]"), new RelativeDate("-1M[+0M]")));
            }
            setCanvas(al);
        }
    
        private class DateShortcut extends Label {
            public DateShortcut(String content, final RelativeDate startRD, final RelativeDate endRD) {
                super();
                setWidth(1);
                setCursor(Cursor.HAND);
                setContents("<span style=\"text-decoration: underline;\">" + content + "</span>");
    
                addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        DateRange dr = new DateRange();
                        dr.setRelativeStartDate(startRD);
                        if (endRD != null)
                            dr.setRelativeEndDate(endRD);
                        createdAtDRI.setValue(dr);
                    }
                });
            }
        }
    }
    I think this would make a nice addition. What do you think?

    Best regards
    Blama

    #2
    Have you see RelativeDateItem.presetOptions? It provides a similar capability, more compact but not as immediate as external buttons.

    Comment


      #3
      Hi Isomorphic,

      no, I did not know about this. This is good to know as well, but it seems this is more for single RelativeDateItem than for period selection fields like DateRangeItem and MiniDateRangeItem.

      Good to know about it, but I'd think quick but configurable YTD, MTD selections there would be great as well.

      Best regards
      Blama

      Comment

      Working...
      X