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

knowledgepixels / nanodash / 28899187612

07 Jul 2026 09:14PM UTC coverage: 28.105% (-0.4%) from 28.465%
28899187612

Pull #543

github

web-flow
Merge 39c9ede0f into f1a7efda7
Pull Request #543: feat: query-form views (gen:QueryFormView) with view-results page

1813 of 7309 branches covered (24.81%)

Branch coverage included in aggregate %.

3717 of 12367 relevant lines covered (30.06%)

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

3
import com.knowledgepixels.nanodash.FilteredQueryResultDataProvider;
4
import com.knowledgepixels.nanodash.NavigationContext;
5
import com.knowledgepixels.nanodash.QueryResult;
6
import com.knowledgepixels.nanodash.QueryResultDataProvider;
7
import com.knowledgepixels.nanodash.Utils;
8
import com.knowledgepixels.nanodash.ViewDisplay;
9
import com.knowledgepixels.nanodash.component.menu.EntryActionMenu;
10
import com.knowledgepixels.nanodash.page.ExplorePage;
11
import org.apache.wicket.ajax.AjaxRequestTarget;
12
import org.apache.wicket.behavior.AttributeAppender;
13
import org.apache.wicket.markup.html.WebMarkupContainer;
14
import org.apache.wicket.markup.html.basic.Label;
15
import org.apache.wicket.markup.html.form.TextField;
16
import org.apache.wicket.markup.html.link.AbstractLink;
17
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
18
import org.apache.wicket.markup.html.list.ListItem;
19
import org.apache.wicket.markup.html.list.ListView;
20
import org.apache.wicket.model.Model;
21
import org.apache.wicket.request.mapper.parameter.PageParameters;
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 QueryResultPlainParagraph extends QueryResult {
33

34
    private FilteredQueryResultDataProvider filteredDataProvider;
35
    private Model<String> filterModel = Model.of("");
×
36
    private WebMarkupContainer paragraphsContainer;
37

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

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

56
        TextField<String> filterField = new TextField<>("filter", filterModel);
×
57
        filterField.setOutputMarkupId(true);
×
58
        filterField.add(new FilterUpdatingBehavior() {
×
59
            @Override
60
            protected void onUpdate(AjaxRequestTarget target) {
61
                if (filteredDataProvider != null && paragraphsContainer != null) {
×
62
                    filteredDataProvider.setFilterText(filterModel.getObject());
×
63
                    paragraphsContainer.addOrReplace(buildParagraphsView());
×
64
                    target.add(paragraphsContainer);
×
65
                }
66
            }
×
67
        });
68
        filterField.setVisible(!fitsOnFirstPage());
×
69
        add(filterField);
×
70

71
        populateComponent();
×
72
    }
×
73

74
    @Override
75
    protected void populateComponent() {
76
        filteredDataProvider = new FilteredQueryResultDataProvider(new QueryResultDataProvider(response.getData()), response);
×
77

78
        paragraphsContainer = new WebMarkupContainer("paragraphs-container");
×
79
        paragraphsContainer.setOutputMarkupId(true);
×
80
        paragraphsContainer.add(buildParagraphsView());
×
81
        paragraphsContainer.add(new Label("no-records", "(nothing found)") {
×
82
            @Override
83
            protected void onConfigure() {
84
                super.onConfigure();
×
85
                setVisible(filteredDataProvider.getFilteredData().isEmpty());
×
86
            }
×
87
        });
88
        add(paragraphsContainer);
×
89
    }
×
90

91
    private ListView<ApiResponseEntry> buildParagraphsView() {
92
        return new ListView<>("paragraphs", filteredDataProvider.getFilteredData()) {
×
93
            @Override
94
            protected void populateItem(ListItem<ApiResponseEntry> item) {
95
                String title = item.getModelObject().get("title");
×
96
                boolean hasTitle = title != null && !title.isBlank();
×
97
                // For a title-less paragraph (e.g. a space description) hide the
98
                // empty heading and float the source link into the corner (via
99
                // the "no-title" class) so the header takes no vertical line.
100
                WebMarkupContainer header = new WebMarkupContainer("header");
×
101
                if (!hasTitle) header.add(new AttributeAppender("class", " no-title"));
×
102
                header.add(new Label("title", title).setVisible(hasTitle));
×
103
                // The view's entry actions, followed by the former "^" source link as a
104
                // "source" entry, bundled into a per-paragraph dropdown as in the other
105
                // view types.
106
                List<AbstractLink> links = ViewActionMappings.buildEntryActionLinks(viewDisplay.getView(),
×
107
                        item.getModelObject(), queryRef,
×
108
                        resourceWithProfile != null ? resourceWithProfile : pageResource,
×
109
                        contextId, partId, refRoot, postPublishTab);
×
110
                String npId = item.getModelObject().get("np");
×
111
                if (npId != null && !npId.isBlank()) {
×
112
                    BookmarkablePageLink<Void> sourceLink = new BookmarkablePageLink<>("link", ExplorePage.class,
×
113
                            new PageParameters().set("id", npId));
×
114
                    sourceLink.add(NavigationContext.pageContextFallback());
×
115
                    sourceLink.setBody(Model.of("<span class=\"actionmenu-icon\">↗︎</span>source")).setEscapeModelStrings(false);
×
116
                    links.add(sourceLink);
×
117
                }
118
                if (links.isEmpty()) {
×
119
                    header.add(new Label("pnp").setVisible(false));
×
120
                } else {
121
                    header.add(new EntryActionMenu("pnp", links));
×
122
                }
123
                item.add(header);
×
124
                String content = item.getModelObject().get("content");
×
125
                item.add(new Label("content", content == null ? null : withContextInHtmlLinks(Utils.sanitizeHtml(content))).setEscapeModelStrings(false));
×
126
            }
×
127
        };
128
    }
129

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