Package: HtmlTemplateCalendarViewController
HtmlTemplateCalendarViewController
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HtmlTemplateCalendarViewController(HtmlTemplateCalendarView, SiteNode, RequestLocaleManager, CalendarDao, TimeProvider) |
|
|
|
|
|
||||||||||||||||||||
lambda$render$0(int, int) |
|
|
|
|
|
||||||||||||||||||||
lambda$render$1(DefaultCalendarViewController.Entry) |
|
|
|
|
|
||||||||||||||||||||
lambda$render$2(SortedMap, int) |
|
|
|
|
|
||||||||||||||||||||
lambda$toAggregate$3(String) |
|
|
|
|
|
||||||||||||||||||||
render(Optional, int, int, int, SortedMap, int) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
toAggregate(DefaultCalendarViewController.Entry) |
|
|
|
|
|
||||||||||||||||||||
toAggregate(int, boolean) |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.frontend.ui.component.calendar.htmltemplate;
28:
29: import javax.annotation.Nonnegative;
30: import javax.annotation.Nonnull;
31: import java.text.DateFormatSymbols;
32: import java.util.List;
33: import java.util.Map;
34: import java.util.Optional;
35: import java.util.SortedMap;
36: import java.util.function.IntFunction;
37: import java.util.stream.IntStream;
38: import it.tidalwave.util.TimeProvider;
39: import it.tidalwave.northernwind.core.model.RequestLocaleManager;
40: import it.tidalwave.northernwind.core.model.SiteNode;
41: import it.tidalwave.northernwind.core.model.Template.Aggregate;
42: import it.tidalwave.northernwind.frontend.ui.component.calendar.CalendarViewController;
43: import it.tidalwave.northernwind.frontend.ui.component.calendar.DefaultCalendarViewController;
44: import it.tidalwave.northernwind.frontend.ui.component.calendar.spi.CalendarDao;
45: import lombok.extern.slf4j.Slf4j;
46: import static java.util.Collections.emptyList;
47: import static java.util.stream.Collectors.*;
48: import static it.tidalwave.util.Pair.*;
49: import static it.tidalwave.northernwind.core.model.Template.Aggregates.toAggregates;
50: import static it.tidalwave.northernwind.frontend.ui.component.Properties.P_TEMPLATE_PATH;
51:
52: /***********************************************************************************************************************
53: *
54: * <p>An implementation of {@link CalendarViewController} based on HTML templates.</p>
55: *
56: * <p>The template for rendering the page can be specified by means of the property {@code P_TEMPLATE_PATH}.</p>
57: *
58: * @see HtmlTemplateCalendarView
59: * @author Fabrizio Giudici
60: *
61: **********************************************************************************************************************/
62: @Slf4j
63: public class HtmlTemplateCalendarViewController extends DefaultCalendarViewController
64: {
65: @Nonnull
66: private final HtmlTemplateCalendarView view;
67:
68: /*******************************************************************************************************************
69: *
70: ******************************************************************************************************************/
71: public HtmlTemplateCalendarViewController (@Nonnull final HtmlTemplateCalendarView view,
72: @Nonnull final SiteNode siteNode,
73: @Nonnull final RequestLocaleManager requestLocaleManager,
74: @Nonnull final CalendarDao dao,
75: @Nonnull final TimeProvider timeProvider)
76: {
77: super(view, siteNode, requestLocaleManager, dao, timeProvider);
78: this.view = view;
79: }
80:
81: /*******************************************************************************************************************
82: *
83: * {@inheritDoc}
84: *
85: ******************************************************************************************************************/
86: @Override
87: protected void render (@Nonnull final Optional<String> title,
88: @Nonnegative final int year,
89: @Nonnegative final int firstYear,
90: @Nonnegative final int lastYear,
91: @Nonnull final SortedMap<Integer, List<Entry>> byMonth,
92: @Nonnegative final int columns)
93: {
94: final var years = IntStream.rangeClosed(firstYear, lastYear)
95:• .mapToObj(y -> toAggregate(y, y == year))
96: .collect(toAggregates("years"));
97:
98: final var monthNames = DateFormatSymbols.getInstance(requestLocaleManager.getLocales().get(0)).getMonths();
99: final IntFunction<List<Map<String, Object>>> entriesByMonth =
100: m -> byMonth.getOrDefault(m + 1, emptyList()).stream().map(x -> toAggregate(x).getMap()).collect(toList());
101: view.render(title,
102: getViewProperties().getProperty(P_TEMPLATE_PATH),
103: indexedPairStream(monthNames, BASE_1).collect(pairsToMap()),
104: Integer.toString(year),
105: years,
106: indexedPairStream(0, 12, entriesByMonth, BASE_1).collect(pairsToMap()),
107: columns);
108: }
109:
110: /*******************************************************************************************************************
111: *
112: ******************************************************************************************************************/
113: @Nonnull
114: private static Aggregate toAggregate (@Nonnull final Entry entry)
115: {
116: return Aggregate.of( "label", entry.name)
117: .with("link", entry.link)
118: .with("class", entry.type.map(s -> "nw-calendar-table-link-" + s));
119: }
120:
121: /*******************************************************************************************************************
122: *
123: ******************************************************************************************************************/
124: @Nonnull
125: private Aggregate toAggregate (final int year, final boolean withLink)
126: {
127: final var a = Aggregate.of("number", year);
128:• return withLink ? a : a.with("link", createYearLink(year));
129: }
130: }