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

3
import java.io.Serializable;
4
import java.util.ArrayList;
5
import java.util.Calendar;
6
import java.util.HashMap;
7
import java.util.Map;
8

9
import org.apache.wicket.markup.html.panel.Panel;
10
import org.apache.wicket.markup.repeater.Item;
11
import org.apache.wicket.markup.repeater.data.DataView;
12
import org.apache.wicket.markup.repeater.data.ListDataProvider;
13
import org.nanopub.extra.services.ApiResponseEntry;
14

15
import com.knowledgepixels.nanodash.QueryRef;
16
import com.knowledgepixels.nanodash.template.Template;
17
import com.knowledgepixels.nanodash.template.TemplateData;
18

19
import jakarta.xml.bind.DatatypeConverter;
20

21
/**
22
 * A list of templates, grouped by topic.
23
 */
24
public class TemplateList extends Panel {
25

26
    /**
27
     * A list of templates, grouped by topic.
28
     *
29
     * @param id the wicket id of this component
30
     */
31
    public TemplateList(String id) {
32
        super(id);
×
33
        setOutputMarkupId(true);
×
34

35
        add(new ItemListPanel<Template>(
×
36
                "popular-templates",
37
                "Popular Templates",
38
                new QueryRef("get-most-used-templates-last30d"),
39
                TemplateData::getTemplateList,
40
                (template) -> new TemplateItem("item", template)
×
41
            ));
42

43
        add(new ItemListPanel<Template>(
×
44
                "getstarted-templates",
45
                "Suggested Templates to Get Started",
46
                new QueryRef("get-suggested-templates-to-get-started"),
47
                TemplateData::getTemplateList,
48
                (template) -> new TemplateItem("item", template)
×
49
            ));
50

51
        ArrayList<ApiResponseEntry> templateList = new ArrayList<>(TemplateData.get().getAssertionTemplates());
×
52
        templateList.sort((t1, t2) -> {
×
53
            Calendar c1 = getTime(t1);
×
54
            Calendar c2 = getTime(t2);
×
55
            if (c1 == null && c2 == null) return 0;
×
56
            if (c1 == null) return 1;
×
57
            if (c2 == null) return -1;
×
58
            return c2.compareTo(c1);
×
59
        });
60

61
        Map<String, Topic> topics = new HashMap<>();
×
62
        for (ApiResponseEntry entry : templateList) {
×
63
            String tag = entry.get("tag");
×
64
            if ("".equals(tag)) tag = null;
×
65
            if (!topics.containsKey(tag)) {
×
66
                topics.put(tag, new Topic(tag));
×
67
            }
68
            topics.get(tag).templates.add(entry);
×
69

70
        }
×
71
        ArrayList<Topic> topicList = new ArrayList<Topic>(topics.values());
×
72
        topicList.sort((t0, t1) -> {
×
73
            if (t0.tag == null) return 1;
×
74
            if (t1.tag == null) return -1;
×
75
            return t1.templates.size() - t0.templates.size();
×
76
        });
77
        DataView<Topic> topicDataView = new DataView<Topic>("topics", new ListDataProvider<Topic>(topicList)) {
×
78

79
            private static final long serialVersionUID = 1L;
80

81
            @Override
82
            protected void populateItem(Item<Topic> item) {
83
                String tag = item.getModelObject().tag;
×
84
                if (tag == null) tag = "Other";
×
85
                item.add(new ItemListPanel<ApiResponseEntry>(
×
86
                        "templates",
87
                        tag,
88
                        item.getModelObject().templates,
×
89
                        (respEntry) -> new TemplateItem("item", respEntry)
×
90
                    ));
91
            }
×
92
        };
93
        topicDataView.setOutputMarkupId(true);
×
94
        add(topicDataView);
×
95
    }
×
96

97
    private static Calendar getTime(ApiResponseEntry entry) {
98
        return DatatypeConverter.parseDateTime(entry.get("date"));
×
99
    }
100

101

102
    private static class Topic implements Serializable {
103

104
        private static final long serialVersionUID = 5919614141679468774L;
105

106
        String tag;
107
        ArrayList<ApiResponseEntry> templates = new ArrayList<>();
×
108

109
        Topic(String tag) {
×
110
            this.tag = tag;
×
111
        }
×
112

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