Package: HtmlTemplateCalendarView
HtmlTemplateCalendarView
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HtmlTemplateCalendarView(Id, Site) |
|
|
|
|
|
||||||||||||||||||||
lambda$render$0(Template, String) |
|
|
|
|
|
||||||||||||||||||||
lambda$render$1(int, int) |
|
|
|
|
|
||||||||||||||||||||
render(Optional, Optional, Map, String, Template.Aggregates, Map, int) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * NorthernWind - lightweight CMS
5: * http://tidalwave.it/projects/northernwind
6: *
7: * Copyright (C) 2011 - 2025 Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/northernwind-src
22: * git clone https://github.com/tidalwave-it/northernwind-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.northernwind.frontend.ui.component.calendar.htmltemplate;
27:
28: import javax.annotation.Nonnull;
29: import java.util.List;
30: import java.util.Map;
31: import java.util.Optional;
32: import java.util.stream.IntStream;
33: import it.tidalwave.util.Id;
34: import it.tidalwave.northernwind.core.model.ResourcePath;
35: import it.tidalwave.northernwind.core.model.Site;
36: import it.tidalwave.northernwind.core.model.Template.Aggregates;
37: import it.tidalwave.northernwind.frontend.ui.annotation.ViewMetadata;
38: import it.tidalwave.northernwind.frontend.ui.component.htmltemplate.HtmlHolder;
39: import it.tidalwave.northernwind.frontend.ui.component.calendar.CalendarView;
40: import it.tidalwave.northernwind.frontend.ui.component.htmlfragment.htmltemplate.HtmlTemplateHtmlFragmentView;
41: import static java.util.stream.Collectors.*;
42:
43: /***************************************************************************************************************************************************************
44: *
45: * <p>An implementation of {@link CalendarView} based on HTML templates.</p>
46: *
47: * @see HtmlTemplateCalendarViewController
48: * @author Fabrizio Giudici
49: *
50: **************************************************************************************************************************************************************/
51: @ViewMetadata(typeUri="http://northernwind.tidalwave.it/component/Calendar/#v1.0",
52: controlledBy=HtmlTemplateCalendarViewController.class)
53: public class HtmlTemplateCalendarView extends HtmlTemplateHtmlFragmentView implements CalendarView
54: {
55: @Nonnull
56: private final Site site;
57:
58: /***********************************************************************************************************************************************************
59: *
60: **********************************************************************************************************************************************************/
61: public HtmlTemplateCalendarView (@Nonnull final Id id, @Nonnull final Site site)
62: {
63: super(id);
64: this.site = site;
65:• }
66:
67: /***********************************************************************************************************************************************************
68: * Renders the diary contents. See {@link HtmlTemplateCalendarViewController} for more information.
69: *
70: * @see HtmlTemplateCalendarViewController *
71: * @param title the optional title
72: * @param templatePath an optional template (otherwise a default one is used)
73: * @param monthNames the name of months in the required language
74: * @param year the current year
75: * @param years the available years
76: * @param entries the items of the current year
77: * @param columns the columns (can be 1, 2, 3, 4, 6)
78: **********************************************************************************************************************************************************/
79: public void render (@Nonnull final Optional<String> title,
80: @Nonnull final Optional<ResourcePath> templatePath,
81: @Nonnull final Map<Integer, String> monthNames,
82: @Nonnull final String year,
83: @Nonnull final Aggregates years,
84: @Nonnull final Map<Integer, List<Map<String, Object>>> entries,
85: final int columns)
86: {
87: final var template = site.getTemplate(getClass(), templatePath, "Calendar.st");
88: title.ifPresent(t -> template.addAttribute("title", t));
89: template.addAttribute("year", year);
90: template.addAttribute("month", monthNames);
91: template.addAttribute("entries", entries);
92: template.addAttribute("columns", columns);
93: template.addAttribute("rows", IntStream.rangeClosed(1, 12 / columns)
94: .mapToObj(r -> IntStream.rangeClosed(1 + (r-1) * columns, r * columns)
95: .boxed()
96: .collect(toList()))
97: .collect(toList()));
98: template.addAttribute("columnWidth", 100 / columns);
99: addComponent(new HtmlHolder(template.render(years)));
100: }
101: }