Skip to content

Commit 94ef21c

Browse files
committed
Feature: adding "sort-by-value" field to cell-value - to allow correct sorting by complex visual-values
1 parent 1e81bbb commit 94ef21c

10 files changed

Lines changed: 48 additions & 23 deletions

File tree

docs/data/data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/misc/report.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ function defaultRender (data, type, row, meta) {
1212
// "href": "<url>", # Link in cell
1313
// "value": "string" # Value of cell
1414
// }
15+
// console.log("defaultRenderer is called with type = " + type);
16+
if (type == 'sort') {
17+
return data.sortByValue;
18+
}
19+
1520
if (data.title && data.href) {
1621
return '<div title="<p class=\'my-tooltip\'>' + data.title + '</p>"><a href="' + data.href + '" target="_blank">' + (data.value || '&nbsp;') + '</a></div>';
1722
} else if (data.title) {
1823
return '<div title="' + data.title + '">' + (data.value || '&nbsp;') + '</div>';
1924
} else if (data.href) {
2025
return '<a href="' + data.href + '" target="_blank">' + (data.value || '&nbsp;') + '</a>';
2126
} else if (data.value) {
22-
return String(data.value);
27+
return String(data.value);
2328
} else {
2429
return String(data);
2530
}

src/main/java/com/github/exadmin/ostm/collectors/impl/repos/ListAllRepositories.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public void collectDataInto(TheReportModel theReportModel, GitHubFacade gitHubFa
2727

2828
int number = 1;
2929
for (Map.Entry<String, String> me : repoNames.entrySet()) {
30-
colRepoNumber.addValue(me.getKey(), new TheCellValue("" + number));
31-
colRepoName.addValue(me.getKey(), new TheCellValue(me.getValue()));
30+
colRepoNumber.addValue(me.getKey(), new TheCellValue("" + number, "" + number));
31+
colRepoName.addValue(me.getKey(), new TheCellValue(me.getValue(), me.getValue()));
3232

3333
number++;
3434
}

src/main/java/com/github/exadmin/ostm/collectors/impl/repos/SonarCodeCoverage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void collectDataInto(TheReportModel theReportModel, GitHubFacade gitHubFa
7676
String component = (String) mData.get("component");
7777

7878
String rowId = componentToRowIdMap.remove(component);
79-
column.addValue(rowId, new TheCellValue(value + "%"));
79+
column.addValue(rowId, new TheCellValue(value + "%", value));
8080
}
8181
}
8282
}
@@ -89,7 +89,7 @@ public void collectDataInto(TheReportModel theReportModel, GitHubFacade gitHubFa
8989

9090
// at this step - componenToRowIdMap contains list of components with absent data
9191
for (Map.Entry<String, String> me : componentToRowIdMap.entrySet()) {
92-
column.addValue(me.getValue(), new TheCellValue("Not Registered"));
92+
column.addValue(me.getValue(), new TheCellValue("Not Registered", "0"));
9393
}
9494
}
9595
}

src/main/java/com/github/exadmin/ostm/collectors/impl/repos/TopicAndTeamPerRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void collectDataInto(TheReportModel theReportModel, GitHubFacade gitHubFa
1919
List<GitHubRepository> repoList = gitHubFacade.getAllRepositories("Netcracker");
2020
for (GitHubRepository repository : repoList) {
2121
String rowId = repository.getId();
22-
TheCellValue cellValue = new TheCellValue(topicsListToStr(repository.getTopics()));
22+
TheCellValue cellValue = new TheCellValue(topicsListToStr(repository.getTopics()), "");
2323
colTopics.addValue(rowId, cellValue);
2424
}
2525
}

src/main/java/com/github/exadmin/ostm/collectors/impl/teams/CountNumberOfCommitsPerUser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void collectDataInto(TheReportModel theReportModel, GitHubFacade gitHubFa
4242
Integer count = ghResponse.getObject("/data/user/contributionsCollection/contributionCalendar/totalContributions");
4343
if (count == null) count = 0;
4444

45-
TheCellValue cellValue = new TheCellValue("" + count);
45+
TheCellValue cellValue = new TheCellValue("" + count, "" + count);
4646
String rowId = "row:" + login;
4747

4848
theColumn.addValue(rowId, cellValue);

src/main/java/com/github/exadmin/ostm/collectors/impl/teams/NumberOfCommitsPerWeekPerUser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void collectDataInto(TheReportModel theReportModel, GitHubFacade gitHubFa
116116
sbTooltip.append("&nbsp;&nbsp;").append(noDomain(me.getKey())).append(": ").append(me.getValue()).append("<br>");
117117
}
118118

119-
TheCellValue cellValue = new TheCellValue("" + totalCount);
119+
TheCellValue cellValue = new TheCellValue("" + totalCount, "" + totalCount);
120120
cellValue.setToolTipText(sbTooltip.toString());
121121
String rowId = "row:" + login;
122122

@@ -127,7 +127,7 @@ public void collectDataInto(TheReportModel theReportModel, GitHubFacade gitHubFa
127127

128128
for (String login : usersWithNoResponse) {
129129
for (TheColumn theColumn : columns) {
130-
TheCellValue cellValue = new TheCellValue("0");
130+
TheCellValue cellValue = new TheCellValue("No data", "0");
131131
String rowId = "row:" + login;
132132

133133
theColumn.addValue(rowId, cellValue);

src/main/java/com/github/exadmin/ostm/collectors/impl/teams/TeamKnownNames.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ public void collectDataInto(TheReportModel theReportModel, GitHubFacade gitHubFa
6969
for (String login : uniqueLogins) {
7070
String rowId = "row:" + login;
7171

72-
TheCellValue cvLogin = new TheCellValue(login);
72+
TheCellValue cvLogin = new TheCellValue(login, login);
7373
colLogin.addValue(rowId, cvLogin);
7474

7575
String realName = ALIAS_TO_NAME.get(login);
7676
if (realName == null) realName = "---";
77-
TheCellValue cvRealName = new TheCellValue(realName);
77+
TheCellValue cvRealName = new TheCellValue(realName, realName);
7878
colRealName.addValue(rowId, cvRealName);
7979
}
8080
}

src/main/java/com/github/exadmin/ostm/persistence/ReportModelPersister.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ public void saveToFile(Path outputFilePath) {
5151
if (theCellValue == null) {
5252
log.warn("No cell value is registered for sheet '{}', column '{}', rowId '{}'", sheet, theColumn, rowId);
5353
}
54-
String valueAsStr = theCellValue == null ? "null" : theCellValue.getValue();
55-
String toolTip = theCellValue == null ? null : theCellValue.getToolTipText();
5654

5755
Map<String, String> cellValueJson = new HashMap<>();
58-
cellValueJson.put("value", valueAsStr);
56+
57+
String visualValue = theCellValue == null ? "null" : theCellValue.getVisualValue();
58+
cellValueJson.put("value", visualValue);
59+
60+
String techValue = theCellValue == null ? "null" : theCellValue.getSortByValue();
61+
cellValueJson.put("sortByValue", techValue);
62+
63+
String toolTip = theCellValue == null ? null : theCellValue.getToolTipText();
5964
if (StringUtils.isNotEmpty(toolTip)) cellValueJson.put("title", toolTip);
6065

6166
dataMap.put(theColumn.getId(), cellValueJson);

src/main/java/com/github/exadmin/ostm/uimodel/TheCellValue.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
package com.github.exadmin.ostm.uimodel;
22

33
public class TheCellValue {
4-
private String value;
4+
private String visualValue;
5+
private String sortByValue;
56
private String toolTipText;
67

7-
public TheCellValue(String value) {
8-
this.value = value;
8+
/**
9+
* Create cell-value to be rendered in the report
10+
* @param visualValue visual value how it will look like
11+
* @param sortByValue hidden value how it will be interpreted by html rendering framework (for instance: sorting will be done by this values, not visual)
12+
*/
13+
public TheCellValue(String visualValue, String sortByValue) {
14+
this.visualValue = visualValue;
15+
this.sortByValue = sortByValue;
916
}
1017

11-
public String getValue() {
12-
return value;
18+
public String getVisualValue() {
19+
return visualValue;
1320
}
1421

15-
public void setValue(String value) {
16-
this.value = value;
22+
public void setVisualValue(String visualValue) {
23+
this.visualValue = visualValue;
24+
}
25+
26+
public String getSortByValue() {
27+
return sortByValue;
28+
}
29+
30+
public void setSortByValue(String sortByValue) {
31+
this.sortByValue = sortByValue;
1732
}
1833

1934
@Override
2035
public String toString() {
21-
return value;
36+
return visualValue;
2237
}
2338

2439
public String getToolTipText() {

0 commit comments

Comments
 (0)