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

knowledgepixels / nanodash / 17636039285

11 Sep 2025 06:27AM UTC coverage: 13.841% (+0.01%) from 13.827%
17636039285

push

github

tkuhn
Work on Spaces

433 of 3952 branches covered (10.96%)

Branch coverage included in aggregate %.

1110 of 7196 relevant lines covered (15.43%)

0.68 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.ArrayList;
5
import java.util.List;
6
import java.util.function.Function;
7
import java.util.function.Supplier;
8

9
import org.apache.wicket.Component;
10
import org.apache.wicket.behavior.AttributeAppender;
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.panel.Panel;
15
import org.apache.wicket.markup.repeater.Item;
16
import org.apache.wicket.markup.repeater.data.DataView;
17
import org.apache.wicket.markup.repeater.data.ListDataProvider;
18
import org.apache.wicket.model.Model;
19
import org.apache.wicket.request.mapper.parameter.PageParameters;
20
import org.nanopub.extra.services.ApiResponse;
21

22
import com.knowledgepixels.nanodash.ApiCache;
23
import com.knowledgepixels.nanodash.QueryRef;
24
import com.knowledgepixels.nanodash.page.NanodashPage;
25

26
public class ItemListPanel<T extends Serializable> extends Panel {
27

28
    private String description;
29
    private List<AbstractLink> buttons = new ArrayList<>();
×
30
    private boolean finalized = false;
×
31

32
    private ItemListPanel(String markupId, String title) {
33
        super(markupId);
×
34
        setOutputMarkupId(true);
×
35

36
        if (markupId.matches("(.*-)?users")) {
×
37
            add(new AttributeAppender("class", " users"));
×
38
        } else if (markupId.matches("(.*-)?(forms|templates)")) {
×
39
            add(new AttributeAppender("class", " forms"));
×
40
        }
41

42
        add(new Label("title", title));
×
43
    }
×
44
    
45
    public ItemListPanel(String markupId, String title, List<T> items, ComponentProvider<T> compProvider) {
46
        this(markupId, title);
×
47

48
        add(new ItemList<T>("itemlist", items, compProvider));
×
49
    }
×
50

51
    public ItemListPanel(String markupId, String title, QueryRef queryRef, ApiResultListProvider<T> resultListProvider, ComponentProvider<T> compProvider) {
52
        this(markupId, title);
×
53

54
        ApiResponse qResponse = ApiCache.retrieveResponse(queryRef);
×
55
        if (qResponse != null) {
×
56
            add(new ItemList<T>("itemlist", resultListProvider.apply(qResponse), compProvider));
×
57
        } else {
58
            add(new ApiResultComponent("itemlist", queryRef) {
×
59

60
                @Override
61
                public Component getApiResultComponent(String markupId, ApiResponse response) {
62
                    return new ItemList<T>(markupId, resultListProvider.apply(response), compProvider);
×
63
                }
64
            });
65

66
        }
67
    }
×
68

69
    public ItemListPanel(String markupId, String title, ReadyFunction readyFunction, ResultFunction<List<T>> resultFunction, ComponentProvider<T> compProvider) {
70
        this(markupId, title);
×
71

72
        if (readyFunction.get()) {
×
73
            add(new ItemList<T>("itemlist", resultFunction.get(), compProvider));
×
74
        } else {
75
            add(new MethodResultComponent<List<T>>("itemlist", readyFunction, resultFunction) {
×
76
                @Override
77
                public Component getResultComponent(String markupId, List<T> result) {
78
                    return new ItemList<T>(markupId, resultFunction.get(), compProvider);
×
79
                }
80
            });
81
        }
82
    }
×
83

84
    public ItemListPanel<T> setDescription(String description) {
85
        this.description = description;
×
86
        return this;
×
87
    }
88

89
    public ItemListPanel<T> addButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
90
        if (parameters == null) parameters = new PageParameters();
×
91
        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", pageClass, parameters);
×
92
        button.setBody(Model.of(label));
×
93
        buttons.add(button);
×
94
        return this;
×
95
    }
96

97
    @Override
98
    protected void onBeforeRender() {
99
        if (!finalized) {
×
100
            add(new Label("description", description).setVisible(description != null));
×
101
            if (buttons.isEmpty()) {
×
102
                add(new Label("buttons").setVisible(false));
×
103
            } else {
104
                add(new DataView<AbstractLink>("buttons", new ListDataProvider<AbstractLink>(buttons)) {
×
105
    
106
                    @Override
107
                    protected void populateItem(Item<AbstractLink> item) {
108
                        item.add(item.getModelObject());
×
109
                    }
×
110
                    
111
                });
112
            }
113
            finalized = true;
×
114
        }
115
        super.onBeforeRender();
×
116
    }
×
117

118

119
    public abstract class MethodResultComponent<R> extends ResultComponent {
120

121
        private final transient Supplier<Boolean> readyFunction;
122
        private final transient Supplier<R> resultFunction;
123

124
        public MethodResultComponent(String id, ReadyFunction readyFunction, ResultFunction<R> resultFunction) {
×
125
            super(id);
×
126
            setOutputMarkupId(true);
×
127
            this.readyFunction = readyFunction;
×
128
            this.resultFunction = resultFunction;
×
129
        }
×
130

131
        /**
132
         * {@inheritDoc}
133
         */
134
        @Override
135
        protected boolean isContentReady() {
136
            return readyFunction.get();
×
137
        }
138

139
        /**
140
         * {@inheritDoc}
141
         */
142
        @Override
143
        public Component getLazyLoadComponent(String markupId) {
144
            R result = resultFunction.get();
×
145
            return getResultComponent(markupId, result);
×
146
        }
147

148
        public abstract Component getResultComponent(String markupId, R result);
149

150
    }
151

152
    public static interface ComponentProvider<T> extends Function<T, Component>, Serializable {
153
    }
154

155
    public static interface ApiResultListProvider<T> extends Function<ApiResponse, List<T>>, Serializable {
156
    }
157

158
    public static interface ReadyFunction extends Supplier<Boolean>, Serializable {
159
    }
160

161
    public static interface ResultFunction<X> extends Supplier<X>, Serializable {
162
    }
163

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