Skip to content

Package: HtmlTemplateCalendarView

HtmlTemplateCalendarView

nameinstructionbranchcomplexitylinemethod
HtmlTemplateCalendarView(Id, Site)
M: 0 C: 32
100%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 3
100%
M: 0 C: 1
100%
lambda$render$0(Template, String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$render$1(int, int)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
render(Optional, Optional, Map, String, Template.Aggregates, Map, int)
M: 0 C: 69
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

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.Nonnull;
30: import java.util.List;
31: import java.util.Map;
32: import java.util.Optional;
33: import java.util.stream.IntStream;
34: import it.tidalwave.util.Id;
35: import it.tidalwave.northernwind.core.model.ResourcePath;
36: import it.tidalwave.northernwind.core.model.Site;
37: import it.tidalwave.northernwind.core.model.Template.Aggregates;
38: import it.tidalwave.northernwind.frontend.ui.annotation.ViewMetadata;
39: import it.tidalwave.northernwind.frontend.ui.component.htmltemplate.HtmlHolder;
40: import it.tidalwave.northernwind.frontend.ui.component.calendar.CalendarView;
41: import it.tidalwave.northernwind.frontend.ui.component.htmlfragment.htmltemplate.HtmlTemplateHtmlFragmentView;
42: import static java.util.stream.Collectors.*;
43:
44: /***********************************************************************************************************************
45: *
46: * <p>An implementation of {@link CalendarView} based on HTML templates.</p>
47: *
48: * @see HtmlTemplateCalendarViewController
49: * @author Fabrizio Giudici
50: *
51: **********************************************************************************************************************/
52: @ViewMetadata(typeUri="http://northernwind.tidalwave.it/component/Calendar/#v1.0",
53: controlledBy=HtmlTemplateCalendarViewController.class)
54: public class HtmlTemplateCalendarView extends HtmlTemplateHtmlFragmentView implements CalendarView
55: {
56: @Nonnull
57: private final Site site;
58:
59: /*******************************************************************************************************************
60: *
61: ******************************************************************************************************************/
62: public HtmlTemplateCalendarView (@Nonnull final Id id, @Nonnull final Site site)
63: {
64: super(id);
65: this.site = site;
66:• }
67:
68: /*******************************************************************************************************************
69: *
70: * Renders the diary contents. See {@link HtmlTemplateCalendarViewController} for more information.
71: *
72: * @see HtmlTemplateCalendarViewController *
73: * @param title the optional title
74: * @param templatePath an optional template (otherwise a default one is used)
75: * @param monthNames the name of months in the required language
76: * @param year the current year
77: * @param years the available years
78: * @param entries the items of the current year
79: * @param columns the columns (can be 1, 2, 3, 4, 6)
80: *
81: ******************************************************************************************************************/
82: public void render (@Nonnull final Optional<String> title,
83: @Nonnull final Optional<ResourcePath> templatePath,
84: @Nonnull final Map<Integer, String> monthNames,
85: @Nonnull final String year,
86: @Nonnull final Aggregates years,
87: @Nonnull final Map<Integer, List<Map<String, Object>>> entries,
88: final int columns)
89: {
90: final var template = site.getTemplate(getClass(), templatePath, "Calendar.st");
91: title.ifPresent(t -> template.addAttribute("title", t));
92: template.addAttribute("year", year);
93: template.addAttribute("month", monthNames);
94: template.addAttribute("entries", entries);
95: template.addAttribute("columns", columns);
96: template.addAttribute("rows", IntStream.rangeClosed(1, 12 / columns)
97: .mapToObj(r -> IntStream.rangeClosed(1 + (r-1) * columns, r * columns)
98: .boxed()
99: .collect(toList()))
100: .collect(toList()));
101: template.addAttribute("columnWidth", 100 / columns);
102: addComponent(new HtmlHolder(template.render(years)));
103: }
104: }