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

knowledgepixels / nanodash / 22630596072

03 Mar 2026 03:41PM UTC coverage: 15.949% (-0.08%) from 16.03%
22630596072

Pull #369

github

web-flow
Merge 6951bc4cf into 85e0af2dc
Pull Request #369: Replace "^" for view displays with dropdown menu

699 of 5317 branches covered (13.15%)

Branch coverage included in aggregate %.

1721 of 9856 relevant lines covered (17.46%)

2.4 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.domain.MaintainedResource;
5
import com.knowledgepixels.nanodash.page.NanodashPage;
6
import com.knowledgepixels.nanodash.page.PublishPage;
7
import com.knowledgepixels.nanodash.repository.MaintainedResourceRepository;
8
import com.knowledgepixels.nanodash.template.Template;
9
import org.apache.wicket.Component;
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.link.AbstractLink;
15
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
16
import org.apache.wicket.markup.repeater.Item;
17
import org.apache.wicket.markup.repeater.RepeatingView;
18
import org.apache.wicket.markup.repeater.data.DataView;
19
import org.apache.wicket.model.Model;
20
import org.apache.wicket.request.mapper.parameter.PageParameters;
21
import org.eclipse.rdf4j.model.IRI;
22
import org.nanopub.extra.services.ApiResponse;
23
import org.nanopub.extra.services.ApiResponseEntry;
24
import org.nanopub.extra.services.QueryRef;
25

26
import java.util.ArrayList;
27
import java.util.List;
28

29
/**
30
 * Component for displaying query results in a list format.
31
 */
32
public class QueryResultList extends QueryResult {
33

34
    private static final String SEPARATOR = " ยท ";
35

36
    /**
37
     * Constructor for QueryResultList.
38
     *
39
     * @param markupId    the markup ID
40
     * @param queryRef    the query reference
41
     * @param response    the API response
42
     * @param viewDisplay the view display
43
     */
44
    QueryResultList(String markupId, QueryRef queryRef, ApiResponse response, ViewDisplay viewDisplay) {
45
        super(markupId, queryRef, response, viewDisplay);
×
46

47
        String label = grlcQuery.getLabel();
×
48
        if (viewDisplay.getView().getTitle() != null) {
×
49
            label = viewDisplay.getView().getTitle();
×
50
        }
51
        add(new Label("label", label));
×
52
        setOutputMarkupId(true);
×
53
        populateComponent();
×
54
    }
×
55

56
    @Override
57
    protected void populateComponent() {
58
        QueryResultDataProvider dataProvider = new QueryResultDataProvider(response.getData());
×
59
        DataView<ApiResponseEntry> dataView = new DataView<>("items", dataProvider) {
×
60

61
            @Override
62
            protected void populateItem(Item<ApiResponseEntry> item) {
63
                ApiResponseEntry entry = item.getModelObject();
×
64
                RepeatingView listItem = new RepeatingView("listItem");
×
65

66
                List<Component> components = new ArrayList<>();
×
67
                for (String key : response.getHeader()) {
×
68
                    if (!key.endsWith("_label")) {
×
69
                        String entryValue = entry.get(key);
×
70
                        if (entryValue != null && !entryValue.isBlank()) {
×
71
                            if (entryValue.matches("https?://.+")) {
×
72
                                String entryLabel = entry.get(key + "_label");
×
73
                                components.add(new NanodashLink("component", entryValue, null, null, entryLabel, contextId));
×
74
                            } else {
×
75
                                if (Utils.looksLikeHtml(entryValue)) {
×
76
                                    entryValue = Utils.sanitizeHtml(entryValue);
×
77
                                }
78
                                components.add(new Label("component", entryValue).setEscapeModelStrings(false));
×
79
                            }
80
                        }
81
                    }
82
                }
83
                View view = viewDisplay.getView();
×
84
                if (view != null && !view.getViewEntryActionList().isEmpty()) {
×
85
                    List<AbstractLink> links = new ArrayList<>();
×
86
                    for (IRI actionIri : view.getViewEntryActionList()) {
×
87
                        // TODO Copied code and adjusted from QueryResultTableBuilder:
88
                        Template t = view.getTemplateForAction(actionIri);
×
89
                        if (t == null) continue;
×
90
                        String targetField = view.getTemplateTargetFieldForAction(actionIri);
×
91
                        if (targetField == null) targetField = "resource";
×
92
                        String labelForAction = view.getLabelForAction(actionIri);
×
93
                        if (labelForAction == null) labelForAction = "action...";
×
94
                        PageParameters params = new PageParameters().set("template", t.getId())
×
95
                                .set("param_" + targetField, contextId)
×
96
                                .set("context", contextId)
×
97
                                .set("template-version", "latest");
×
98
                        String partField = view.getTemplatePartFieldForAction(actionIri);
×
99
                        if (partField != null) {
×
100
                            // TODO Find a better way to pass the MaintainedResource object to this method:
101
                            MaintainedResource r = MaintainedResourceRepository.get().findById(contextId);
×
102
                            if (r != null && r.getNamespace() != null) {
×
103
                                params.set("param_" + partField, r.getNamespace() + "<SET-SUFFIX>");
×
104
                            }
105
                        }
106
                        String queryMapping = view.getTemplateQueryMapping(actionIri);
×
107
                        if (queryMapping != null && queryMapping.contains(":")) {
×
108
                            // This part is different from the code in QueryResultTableBuilder:
109
                            String queryParam = queryMapping.split(":")[0];
×
110
                            String templateParam = queryMapping.split(":")[1];
×
111
                            params.set("param_" + templateParam, entry.get(queryParam));
×
112
                        }
113
                        params.set("refresh-upon-publish", queryRef.getAsUrlString());
×
114
                        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, params);
×
115
                        button.setBody(Model.of(labelForAction));
×
116
                        links.add(button);
×
117
                    }
×
118
                    components.add(new ButtonList("component", resourceWithProfile, links, null, null));
×
119
                }
120
                ComponentSequence componentSequence = new ComponentSequence(listItem.newChildId(), SEPARATOR, components);
×
121
                listItem.add(componentSequence);
×
122
                item.add(listItem);
×
123
            }
×
124
        };
125
        dataView.setItemsPerPage(10);
×
126
        dataView.setOutputMarkupId(true);
×
127

128
        WebMarkupContainer navigation = new WebMarkupContainer("navigation");
×
129
        navigation.add(new NavigatorLabel("navigatorLabel", dataView));
×
130
        AjaxPagingNavigator pagingNavigator = new AjaxPagingNavigator("navigator", dataView);
×
131
        navigation.setVisible(dataView.getPageCount() > 1);
×
132
        navigation.add(pagingNavigator);
×
133

134
        add(navigation);
×
135
        add(dataView);
×
136
    }
×
137

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