diff --git a/datatable/src/main/java/org/dominokit/domino/datatable/client/views/ui/BasicDataTableViewImpl.java b/datatable/src/main/java/org/dominokit/domino/datatable/client/views/ui/BasicDataTableViewImpl.java index 93a575d7..bbcdc8f6 100644 --- a/datatable/src/main/java/org/dominokit/domino/datatable/client/views/ui/BasicDataTableViewImpl.java +++ b/datatable/src/main/java/org/dominokit/domino/datatable/client/views/ui/BasicDataTableViewImpl.java @@ -58,6 +58,7 @@ private void basicTable() { .setTextAlign(CellTextAlign.RIGHT) .setHeaderTextAlign(CellTextAlign.RIGHT) .setCellRenderer(cell -> text(cell.getTableRow().getRecord().getIndex() + 1 + "")) + ) .addColumn(ColumnConfig.create("status", "Status") diff --git a/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/DatePickerViewImpl.java b/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/DatePickerViewImpl.java index cd472757..4faafa35 100644 --- a/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/DatePickerViewImpl.java +++ b/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/DatePickerViewImpl.java @@ -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; @@ -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) @@ -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())) ) diff --git a/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/DisableWeekendDaysPlugin.java b/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/DisableWeekendDaysPlugin.java new file mode 100644 index 00000000..f85d81ae --- /dev/null +++ b/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/DisableWeekendDaysPlugin.java @@ -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"); + } + } +} diff --git a/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/SimpleEventsPlugin.java b/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/SimpleEventsPlugin.java new file mode 100644 index 00000000..7fb0cbe6 --- /dev/null +++ b/datepicker/src/main/java/org/dominokit/domino/datepicker/client/views/ui/SimpleEventsPlugin.java @@ -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> eventsMap = new HashMap<>(); + private Calendar calendar; + + public SimpleEventsPlugin(Collection 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 { + + 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(); + } + } + +} diff --git a/menu/src/main/java/org/dominokit/domino/menu/client/views/ui/MenuViewImpl.java b/menu/src/main/java/org/dominokit/domino/menu/client/views/ui/MenuViewImpl.java index 193b9ac0..74f49327 100644 --- a/menu/src/main/java/org/dominokit/domino/menu/client/views/ui/MenuViewImpl.java +++ b/menu/src/main/java/org/dominokit/domino/menu/client/views/ui/MenuViewImpl.java @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) @@ -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(); }); }) ) diff --git a/ui-demo-backend/src/main/resources/app/dev.css b/ui-demo-backend/src/main/resources/app/dev.css index e69de29b..930ef9d7 100644 --- a/ui-demo-backend/src/main/resources/app/dev.css +++ b/ui-demo-backend/src/main/resources/app/dev.css @@ -0,0 +1,3 @@ +.dui-mark-weekend-day { + background: var(--dui-clr-grey-l-3); +} \ No newline at end of file diff --git a/ui-demo-frontend/src/main/java/org/dominokit/domino/ui/demo/AppClientModule.java b/ui-demo-frontend/src/main/java/org/dominokit/domino/ui/demo/AppClientModule.java index 81299328..ddbe87de 100644 --- a/ui-demo-frontend/src/main/java/org/dominokit/domino/ui/demo/AppClientModule.java +++ b/ui-demo-frontend/src/main/java/org/dominokit/domino/ui/demo/AppClientModule.java @@ -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();