Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Aug 4, 2024
1 parent 3c09416 commit 14ee0a7
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private void basicTable() {
.setTextAlign(CellTextAlign.RIGHT)
.setHeaderTextAlign(CellTextAlign.RIGHT)
.setCellRenderer(cell -> text(cell.getTableRow().getRecord().getIndex() + 1 + ""))

)

.addColumn(ColumnConfig.<Contact>create("status", "Status")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.dominokit.domino.ui.button.Button;
import org.dominokit.domino.ui.cards.Card;
import org.dominokit.domino.ui.datepicker.Calendar;
import org.dominokit.domino.ui.datepicker.CalendarInitConfig;
import org.dominokit.domino.ui.elements.DivElement;
import org.dominokit.domino.ui.forms.DateBox;
import org.dominokit.domino.ui.grid.Row;
Expand All @@ -23,6 +24,7 @@
import org.gwtproject.i18n.shared.cldr.impl.DateTimeFormatInfoImpl_ar;
import org.gwtproject.i18n.shared.cldr.impl.DateTimeFormatInfoImpl_es;

import java.util.Arrays;
import java.util.Date;

@UiView(presentable = DatePickerProxy.class)
Expand Down Expand Up @@ -59,10 +61,21 @@ protected HTMLDivElement init() {
@SampleMethod
private void inlineCalendar() {
element
.appendChild(Card.create("INLINE CALENDAR", "Different locales")
.appendChild(Calendar.create(new CalendarInitConfig()
.addPlugin(new DisableWeekendDaysPlugin())
.addPlugin(new SimpleEventsPlugin(Arrays.asList(SimpleEventsPlugin.CalendarEvent.of("My best friend birthday", new Date()))))
)
.addCss(dui_w_full)
)
)
.appendChild(Card.create("INLINE CALENDAR", "Different locales")
.setCollapsible(true)
.appendChild(Row.create()
.span4(Calendar.create())
.span4(Calendar.create(new CalendarInitConfig()
.addPlugin(new DisableWeekendDaysPlugin())
)
)
.span4(Calendar.create(new DateTimeFormatInfoImpl_ar()))
.span4(Calendar.create(new DateTimeFormatInfoImpl_es()))
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.dominokit.domino.datepicker.client.views.ui;

import org.dominokit.domino.ui.datepicker.CalendarDay;
import org.dominokit.domino.ui.datepicker.CalendarPlugin;

public class DisableWeekendDaysPlugin implements CalendarPlugin {

@Override
public void onCalendarDayAdded(CalendarDay calendarDay) {
if (calendarDay.isWeekend()) {
calendarDay.disable();
calendarDay.addCss("dui-mark-weekend-day");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package org.dominokit.domino.datepicker.client.views.ui;

import elemental2.dom.HTMLDivElement;
import org.dominokit.domino.ui.datepicker.Calendar;
import org.dominokit.domino.ui.datepicker.CalendarDay;
import org.dominokit.domino.ui.datepicker.CalendarPlugin;
import org.dominokit.domino.ui.elements.DivElement;
import org.dominokit.domino.ui.popover.Popover;
import org.dominokit.domino.ui.typography.BlockHeader;
import org.dominokit.domino.ui.utils.BaseDominoElement;
import org.gwtproject.i18n.client.DateTimeFormat;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Objects.nonNull;
import static org.dominokit.domino.ui.style.ColorsCss.dui_bg_accent;
import static org.dominokit.domino.ui.style.ColorsCss.dui_fg_white;
import static org.dominokit.domino.ui.style.DisplayCss.dui_flex;
import static org.dominokit.domino.ui.style.SpacingCss.*;
import static org.dominokit.domino.ui.utils.Domino.div;

public class SimpleEventsPlugin implements CalendarPlugin {

private Map<Long, List<CalendarEvent>> eventsMap = new HashMap<>();
private Calendar calendar;

public SimpleEventsPlugin(Collection<CalendarEvent> events) {
if (nonNull(events)) {
events.forEach(event -> {
long longDate = toPlainDate(event.getDate());
if (!eventsMap.containsKey(longDate)) {
eventsMap.put(longDate, new ArrayList<>());
}
eventsMap.get(longDate).add(event);
});
}
}

@Override
public void onInit(Calendar calendar) {
this.calendar = calendar;
}

@Override
public void onCalendarDayAdded(CalendarDay calendarDay) {
long longDate = toPlainDate(calendarDay.getDate());
calendarDay.addCss(dui_justify_start);
if (eventsMap.containsKey(longDate)) {
calendarDay.appendChild(div()
.addCss(dui_w_4, dui_h_4, dui_rounded_full, dui_bg_accent, dui_self_center)
.apply(self -> {
Popover.create(self)
.addCss(dui_rounded_md)
.apply(popover -> {
DivElement eventsElement = div().addCss(dui_flex, dui_flex_col, dui_gap_2, dui_p_4);
popover.appendChild(eventsElement);
eventsMap.get(longDate)
.forEach(event -> {
eventsElement.appendChild(div()
.addCss(dui_w_64, dui_rounded_md, dui_bg_accent, dui_p_2, dui_fg_white)
.appendChild(BlockHeader.create(toTimeString(event.date), event.getDescription()))
);
});
});
})
);
}
}

private String toTimeString(Date date){
return DateTimeFormat.getFormat(this.calendar.getDateTimeFormatInfo().formatHour12Minute()).format(date);
}

private long toPlainDate(Date date) {
long timeInMillis = date.getTime();

// Convert to the beginning of the day
long millisInDay = 24 * 60 * 60 * 1000; // Milliseconds in a day
long millisSinceMidnight = timeInMillis % millisInDay;
return timeInMillis - millisSinceMidnight;
}

public static class CalendarEvent {
private final String description;
private final Date date;
private String color;

public CalendarEvent(String description, Date date) {
this.description = description;
this.date = date;
}

public CalendarEvent(String description, Date date, String color) {
this(description, date);
this.color = color;
}

public static CalendarEvent of(String description, Date date) {
return new CalendarEvent(description, date);
}

public String getDescription() {
return description;
}

public Date getDate() {
return date;
}

public String getColor() {
return color;
}
}

public static class EventComponent extends BaseDominoElement<HTMLDivElement, EventComponent> {

private final DivElement root;
private final CalendarEvent event;


public EventComponent(CalendarEvent event) {
this.event = event;
this.root = div();
init(this);
}

public DivElement getRoot() {
return root;
}

public CalendarEvent getEvent() {
return event;
}

@Override
public HTMLDivElement element() {
return root.element();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void basicMenu() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -220,7 +220,7 @@ private void basicMenuWithHeaderAndActions() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -307,7 +307,7 @@ private void basicMenuSearchableAndAddMissing() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -384,7 +384,7 @@ private void basicMenuCustomItems() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -481,7 +481,7 @@ private void basicMenuSubHeader() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -590,7 +590,7 @@ private void basicMenuAllBasicFeatures() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -705,7 +705,7 @@ private void embedIntoElements() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -806,7 +806,7 @@ private void embedIntoElements() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -924,7 +924,7 @@ private void dropMenu() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -1023,7 +1023,7 @@ private void dropMenu() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -1122,7 +1122,7 @@ private void dropMenu() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -1245,7 +1245,7 @@ private void contextMenu() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -1384,7 +1384,7 @@ private void nestedMenu() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down Expand Up @@ -1515,7 +1515,7 @@ private void nestedMenu() {
)
.addSelectionListener((source, selectedItems) -> {
source.ifPresent(menuItem -> {
Notification.create("Key : " + menuItem + ", value : " + menuItem.getValue()).show();
Notification.create("Key : " + menuItem.getKey() + ", value : " + menuItem.getValue()).show();
});
})
)
Expand Down
3 changes: 3 additions & 0 deletions ui-demo-backend/src/main/resources/app/dev.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.dui-mark-weekend-day {
background: var(--dui-clr-grey-l-3);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AppClientModule implements EntryPoint {
public void onModuleLoad() {
if (System.getProperty("superdevmode").equals("on")) {
DominoGWT.init(DominoViewOptions.getInstance());
}else {
} else {
DominoGWT.init(DominoViewOptions.getInstance().setRootPath("domino-ui/demo/v2"));
}
DominoThemeManager.INSTANCE.applyUserThemes();
Expand Down

0 comments on commit 14ee0a7

Please sign in to comment.