Skip to content
Permalink
Browse files
[JENKINS-31162] Renamed weight instead of order. Client-side ordering…
… was removed, no needed
  • Loading branch information
recena committed Mar 23, 2016
1 parent b61bfc0 commit 152a9f8fe14220f1f1c6096ca99fab6b5e8b6998
Showing 4 changed files with 18 additions and 32 deletions.
@@ -1013,14 +1013,14 @@ public synchronized void doDoDelete(StaplerRequest req, StaplerResponse rsp) thr
@Restricted(DoNotUse.class)
public Categories doCategories(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
Categories categories = new Categories();
int weight = 0;
int order = 0;
for (TopLevelItemDescriptor descriptor : DescriptorVisibilityFilter.apply(getOwnerItemGroup(), Items.all(Jenkins.getAuthentication(), getOwnerItemGroup()))) {
ItemCategory ic = ItemCategory.getCategory(descriptor);
Map<String, Serializable> metadata = new HashMap<String, Serializable>();

// Information about Item.
metadata.put("class", descriptor.getId());
metadata.put("weight", ++weight);
metadata.put("order", ++order);
metadata.put("displayName", descriptor.getDisplayName());
metadata.put("description", descriptor.getDescription());
metadata.put("iconFilePathPattern", descriptor.getIconFilePathPattern());
@@ -1031,7 +1031,7 @@ public Categories doCategories(StaplerRequest req, StaplerResponse rsp) throws I
} else {
List<Map<String, Serializable>> temp = new ArrayList<Map<String, Serializable>>();
temp.add(metadata);
category = new Category(ic.getId(), ic.getDisplayName(), ic.getDescription(), ic.getWeight() , ic.getMinToShow(), temp);
category = new Category(ic.getId(), ic.getDisplayName(), ic.getDescription(), ic.getOrder(), ic.getMinToShow(), temp);
categories.getItems().add(category);
}
}
@@ -25,17 +25,17 @@ public class Category implements Serializable {

private String description;

private int weight;
private int order;

private int minToShow;

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

public Category(String id, String name, String description, int weight, int minToShow, List<Map<String, Serializable>> items) {
public Category(String id, String name, String description, int order, int minToShow, List<Map<String, Serializable>> items) {
this.id= id;
this.name = name;
this.description = description;
this.weight = weight;
this.order = order;
this.minToShow = minToShow;
this.items = items;
}
@@ -56,8 +56,8 @@ public String getDescription() {
}

@Exported
public int getWeight() {
return weight;
public int getOrder() {
return order;
}

@Exported
@@ -20,7 +20,7 @@ public abstract class ItemCategory implements ExtensionPoint {
/**
* Helpful to set the order.
*/
private int weight = 1;
private int order = 1;

/**
* Identifier, e.g. "standaloneprojects", etc.
@@ -50,12 +50,12 @@ public abstract class ItemCategory implements ExtensionPoint {
*/
public abstract int getMinToShow();

private void setWeight(int weight) {
this.weight = weight;
private void setOrder(int order) {
this.order = order;
}

public int getWeight() {
return weight;
public int getOrder() {
return order;
}

/**
@@ -65,14 +65,14 @@ public int getWeight() {
*/
@Nonnull
public static ItemCategory getCategory(TopLevelItemDescriptor descriptor) {
int weight = 0;
int order = 0;
ExtensionList<ItemCategory> categories = ExtensionList.lookup(ItemCategory.class);
for (ItemCategory category : categories) {
if (category.getId().equals(descriptor.getCategoryId())) {
category.setWeight(categories.size() - weight);
category.setOrder(++order);
return category;
}
weight++;
order++;
}
return new UncategorizedCategory();
}
@@ -180,12 +180,6 @@ $.when(getItems()).done(function(data){
var newDesc = desc.replace(/\&lt;/g,'<').replace(/\&gt;/g,'>');
return newDesc;
}
function sortItemsByOrder(itemTypes) {
function sortByOrder(a, b) {
return b.weight - a.weight;
}
return itemTypes.sort(sortByOrder);
}

function checkCatCount(elem){
var minToShow = (typeof elem.minToShow === 'number')? elem.minToShow : defaultMinToShow;
@@ -385,18 +379,10 @@ $.when(getItems()).done(function(data){
return $icn;
}

// Sort the categories.
var sortedDCategories = sortItemsByOrder(data.categories);
var sortedDCategoriesWithCopy = addCopyOption(sortedDCategories);

// Sort the items in each category.
for (var i = 0; i < data.categories.length; i++) {
var category = data.categories[i];
category.items = sortItemsByOrder(category.items);
}
var categoriesWithCopy = addCopyOption(data.categories);

makeButtonWrapper();
drawTabs(sortedDCategoriesWithCopy);
drawTabs(categoriesWithCopy);

});
});

0 comments on commit 152a9f8

Please sign in to comment.