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

knowledgepixels / nanodash / 18315129204

07 Oct 2025 01:57PM UTC coverage: 14.516% (+0.6%) from 13.943%
18315129204

push

github

tkuhn
feat(Spaces): Add buttons for views and pinned resources

480 of 4188 branches covered (11.46%)

Branch coverage included in aggregate %.

1249 of 7723 relevant lines covered (16.17%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/nanodash/page/SpacePage.java
1
package com.knowledgepixels.nanodash.page;
2

3
import java.time.LocalDateTime;
4
import java.time.ZoneId;
5
import java.time.format.DateTimeFormatter;
6
import java.util.ArrayList;
7
import java.util.List;
8

9
import org.apache.wicket.Component;
10
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
11
import org.apache.wicket.markup.html.basic.Label;
12
import org.apache.wicket.markup.html.link.AbstractLink;
13
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
14
import org.apache.wicket.markup.html.link.ExternalLink;
15
import org.apache.wicket.model.Model;
16
import org.apache.wicket.request.mapper.parameter.PageParameters;
17
import org.eclipse.rdf4j.model.IRI;
18
import org.nanopub.Nanopub;
19
import org.nanopub.extra.services.FailedApiCallException;
20

21
import com.knowledgepixels.nanodash.Space;
22
import com.knowledgepixels.nanodash.SpaceMemberRole;
23
import com.knowledgepixels.nanodash.User;
24
import com.knowledgepixels.nanodash.Utils;
25
import com.knowledgepixels.nanodash.component.ButtonList;
26
import com.knowledgepixels.nanodash.component.ItemListElement;
27
import com.knowledgepixels.nanodash.component.ItemListPanel;
28
import com.knowledgepixels.nanodash.component.PinGroupList;
29
import com.knowledgepixels.nanodash.component.SpaceUserList;
30
import com.knowledgepixels.nanodash.component.TitleBar;
31
import com.knowledgepixels.nanodash.component.ViewList;
32
import com.knowledgepixels.nanodash.connector.ConnectorConfig;
33
import com.knowledgepixels.nanodash.connector.GenOverviewPage;
34

35

36

37
/**
38
 * The ProjectPage class represents a space page in the Nanodash application.
39
 */
40
public class SpacePage extends NanodashPage {
41

42
    /**
43
     * The mount path for this page.
44
     */
45
    public static final String MOUNT_PATH = "/space";
46

47
    /**
48
     * {@inheritDoc}
49
     */
50
    @Override
51
    public String getMountPath() {
52
        return MOUNT_PATH;
×
53
    }
54

55
    /**
56
     * Space object with the data shown on this page.
57
     */
58
    private Space space;
59

60
    private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
×
61

62
    /**
63
     * Constructor for the SpacePage.
64
     *
65
     * @param parameters the page parameters
66
     * @throws org.nanopub.extra.services.FailedApiCallException if the API call fails
67
     */
68
    public SpacePage(final PageParameters parameters) throws FailedApiCallException {
69
        super(parameters);
×
70

71
        space = Space.get(parameters.get("id").toString());
×
72
        Nanopub np = space.getRootNanopub();
×
73

74
        add(new TitleBar("titlebar", this, "connectors"));
×
75

76
        add(new Label("pagetitle", space.getLabel() + " (space) | nanodash"));
×
77
        add(new Label("spacename", space.getLabel()));
×
78
        add(new Label("spacetype", space.getTypeLabel()));
×
79
        add(new ExternalLink("id", space.getId(), space.getId()));
×
80
        add(new BookmarkablePageLink<Void>("np", ExplorePage.class, new PageParameters().add("id", np.getUri())));
×
81

82
        add(new ItemListPanel<String>(
×
83
                "altids",
84
                "Alternative IDs:",
85
                space.getAltIDs(),
×
86
                id -> new ItemListElement("item", ExplorePage.class, new PageParameters().add("id", id), id)
×
87
            ));
88

89
        if (space.getStartDate() != null) {
×
90
            String dateString;
91
            LocalDateTime dt = LocalDateTime.ofInstant(space.getStartDate().toInstant(), ZoneId.systemDefault());
×
92
            dateString = dateTimeFormatter.format(dt);
×
93
            if (space.getEndDate() != null) {
×
94
                dt = LocalDateTime.ofInstant(space.getEndDate().toInstant(), ZoneId.systemDefault());
×
95
                String endDate = dateTimeFormatter.format(dt);
×
96
                if (!dateString.equals(endDate)) {
×
97
                    dateString += " - " + endDate;
×
98
                }
99
            }
100
            add(new Label("date", dateString));
×
101
        } else {
×
102
            add(new Label("date").setVisible(false));
×
103
        }
104

105
        add(new Label("description", "<span>" + Utils.sanitizeHtml(space.getDescription()) + "</span>").setEscapeModelStrings(false));
×
106

107
        final List<AbstractLink> pinButtons = new ArrayList<>();
×
108
        AbstractLink addPinnedTemplateButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
109
                .add("template", "https://w3id.org/np/RA2YwreWrGW9HkzWls8jgwaIINKUB5ZTli1aFKQt13dUk")
×
110
                .add("param_space", space.getId())
×
111
            );
112
        addPinnedTemplateButton.setBody(Model.of("+ template"));
×
113
        pinButtons.add(addPinnedTemplateButton);
×
114
        AbstractLink addPinnedQueryButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
115
                .add("template", "https://w3id.org/np/RAuLESdeRUlk1GcTwvzVXShiBMI0ntJs2DL2Bm5DzW_ZQ")
×
116
                .add("param_space", space.getId())
×
117
            );
118
        addPinnedQueryButton.setBody(Model.of("+ query"));
×
119
        pinButtons.add(addPinnedQueryButton);
×
120

121
        if (space.isDataInitialized()) {
×
122
            add(new PinGroupList("pin-groups", space));
×
123
            add(new ButtonList("pin-buttons", space, null, null, pinButtons));
×
124
        } else {
125
            add(new AjaxLazyLoadPanel<Component>("pin-groups") {
×
126
    
127
                @Override
128
                public Component getLazyLoadComponent(String markupId) {
129
                    return new PinGroupList(markupId, space);
×
130
                }
131
    
132
                @Override
133
                protected boolean isContentReady() {
134
                    return space.isDataInitialized();
×
135
                }
136
    
137
            });
138
            add(new AjaxLazyLoadPanel<Component>("pin-buttons") {
×
139
    
140
                @Override
141
                public Component getLazyLoadComponent(String markupId) {
142
                    return new ButtonList(markupId, space, null, null, pinButtons);
×
143
                }
144
    
145
                @Override
146
                protected boolean isContentReady() {
147
                    return space.isDataInitialized();
×
148
                }
149

150
                public Component getLoadingComponent(String id) {
151
                    return new Label(id).setVisible(false);
×
152
                };
153
    
154
            });
155
        }
156

157
        final List<AbstractLink> viewButtons = new ArrayList<>();
×
158
        AbstractLink addViewButton = new BookmarkablePageLink<NanodashPage>("button", PublishPage.class, new PageParameters()
×
159
                .add("template", "https://w3id.org/np/RAKKxyVdBLv-T1o5psQBtmGQvy1XBmh4LaJf7KxLmwszk")
×
160
                .add("param_space", space.getId())
×
161
            );
162
        addViewButton.setBody(Model.of("+"));
×
163
        viewButtons.add(addViewButton);
×
164

165
        if (space.isDataInitialized()) {
×
166
            add(new ViewList("views", space));
×
167
            add(new ButtonList("view-buttons", space, null, null, viewButtons));
×
168
        } else {
169
            add(new AjaxLazyLoadPanel<Component>("views") {
×
170
    
171
                @Override
172
                public Component getLazyLoadComponent(String markupId) {
173
                    return new ViewList(markupId, space);
×
174
                }
175
    
176
                @Override
177
                protected boolean isContentReady() {
178
                    return space.isDataInitialized();
×
179
                }
180
    
181
            });
182
            add(new AjaxLazyLoadPanel<Component>("view-buttons") {
×
183
    
184
                @Override
185
                public Component getLazyLoadComponent(String markupId) {
186
                    return new ButtonList(markupId, space, null, null, viewButtons);
×
187
                }
188
    
189
                @Override
190
                protected boolean isContentReady() {
191
                    return space.isDataInitialized();
×
192
                }
193

194
                public Component getLoadingComponent(String id) {
195
                    return new Label(id).setVisible(false);
×
196
                };
197
    
198
            });
199
        }
200

201
        add(new ItemListPanel<>(
×
202
                "roles",
203
                "Roles:",
204
                () -> space.isDataInitialized(),
×
205
                () -> space.getRoles(),
×
206
                r -> new ItemListElement("item", ExplorePage.class, new PageParameters().add("id", r.getId()), r.getName())
×
207
            )
208
            .makeInline()
×
209
            .setSpace(space)
×
210
            .addAdminButton("+", PublishPage.class, new PageParameters()
×
211
                    .add("template", "https://w3id.org/np/RARBzGkEqiQzeiHk0EXFcv9Ol1d-17iOh9MoFJzgfVQDc")
×
212
                    .add("param_space", space.getId())
×
213
                    .add("template-version", "latest")
×
214
                )
215
            );
216

217
        add(new ItemListPanel<IRI>(
×
218
                "users",
219
                "Users",
220
                () -> space.isDataInitialized(),
×
221
                () -> space.getUsers(),
×
222
                m -> {
223
                        String roleLabel = "(";
×
224
                        for (SpaceMemberRole r : space.getMemberRoles(m)) {
×
225
                            roleLabel += r.getName() + ", ";
×
226
                        }
×
227
                        roleLabel = roleLabel.replaceFirst(", $", ")");
×
228
                        return new ItemListElement("item", UserPage.class, new PageParameters().add("id", m), User.getShortDisplayName(m), roleLabel);
×
229
                    }
230
            ));
231

232

233
        if (space.isDataInitialized()) {
×
234
            add(new SpaceUserList("user-lists", space));
×
235
        } else {
236
            add(new AjaxLazyLoadPanel<Component>("user-lists") {
×
237
    
238
                @Override
239
                public Component getLazyLoadComponent(String markupId) {
240
                    return new SpaceUserList(markupId, space);
×
241
                }
242
    
243
                @Override
244
                protected boolean isContentReady() {
245
                    return space.isDataInitialized();
×
246
                }
247
    
248
            });
249
        }
250

251
        add(new ItemListPanel<Space>(
×
252
                "superspaces",
253
                "Part of",
254
                space.getSuperspaces(),
×
255
                (space) -> new ItemListElement("item", SpacePage.class, new PageParameters().add("id", space), space.getLabel(), "(" + space.getTypeLabel() + ")")
×
256
            ));
257

258
        addSubspacePanel("Alliance", true);
×
259
        addSubspacePanel("Consortium", false);
×
260
        addSubspacePanel("Organization", true);
×
261
        addSubspacePanel("Taskforce", false);
×
262
        addSubspacePanel("Division", true);
×
263
        addSubspacePanel("Taskunit", false);
×
264
        addSubspacePanel("Group", true);
×
265
        addSubspacePanel("Project", false);
×
266
        addSubspacePanel("Program", true);
×
267
        addSubspacePanel("Initiative", false);
×
268
        addSubspacePanel("Outlet", true);
×
269
        addSubspacePanel("Campaign", false);
×
270
        addSubspacePanel("Community", true);
×
271
        addSubspacePanel("Event", false);
×
272

273
        String shortId = space.getId().replace("https://w3id.org/spaces/", "");
×
274
        ConnectorConfig cc = ConnectorConfig.get(shortId);
×
275
        if (cc != null) {
×
276
            add(new BookmarkablePageLink<Void>("content-button", GenOverviewPage.class, new PageParameters().add("journal", shortId)).setBody(Model.of("Nanopublication Submissions")));
×
277
        } else {
278
            add(new Label("content-button").setVisible(false));
×
279
        }
280
    }
×
281

282
    private void addSubspacePanel(String type, boolean openEnded) {
283
        String typePl = type + "s";
×
284
        typePl = typePl.replaceFirst("ys$", "ies");
×
285

286
        add(new ItemListPanel<>(
×
287
                typePl.toLowerCase(),
×
288
                typePl,
289
                space.getSubspaces("https://w3id.org/kpxl/gen/terms/" + type),
×
290
                (space) -> new ItemListElement("item", SpacePage.class, new PageParameters().add("id", space), space.getLabel())
×
291
            )
292
            .setSpace(space)
×
293
            .setReadyFunction(space::isDataInitialized)
×
294
            .addMemberButton("+", PublishPage.class, new PageParameters()
×
295
                    .add("template", openEnded ? "https://w3id.org/np/RA7dQfmndqKmooQ4PlHyQsAql9i2tg_8GLHf_dqtxsGEQ" : "https://w3id.org/np/RAaE7NP9RNIx03AHZxanFMdtUuaTfe50ns5tHhpEVloQ4")
×
296
                    .add("param_type", "https://w3id.org/kpxl/gen/terms/" + type)
×
297
                    .add("param_space", space.getId().replaceFirst("https://w3id.org/spaces/", "") + "/<...>")
×
298
                    .add("template-version", "latest"))
×
299
            );
300
    }
×
301

302
    /**
303
     * Checks if auto-refresh is enabled for this page.
304
     *
305
     * @return true if auto-refresh is enabled, false otherwise
306
     */
307
    protected boolean hasAutoRefreshEnabled() {
308
        return true;
×
309
    }
310

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