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

knowledgepixels / nanodash / 23265765136

18 Mar 2026 08:34PM UTC coverage: 16.251% (-0.02%) from 16.273%
23265765136

Pull #406

github

web-flow
Merge 50e7060f4 into 399d749bf
Pull Request #406: Redesign Explore page layout and extract References page

728 of 5521 branches covered (13.19%)

Branch coverage included in aggregate %.

1850 of 10343 relevant lines covered (17.89%)

2.44 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.WebMarkupContainer;
5
import org.apache.wicket.markup.html.basic.Label;
6
import org.apache.wicket.markup.html.panel.Panel;
7
import org.nanopub.extra.services.ApiResponse;
8
import org.nanopub.extra.services.QueryRef;
9

10
import com.knowledgepixels.nanodash.ApiCache;
11
import com.knowledgepixels.nanodash.QueryApiAccess;
12
import com.knowledgepixels.nanodash.Utils;
13
import com.knowledgepixels.nanodash.template.Template;
14
import com.knowledgepixels.nanodash.template.TemplateData;
15

16
/**
17
 * Panel to show a list of things.
18
 */
19
public class ThingListPanel extends Panel {
20

21
    /**
22
     * Constructor for the ThingListPanel.
23
     *
24
     * @param markupId the Wicket markup ID for this panel
25
     * @param mode     the mode of the panel, determining what kind of things to show
26
     * @param thingRef the reference of the thing to show the list for
27
     * @param response the API response containing the data to display
28
     */
29
    private ThingListPanel(String markupId, final Mode mode, final String thingRef, ApiResponse response) {
30
        super(markupId);
×
31
        // 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:
32
        response.getData().sort(new Utils.ApiResponseEntrySorter("date", true));
×
33
        WebMarkupContainer messageRow = new WebMarkupContainer("message-row");
×
34
        if (response.getData().isEmpty()) {
×
35
            setVisible(false);
×
36
            messageRow.add(new Label("message", ""));
×
37
        } else if (mode == Mode.TEMPLATES) {
×
38
            messageRow.setVisible(false);
×
39
            messageRow.add(new Label("message", ""));
×
40
        } else if (response.getData().size() == 1) {
×
41
            messageRow.add(new Label("message", mode.messageStart + " 1 " + mode.wordSg + ":"));
×
42
        } else if (response.getData().size() == 1000) {
×
43
            messageRow.add(new Label("message", mode.messageStart + " more " + mode.wordPl + " (>999) than what can be shown here:"));
×
44
        } else {
45
            messageRow.add(new Label("message", mode.messageStart + " " + response.getData().size() + " " + mode.wordPl + ":"));
×
46
        }
47
        add(messageRow);
×
48
        if (mode == Mode.TEMPLATES) {
×
49
            add(new ItemListPanel<Template>(
×
50
                    "templates",
51
                    "📝 Related Templates",
52
                    TemplateData.getTemplateList(response),
×
53
                    (template) -> new TemplateItem("item", template)
×
54
                ));
55
            add(new Label("things").setVisible(false));
×
56
        } else {
57
            add(ThingResults.fromApiResponse("things", mode.returnField, response));
×
58
            add(new Label("templates").setVisible(false));
×
59
        }
60
    }
×
61

62
    /**
63
     * Factory method to create a ThingListPanel component.
64
     *
65
     * @param markupId    the Wicket markup ID for the panel
66
     * @param mode        the mode of the panel, determining what kind of things to show
67
     * @param thingRef    the reference of the thing to show the list for
68
     * @param waitMessage the message to display while waiting for the API response
69
     * @return a new ThingListPanel component
70
     */
71
    public static Component createComponent(final String markupId, final Mode mode, final String thingRef, final String waitMessage) {
72
        QueryRef queryRef = new QueryRef(mode.queryName, mode.queryParamKey, thingRef);
×
73
        ApiResponse response = ApiCache.retrieveResponseAsync(queryRef);
×
74
        if (response != null) {
×
75
            return new ThingListPanel(markupId, mode, thingRef, response);
×
76
        } else {
77
            ApiResultComponent c = new ApiResultComponent(markupId, queryRef) {
×
78

79
                @Override
80
                public Component getApiResultComponent(String markupId, ApiResponse response) {
81
                    return new ThingListPanel(markupId, mode, thingRef, response);
×
82
                }
83

84
            };
85
            c.setWaitMessage(waitMessage);
×
86
            return c;
×
87
        }
88
    }
89

90
    /**
91
     * Enum representing the different modes of the ThingListPanel.
92
     * Each mode corresponds to a specific type of thing and defines how to query and display them.
93
     */
94
    public enum Mode {
×
95
        CLASSES(QueryApiAccess.GET_CLASSES_FOR_THING, "thing", "class", "class", "classes", "🏷 Assigned to"),
×
96
        INSTANCES(QueryApiAccess.GET_INSTANCES, "class", "instance", "instance", "instances", "𓃌 Has"),
×
97
        PARTS(QueryApiAccess.GET_PARTS, "thing", "part", "part", "parts", "🧩 Has"),
×
98
        TEMPLATES(QueryApiAccess.GET_TEMPLATES_WITH_URI, "thing", "np", "template", "templates", "Used in"),
×
99
        DESCRIPTIONS(QueryApiAccess.GET_TERM_DEFINITIONS, "term", "np", "nanopublication", "nanopublications", "📄 Described in");
×
100

101
        /**
102
         * The name of the query to be used for this mode.
103
         */
104
        public final String queryName;
105
        /**
106
         * The parameter to be used in the query for this mode.
107
         */
108
        public final String queryParamKey;
109
        /**
110
         * The field in the API response that contains the relevant data for this mode.
111
         */
112
        public final String returnField;
113
        /**
114
         * The singular word used in messages for this mode.
115
         */
116
        public final String wordSg;
117
        /**
118
         * The plural word used in messages for this mode.
119
         */
120
        public final String wordPl;
121
        /**
122
         * The start of the message displayed in the panel for this mode.
123
         */
124
        public final String messageStart;
125
        /**
126
         * The identifier for this mode, used in URLs and other references.
127
         */
128
        public final String modeId;
129

130
        private Mode(String queryName, String queryParamKey, String returnField, String wordSg, String wordPl, String messageStart) {
×
131
            this.queryName = queryName;
×
132
            this.queryParamKey = queryParamKey;
×
133
            this.returnField = returnField;
×
134
            this.wordSg = wordSg;
×
135
            this.wordPl = wordPl;
×
136
            this.messageStart = messageStart;
×
137
            this.modeId = name().toLowerCase();
×
138
        }
×
139

140
    }
141

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