|
28 | 28 | }); |
29 | 29 | } |
30 | 30 |
|
31 | | - function createItem(label, value) { |
32 | | - return "<li><strong>" + label + ":</strong> " + value + "</li>"; |
| 31 | + function createMetricItem(label, value) { |
| 32 | + var item = document.createElement("li"); |
| 33 | + item.innerHTML = "<strong>" + label + ":</strong> " + value; |
| 34 | + return item; |
33 | 35 | } |
34 | 36 |
|
35 | | - function createCardColumn(title, description, items, linkUrl, linkLabel) { |
36 | | - var column = document.createElement("div"); |
37 | | - column.className = "col-md-12"; |
| 37 | + function createSection(title, description, metrics, linkUrl, linkLabel) { |
| 38 | + var section = document.createElement("section"); |
| 39 | + section.style.marginBottom = "14px"; |
| 40 | + |
| 41 | + var heading = document.createElement("h4"); |
| 42 | + heading.textContent = title; |
| 43 | + heading.style.marginBottom = "4px"; |
| 44 | + section.appendChild(heading); |
| 45 | + |
| 46 | + if (description) { |
| 47 | + var blurb = document.createElement("p"); |
| 48 | + blurb.className = "text-muted"; |
| 49 | + blurb.style.marginBottom = "6px"; |
| 50 | + blurb.style.fontSize = "0.95em"; |
| 51 | + blurb.textContent = description; |
| 52 | + section.appendChild(blurb); |
| 53 | + } |
| 54 | + |
| 55 | + var list = document.createElement("ul"); |
| 56 | + list.className = "list-unstyled"; |
| 57 | + list.style.marginBottom = "6px"; |
38 | 58 |
|
39 | | - var card = document.createElement("div"); |
40 | | - card.className = "panel panel-primary panel-precice"; |
41 | | - card.style.marginBottom = "14px"; |
| 59 | + for (var i = 0; i < metrics.length; i += 1) { |
| 60 | + var metric = metrics[i]; |
| 61 | + list.appendChild(createMetricItem(metric[0], metric[1])); |
| 62 | + } |
| 63 | + section.appendChild(list); |
42 | 64 |
|
43 | | - var list = "<ul class=\"list-unstyled no-margin\">" + items.join("") + "</ul>"; |
44 | | - var descriptionHtml = description ? "<p class=\"text-muted\" style=\"font-size: 0.9em; margin-bottom: 8px;\">" + description + "</p>" : ""; |
45 | | - var linkHtml = ""; |
46 | 65 | if (linkUrl && linkLabel) { |
47 | | - linkHtml = |
48 | | - "<p class=\"no-margin\" style=\"margin-top: 10px;\"><a href=\"" + |
49 | | - linkUrl + |
50 | | - "\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"no-external-marker\">" + |
51 | | - linkLabel + |
52 | | - " <i class=\"fas fa-chevron-right\"></i></a></p>"; |
| 66 | + var paragraph = document.createElement("p"); |
| 67 | + paragraph.className = "no-margin"; |
| 68 | + var link = document.createElement("a"); |
| 69 | + link.href = linkUrl; |
| 70 | + link.target = "_blank"; |
| 71 | + link.rel = "noopener noreferrer"; |
| 72 | + link.className = "no-external-marker"; |
| 73 | + link.innerHTML = linkLabel + " <i class=\"fas fa-chevron-right\"></i>"; |
| 74 | + paragraph.appendChild(link); |
| 75 | + section.appendChild(paragraph); |
53 | 76 | } |
54 | 77 |
|
55 | | - card.innerHTML = |
56 | | - "<div class=\"panel-heading-precice text-left\"><strong>" + |
57 | | - title + |
58 | | - "</strong></div>" + |
59 | | - "<div class=\"panel-body\" style=\"font-size: 0.92em; line-height: 1.35;\">" + |
60 | | - descriptionHtml + |
61 | | - list + |
62 | | - linkHtml + |
63 | | - "</div>"; |
64 | | - |
65 | | - column.appendChild(card); |
66 | | - return column; |
| 78 | + return section; |
67 | 79 | } |
68 | 80 |
|
69 | | - function createRepositoryCard(repo) { |
| 81 | + function createRepositorySection(repo) { |
70 | 82 | var latestRelease = repo.latest_release; |
71 | 83 | var latestReleaseValue = "n/a"; |
72 | 84 | if (latestRelease && latestRelease.url) { |
|
82 | 94 |
|
83 | 95 | var releaseDownloads = latestRelease ? formatNumber(latestRelease.downloads_count) : "n/a"; |
84 | 96 |
|
85 | | - return createCardColumn( |
| 97 | + return createSection( |
86 | 98 | repo.label, |
87 | 99 | REPO_BLURBS[repo.id] || "", |
88 | 100 | [ |
89 | | - createItem("Stars", formatNumber(repo.stars)), |
90 | | - createItem("Contributors", formatNumber(repo.contributors)), |
91 | | - createItem("Open issues", formatNumber(repo.open_issues)), |
92 | | - createItem("Latest commit", formatDate(repo.latest_commit_at)), |
93 | | - createItem("Latest release", latestReleaseValue), |
94 | | - createItem("Release downloads", releaseDownloads), |
| 101 | + ["Stars", formatNumber(repo.stars)], |
| 102 | + ["Contributors", formatNumber(repo.contributors)], |
| 103 | + ["Open issues", formatNumber(repo.open_issues)], |
| 104 | + ["Latest commit", formatDate(repo.latest_commit_at)], |
| 105 | + ["Latest release", latestReleaseValue], |
| 106 | + ["Release downloads", releaseDownloads], |
95 | 107 | ], |
96 | 108 | repo.url, |
97 | 109 | "Open repository" |
98 | 110 | ); |
99 | 111 | } |
100 | 112 |
|
101 | | - function createDiscourseCard(discourse) { |
102 | | - return createCardColumn( |
| 113 | + function createDiscourseSection(discourse) { |
| 114 | + return createSection( |
103 | 115 | "Discourse forum", |
104 | 116 | "Community activity snapshot.", |
105 | 117 | [ |
106 | | - createItem("Users", formatNumber(discourse.users_count)), |
107 | | - createItem("Topics", formatNumber(discourse.topics_count)), |
108 | | - createItem("Posts", formatNumber(discourse.posts_count)), |
109 | | - createItem("Active users (30d)", formatNumber(discourse.active_users_30_days)), |
110 | | - createItem("Topics (30d)", formatNumber(discourse.topics_30_days)), |
111 | | - createItem("Posts (30d)", formatNumber(discourse.posts_30_days)), |
| 118 | + ["Users", formatNumber(discourse.users_count)], |
| 119 | + ["Topics", formatNumber(discourse.topics_count)], |
| 120 | + ["Posts", formatNumber(discourse.posts_count)], |
| 121 | + ["Active users (30d)", formatNumber(discourse.active_users_30_days)], |
| 122 | + ["Topics (30d)", formatNumber(discourse.topics_30_days)], |
| 123 | + ["Posts (30d)", formatNumber(discourse.posts_30_days)], |
112 | 124 | ], |
113 | 125 | discourse.url, |
114 | 126 | "Open forum" |
|
143 | 155 | throw new Error("Missing metrics data"); |
144 | 156 | } |
145 | 157 |
|
146 | | - var row = document.createElement("div"); |
147 | | - row.className = "row"; |
148 | | - |
| 158 | + container.innerHTML = ""; |
149 | 159 | for (var i = 0; i < repositories.length; i += 1) { |
150 | | - row.appendChild(createRepositoryCard(repositories[i])); |
| 160 | + container.appendChild(createRepositorySection(repositories[i])); |
151 | 161 | } |
152 | | - row.appendChild(createDiscourseCard(discourse)); |
153 | | - |
154 | | - container.innerHTML = ""; |
155 | | - container.appendChild(row); |
| 162 | + container.appendChild(createDiscourseSection(discourse)); |
156 | 163 |
|
157 | 164 | if (status) { |
158 | 165 | status.textContent = |
|
0 commit comments