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

knowledgepixels / nanodash / 18933056119

30 Oct 2025 07:23AM UTC coverage: 13.749% (-0.6%) from 14.376%
18933056119

push

github

tkuhn
Merge branch 'master' of github.com:knowledgepixels/nanodash

492 of 4504 branches covered (10.92%)

Branch coverage included in aggregate %.

1282 of 8399 relevant lines covered (15.26%)

0.68 hits per line

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

48.89
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.Project;
5
import com.knowledgepixels.nanodash.Space;
6
import com.knowledgepixels.nanodash.User;
7
import com.knowledgepixels.nanodash.Utils;
8
import com.knowledgepixels.nanodash.WicketApplication;
9
import com.knowledgepixels.nanodash.template.TemplateData;
10
import org.apache.wicket.markup.head.IHeaderResponse;
11
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
12
import org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem;
13
import org.apache.wicket.markup.html.WebPage;
14
import org.apache.wicket.request.flow.RedirectToUrlException;
15
import org.apache.wicket.request.mapper.parameter.PageParameters;
16
import org.apache.wicket.request.resource.JavaScriptResourceReference;
17
import org.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
19

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

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

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

32
    private long state = 0L;
3✔
33

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

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

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

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

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

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

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

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