• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanodash / 17548792663

08 Sep 2025 11:10AM UTC coverage: 11.88% (-0.03%) from 11.91%
17548792663

push

github

tkuhn
Paging for template lists

334 of 3888 branches covered (8.59%)

Branch coverage included in aggregate %.

960 of 7004 relevant lines covered (13.71%)

0.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/nanodash/component/TemplateResults.java
1
package com.knowledgepixels.nanodash.component;
2

3
import com.knowledgepixels.nanodash.template.Template;
4
import com.knowledgepixels.nanodash.template.TemplateData;
5

6
import org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator;
7
import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigatorLabel;
8
import org.apache.wicket.markup.html.WebMarkupContainer;
9
import org.apache.wicket.markup.html.panel.Panel;
10
import org.apache.wicket.markup.repeater.Item;
11
import org.apache.wicket.markup.repeater.data.DataView;
12
import org.apache.wicket.markup.repeater.data.ListDataProvider;
13
import org.apache.wicket.request.mapper.parameter.PageParameters;
14
import org.nanopub.extra.services.ApiResponse;
15
import org.nanopub.extra.services.ApiResponseEntry;
16

17
import java.util.ArrayList;
18
import java.util.List;
19

20
/**
21
 * A panel that displays a list of templates, either from a list of Template objects or from an ApiResponse.
22
 */
23
public class TemplateResults extends Panel {
24

25
    private static final long serialVersionUID = -5109507637942030910L;
26

27
    /**
28
     * Creates a TemplateResults panel from a list of Template objects.
29
     *
30
     * @param id           the Wicket component ID
31
     * @param templateList the list of Template objects to display
32
     * @return a TemplateResults panel
33
     */
34
    public static TemplateResults fromList(String id, List<Template> templateList) {
35
        return fromList(id, templateList, null);
×
36
    }
37

38
    /**
39
     * Creates a TemplateResults panel from a list of Template objects with additional parameters.
40
     *
41
     * @param id               the Wicket component ID
42
     * @param templateList     the list of Template objects to display
43
     * @param additionalParams additional parameters to pass to the TemplateItem components
44
     * @return a TemplateResults panel
45
     */
46
    public static TemplateResults fromList(String id, List<Template> templateList, final PageParameters additionalParams) {
47
        TemplateResults r = new TemplateResults(id);
×
48

49
        r.add(new DataView<Template>("templates", new ListDataProvider<Template>(templateList)) {
×
50

51
            private static final long serialVersionUID = 1L;
52

53
            @Override
54
            protected void populateItem(Item<Template> item) {
55
                item.add(new TemplateItem("template", item.getModelObject(), additionalParams));
×
56
            }
×
57

58
        });
59

60
        return r;
×
61
    }
62

63
    /**
64
     * Creates a TemplateResults panel from an ApiResponse.
65
     *
66
     * @param id          the Wicket component ID
67
     * @param apiResponse the ApiResponse containing the template data
68
     * @return a TemplateResults panel
69
     */
70
    public static TemplateResults fromApiResponse(String id, ApiResponse apiResponse) {
71
        return fromApiResponse(id, apiResponse, 0, null);
×
72
    }
73

74
    /**
75
     * Creates a TemplateResults panel from an ApiResponse with a limit on the number of templates displayed.
76
     *
77
     * @param id          the Wicket component ID
78
     * @param apiResponse the ApiResponse containing the template data
79
     * @param limit       the maximum number of templates to display (0 means no limit)
80
     * @return a TemplateResults panel
81
     */
82
    public static TemplateResults fromApiResponse(String id, ApiResponse apiResponse, int limit) {
83
        return fromApiResponse(id, apiResponse, limit, null);
×
84
    }
85

86
    /**
87
     * Creates a TemplateResults panel from an ApiResponse with a limit on the number of templates displayed and additional parameters.
88
     *
89
     * @param id               the Wicket component ID
90
     * @param apiResponse      the ApiResponse containing the template data
91
     * @param limit            the maximum number of templates to display (0 means no limit)
92
     * @param additionalParams additional parameters to pass to the TemplateItem components
93
     * @return a TemplateResults panel
94
     */
95
    public static TemplateResults fromApiResponse(final String id, ApiResponse apiResponse, int limit, final PageParameters additionalParams) {
96
        List<ApiResponseEntry> list = apiResponse.getData();
×
97
        if (limit > 0 && list.size() > limit) {
×
98
            List<ApiResponseEntry> shortList = new ArrayList<>();
×
99
            for (ApiResponseEntry e : list) {
×
100
                shortList.add(e);
×
101
                if (shortList.size() == limit) break;
×
102
            }
×
103
            list = shortList;
×
104
        }
105
        TemplateResults r = new TemplateResults(id);
×
106

107
        DataView<ApiResponseEntry> dataView = new DataView<>("templates", new ListDataProvider<ApiResponseEntry>(list)) {
×
108

109
            private static final long serialVersionUID = 1L;
110

111
            @Override
112
            protected void populateItem(Item<ApiResponseEntry> item) {
113
                String templateNpField = item.getModelObject().get("template_np");
×
114
                if (templateNpField == null) templateNpField = item.getModelObject().get("np");
×
115
                Template template = TemplateData.get().getTemplate(templateNpField);
×
116
                item.add(new TemplateItem("template", template));
×
117
            }
×
118

119
        };
120
        dataView.setItemsPerPage(10);
×
121
        dataView.setOutputMarkupId(true);
×
122
        r.add(dataView);
×
123

124
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
125
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
126
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
127
        navigation.setVisible(dataView.getPageCount() > 1);
×
128
        navigation.add(pagingNavigator);
×
129
        r.add(navigation);
×
130

131
        return r;
×
132
    }
133

134
    private TemplateResults(String id) {
135
        super(id);
×
136
        setOutputMarkupId(true);
×
137
    }
×
138

139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc