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

knowledgepixels / nanodash / 17549674654

08 Sep 2025 11:45AM UTC coverage: 12.054% (+0.2%) from 11.88%
17549674654

push

github

tkuhn
Add pagination to more views

335 of 3858 branches covered (8.68%)

Branch coverage included in aggregate %.

970 of 6968 relevant lines covered (13.92%)

0.61 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 java.util.List;
4

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

16
import com.knowledgepixels.nanodash.template.Template;
17
import com.knowledgepixels.nanodash.template.TemplateData;
18

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

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

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

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

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

50
            private static final long serialVersionUID = 1L;
51

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

57
        });
58

59
        return r;
×
60
    }
61

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

73
    /**
74
     * Creates a TemplateResults panel from an ApiResponse with a limit on the number of templates displayed and additional parameters.
75
     *
76
     * @param id               the Wicket component ID
77
     * @param apiResponse      the ApiResponse containing the template data
78
     * @param additionalParams additional parameters to pass to the TemplateItem components
79
     * @return a TemplateResults panel
80
     */
81
    public static TemplateResults fromApiResponse(final String id, ApiResponse apiResponse, final PageParameters additionalParams) {
82
        List<ApiResponseEntry> list = apiResponse.getData();
×
83
        TemplateResults r = new TemplateResults(id);
×
84

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

87
            private static final long serialVersionUID = 1L;
88

89
            @Override
90
            protected void populateItem(Item<ApiResponseEntry> item) {
91
                String templateNpField = item.getModelObject().get("template_np");
×
92
                if (templateNpField == null) templateNpField = item.getModelObject().get("np");
×
93
                Template template = TemplateData.get().getTemplate(templateNpField);
×
94
                item.add(new TemplateItem("template", template));
×
95
            }
×
96

97
        };
98
        dataView.setItemsPerPage(10);
×
99
        dataView.setOutputMarkupId(true);
×
100
        r.add(dataView);
×
101

102
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
103
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
104
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
105
        navigation.setVisible(dataView.getPageCount() > 1);
×
106
        navigation.add(pagingNavigator);
×
107
        r.add(navigation);
×
108

109
        return r;
×
110
    }
111

112
    private TemplateResults(String id) {
113
        super(id);
×
114
        setOutputMarkupId(true);
×
115
    }
×
116

117
}
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