Hi Isomorphic,
I have a MiniDateRangeItem for creationDate daterange selection. Now, in order to improve the GUI, I added "yearToDate" and "lastYear", ... shortcuts.
Basically all those shortcuts have problems, even though they should work IMHO.
Tested using v10.1p_2017-04-13 and SNAPSHOT_v11.1d_2017-04-16.
BuiltInDS.java:
Problems:
Best regards
Blama
I have a MiniDateRangeItem for creationDate daterange selection. Now, in order to improve the GUI, I added "yearToDate" and "lastYear", ... shortcuts.
Basically all those shortcuts have problems, even though they should work IMHO.
Tested using v10.1p_2017-04-13 and SNAPSHOT_v11.1d_2017-04-16.
BuiltInDS.java:
Code:
package com.smartgwt.sample.client;
import java.util.Date;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.datepicker.client.CalendarUtil;
import com.smartgwt.client.Version;
import com.smartgwt.client.core.KeyIdentifier;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DateRange;
import com.smartgwt.client.data.RelativeDate;
import com.smartgwt.client.types.Cursor;
import com.smartgwt.client.util.Page;
import com.smartgwt.client.util.PageKeyHandler;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.CanvasItem;
import com.smartgwt.client.widgets.form.fields.MiniDateRangeItem;
import com.smartgwt.client.widgets.form.fields.SpacerItem;
import com.smartgwt.client.widgets.layout.HStack;
import com.smartgwt.client.widgets.layout.VLayout;
public class BuiltInDS implements EntryPoint {
private VLayout mainLayout;
private IButton recreateBtn;
public void onModuleLoad() {
KeyIdentifier debugKey = new KeyIdentifier();
debugKey.setCtrlKey(true);
debugKey.setKeyName("D");
Page.registerKey(debugKey, new PageKeyHandler() {
public void execute(String keyName) {
SC.showConsole();
}
});
mainLayout = new VLayout(20);
mainLayout.setWidth100();
mainLayout.setHeight100();
recreateBtn = new IButton("Recreate");
recreateBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
recreate();
}
});
mainLayout.addMember(recreateBtn);
recreate();
mainLayout.draw();
}
private void recreate() {
Window w = new Window();
w.setWidth("95%");
w.setHeight("95%");
w.setMembersMargin(0);
w.setModalMaskOpacity(70);
w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
w.setTitle("5.1p / 6.1d MiniDateRangeItem problems (no date, wrong calculation)" + w.getTitle());
w.setShowMinimizeButton(false);
w.setIsModal(true);
w.setShowModalMask(true);
w.centerInPage();
final DynamicForm df = new DynamicForm();
df.setColWidths("100", "180");
df.setDataSource(DataSource.get("supplyItem"));
MiniDateRangeItem createdAtMDRI = new MiniDateRangeItem("nextShipment");
createdAtMDRI.setWidth("*");
MDRIConfiguer mdriConfiguer = new MDRIConfiguer("MDRIConfiguer", createdAtMDRI);
df.setFields(createdAtMDRI, new SpacerItem(), mdriConfiguer);
IButton showValue = new IButton("Show value", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
SC.say(df.getValuesAsAdvancedCriteria() != null ? df.getValuesAsAdvancedCriteria().toJSON() : "no criteria");
}
});
w.addItem(df);
w.addItem(showValue);
w.show();
w.focus();
}
private class MDRIConfiguer extends CanvasItem {
private MiniDateRangeItem createdAtDRI;
public MDRIConfiguer(String name, final MiniDateRangeItem createdAtDRI) {
super(name);
this.createdAtDRI = createdAtDRI;
setStartRow(false);
setShowTitle(false);
setWidth("*");
setHeight(createdAtDRI.getHeight());
HStack al = new HStack(5);
{
al.addMember(new MyLabel("YTD", new RelativeDate("-0Y"), new RelativeDate("$today")));
al.addMember(new MyLabel("QTD", new RelativeDate("-0Q"), new RelativeDate("$today")));
al.addMember(new MyLabel("MTD", new RelativeDate("-0M"), new RelativeDate("$today")));
Date d = new Date();
CalendarUtil.addMonthsToDate(d, -12);
String lastYear = DateTimeFormat.getFormat("yyyy").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("MMMM").format(d);
al.addMember(new MyLabel(lastYear, new RelativeDate("-1Y"), new RelativeDate("-1d[-0Y]"))); // -0Y[-1D] does not work, either
al.addMember(new MyLabel(lastQuarter, new RelativeDate("-1Q"), new RelativeDate("-1d[-0Q]")));// -0Q[-1D] does not work, either
al.addMember(new MyLabel(lastMonth, new RelativeDate("-1M"), new RelativeDate("-1d[-0M]")));// -0M[-1D] does not work, either
}
setCanvas(al);
}
private class MyLabel extends Label {
public MyLabel(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);
dr.setRelativeEndDate(endRD);
createdAtDRI.setValue(dr);
}
});
}
}
}
}
- YTD: DateRange looks OK in the DynamicForm, but if calling getValuesAsAdvancedCriteria() via the button, it returns null. Reason: From-value has a validation error, if you click the calendar icon.
- QTD: DateRange looks OK in the DynamicForm, but if calling getValuesAsAdvancedCriteria() via the button, it returns null. Reason: From-value has a validation error, if you click the calendar icon.
- MTD: From-value is wrong. Like above it should be Apr, 1st.
- 2016: To-value should be 2016-12-31. From-value has a validation error, if you click the calendar icon.
- Q1: To-value should be 2017-03-31. From-value has a validation error, if you click the calendar icon.
- March: From-value should be 2017-03-01. To-value should be 2017-03-31.
...eg, +1d[+1W] indicates "plus one day from the end of NEXT week".
So -1d[-0Y] should be "minus one day from the beginning of THIS year".
So -1d[-0Y] should be "minus one day from the beginning of THIS year".
Best regards
Blama
Comment