• 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/ThingListPanel.java
1
package com.knowledgepixels.nanodash.component;
2

3
import org.apache.wicket.Component;
4
import org.apache.wicket.markup.html.basic.Label;
5
import org.apache.wicket.markup.html.panel.Panel;
6
import org.nanopub.extra.services.ApiResponse;
7

8
import com.knowledgepixels.nanodash.ApiCache;
9
import com.knowledgepixels.nanodash.Utils;
10

11
/**
12
 * Panel to show a list of things.
13
 */
14
public class ThingListPanel extends Panel {
15

16
    private static final long serialVersionUID = 1L;
17

18
    /**
19
     * Constructor for the ThingListPanel.
20
     *
21
     * @param markupId the Wicket markup ID for this panel
22
     * @param mode     the mode of the panel, determining what kind of things to show
23
     * @param thingRef the reference of the thing to show the list for
24
     * @param response the API response containing the data to display
25
     */
26
    private ThingListPanel(String markupId, final Mode mode, final String thingRef, ApiResponse response) {
27
        super(markupId);
×
28
        // TODO Not copying the table here, which can lead to problems if at some point the same result list is sorted differently at different places:
29
        response.getData().sort(new Utils.ApiResponseEntrySorter("date", true));
×
30
        if (response.getData().isEmpty()) {
×
31
            setVisible(false);
×
32
        } else if (response.getData().size() == 1) {
×
33
            add(new Label("message", mode.messageStart + " 1 " + mode.wordSg));
×
34
        } else if (response.getData().size() == 1000) {
×
35
            add(new Label("message", mode.messageStart + " more " + mode.wordPl + " (>999) than what can be shown here"));
×
36
        } else {
37
            add(new Label("message", mode.messageStart + " " + response.getData().size() + " " + mode.wordPl));
×
38
        }
39
        if (mode == Mode.TEMPLATES) {
×
40
            add(TemplateResults.fromApiResponse("things", response));
×
41
        } else {
42
            add(ThingResults.fromApiResponse("things", mode.returnField, response));
×
43
        }
44
    }
×
45

46
    /**
47
     * Factory method to create a ThingListPanel component.
48
     *
49
     * @param markupId    the Wicket markup ID for the panel
50
     * @param mode        the mode of the panel, determining what kind of things to show
51
     * @param thingRef    the reference of the thing to show the list for
52
     * @param waitMessage the message to display while waiting for the API response
53
     * @return a new ThingListPanel component
54
     */
55
    public static Component createComponent(final String markupId, final Mode mode, final String thingRef, final String waitMessage) {
56
        ApiResponse response = ApiCache.retrieveResponse(mode.queryName, mode.queryParam, thingRef);
×
57
        if (response != null) {
×
58
            return new ThingListPanel(markupId, mode, thingRef, response);
×
59
        } else {
60
            ApiResultComponent c = new ApiResultComponent(markupId, mode.queryName, mode.queryParam, thingRef) {
×
61

62
                private static final long serialVersionUID = 1L;
63

64
                @Override
65
                public Component getApiResultComponent(String markupId, ApiResponse response) {
66
                    return new ThingListPanel(markupId, mode, thingRef, response);
×
67
                }
68

69
            };
70
            c.setWaitMessage(waitMessage);
×
71
            return c;
×
72
        }
73
    }
74

75
    /**
76
     * Enum representing the different modes of the ThingListPanel.
77
     * Each mode corresponds to a specific type of thing and defines how to query and display them.
78
     */
79
    public enum Mode {
×
80
        CLASSES("get-classes-for-thing", "thing", "class", "class", "classes", "Assigned to"),
×
81
        INSTANCES("get-instances", "class", "instance", "instance", "instances", "Has"),
×
82
        PARTS("get-parts", "thing", "part", "part", "parts", "Has"),
×
83
        TEMPLATES("get-templates-with-uri", "thing", "np", "template", "templates", "Used in");
×
84

85
        /**
86
         * The name of the query to be used for this mode.
87
         */
88
        public final String queryName;
89
        /**
90
         * The parameter to be used in the query for this mode.
91
         */
92
        public final String queryParam;
93
        /**
94
         * The field in the API response that contains the relevant data for this mode.
95
         */
96
        public final String returnField;
97
        /**
98
         * The singular word used in messages for this mode.
99
         */
100
        public final String wordSg;
101
        /**
102
         * The plural word used in messages for this mode.
103
         */
104
        public final String wordPl;
105
        /**
106
         * The start of the message displayed in the panel for this mode.
107
         */
108
        public final String messageStart;
109
        /**
110
         * The identifier for this mode, used in URLs and other references.
111
         */
112
        public final String modeId;
113

114
        private Mode(String queryName, String queryParam, String returnField, String wordSg, String wordPl, String messageStart) {
×
115
            this.queryName = queryName;
×
116
            this.queryParam = queryParam;
×
117
            this.returnField = returnField;
×
118
            this.wordSg = wordSg;
×
119
            this.wordPl = wordPl;
×
120
            this.messageStart = messageStart;
×
121
            this.modeId = name().toLowerCase();
×
122
        }
×
123

124
    }
125

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