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

knowledgepixels / nanodash / 21797922750

08 Feb 2026 12:10PM UTC coverage: 14.246% (+0.8%) from 13.435%
21797922750

push

github

tkuhn
fix: hide action menu on preview page

Actions like update/retract only apply to published nanopublications.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

592 of 5272 branches covered (11.23%)

Branch coverage included in aggregate %.

1532 of 9637 relevant lines covered (15.9%)

2.06 hits per line

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

54.35
src/main/java/com/knowledgepixels/nanodash/page/NanodashPage.java
1
package com.knowledgepixels.nanodash.page;
2

3
import com.knowledgepixels.nanodash.MaintainedResource;
4
import com.knowledgepixels.nanodash.ResourceWithProfile;
5
import com.knowledgepixels.nanodash.Project;
6
import com.knowledgepixels.nanodash.Space;
7
import com.knowledgepixels.nanodash.User;
8
import com.knowledgepixels.nanodash.Utils;
9
import com.knowledgepixels.nanodash.WicketApplication;
10
import com.knowledgepixels.nanodash.template.TemplateData;
11
import org.apache.wicket.markup.head.IHeaderResponse;
12
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
13
import org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem;
14
import org.apache.wicket.markup.html.WebPage;
15
import org.apache.wicket.request.flow.RedirectToUrlException;
16
import org.apache.wicket.request.mapper.parameter.PageParameters;
17
import org.apache.wicket.request.resource.JavaScriptResourceReference;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

21
/**
22
 * Abstract base class for Nanodash pages.
23
 * Provides functionality for auto-refreshing data and rendering JavaScript resources.
24
 */
25
public abstract class NanodashPage extends WebPage {
26

27
    private static final Logger logger = LoggerFactory.getLogger(NanodashPage.class);
9✔
28

29
    private static long lastRefresh = 0L;
6✔
30
    private static final long REFRESH_INTERVAL = 60 * 1000; // 1 minute
31
    private static boolean refreshRunning = false;
6✔
32

33
    private long state = 0L;
9✔
34

35
    private static JavaScriptResourceReference nanodashJs = new JavaScriptResourceReference(WicketApplication.class, "script/nanodash.js");
21✔
36

37
    /**
38
     * Returns the mount path for this page.
39
     *
40
     * @return the mount path as a String
41
     */
42
    public abstract String getMountPath();
43

44
    /**
45
     * Constructor for NanodashPage.
46
     *
47
     * @param parameters the page parameters
48
     */
49
    protected NanodashPage(PageParameters parameters) {
50
        super(parameters);
9✔
51
        ensureRefreshed();
6✔
52
    }
3✔
53

54
    private void ensureRefreshed() {
55
        synchronized (getClass()) {
15✔
56
            state = lastRefresh;
9✔
57
            if (!refreshRunning && System.currentTimeMillis() - lastRefresh > REFRESH_INTERVAL) {
24!
58
                lastRefresh = System.currentTimeMillis();
6✔
59
                refreshRunning = true;
6✔
60
                new Thread(() -> {
12✔
61
//                                                try {
62
//                                                        Thread.sleep(2000);
63
//                                                } catch (InterruptedException ex) {
64
//                                                        logger.error();
65
//                                                }
66
                    try {
67
                        logger.info("Refreshing ...");
9✔
68
                        User.refreshUsers();
3✔
69
                        TemplateData.refreshTemplates();
3✔
70
                        Space.refresh();
3✔
71
                        MaintainedResource.refresh();
1✔
72
                        ResourceWithProfile.refresh();
1✔
73
                        Project.refresh();
×
74
                        logger.info("Refreshing done.");
×
75
                        lastRefresh = System.currentTimeMillis();
×
76
                    } catch (Exception ex) {
×
77
                        logger.error("Error during refresh", ex);
×
78
                    } finally {
79
                        refreshRunning = false;
×
80
                    }
81
                }).start();
3✔
82
            }
83
        }
9✔
84
    }
3✔
85

86
    /**
87
     * Checks if auto-refresh is enabled for this page.
88
     * Override this method in subclasses to enable auto-refresh.
89
     *
90
     * @return true if auto-refresh is enabled, false otherwise
91
     */
92
    protected boolean hasAutoRefreshEnabled() {
93
        return false;
×
94
    }
95

96
    /**
97
     * {@inheritDoc}
98
     */
99
    @Override
100
    protected void onRender() {
101
        if (hasAutoRefreshEnabled() && state < lastRefresh) {
×
102
            throw new RedirectToUrlException(getMountPath() + "?" + Utils.getPageParametersAsString(getPageParameters()));
×
103
        }
104
        super.onRender();
×
105
    }
×
106

107
    /**
108
     * {@inheritDoc}
109
     * <p>
110
     * Renders the head section of the page, including JavaScript references.
111
     */
112
    @Override
113
    public void renderHead(IHeaderResponse response) {
114
        super.renderHead(response);
×
115
        response.render(JavaScriptHeaderItem.forReference(getApplication().getJavaScriptLibrarySettings().getJQueryReference()));
×
116
        response.render(JavaScriptReferenceHeaderItem.forReference(nanodashJs));
×
117
    }
×
118

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