Skip to content

Commit

Permalink
[JENKINS-31162] @gusreiber's comments were addresed
Browse files Browse the repository at this point in the history
  • Loading branch information
recena committed Mar 13, 2016
1 parent e0946ee commit 25f9c99
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/ItemGroupMixIn.java
Expand Up @@ -350,6 +350,7 @@ public static Categories getCategories(Authentication a, ItemGroup c) {
metadata.put("class", descriptor.clazz.getName());
metadata.put("iconClassName", "item-icon-" + descriptor.clazz.getName().substring(descriptor.clazz.getName().lastIndexOf(".") + 1).toLowerCase());
metadata.put("weight", ItemCategoryConfigurator.getWeight(descriptor));
metadata.put("name", descriptor.getDisplayName());

Category category = categories.getItem(ic.getId());
if (category != null) {
Expand All @@ -358,7 +359,7 @@ public static Categories getCategories(Authentication a, ItemGroup c) {
List<Map<String, Object>> temp = new ArrayList<Map<String, Object>>();
temp.add(metadata);
category = new Category(ic.getId(), ic.getDisplayName(), ic.getDescription(), ic.getIconClassName(),
ic.getWeight(), temp);
ic.getWeight(), ic.getMinToShow(), temp);
categories.getItems().add(category);
}
}
Expand Down
11 changes: 10 additions & 1 deletion core/src/main/java/jenkins/model/item_category/Category.java
Expand Up @@ -24,14 +24,18 @@ public class Category implements Serializable {

private int weight;

private int minToShow;

private List<Map<String, Object>> items;

public Category(String id, String name, String description, String iconClassName, int weight, List<Map<String, Object>> items) {
public Category(String id, String name, String description, String iconClassName, int weight, int minToShow,
List<Map<String, Object>> items) {
this.id= id;
this.name = name;
this.description = description;
this.iconClassName = iconClassName;
this.weight = weight;
this.minToShow = minToShow;
this.items = items;
}

Expand Down Expand Up @@ -60,6 +64,11 @@ public int getWeight() {
return weight;
}

@Exported
public int getMinToShow() {
return minToShow;
}

@Exported
public List<Map<String, Object>> getItems() {
return items;
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/jenkins/model/item_category/ItemCategory.java
Expand Up @@ -10,6 +10,10 @@
*/
public abstract class ItemCategory implements ModelObject, ExtensionPoint {

public static int MIN_WEIGHT = Integer.MIN_VALUE;

public static int MIN_TOSHOW = 1;

/**
* Identifier, e.g. "category-id-default", etc.
*
Expand Down Expand Up @@ -38,6 +42,13 @@ public abstract class ItemCategory implements ModelObject, ExtensionPoint {
*/
public abstract int getWeight();

/**
* Minimum number required to show the category.
*
* @return the minimum items required
*/
public abstract int getMinToShow();

/**
* The default category, if an item doesn't belong anywhere else, this is where it goes by default.
*/
Expand Down Expand Up @@ -69,6 +80,11 @@ public int getWeight() {
return Integer.MIN_VALUE;
}

@Override
public int getMinToShow() {
return 1;
}

}

}
Expand Up @@ -40,7 +40,7 @@ public static ItemCategory getCategory(@Nonnull TopLevelItemDescriptor descripto
return category;
}
}
throw new IllegalStateException();
throw new IllegalStateException("At least, must exist the category: " + ItemCategory.Default.class);
}

/**
Expand Down Expand Up @@ -69,7 +69,7 @@ public static Integer getWeight(@Nonnull TopLevelItemDescriptor descriptor) {
return weight;
}
}
throw new IllegalStateException();
throw new IllegalStateException("At least, must exist the category: " + ItemCategory.Default.class);
}

public static Collection<ItemCategoryConfigurator> all() {
Expand Down

0 comments on commit 25f9c99

Please sign in to comment.