Skip to content

Commit

Permalink
Consumers are added to config; Example page is improved
Browse files Browse the repository at this point in the history
  • Loading branch information
solomax committed Aug 31, 2023
1 parent 42d90fb commit fd0fd13
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.Map;
import java.util.function.Consumer;

import de.agilecoders.wicket.jquery.AbstractConfig;
import de.agilecoders.wicket.jquery.IKey;
Expand Down Expand Up @@ -104,12 +105,26 @@ public <T> TempusDominusConfig withDefaultDate(T defDate) {
}

/**
* @param cfg The display options allow you to control much of the picker's look and feel.
* @param cfgUpdater Consumer accepting TempusDominusDisplayConfig so it can be updated:
* The display options allow you to control much of the picker's look and feel.
* You can disable components, buttons and change the default icons.
* @return current instance
*/
public TempusDominusConfig withDisplayConfig(TempusDominusDisplayConfig cfg) {
put(Display, cfg);
public TempusDominusConfig withDisplayConfig(Consumer<TempusDominusDisplayConfig> cfgUpdater) {
cfgUpdater.accept(get(Display));
return this;
}

/**
* Shortcut for Display -> Icons
*
* @param cfgUpdater Consumer accepting TempusDominusIconConfig so it can be updated:
* The display options allow you to control much of the picker's look and feel.
* You can disable components, buttons and change the default icons.
* @return current instance
*/
public TempusDominusConfig withIcons(Consumer<TempusDominusIconConfig> cfgUpdater) {
get(Display).withIcons(cfgUpdater);
return this;
}

Expand All @@ -123,11 +138,12 @@ public TempusDominusConfig withKeepInvalid(boolean keep) {
}

/**
* @param cfg Most of the localization options are for title tooltips over icons.
* @param cfgUpdater Consumer accepting TempusDominusDisplayConfig so it can be updated:
* Most of the localization options are for title tooltips over icons.
* @return current instance
*/
public TempusDominusConfig withLocalization(TempusDominusLocalizationConfig cfg) {
put(Localization, cfg);
public TempusDominusConfig withLocalization(Consumer<TempusDominusLocalizationConfig> cfgUpdater) {
cfgUpdater.accept(get(Localization));
return this;
}

Expand Down Expand Up @@ -182,12 +198,13 @@ public TempusDominusConfig withPromptTimeOnDateChangeTransitionDelay(int delay)
}

/**
* @param cfg Restrictions allow you to prevent users from selected dates or times based
* @param cfgUpdater Consumer accepting TempusDominusDisplayConfig so it can be updated:
* Restrictions allow you to prevent users from selected dates or times based
* on a set of rules.
* @return current instance
*/
public TempusDominusConfig withRestrictions(TempusDominusRestrictionsConfig cfg) {
put(Restrictions, cfg);
public TempusDominusConfig withRestrictions(Consumer<TempusDominusRestrictionsConfig> cfgUpdater) {
cfgUpdater.accept(get(Restrictions));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

import de.agilecoders.wicket.jquery.AbstractConfig;
import de.agilecoders.wicket.jquery.IKey;
Expand Down Expand Up @@ -155,13 +156,14 @@ public <T> TempusDominusDisplayConfig withClass(Class<T> clazz) {
}

/**
* @param cfg Any icon library that expects icons to be used like
* @param cfgUpdater Consumer accepting TempusDominusIconConfig so it can be updated:
* Any icon library that expects icons to be used like
* &lt;i class='fas fa-calendar'&gt;&lt;/i&gt; will work, provided you include the
* correct styles and scripts needed.
* @return current instance
*/
public TempusDominusDisplayConfig withIcons(TempusDominusIconConfig cfg) {
put(Icons, cfg);
public TempusDominusDisplayConfig withIcons(Consumer<TempusDominusIconConfig> cfgUpdater) {
cfgUpdater.accept(get(Icons));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.wicket.Session;
import org.apache.wicket.util.lang.Args;
Expand All @@ -23,6 +25,7 @@
*/
public class TempusDominusLocalizationConfig extends AbstractConfig {
private static final long serialVersionUID = 1L;
private static final Pattern YEAR_PATTERN = Pattern.compile("^[^y]*([y]+)[^y]*$", Pattern.CASE_INSENSITIVE);

public enum HourCycleType {
H11("h11"), // Midnight: 00 AM; Night: 11 PM
Expand Down Expand Up @@ -418,7 +421,7 @@ public TempusDominusLocalizationConfig withHourCycle(HourCycleType cycle) {
* @return current instance
*/
public TempusDominusLocalizationConfig withDateFormat(DateFormatType type, String format) {
get(DateFormats).put(type.name(), format);
get(DateFormats).put(type.name(), toJavaScriptDateFormat(format));
return this;
}

Expand All @@ -443,8 +446,17 @@ public TempusDominusLocalizationConfig withFormat(String format) {
return this;
}

private static String toJavaScriptDateFormat(final String javaFormat) {
return nullToEmpty(javaFormat).replace('a', 't');
private static String toJavaScriptDateFormat(final String _fmt) {
String jsFormat = nullToEmpty(_fmt).replace(" a", " t");
Matcher yearMatcher = YEAR_PATTERN.matcher(jsFormat);
if (yearMatcher.find()) {
String year = yearMatcher.group(1);
// only 2 or 4 'yyyy' are supported
if (year.length() < 2 || year.length() > 2) {
return jsFormat.substring(0, yearMatcher.start(1)) + "yyyy" + jsFormat.substring(yearMatcher.end(1));
}
}
return jsFormat;
}

public String getFormat() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public BasePage(final PageParameters parameters) {
mvt.setWidth("device-width");
mvt.setInitialScale("1");
add(mvt);
// add(new OptimizedMobileViewportNoZoomMetaTag("viewport1"));
add(new IeEdgeMetaTag("ie-edge"));
add(new MetaTag("description", Model.of("description"), Model.of("Apache Wicket & Bootstrap Demo")));
add(new MetaTag("author", Model.of("author"), Model.of("Michael Haitz <[email protected]>")));
Expand Down Expand Up @@ -265,11 +264,8 @@ protected boolean hasNavigation() {
*/
private Component newNavigation(String markupId) {
WebMarkupContainer navigation = new WebMarkupContainer(markupId);
//navigation.add(new AffixBehavior("200"));
navigation.setVisible(hasNavigation());

return navigation;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,59 @@
</head>
<body>
<wicket:extend>
<div class="container bd-layout mt-3">
<div class="bd-sidebar">
<ul wicket:id="navigation" class="dropdown-menu d-block">
<li><h6 class="dropdown-header">java.util.Date based Model</h6></li>
<li><a class="dropdown-item" href="#datepicker" data-bs-toggle="collapse" aria-expanded="false" aria-controls="datepicker">
<i class="fas fa-chevron-right"></i>&nbsp;DatetimePicker</a>
</li>
<li><a class="dropdown-item" href="#datepicker-birthday" data-bs-toggle="collapse" aria-expanded="false" aria-controls="datepicker-birthday">
<i class="fas fa-chevron-right"></i>&nbsp;BirthdayPicker</a>
</li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#datepicker-icons" data-bs-toggle="collapse" aria-expanded="false" aria-controls="datepicker-icons">
<i class="fas fa-chevron-right"></i>&nbsp;DatetimePicker with icons</a>
</li>
<li><h6 class="dropdown-header">java.time.* based Model</h6></li>
<li><a class="dropdown-item" href="#localdatepicker" data-bs-toggle="collapse" aria-expanded="false" aria-controls="localdatepicker">
<i class="fas fa-chevron-right"></i>&nbsp;LocalDateTime based</a>
</li>
<li><a class="dropdown-item" href="#localdatepicker-birthday" data-bs-toggle="collapse" aria-expanded="false" aria-controls="localdatepicker-birthday">
<i class="fas fa-chevron-right"></i>&nbsp;LocalDate based</a>
</li>
<li><a class="dropdown-item" href="#localdatepicker-time" data-bs-toggle="collapse" aria-expanded="false" aria-controls="localdatepicker-time">
<i class="fas fa-chevron-right"></i>&nbsp;LocalTime based</a>
</li>
<li><a class="dropdown-item" href="#zoneddatepicker-icon" data-bs-toggle="collapse" aria-expanded="false" aria-controls="zoneddatepicker-icon">
<i class="fas fa-chevron-right"></i>&nbsp;ZonedDateTime based with icon</a>
</li>
</ul>
</div>

<div wicket:id="navigation"></div> <!-- required by parent -->
<form wicket:id="form">
<div class="container bd-layout mt-3">
<div class="bd-sidebar">
<ul class="dropdown-menu d-block">
<li><h6 class="dropdown-header">java.util.Date based Model</h6></li>
<li><a class="dropdown-item" href="#datepicker" data-bs-toggle="collapse" aria-expanded="false" aria-controls="datepicker">
<i class="fas fa-chevron-right"></i>&nbsp;DatetimePicker</a>
</li>
<li><a class="dropdown-item" href="#datepicker-birthday" data-bs-toggle="collapse" aria-expanded="false" aria-controls="datepicker-birthday">
<i class="fas fa-chevron-right"></i>&nbsp;BirthdayPicker</a>
</li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#datepicker-icons" data-bs-toggle="collapse" aria-expanded="false" aria-controls="datepicker-icons">
<i class="fas fa-chevron-right"></i>&nbsp;DatetimePicker with icons</a>
</li>
<li><h6 class="dropdown-header">java.time.* based Model</h6></li>
<li><a class="dropdown-item" href="#localdatepicker" data-bs-toggle="collapse" aria-expanded="false" aria-controls="localdatepicker">
<i class="fas fa-chevron-right"></i>&nbsp;LocalDateTime based</a>
</li>
<li><a class="dropdown-item" href="#localdatepicker-birthday" data-bs-toggle="collapse" aria-expanded="false" aria-controls="localdatepicker-birthday">
<i class="fas fa-chevron-right"></i>&nbsp;LocalDate based</a>
</li>
<li><a class="dropdown-item" href="#localdatepicker-time" data-bs-toggle="collapse" aria-expanded="false" aria-controls="localdatepicker-time">
<i class="fas fa-chevron-right"></i>&nbsp;LocalTime based</a>
</li>
<li><a class="dropdown-item" href="#zoneddatepicker-icon" data-bs-toggle="collapse" aria-expanded="false" aria-controls="zoneddatepicker-icon">
<i class="fas fa-chevron-right"></i>&nbsp;ZonedDateTime based with icon</a>
</li>
<li>
<div class="p-2">
<h5>Set page Locale</h5>
<div class="mb-3">
<label wicket:for="languages" class="form-label">Select Language</label>
<select class="form-select" wicket:id="languages"></select>
</div>
<div class="mb-3">
<label wicket:for="countries" class="form-label">Select Country</label>
<select class="form-select" wicket:id="countries"></select>
</div>
<button class="btn btn-primary" wicket:id="submit">Set</button>
</div>
</li>
</ul>
</div>

<div class="bd-main">
<div class="container">
<h1>TempusDominus Picker</h1>
<div class="bd-main">
<div class="container">
<h1>TempusDominus Picker</h1>

<p class="lead">A tempus-dominus picker from Eonasdan v6</p>
</div>
<form wicket:id="form">
<p class="lead">A tempus-dominus picker from Eonasdan v6</p>
</div>
<div wicket:id="feedback"></div>
<div class="card" id="datepicker">
<div class="card-body">
<h5 class="card-title">Simple datetime picker.</h5>
Expand Down Expand Up @@ -116,9 +131,9 @@ <h6 class="card-subtitle mb-2 text-body-secondary">Configuration code:</h6>
<pre wicket:id="zoned-java-code"></pre>
</div>
</div>
</form>
</div>
</div>
</div>
</form>
</wicket:extend>
</body>
</html>
Loading

0 comments on commit fd0fd13

Please sign in to comment.