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

knowledgepixels / nanodash / 28789064412

06 Jul 2026 11:44AM UTC coverage: 28.51% (+0.008%) from 28.502%
28789064412

push

github

web-flow
Merge pull request #535 from knowledgepixels/feat/navigation-context

feat: persistent navigation context with back-link and post-publish forwarding

1811 of 7177 branches covered (25.23%)

Branch coverage included in aggregate %.

3710 of 12188 relevant lines covered (30.44%)

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

30
import java.util.List;
31

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

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

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

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

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

83
        IRI nanopubId = viewDisplay.getNanopubId();
×
84

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

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

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

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

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

172
        BookmarkablePageLink<Void> viewDeclarationLink = new BookmarkablePageLink<>("viewDeclaration", ExplorePage.class,
×
173
                new PageParameters().set("id", nanopubId));
×
174
        viewDeclarationLink.add(NavigationContext.pageContextFallback());
×
175
        viewDeclarationLink.setVisible(viewDisplay.getId() != null);
×
176
        addEntry("viewDeclaration", viewDeclarationLink);
×
177
    }
×
178

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