Initial change view of custom views not working
Closed this issue · 9 comments
Original from @aetasoul
Seems to not be fully fixed the changeView problem. It correctly work with calendar.changeView(CalendarViewImpl.TIME_GRID_WEEK);
and calendar.changeView(SchedulerView.RESOURCE_TIMELINE_YEAR);
but not with custom view
MyCustomView customView = new MyCustomView(75);
calendar = new MyFullTimeline(customView.getInitialOptions());
calendar.changeView(customView);
public class MyCustomView implements CalendarView {
private final int numberOfDays;
public MyCustomView(int numberOfDays) {
this.numberOfDays = numberOfDays;
}
@Override
public String getClientSideValue() {
return "customResourceTimeline";
}
public JreJsonObject getInitialOptions() {
JsonFactory factory = new JreJsonFactory();
JreJsonObject initialOptions = new JreJsonObject(factory);
JreJsonObject durationHolder = new JreJsonObject(factory);
durationHolder.set("days", factory.create(numberOfDays));
JreJsonObject customViewHolder = new JreJsonObject(factory);
customViewHolder.set("type", factory.create("resourceTimeline"));
customViewHolder.set("duration", durationHolder);
JreJsonObject viewsHolder = new JreJsonObject(factory);
viewsHolder.set(getName(), customViewHolder);
initialOptions.set("views", viewsHolder);
return initialOptions;
}
@Override
public String getName() {
return "customResourceTimeline";
}
}
branch v6 with vaadin 14.10.0
Using the demo http://localhost:8080/demotimelinecustomdays I can test this issue
On the top there is a button "Change", the changeView never work with customView, on button click or calling it on page loading
Looks like some idiot (aka me ;) ) removed the intial options from the calendar init. Reintrating it made the custom view work.
I totally missed that looking in the code
The demo is good, I'm testing it also on my application, for now it's not working let me check
I am going to implement something to proper register custom views on calendar creation time.
found the problem
My js class:
_initCalendar(){
super._initCalendar();
}
The correct way
initCalendar(){
super.initCalendar();
}
I have added new api to register custom calendar views. Feel free to try it out. The old variant still works, but the new one is recommended as it is clearer Java, not just messing around with json objects :)
Interface is "CustomCalendarView", builder method is "withCustomCalendarViews()" and the FC itself has a "setCustomCalendarViews" method. Demos are "CustomViewDemo" (new way using api) and "AnonymousCustomViewDemo" (old way using init props)
But yeah, calling the correct init method also might help :D
Will test it tomorrow morning!
I have added new api to register custom calendar views. Feel free to try it out. The old variant still works, but the new one is recommended as it is clearer Java, not just messing around with json objects :)
Interface is "CustomCalendarView", builder method is "withCustomCalendarViews()" and the FC itself has a "setCustomCalendarViews" method. Demos are "CustomViewDemo" (new way using api) and "AnonymousCustomViewDemo" (old way using init props)