Skip to content

Commit

Permalink
[JENKINS-31162] Renamed weight instead of order. Client-side ordering…
Browse files Browse the repository at this point in the history
… was removed, no needed
  • Loading branch information
recena committed Mar 23, 2016
1 parent b61bfc0 commit 152a9f8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 32 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/hudson/model/View.java
Expand Up @@ -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());
Expand All @@ -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);
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/jenkins/model/item_category/Category.java
Expand Up @@ -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;
}
Expand All @@ -56,8 +56,8 @@ public String getDescription() {
}

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

@Exported
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/jenkins/model/item_category/ItemCategory.java
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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();
}
Expand Down
18 changes: 2 additions & 16 deletions war/src/main/js/add-item.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

});
});
Expand Down

0 comments on commit 152a9f8

Please sign in to comment.