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

knowledgepixels / nanodash / 17547526330

08 Sep 2025 10:19AM UTC coverage: 12.079% (+0.1%) from 11.975%
17547526330

push

github

tkuhn
Make nanopub result component paginated

335 of 3880 branches covered (8.63%)

Branch coverage included in aggregate %.

974 of 6957 relevant lines covered (14.0%)

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/NanopubResults.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.nanopub.extra.services.ApiResponse;
13
import org.nanopub.extra.services.ApiResponseEntry;
14

15
import com.knowledgepixels.nanodash.NanopubElement;
16
import com.knowledgepixels.nanodash.Utils;
17

18
/**
19
 * A panel that displays a list of nanopubs.
20
 */
21
public class NanopubResults extends Panel {
22

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

25
    /**
26
     * Creates a NanopubResults panel from a list of NanopubElements.
27
     *
28
     * @param id          the component id
29
     * @param nanopubList the list of NanopubElements to display
30
     * @return a new NanopubResults panel
31
     */
32
    public static NanopubResults fromList(String id, List<NanopubElement> nanopubList) {
33
        NanopubResults r = new NanopubResults(id);
×
34
        DataView<NanopubElement> dataView = new DataView<>("nanopubs", new ListDataProvider<NanopubElement>(nanopubList)) {
×
35

36
            private static final long serialVersionUID = 1L;
37

38
            @Override
39
            protected void populateItem(Item<NanopubElement> item) {
40
                item.add(new NanopubItem("nanopub", item.getModelObject()).setMinimal());
×
41
            }
×
42

43
        };
44
        dataView.setItemsPerPage(10);
×
45
        dataView.setOutputMarkupId(true);
×
46
        r.add(dataView);
×
47

48
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
49
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
50
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
51
        navigation.setVisible(dataView.getPageCount() > 1);
×
52
        navigation.add(pagingNavigator);
×
53
        r.add(navigation);
×
54

55
        return r;
×
56
    }
57

58
    /**
59
     * Creates a NanopubResults panel from an ApiResponse.
60
     *
61
     * @param id          the component id
62
     * @param apiResponse the ApiResponse containing nanopub data
63
     * @return a new NanopubResults panel
64
     */
65
    public static NanopubResults fromApiResponse(String id, ApiResponse apiResponse) {
66
        return fromApiResponse(id, apiResponse, -1);
×
67
    }
68

69
    /**
70
     * Creates a NanopubResults panel from an ApiResponse with a limit on the number of nanopubs.
71
     *
72
     * @param id          the component id
73
     * @param apiResponse the ApiResponse containing nanopub data
74
     * @param limit       the maximum number of nanopubs to display, or -1 for no limit
75
     * @return a new NanopubResults panel
76
     */
77
    public static NanopubResults fromApiResponse(String id, ApiResponse apiResponse, int limit) {
78
        List<ApiResponseEntry> list = apiResponse.getData();
×
79
        if (limit >= 0 && list.size() > limit) {
×
80
            list = Utils.subList(list, 0, limit);
×
81
        }
82
        NanopubResults r = new NanopubResults(id);
×
83
        DataView<ApiResponseEntry> dataView = new DataView<ApiResponseEntry>("nanopubs", new ListDataProvider<ApiResponseEntry>(list)) {
×
84

85
            private static final long serialVersionUID = 1L;
86

87
            @Override
88
            protected void populateItem(Item<ApiResponseEntry> item) {
89
                item.add(new NanopubItem("nanopub", NanopubElement.get(item.getModelObject().get("np"))).setMinimal());
×
90
            }
×
91

92
        };
93
        dataView.setItemsPerPage(10);
×
94
        dataView.setOutputMarkupId(true);
×
95
        r.add(dataView);
×
96

97
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
98
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
99
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
100
        navigation.setVisible(dataView.getPageCount() > 1);
×
101
        navigation.add(pagingNavigator);
×
102
        r.add(navigation);
×
103

104
        return r;
×
105
    }
106

107
    private NanopubResults(String id) {
108
        super(id);
×
109
        setOutputMarkupId(true);
×
110
    }
×
111

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