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

knowledgepixels / nanodash / 27622310436

16 Jun 2026 01:49PM UTC coverage: 26.963% (+6.3%) from 20.697%
27622310436

Pull #483

github

web-flow
Merge dbba567c9 into 663f14f46
Pull Request #483: Space/resource About pages, ref-aware spaces, and magic query params

1542 of 6717 branches covered (22.96%)

Branch coverage included in aggregate %.

3407 of 11638 relevant lines covered (29.27%)

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

29
import java.util.List;
30

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

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

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

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

77
        addEntry("showView", new BookmarkablePageLink<Void>("showView", ExplorePage.class,
×
78
                new PageParameters().set("id", viewDisplay.getView().getNanopub().getUri())));
×
79

80
        IRI nanopubId = viewDisplay.getNanopubId();
×
81

82
        // Determine whether "adjust" should be visible for this user on this page
83
        boolean showAdjust = false;
×
84
        NanodashSession session = NanodashSession.get();
×
85
        if (pageResource instanceof IndividualAgent ia) {
×
86
            showAdjust = ia.isCurrentUser();
×
87
        } else if (pageResource instanceof Space s) {
×
88
            String pubkeyhash = session.getPubkeyhash();
×
89
            showAdjust = pubkeyhash != null && s.isAdminPubkey(pubkeyhash);
×
90
        } else if (pageResource != null) {
×
91
            Space space = pageResource.getSpace();
×
92
            if (space != null) {
×
93
                String pubkeyhash = session.getPubkeyhash();
×
94
                showAdjust = pubkeyhash != null && space.isAdminPubkey(pubkeyhash);
×
95
            }
96
        }
97

98
        // Determine supersede vs derive based on whether this user's pubkey matches the nanopub's.
99
        // These are only needed when showAdjust is true (i.e. pageResource is non-null).
100
        String adjustUrl = "";
×
101
        String pageResourceId = pageResource != null ? pageResource.getId() : "";
×
102
        if (showAdjust) {
×
103
            String nanopubPubkey = NanopubElement.get(viewDisplay.getNanopub()).getPubkey();
×
104
            String sessionPubkey = session.getPubkeyString();
×
105
            String adjustParam = (nanopubPubkey != null && nanopubPubkey.equals(sessionPubkey))
×
106
                    ? "supersede" : "derive";
×
107
            IRI templateId = TemplateData.get().getTemplateId(viewDisplay.getNanopub());
×
108
            String templateUri = templateId != null ? templateId.stringValue()
×
109
                    : "http://purl.org/np/RACyK2NjqFgezYLiE8FQu7JI0xY1M1aNQbykeCW8oqXkA";
×
110
            adjustUrl = PublishPage.MOUNT_PATH + "?template=" + Utils.urlEncode(templateUri)
×
111
                    + "&" + adjustParam + "=" + Utils.urlEncode(nanopubId.stringValue())
×
112
                    + "&template-version=latest"
113
                    + "&context=" + Utils.urlEncode(pageResourceId);
×
114
        }
115
        // "edit"/"deactivate view display" only make sense for an actual view-display
116
        // assignment (one with a resolved view IRI). Built-in views rendered directly —
117
        // e.g. a space's About-tab meta-views (roles/members/presets/view-displays) — have
118
        // no view-display nanopub, so these options are hidden for them.
119
        boolean isViewDisplay = viewDisplay.getViewIri() != null;
×
120
        // Label (with its leading icon) comes from the markup body, so no label arg here.
121
        ExternalLink adjustLink = new ExternalLink("adjust", adjustUrl);
×
122
        adjustLink.setVisible(showAdjust && isViewDisplay);
×
123
        addEntry("adjust", adjustLink);
×
124

125
        BookmarkablePageLink<Void> deactivateLink = new BookmarkablePageLink<>("deactivate", PublishPage.class,
×
126
                new PageParameters()
127
                        .set("template", "https://w3id.org/np/RAZ47_4JquvEXk30HYnVeSgFRcQqHtpdibcfBOeqHI2j4")
×
128
                        .set("template-version", "latest")
×
129
                        .set("param_resource", pageResourceId)
×
130
                        .set("param_view", viewDisplay.getViewIri() != null ? viewDisplay.getViewIri().stringValue() : viewDisplay.getView().getId())
×
131
                        .set("context", pageResourceId)
×
132
                        .set("refresh-upon-publish", pageResourceId));
×
133
        deactivateLink.setVisible(showAdjust && isViewDisplay);
×
134
        addEntry("deactivate", deactivateLink);
×
135

136
        boolean showAddToOwn = session.getUserIri() != null
×
137
                && viewDisplay.getViewIri() != null
×
138
                && pageResource instanceof IndividualAgent ia && !ia.isCurrentUser();
×
139
        String addToOwnUrl = "";
×
140
        if (showAddToOwn) {
×
141
            String userIri = session.getUserIri().stringValue();
×
142
            String viewIri = viewDisplay.getViewIri().stringValue();
×
143
            if (viewDisplay.getView() != null && viewDisplay.getView().getLabel() != null) {
×
144
                GuidedChoiceItem.setLabel(viewIri, viewDisplay.getView().getLabel());
×
145
            }
146
            addToOwnUrl = PublishPage.MOUNT_PATH + "?template=" + Utils.urlEncode("https://w3id.org/np/RAQhTCHtfzGCj1YiE1LualWcZjg3thlRiquFWUE14UF-g")
×
147
                    + "&template-version=latest"
148
                    + "&param_resource=" + Utils.urlEncode(userIri)
×
149
                    + "&param_view=" + Utils.urlEncode(viewIri)
×
150
                    + "&context=" + Utils.urlEncode(userIri)
×
151
                    + "&refresh-upon-publish=" + Utils.urlEncode(userIri)
×
152
                    + "&param_appliesToResource=" + Utils.urlEncode(userIri);
×
153
        }
154
        // Label (with its leading icon) comes from the markup body, so no label arg here.
155
        ExternalLink addToOwnLink = new ExternalLink("addToOwn", addToOwnUrl);
×
156
        addToOwnLink.setVisible(showAddToOwn);
×
157
        addEntry("addToOwn", addToOwnLink);
×
158

159
        Link<Void> refreshLink = new Link<>("refreshNow") {
×
160
            @Override
161
            public void onClick() {
162
                ApiCache.clearCache(queryRef, 0);
×
163
                setResponsePage(getPage().getClass(), getPage().getPageParameters());
×
164
            }
×
165
        };
166
        refreshLink.setVisible(session.getUserIri() != null);
×
167
        addEntry("refreshNow", refreshLink);
×
168

169
        BookmarkablePageLink<Void> viewDeclarationLink = new BookmarkablePageLink<>("viewDeclaration", ExplorePage.class,
×
170
                new PageParameters().set("id", nanopubId));
×
171
        viewDeclarationLink.setVisible(viewDisplay.getId() != null);
×
172
        addEntry("viewDeclaration", viewDeclarationLink);
×
173
    }
×
174

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