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

knowledgepixels / nanodash / 28896622329

07 Jul 2026 08:31PM UTC coverage: 28.117% (-0.3%) from 28.465%
28896622329

Pull #543

github

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

1813 of 7315 branches covered (24.78%)

Branch coverage included in aggregate %.

3717 of 12353 relevant lines covered (30.09%)

4.47 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/menu/ViewDisplayMenu.java
1
package com.knowledgepixels.nanodash.component.menu;
2

3
import com.knowledgepixels.nanodash.ApiCache;
4
import com.knowledgepixels.nanodash.MagicQueryParams;
5
import com.knowledgepixels.nanodash.NanodashSession;
6
import com.knowledgepixels.nanodash.NanopubElement;
7
import com.knowledgepixels.nanodash.NavigationContext;
8
import com.knowledgepixels.nanodash.QueryResult;
9
import com.knowledgepixels.nanodash.Utils;
10
import com.knowledgepixels.nanodash.ViewDisplay;
11
import com.knowledgepixels.nanodash.component.GuidedChoiceItem;
12
import com.knowledgepixels.nanodash.domain.AbstractResourceWithProfile;
13
import com.knowledgepixels.nanodash.domain.IndividualAgent;
14
import com.knowledgepixels.nanodash.domain.Space;
15
import com.knowledgepixels.nanodash.page.ExplorePage;
16
import com.knowledgepixels.nanodash.page.PublishPage;
17
import com.knowledgepixels.nanodash.page.QueryPage;
18
import com.knowledgepixels.nanodash.page.ViewResultsPage;
19
import com.knowledgepixels.nanodash.template.TemplateData;
20
import org.apache.wicket.markup.html.WebMarkupContainer;
21
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
22
import org.apache.wicket.markup.html.link.ExternalLink;
23
import org.apache.wicket.markup.html.link.Link;
24
import org.apache.wicket.markup.repeater.Item;
25
import org.apache.wicket.markup.repeater.data.DataView;
26
import org.apache.wicket.markup.repeater.data.ListDataProvider;
27
import org.apache.wicket.model.Model;
28
import org.apache.wicket.request.mapper.parameter.PageParameters;
29
import org.eclipse.rdf4j.model.IRI;
30
import org.nanopub.extra.services.QueryRef;
31

32
import java.util.List;
33

34
/**
35
 * A dropdown menu panel for view displays, replacing the "^" source link.
36
 * Provides options to show the query, adjust the view display, and see its declaration.
37
 */
38
public class ViewDisplayMenu extends BaseDisplayMenu {
39

40
    /**
41
     * Constructs a ViewDisplayMenu.
42
     *
43
     * @param id           the Wicket component ID
44
     * @param viewDisplay  the view display this menu acts on (must have a non-null nanopub)
45
     * @param queryRef     the query reference used by this view display
46
     * @param pageResource the page-level resource used to determine whether "adjust" is visible
47
     * @param viewActions  the view-level actions to show as top entries (may be empty)
48
     */
49
    public ViewDisplayMenu(String id, ViewDisplay viewDisplay, QueryRef queryRef, AbstractResourceWithProfile pageResource, List<QueryResult.MenuAction> viewActions) {
50
        super(id);
×
51

52
        // View-level actions become the top entries of the menu, followed by a
53
        // separator and then the standard view-display options below.
54
        DataView<QueryResult.MenuAction> viewActionView = new DataView<>("viewActions", new ListDataProvider<>(viewActions)) {
×
55
            @Override
56
            protected void populateItem(Item<QueryResult.MenuAction> item) {
57
                QueryResult.MenuAction action = item.getModelObject();
×
58
                BookmarkablePageLink<Void> link = new BookmarkablePageLink<>("viewAction", action.pageClass(), action.params());
×
59
                // A label that starts with a leading symbol/emoji renders that as the entry icon.
60
                String iconBody = Utils.menuEntryIconBodyHtml(action.label());
×
61
                if (iconBody != null) {
×
62
                    link.setBody(Model.of(iconBody)).setEscapeModelStrings(false);
×
63
                } else {
64
                    link.setBody(Model.of(action.label()));
×
65
                }
66
                item.add(link);
×
67
            }
×
68
        };
69
        addEntry("viewActions", viewActionView);
×
70
        WebMarkupContainer separator = new WebMarkupContainer("separator");
×
71
        separator.setVisible(!viewActions.isEmpty());
×
72
        addEntry("separator", separator);
×
73

74
        PageParameters showQueryParams = new PageParameters().set("id", queryRef.getQueryId());
×
75
        for (var entry : queryRef.getParams().entries()) {
×
76
            showQueryParams.add("queryparam_" + entry.getKey(), entry.getValue());
×
77
        }
×
78
        addEntry("showQuery", new BookmarkablePageLink<Void>("showQuery", QueryPage.class, showQueryParams)
×
79
                .add(NavigationContext.pageContextFallback()));
×
80

81
        addEntry("showView", new BookmarkablePageLink<Void>("showView", ExplorePage.class,
×
82
                new PageParameters().set("id", viewDisplay.getView().getNanopub().getUri()))
×
83
                .add(NavigationContext.pageContextFallback()));
×
84

85
        // Full-screen version of this view on the standalone view-results page, with the
86
        // current query parameters carried along (magic ones excluded — the results page
87
        // re-binds them from the session, so carrying them would duplicate the bindings).
88
        PageParameters fullScreenParams = new PageParameters().set("view", viewDisplay.getView().getId());
×
89
        for (var entry : queryRef.getParams().entries()) {
×
90
            if (MagicQueryParams.isMagic(entry.getKey())) continue;
×
91
            fullScreenParams.add("queryparam_" + entry.getKey(), entry.getValue());
×
92
        }
×
93
        BookmarkablePageLink<Void> fullScreenLink = new BookmarkablePageLink<>("fullScreen", ViewResultsPage.class, fullScreenParams) {
×
94
            @Override
95
            protected void onConfigure() {
96
                super.onConfigure();
×
97
                // Self-referential on the full-screen page itself.
98
                setVisible(!(getPage() instanceof ViewResultsPage));
×
99
            }
×
100
        };
101
        fullScreenLink.add(NavigationContext.pageContextFallback());
×
102
        addEntry("fullScreen", fullScreenLink);
×
103

104
        IRI nanopubId = viewDisplay.getNanopubId();
×
105

106
        // Determine whether "adjust" should be visible for this user on this page
107
        boolean showAdjust = false;
×
108
        NanodashSession session = NanodashSession.get();
×
109
        if (pageResource instanceof IndividualAgent ia) {
×
110
            showAdjust = ia.isCurrentUser();
×
111
        } else if (pageResource instanceof Space s) {
×
112
            String pubkeyhash = session.getPubkeyhash();
×
113
            showAdjust = pubkeyhash != null && s.isAdminPubkey(pubkeyhash);
×
114
        } else if (pageResource != null) {
×
115
            Space space = pageResource.getSpace();
×
116
            if (space != null) {
×
117
                String pubkeyhash = session.getPubkeyhash();
×
118
                showAdjust = pubkeyhash != null && space.isAdminPubkey(pubkeyhash);
×
119
            }
120
        }
121

122
        // Determine supersede vs derive based on whether this user's pubkey matches the nanopub's.
123
        // These are only needed when showAdjust is true (i.e. pageResource is non-null).
124
        String adjustUrl = "";
×
125
        String pageResourceId = pageResource != null ? pageResource.getId() : "";
×
126
        if (showAdjust) {
×
127
            String nanopubPubkey = NanopubElement.get(viewDisplay.getNanopub()).getPubkey();
×
128
            String sessionPubkey = session.getPubkeyString();
×
129
            String adjustParam = (nanopubPubkey != null && nanopubPubkey.equals(sessionPubkey))
×
130
                    ? "supersede" : "derive";
×
131
            IRI templateId = TemplateData.get().getTemplateId(viewDisplay.getNanopub());
×
132
            String templateUri = templateId != null ? templateId.stringValue()
×
133
                    : "http://purl.org/np/RACyK2NjqFgezYLiE8FQu7JI0xY1M1aNQbykeCW8oqXkA";
×
134
            adjustUrl = PublishPage.MOUNT_PATH + "?template=" + Utils.urlEncode(templateUri)
×
135
                    + "&" + adjustParam + "=" + Utils.urlEncode(nanopubId.stringValue())
×
136
                    + "&template-version=latest"
137
                    + "&context=" + Utils.urlEncode(pageResourceId);
×
138
        }
139
        // "edit"/"deactivate view display" only make sense for an actual view-display
140
        // assignment (one with a resolved view IRI). Built-in views rendered directly —
141
        // e.g. a space's About-tab meta-views (roles/members/presets/view-displays) — have
142
        // no view-display nanopub, so these options are hidden for them.
143
        boolean isViewDisplay = viewDisplay.getViewIri() != null;
×
144
        // Label (with its leading icon) comes from the markup body, so no label arg here.
145
        ExternalLink adjustLink = new ExternalLink("adjust", adjustUrl);
×
146
        adjustLink.setVisible(showAdjust && isViewDisplay);
×
147
        addEntry("adjust", adjustLink);
×
148

149
        BookmarkablePageLink<Void> deactivateLink = new BookmarkablePageLink<>("deactivate", PublishPage.class,
×
150
                new PageParameters()
151
                        .set("template", "https://w3id.org/np/RAZ47_4JquvEXk30HYnVeSgFRcQqHtpdibcfBOeqHI2j4")
×
152
                        .set("template-version", "latest")
×
153
                        .set("param_resource", pageResourceId)
×
154
                        .set("param_view", viewDisplay.getViewIri() != null ? viewDisplay.getViewIri().stringValue() : viewDisplay.getView().getId())
×
155
                        .set("context", pageResourceId)
×
156
                        .set("refresh-upon-publish", pageResourceId));
×
157
        deactivateLink.setVisible(showAdjust && isViewDisplay);
×
158
        addEntry("deactivate", deactivateLink);
×
159

160
        boolean showAddToOwn = session.getUserIri() != null
×
161
                && viewDisplay.getViewIri() != null
×
162
                && pageResource instanceof IndividualAgent ia && !ia.isCurrentUser();
×
163
        String addToOwnUrl = "";
×
164
        if (showAddToOwn) {
×
165
            String userIri = session.getUserIri().stringValue();
×
166
            String viewIri = viewDisplay.getViewIri().stringValue();
×
167
            if (viewDisplay.getView() != null && viewDisplay.getView().getLabel() != null) {
×
168
                GuidedChoiceItem.setLabel(viewIri, viewDisplay.getView().getLabel());
×
169
            }
170
            addToOwnUrl = PublishPage.MOUNT_PATH + "?template=" + Utils.urlEncode("https://w3id.org/np/RAQhTCHtfzGCj1YiE1LualWcZjg3thlRiquFWUE14UF-g")
×
171
                    + "&template-version=latest"
172
                    + "&param_resource=" + Utils.urlEncode(userIri)
×
173
                    + "&param_view=" + Utils.urlEncode(viewIri)
×
174
                    + "&context=" + Utils.urlEncode(userIri)
×
175
                    + "&refresh-upon-publish=" + Utils.urlEncode(userIri)
×
176
                    + "&param_appliesToResource=" + Utils.urlEncode(userIri);
×
177
        }
178
        // Label (with its leading icon) comes from the markup body, so no label arg here.
179
        ExternalLink addToOwnLink = new ExternalLink("addToOwn", addToOwnUrl);
×
180
        addToOwnLink.setVisible(showAddToOwn);
×
181
        addEntry("addToOwn", addToOwnLink);
×
182

183
        Link<Void> refreshLink = new Link<>("refreshNow") {
×
184
            @Override
185
            public void onClick() {
186
                ApiCache.clearCache(queryRef, 0);
×
187
                setResponsePage(getPage().getClass(), getPage().getPageParameters());
×
188
            }
×
189
        };
190
        refreshLink.setVisible(session.getUserIri() != null);
×
191
        addEntry("refreshNow", refreshLink);
×
192

193
        BookmarkablePageLink<Void> viewDeclarationLink = new BookmarkablePageLink<>("viewDeclaration", ExplorePage.class,
×
194
                new PageParameters().set("id", nanopubId));
×
195
        viewDeclarationLink.add(NavigationContext.pageContextFallback());
×
196
        viewDeclarationLink.setVisible(viewDisplay.getId() != null);
×
197
        addEntry("viewDeclaration", viewDeclarationLink);
×
198
    }
×
199

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