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

knowledgepixels / nanodash / 18747524808

23 Oct 2025 11:56AM UTC coverage: 12.836% (-0.8%) from 13.683%
18747524808

push

github

tkuhn
feat(SpacePage): Add button to add resource

448 of 4402 branches covered (10.18%)

Branch coverage included in aggregate %.

1174 of 8234 relevant lines covered (14.26%)

0.63 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.extensions.ajax.markup.html.AjaxLazyLoadPanel;
12
import org.apache.wicket.markup.html.basic.Label;
13
import org.apache.wicket.markup.html.link.AbstractLink;
14
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
15
import org.apache.wicket.markup.html.panel.Panel;
16
import org.apache.wicket.model.Model;
17
import org.apache.wicket.request.mapper.parameter.PageParameters;
18
import org.nanopub.extra.services.ApiResponse;
19
import org.nanopub.extra.services.QueryRef;
20

21
import com.knowledgepixels.nanodash.ApiCache;
22
import com.knowledgepixels.nanodash.Space;
23
import com.knowledgepixels.nanodash.page.NanodashPage;
24

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

27
    private String description;
28
    private List<AbstractLink> buttons = new ArrayList<>();
×
29
    private List<AbstractLink> memberButtons = new ArrayList<>();
×
30
    private List<AbstractLink> adminButtons = new ArrayList<>();
×
31
    private Space space;
32
    private boolean finalized = false;
×
33
    private boolean lazyLoading = false;
×
34
    private ReadyFunction readyFunction;
35

36
    private ItemListPanel(String markupId, String title) {
37
        super(markupId);
×
38
        setOutputMarkupId(true);
×
39

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

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

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

52
        ApiResponse qResponse = ApiCache.retrieveResponse(queryRef);
×
53
        if (qResponse != null) {
×
54
            add(new ItemList<T>("itemlist", resultListProvider.apply(qResponse), compProvider));
×
55
        } else {
56
            lazyLoading = true;
×
57
            add(new ApiResultComponent("itemlist", queryRef) {
×
58
                @Override
59
                public Component getApiResultComponent(String markupId, ApiResponse response) {
60
                    return new ItemList<T>(markupId, resultListProvider.apply(response), compProvider);
×
61
                }
62
            });
63
        }
64
    }
×
65

66
    public ItemListPanel(String markupId, String title, ReadyFunction readyFunction, ResultFunction<List<T>> resultFunction, ComponentProvider<T> compProvider) {
67
        this(markupId, title);
×
68
        this.readyFunction = readyFunction;
×
69

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

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

88
    public ItemListPanel<T> makeInline() {
89
        add(new AttributeAppender("class", " inline"));
×
90
        return this;
×
91
    }
92

93
    // TODO Improve this (member/admin) button handling:
94
    public ItemListPanel<T> addButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
95
        if (parameters == null) parameters = new PageParameters();
×
96
        if (space != null) parameters.add("context", space.getId());
×
97
        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", pageClass, parameters);
×
98
        button.setBody(Model.of(label));
×
99
        buttons.add(button);
×
100
        return this;
×
101
    }
102

103
    public ItemListPanel<T> addMemberButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
104
        if (parameters == null) parameters = new PageParameters();
×
105
        if (space != null) parameters.add("context", space.getId());
×
106
        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", pageClass, parameters);
×
107
        button.setBody(Model.of(label));
×
108
        memberButtons.add(button);
×
109
        return this;
×
110
    }
111

112
    public ItemListPanel<T> addAdminButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
113
        if (parameters == null) parameters = new PageParameters();
×
114
        if (space != null) parameters.add("context", space.getId());
×
115
        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", pageClass, parameters);
×
116
        button.setBody(Model.of(label));
×
117
        adminButtons.add(button);
×
118
        return this;
×
119
    }
120

121
    public ItemListPanel<T> setSpace(Space space) {
122
        this.space = space;
×
123
        return this;
×
124
    }
125

126
    public ItemListPanel<T> setReadyFunction(ReadyFunction readyFunction) {
127
        this.readyFunction = readyFunction;
×
128
        return this;
×
129
    }
130

131
    @Override
132
    protected void onBeforeRender() {
133
        if (!finalized) {
×
134
            add(new Label("description", description).setVisible(description != null));
×
135
            if (space != null && readyFunction != null && !readyFunction.get()) {
×
136
                add(new AjaxLazyLoadPanel<Component>("buttons") {
×
137

138
                    @Override
139
                    public Component getLazyLoadComponent(String markupId) {
140
                        return new ButtonList(markupId, space, buttons, memberButtons, adminButtons);
×
141
                    }
142

143
                    @Override
144
                    protected boolean isContentReady() {
145
                        return readyFunction.get();
×
146
                    }
147

148
                    @Override
149
                    public Component getLoadingComponent(String id) {
150
                        if (lazyLoading) {
×
151
                            return new Label(id).setVisible(false);
×
152
                        } else {
153
                            return new Label(id, ResultComponent.getWaitComponentHtml(null)).setEscapeModelStrings(false);
×
154
                        }
155
                    }
156

157
                });
158
            } else {
159
                add(new ButtonList("buttons", space, buttons, memberButtons, adminButtons));
×
160
            }
161
            finalized = true;
×
162
        }
163
        super.onBeforeRender();
×
164
    }
×
165

166

167
    public abstract class MethodResultComponent<R> extends ResultComponent {
168

169
        private final transient Supplier<Boolean> readyFunction;
170
        private final transient Supplier<R> resultFunction;
171

172
        public MethodResultComponent(String id, ReadyFunction readyFunction, ResultFunction<R> resultFunction) {
×
173
            super(id);
×
174
            setOutputMarkupId(true);
×
175
            this.readyFunction = readyFunction;
×
176
            this.resultFunction = resultFunction;
×
177
        }
×
178

179
        /**
180
         * {@inheritDoc}
181
         */
182
        @Override
183
        protected boolean isContentReady() {
184
            return readyFunction.get();
×
185
        }
186

187
        /**
188
         * {@inheritDoc}
189
         */
190
        @Override
191
        public Component getLazyLoadComponent(String markupId) {
192
            R result = resultFunction.get();
×
193
            return getResultComponent(markupId, result);
×
194
        }
195

196
        public abstract Component getResultComponent(String markupId, R result);
197

198
    }
199

200
    public static interface ComponentProvider<T> extends Function<T, Component>, Serializable {
201
    }
202

203
    public static interface ApiResultListProvider<T> extends Function<ApiResponse, List<T>>, Serializable {
204
    }
205

206
    public static interface ReadyFunction extends Supplier<Boolean>, Serializable {
207
    }
208

209
    public static interface ResultFunction<X> extends Supplier<X>, Serializable {
210
    }
211

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