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

knowledgepixels / nanodash / 17606718291

10 Sep 2025 07:37AM UTC coverage: 13.824% (+0.1%) from 13.688%
17606718291

push

github

tkuhn
Replace usage of TemplateResults with generic ItemListPanel

414 of 3878 branches covered (10.68%)

Branch coverage included in aggregate %.

1090 of 7002 relevant lines covered (15.57%)

0.69 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/ItemListPanel.java
1
package com.knowledgepixels.nanodash.component;
2

3
import java.io.Serializable;
4
import java.util.List;
5
import java.util.function.Function;
6
import java.util.function.Supplier;
7

8
import org.apache.wicket.Component;
9
import org.apache.wicket.behavior.AttributeAppender;
10
import org.apache.wicket.markup.html.basic.Label;
11
import org.apache.wicket.markup.html.panel.Panel;
12
import org.nanopub.extra.services.ApiResponse;
13

14
import com.knowledgepixels.nanodash.ApiCache;
15
import com.knowledgepixels.nanodash.QueryRef;
16

17
public class ItemListPanel<T extends Serializable> extends Panel {
18

19
    private ItemListPanel(String markupId, String title) {
20
        super(markupId);
×
21
        setOutputMarkupId(true);
×
22

23
        if (markupId.matches("(.*-)?users")) {
×
24
            add(new AttributeAppender("class", " users"));
×
25
        } else if (markupId.matches("(.*-)?(forms|templates)")) {
×
26
            add(new AttributeAppender("class", " forms"));
×
27
        }
28

29
        if (title.contains("  ")) {
×
30
            add(new Label("description", title.replaceFirst("^.*  ", "")));
×
31
            title = title.replaceFirst("  .*$", "");
×
32
        } else {
33
            add(new Label("description").setVisible(false));
×
34
        }
35
        add(new Label("title", title));
×
36
        add(new Label("button").setVisible(false));
×
37
    }
×
38
    
39
    public ItemListPanel(String markupId, String title, List<T> items, ComponentProvider<T> compProvider) {
40
        this(markupId, title);
×
41

42
        add(new ItemList<T>("itemlist", items, compProvider));
×
43
    }
×
44

45
    public ItemListPanel(String markupId, String title, QueryRef queryRef, ApiResultListProvider<T> resultListProvider, ComponentProvider<T> compProvider) {
46
        this(markupId, title);
×
47

48
        ApiResponse qResponse = ApiCache.retrieveResponse(queryRef);
×
49
        if (qResponse != null) {
×
50
            add(new ItemList<T>("itemlist", resultListProvider.apply(qResponse), compProvider));
×
51
        } else {
52
            add(new ApiResultComponent("itemlist", queryRef) {
×
53

54
                @Override
55
                public Component getApiResultComponent(String markupId, ApiResponse response) {
56
                    return new ItemList<T>(markupId, resultListProvider.apply(response), compProvider);
×
57
                }
58
            });
59

60
        }
61
    }
×
62

63
    public ItemListPanel(String markupId, String title, ReadyFunction readyFunction, ResultFunction<List<T>> resultFunction, ComponentProvider<T> compProvider) {
64
        this(markupId, title);
×
65

66
        if (readyFunction.get()) {
×
67
            add(new ItemList<T>("itemlist", resultFunction.get(), compProvider));
×
68
        } else {
69
            add(new MethodResultComponent<List<T>>("itemlist", readyFunction, resultFunction) {
×
70
                @Override
71
                public Component getResultComponent(String markupId, List<T> result) {
72
                    return new ItemList<T>(markupId, resultFunction.get(), compProvider);
×
73
                }
74
            });
75
        }
76
    }
×
77

78
    public abstract class MethodResultComponent<R> extends ResultComponent {
79

80
        private final transient Supplier<Boolean> readyFunction;
81
        private final transient Supplier<R> resultFunction;
82

83
        public MethodResultComponent(String id, ReadyFunction readyFunction, ResultFunction<R> resultFunction) {
×
84
            super(id);
×
85
            setOutputMarkupId(true);
×
86
            this.readyFunction = readyFunction;
×
87
            this.resultFunction = resultFunction;
×
88
        }
×
89

90
        /**
91
         * {@inheritDoc}
92
         */
93
        @Override
94
        protected boolean isContentReady() {
95
            return readyFunction.get();
×
96
        }
97

98
        /**
99
         * {@inheritDoc}
100
         */
101
        @Override
102
        public Component getLazyLoadComponent(String markupId) {
103
            R result = resultFunction.get();
×
104
            return getResultComponent(markupId, result);
×
105
        }
106

107
        public abstract Component getResultComponent(String markupId, R result);
108

109
    }
110

111
    public static interface ComponentProvider<T> extends Function<T, Component>, Serializable {
112
    }
113

114
    public static interface ApiResultListProvider<T> extends Function<ApiResponse, List<T>>, Serializable {
115
    }
116

117
    public static interface ReadyFunction extends Supplier<Boolean>, Serializable {
118
    }
119

120
    public static interface ResultFunction<X> extends Supplier<X>, Serializable {
121
    }
122

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