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

knowledgepixels / nanodash / 29574247112

17 Jul 2026 10:40AM UTC coverage: 28.791% (-0.6%) from 29.361%
29574247112

Pull #560

github

web-flow
Merge b16ec84aa into 809bff55b
Pull Request #560: Show dates in a consistent format

1960 of 7501 branches covered (26.13%)

Branch coverage included in aggregate %.

3818 of 12568 relevant lines covered (30.38%)

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

3
import com.knowledgepixels.nanodash.*;
4
import com.knowledgepixels.nanodash.component.menu.EntryActionMenu;
5
import com.knowledgepixels.nanodash.domain.IndividualAgent;
6
import com.knowledgepixels.nanodash.domain.User;
7
import com.knowledgepixels.nanodash.page.*;
8
import org.apache.wicket.Component;
9
import org.apache.wicket.ajax.AjaxRequestTarget;
10
import org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator;
11
import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigatorLabel;
12
import org.apache.wicket.markup.html.WebMarkupContainer;
13
import org.apache.wicket.markup.html.basic.Label;
14
import org.apache.wicket.markup.html.form.TextField;
15
import org.apache.wicket.markup.html.link.AbstractLink;
16
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
17
import org.apache.wicket.markup.html.list.ListItem;
18
import org.apache.wicket.markup.html.list.ListView;
19
import org.apache.wicket.markup.repeater.Item;
20
import org.apache.wicket.markup.repeater.RepeatingView;
21
import org.apache.wicket.markup.repeater.data.DataView;
22
import org.apache.wicket.model.Model;
23
import org.apache.wicket.model.util.ListModel;
24
import org.apache.wicket.request.cycle.RequestCycle;
25
import org.apache.wicket.request.mapper.parameter.PageParameters;
26
import org.apache.wicket.request.resource.ContextRelativeResourceReference;
27
import org.apache.wicket.util.string.Strings;
28
import org.eclipse.rdf4j.model.IRI;
29
import org.nanopub.extra.services.ApiResponse;
30
import org.nanopub.extra.services.ApiResponseEntry;
31
import org.nanopub.extra.services.QueryRef;
32

33
import java.util.*;
34

35
/**
36
 * Component for displaying query results in a list format.
37
 */
38
public class QueryResultList extends QueryResult {
39

40
    private static final String SEPARATOR = " · ";
41

42
    private FilteredQueryResultDataProvider filteredDataProvider;
43
    private Model<String> filterModel = Model.of("");
×
44
    private WebMarkupContainer itemsContainer;
45

46
    /**
47
     * Constructor for QueryResultList.
48
     *
49
     * @param markupId    the markup ID
50
     * @param queryRef    the query reference
51
     * @param response    the API response
52
     * @param viewDisplay the view display
53
     */
54
    QueryResultList(String markupId, QueryRef queryRef, ApiResponse response, ViewDisplay viewDisplay) {
55
        super(markupId, queryRef, response, viewDisplay);
×
56

57
        String label = grlcQuery.getLabel();
×
58
        if (viewDisplay.getTitle() != null) {
×
59
            label = viewDisplay.getTitle();
×
60
        }
61
        add(new Label("label", label).setVisible(label != null && !label.isEmpty()));
×
62
        setOutputMarkupId(true);
×
63

64
        TextField<String> filterField = new TextField<>("filter", filterModel);
×
65
        filterField.setOutputMarkupId(true);
×
66
        filterField.add(new FilterUpdatingBehavior() {
×
67
            @Override
68
            protected void onUpdate(AjaxRequestTarget target) {
69
                if (filteredDataProvider != null && itemsContainer != null) {
×
70
                    filteredDataProvider.setFilterText(filterModel.getObject());
×
71
                    target.add(itemsContainer);
×
72
                }
73
            }
×
74
        });
75
        filterField.setVisible(!fitsOnFirstPage());
×
76
        add(filterField);
×
77

78
        populateComponent();
×
79
    }
×
80

81
    @Override
82
    protected void populateComponent() {
83
        QueryResultDataProvider dataProvider = new QueryResultDataProvider(response.getData());
×
84
        filteredDataProvider = new FilteredQueryResultDataProvider(dataProvider, response);
×
85
        DataView<ApiResponseEntry> dataView = new DataView<>("items", filteredDataProvider) {
×
86

87
            @Override
88
            protected void populateItem(Item<ApiResponseEntry> item) {
89
                ApiResponseEntry entry = item.getModelObject();
×
90
                RepeatingView listItem = new RepeatingView("listItem");
×
91

92
                // Columns that only feed action query mappings carry action data, not
93
                // row content — don't render them as visible row text.
94
                View viewForColumns = viewDisplay.getView();
×
95
                Set<String> hiddenColumns = viewForColumns != null
×
96
                        ? viewForColumns.getActionMappingSourceColumns() : Collections.emptySet();
×
97
                List<Component> components = new ArrayList<>();
×
98
                // The row's "^" source link, if any — folded into the per-row actions
99
                // dropdown appended at the end of the row.
100
                String sourceUri = null;
×
101
                for (String key : response.getHeader()) {
×
102
                    if (key.endsWith("_label") || key.endsWith("_label_multi") || hiddenColumns.contains(key)) {
×
103
                        continue;
×
104
                    }
105
                    String entryValue = entry.get(key);
×
106
                    if (entryValue != null && !entryValue.isBlank()) {
×
107
                        if (key.endsWith("user_iri")) {
×
108
                            IRI userIri = Utils.vf.createIRI(entryValue);
×
109
                            IRI profilePicIri = User.getProfilePicture(userIri);
×
110
                            String imgSrc;
111
                            if (profilePicIri != null) {
×
112
                                imgSrc = Strings.escapeMarkup(profilePicIri.stringValue()).toString();
×
113
                            } else if (IndividualAgent.isSoftware(userIri)) {
×
114
                                imgSrc = RequestCycle.get().urlFor(new ContextRelativeResourceReference("images/bot-icon.svg", false), null).toString();
×
115
                            } else {
116
                                imgSrc = RequestCycle.get().urlFor(new ContextRelativeResourceReference("images/user-icon.svg", false), null).toString();
×
117
                            }
118
                            String userLabel = entry.get(key + "_label");
×
119
                            String displayLabel = userLabel != null && !userLabel.isBlank() ? userLabel : User.getShortDisplayName(userIri);
×
120
                            String userUrl = UserPage.MOUNT_PATH + "?id=" + Utils.urlEncode(entryValue);
×
121
                            String linkHtml = "<a href=\"" + Strings.escapeMarkup(userUrl) + "\">" + Strings.escapeMarkup(displayLabel) + "</a>";
×
122
                            components.add(new ComponentSequence("component", " ", List.of(
×
123
                                    new Label("component", "<img class=\"user-icon\" src=\"" + imgSrc + "\" />").setEscapeModelStrings(false),
×
124
                                    new Label("component", linkHtml).setEscapeModelStrings(false))));
×
125
                        } else if (key.endsWith("template_iri")) {
×
126
                            String templateLabel = entry.get(key + "_label");
×
127
                            String displayLabel = templateLabel != null && !templateLabel.isBlank() ? templateLabel : entryValue;
×
128
                            String templateUrl = PublishPage.MOUNT_PATH + "?template=" + Utils.urlEncode(entryValue) + "&template-version=latest" + templateLinkContextParam();
×
129
                            String linkHtml = "<a href=\"" + Strings.escapeMarkup(templateUrl) + "\">" + Strings.escapeMarkup(displayLabel) + "</a>";
×
130
                            components.add(new ComponentSequence("component", " ", List.of(
×
131
                                    new Label("component", "<span class=\"form-icon\"></span>").setEscapeModelStrings(false),
×
132
                                    new Label("component", linkHtml).setEscapeModelStrings(false))));
×
133
                        } else if (key.endsWith("query_iri")) {
×
134
                            String queryLabel = entry.get(key + "_label");
×
135
                            String displayLabel = queryLabel != null && !queryLabel.isBlank() ? queryLabel : entryValue;
×
136
                            String queryUrl = QueryPage.MOUNT_PATH + "?id=" + Utils.urlEncode(entryValue) + templateLinkContextParam();
×
137
                            String linkHtml = "<a href=\"" + Strings.escapeMarkup(queryUrl) + "\">" + Strings.escapeMarkup(displayLabel) + "</a>";
×
138
                            components.add(new Label("component", linkHtml).setEscapeModelStrings(false));
×
139
                        } else if (key.endsWith("_multi_iri")) {
×
140
                            String[] uris = entryValue.split("\\s+");
×
141
                            String labelKey = key.substring(0, key.length() - "_multi_iri".length()) + "_label_multi";
×
142
                            String labelValue = entry.get(labelKey);
×
143
                            String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
144
                            List<Component> links = new ArrayList<>();
×
145
                            for (int i = 0; i < uris.length; i++) {
×
146
                                String uri = uris[i];
×
147
                                if (uri.isBlank()) {
×
148
                                    continue;
×
149
                                }
150
                                String label = (labels != null && i < labels.length && !labels[i].isBlank()) ? Utils.unescapeMultiValue(labels[i]) : null;
×
151
                                // SPARQL coalesce often falls back to the URI string itself; treat that as no label
152
                                // so NanodashLink can derive a short name from the URI.
153
                                if (label != null && label.equals(uri)) {
×
154
                                    label = null;
×
155
                                }
156
                                links.add(new NanodashLink("component", uri, null, null, label, contextId));
×
157
                            }
158
                            components.add(new ComponentSequence("component", ", ", links));
×
159
                        } else if (key.endsWith("_multi_val")) {
×
160
                            String labelKey = key.substring(0, key.length() - "_multi_val".length()) + "_label_multi";
×
161
                            String labelValue = entry.get(labelKey);
×
162
                            String[] parts = entryValue.split("\n", -1);
×
163
                            String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
164
                            List<Component> multiComponents = new ArrayList<>();
×
165
                            for (int i = 0; i < parts.length; i++) {
×
166
                                String part = parts[i];
×
167
                                String label = (labels != null && i < labels.length && !labels[i].isBlank()) ? Utils.unescapeMultiValue(labels[i]) : null;
×
168
                                if (part.matches("https?://.+")) {
×
169
                                    if (label != null && label.equals(part)) {
×
170
                                        label = null;
×
171
                                    }
172
                                    multiComponents.add(new NanodashLink("component", part, null, null, label, contextId));
×
173
                                } else {
174
                                    String unescaped = Utils.unescapeMultiValue(part);
×
175
                                    if (label == null && Utils.isDate(unescaped)) {
×
176
                                        // Friendly relative time, matching single-value items.
177
                                        multiComponents.add(new Label("component", Utils.friendlyDateHtml(unescaped, unescaped)).setEscapeModelStrings(false));
×
178
                                    } else {
179
                                        String display = label != null ? label : unescaped;
×
180
                                        boolean isHtml = Utils.looksLikeHtml(display);
×
181
                                        if (isHtml) {
×
182
                                            display = withContextInHtmlLinks(Utils.sanitizeHtml(display));
×
183
                                        }
184
                                        multiComponents.add(new Label("component", display).setEscapeModelStrings(!isHtml));
×
185
                                    }
186
                                }
187
                            }
188
                            components.add(new ComponentSequence("component", ", ", multiComponents));
×
189
                        } else if (key.endsWith("_multi")) {
×
190
                            String[] parts = entryValue.split("\n", -1);
×
191
                            String labelKey = key.substring(0, key.length() - "_multi".length()) + "_label_multi";
×
192
                            String labelValue = entry.get(labelKey);
×
193
                            String[] labels = labelValue != null ? labelValue.split("\n", -1) : null;
×
194
                            List<Component> multiComponents = new ArrayList<>();
×
195
                            for (int i = 0; i < parts.length; i++) {
×
196
                                boolean hasLabel = labels != null && i < labels.length && !labels[i].isBlank();
×
197
                                String display = hasLabel ? Utils.unescapeMultiValue(labels[i]) : Utils.unescapeMultiValue(parts[i]);
×
198
                                if (!hasLabel && Utils.isDate(display)) {
×
199
                                    // Friendly relative time, matching single-value items.
200
                                    multiComponents.add(new Label("component", Utils.friendlyDateHtml(display, display)).setEscapeModelStrings(false));
×
201
                                } else {
202
                                    multiComponents.add(new Label("component", display));
×
203
                                }
204
                            }
205
                            components.add(new ComponentSequence("component", ", ", multiComponents));
×
206
                        } else if (entryValue.matches("https?://.+")) {
×
207
                            String entryLabel = entry.get(key + "_label");
×
208
                            if ("^".equals(entryLabel)) {
×
209
                                // Folded into the per-row actions dropdown appended below.
210
                                sourceUri = entryValue;
×
211
                            } else {
212
                                components.add(new NanodashLink("component", entryValue, null, null, entryLabel, contextId));
×
213
                            }
214
                        } else {
×
215
                            String entryLabel = entry.get(key + "_label");
×
216
                            boolean hasLabel = entryLabel != null && !entryLabel.isBlank() && !entryLabel.equals(entryValue);
×
217
                            if (!hasLabel && Utils.isDate(entryValue)) {
×
218
                                // Show a friendly relative time (client-side); raw ISO value stays as no-script fallback.
219
                                components.add(new Label("component", Utils.friendlyDateHtml(entryValue, entryValue)).setEscapeModelStrings(false));
×
220
                            } else {
221
                                String display = hasLabel ? entryLabel : entryValue;
×
222
                                if (Utils.looksLikeHtml(display)) {
×
223
                                    display = withContextInHtmlLinks(Utils.sanitizeHtml(display));
×
224
                                } else if (hasLabel) {
×
225
                                    display = Strings.escapeMarkup(display).toString();
×
226
                                }
227
                                if (hasLabel) {
×
228
                                    // Separate display label for a (non-IRI) literal value; the full
229
                                    // literal is shown on hover via the standard styled tooltip.
230
                                    display = "<span class=\"tooltip\"><span class=\"tooltiptext tooltiptext-auto\">" + Strings.escapeMarkup(entryValue) + "</span>" + display + "</span>";
×
231
                                }
232
                                components.add(new Label("component", display).setEscapeModelStrings(false));
×
233
                            }
234
                        }
235
                    }
236
                }
237
                List<AbstractLink> actionLinks = ViewActionMappings.buildEntryActionLinks(viewDisplay.getView(), entry,
×
238
                        queryRef, resourceWithProfile, contextId, partId, refRoot, postPublishTab);
×
239
                // The former "^" source link joins the same dropdown, as a "source" entry.
240
                if (sourceUri != null) {
×
241
                    AbstractLink sourceLink = new BookmarkablePageLink<NanodashPage>("link", ExplorePage.class,
×
242
                            new PageParameters().set("id", sourceUri));
×
243
                    sourceLink.add(NavigationContext.pageContextFallback());
×
244
                    sourceLink.setBody(Model.of("<span class=\"actionmenu-icon\">↗︎</span>source")).setEscapeModelStrings(false);
×
245
                    actionLinks.add(sourceLink);
×
246
                }
247
                // Append the per-row dropdown (entry actions + source) as the trailing item;
248
                // it hugs the preceding content with a plain space, not the list separator.
249
                Set<Integer> spaceBeforeMenu = new HashSet<>();
×
250
                if (!actionLinks.isEmpty()) {
×
251
                    spaceBeforeMenu.add(components.size());
×
252
                    components.add(new EntryActionMenu("component", actionLinks));
×
253
                }
254
                ComponentSequence componentSequence = new ComponentSequence(listItem.newChildId(), SEPARATOR, components, spaceBeforeMenu);
×
255
                listItem.add(componentSequence);
×
256
                item.add(listItem);
×
257
            }
×
258
        };
259
        dataView.setItemsPerPage(viewDisplay.getPageSize());
×
260

261
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
262
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
263
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
264
        navigation.setVisible(dataView.getPageCount() > 1);
×
265
        navigation.add(pagingNavigator);
×
266

267
        // Hidden when the empty-actions line below shows instead, which carries
268
        // its own "Nothing here yet:" text; this note still covers the case of
269
        // the filter text matching no row.
270
        Label noRecordsLabel = new Label("no-records", "(nothing found)") {
×
271
            @Override
272
            protected void onConfigure() {
273
                super.onConfigure();
×
274
                setVisible(filteredDataProvider.size() == 0 && !hasEmptyStateActions());
×
275
            }
×
276
        };
277

278
        // When the result is genuinely empty (not merely filtered down to zero
279
        // rows), the view-level actions are promoted from the dropdown menu to
280
        // visible buttons in the empty state — same as in QueryResultTable.
281
        WebMarkupContainer emptyActions = new WebMarkupContainer("empty-actions") {
×
282
            @Override
283
            protected void onConfigure() {
284
                super.onConfigure();
×
285
                setVisible(hasEmptyStateActions());
×
286
            }
×
287
        };
288
        // menuActions is filled by the builder after construction, so the list
289
        // is wrapped as a live model rather than copied here.
290
        emptyActions.add(new ListView<MenuAction>("actions", new ListModel<>(menuActions)) {
×
291
            @Override
292
            protected void populateItem(ListItem<MenuAction> item) {
293
                MenuAction action = item.getModelObject();
×
294
                AbstractLink link = new BookmarkablePageLink<NanodashPage>("link", action.pageClass(), action.params());
×
295
                link.setBody(Model.of(action.label()));
×
296
                item.add(link);
×
297
            }
×
298
        });
299

300
        itemsContainer = new WebMarkupContainer("items-container");
×
301
        itemsContainer.setOutputMarkupId(true);
×
302
        itemsContainer.add(dataView);
×
303
        itemsContainer.add(noRecordsLabel);
×
304
        itemsContainer.add(emptyActions);
×
305
        itemsContainer.add(navigation);
×
306
        add(itemsContainer);
×
307
    }
×
308

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