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

knowledgepixels / nanodash / 18009437243

25 Sep 2025 01:41PM UTC coverage: 13.394% (-1.0%) from 14.385%
18009437243

push

github

tkuhn
Version 3.56

437 of 4084 branches covered (10.7%)

Branch coverage included in aggregate %.

1117 of 7518 relevant lines covered (14.86%)

0.66 hits per line

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

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

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

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

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

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

31
    private long state = 0L;
3✔
32

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

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

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

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

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

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

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

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