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

knowledgepixels / nanodash / 18308478708

07 Oct 2025 09:37AM UTC coverage: 13.522% (-0.2%) from 13.709%
18308478708

push

github

tkuhn
feat(Spaces): Improve template button links on Space pages

446 of 4164 branches covered (10.71%)

Branch coverage included in aggregate %.

1153 of 7661 relevant lines covered (15.05%)

0.67 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

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

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

71
        if (readyFunction.get()) {
×
72
            add(new ItemList<T>("itemlist", resultFunction.get(), compProvider));
×
73
        } else {
74
            lazyLoading = true;
×
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> makeInline() {
90
        add(new AttributeAppender("class", " inline"));
×
91
        return this;
×
92
    }
93

94
    // TODO Improve this (member/admin) button handling:
95
    public ItemListPanel<T> addButton(String label, Class<? extends NanodashPage> pageClass, PageParameters parameters) {
96
        if (parameters == null) parameters = new PageParameters();
×
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
        AbstractLink button = new BookmarkablePageLink<NanodashPage>("button", pageClass, parameters);
×
106
        button.setBody(Model.of(label));
×
107
        memberButtons.add(button);
×
108
        return this;
×
109
    }
110

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

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

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

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

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

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

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

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

164

165
    public abstract class MethodResultComponent<R> extends ResultComponent {
166

167
        private final transient Supplier<Boolean> readyFunction;
168
        private final transient Supplier<R> resultFunction;
169

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

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

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

194
        public abstract Component getResultComponent(String markupId, R result);
195

196
    }
197

198
    public static interface ComponentProvider<T> extends Function<T, Component>, Serializable {
199
    }
200

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

204
    public static interface ReadyFunction extends Supplier<Boolean>, Serializable {
205
    }
206

207
    public static interface ResultFunction<X> extends Supplier<X>, Serializable {
208
    }
209

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