Skip to content

Commit

Permalink
SAK-41132: GBNG > make category colour selection deterministic on cat…
Browse files Browse the repository at this point in the history
…egory name rather than ID (sakaiproject#6427)
  • Loading branch information
bjones86 authored Dec 21, 2018
1 parent b338043 commit 7b10e2d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ private List<ColumnDefinition> loadColumns(final List<Assignment> assignments) {

nullable(a1.getCategoryId()),
a1.getCategoryName(),
userSettings.getCategoryColor(a1.getCategoryName(), a1.getCategoryId()),
userSettings.getCategoryColor(a1.getCategoryName()),
nullable(categoryWeight),
a1.isCategoryExtraCredit(),

Expand All @@ -549,7 +549,7 @@ private List<ColumnDefinition> loadColumns(final List<Assignment> assignments) {
nullable(categoryWeight),
getCategoryPoints(a1.getCategoryId()),
a1.isCategoryExtraCredit(),
userSettings.getCategoryColor(a1.getCategoryName(), a1.getCategoryId()),
userSettings.getCategoryColor(a1.getCategoryName()),
!this.uiSettings.isCategoryScoreVisible(a1.getCategoryName()),
FormatHelper.formatCategoryDropInfo(this.categories.stream()
.filter(c -> c.getId().equals(a1.getCategoryId()))
Expand All @@ -574,7 +574,7 @@ private List<ColumnDefinition> loadColumns(final List<Assignment> assignments) {
nullable(categoryWeight),
category.getTotalPoints(),
category.getExtraCredit(),
userSettings.getCategoryColor(category.getName(), category.getId()),
userSettings.getCategoryColor(category.getName()),
!this.uiSettings.isCategoryScoreVisible(category.getName()),
FormatHelper.formatCategoryDropInfo(category)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ public void setCategoryColor(final String categoryName, final String rgbColorStr
this.categoryColors.put(categoryName, rgbColorString);
}

public String getCategoryColor(final String categoryName, final Long categoryID) {
public String getCategoryColor(final String categoryName) {
if (!this.categoryColors.containsKey(categoryName)) {
setCategoryColor(categoryName, generateRandomRGBColorString(categoryID));
setCategoryColor(categoryName, generateRandomRGBColorString(categoryName));
}
return this.categoryColors.get(categoryName);
}

public void initializeCategoryColors(final List<CategoryDefinition> categories) {
for (CategoryDefinition category : categories) {
setCategoryColor(category.getName(), generateRandomRGBColorString(category.getId()));
setCategoryColor(category.getName(), generateRandomRGBColorString(category.getName()));
}
}

Expand All @@ -178,11 +178,11 @@ public void setGroupedByCategory(final boolean groupedByCategory) {
/**
* Helper to generate a RGB CSS color string with values between 180-250 to ensure a lighter color e.g. rgb(181,222,199)
*/
public static String generateRandomRGBColorString(Long categoryID) {
if (categoryID == null) {
categoryID = -1L;
public static String generateRandomRGBColorString(String categoryName) {
if (categoryName == null) {
categoryName = "";
}
final Random rand = new Random(categoryID);
final Random rand = new Random(categoryName.hashCode());
final int min = 180;
final int max = 250;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void populateItem(final ListItem<CategoryDefinition> categoryItem) {
Collections.sort(assignments, new CategorizedAssignmentComparator());

categoryItem.add(new AttributeModifier("style",
String.format("border-left-color: %s", settings.getCategoryColor(category.getName(), category.getId()))));
String.format("border-left-color: %s", settings.getCategoryColor(category.getName()))));
categoryItem.add(new Label("name", category.getName()));
categoryItem.add(new ListView<Assignment>("gradeItemList", assignments) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public void onInitialize() {
@Override
protected void populateItem(final ListItem<String> categoryItem) {
final String categoryName = categoryItem.getModelObject();
final Long categoryID = categoryNameToIdMap.get(categoryName);
final String categoryColor = settings.getCategoryColor(categoryName, categoryID);
final String categoryColor = settings.getCategoryColor(categoryName);

WebMarkupContainer categoryFilter = new WebMarkupContainer("categoryFilter");
if (!categoriesEnabled) {
Expand Down

0 comments on commit 7b10e2d

Please sign in to comment.