Skip to content

Commit

Permalink
Store table order and paging size a user select (#415)
Browse files Browse the repository at this point in the history
Store table order and paging size a user select
  • Loading branch information
mPokornyETM committed Dec 20, 2022
1 parent cbeb0a0 commit de5663d
Show file tree
Hide file tree
Showing 224 changed files with 1,348 additions and 6,553 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -58,7 +57,7 @@ public class LockableResource extends AbstractDescribableImpl<LockableResource>

private final String name;
private String description = "";
private String labels = "";
private List<String> labels = new ArrayList<>();
private String reservedBy = null;
private Date reservedTimestamp = null;
private String note = "";
Expand Down Expand Up @@ -106,16 +105,20 @@ public class LockableResource extends AbstractDescribableImpl<LockableResource>
@Deprecated
@ExcludeFromJacocoGeneratedReport
public LockableResource(String name, String description, String labels, String reservedBy, String note) {
// todo throw exception, when the name is empty
// todo check if the name contains only valid characters (no spaces, new lines ...)
this.name = name;
this.description = description;
this.labels = labels;
this.reservedBy = Util.fixEmptyAndTrim(reservedBy);
this.note = note;
this.setDescription(description);
this.setLabels(labels);
this.setReservedBy(reservedBy);
this.setNote(note);
}

@DataBoundConstructor
public LockableResource(String name) {
this.name = name;
this.name = Util.fixNull(name);
// todo throw exception, when the name is empty
// todo check if the name contains only valid characters (no spaces, new lines ...)
}

protected Object readResolve() {
Expand All @@ -132,29 +135,56 @@ public List<StepContext> getQueuedContexts() {
return this.queuedContexts;
}

@Exported
public String getName() {
return name;
}

@Exported
public String getDescription() {
return description;
}

@DataBoundSetter
public void setDescription(String description) {
this.description = description;
this.description = Util.fixNull(description);
}

@Exported
public String getNote() {
return this.note;
}

@DataBoundSetter
public void setLabels(String labels) {
this.labels = labels;
public void setNote(String note) {
this.note = Util.fixNull(note);
}

@Exported
public String getName() {
return name;
@DataBoundSetter
public void setEphemeral(boolean ephemeral) {
this.ephemeral = ephemeral;
}

@Exported
public String getDescription() {
return description;
public boolean isEphemeral() {
return ephemeral;
}

@Exported
public String getLabels() {
return labels;
return String.join(" ", this.labels);
}

@DataBoundSetter
public void setLabels(String labels) {
// todo use label parser from Jenkins.Label to allow the same syntax
this.labels = new ArrayList<>();
for(String label : labels.split("\\s+")) {
if (label == null || label.isEmpty()) {
continue;
}
this.labels.add(label);
}
}

/**
Expand All @@ -163,7 +193,7 @@ public String getLabels() {
*/
@Exported
public List<String> getLabelsAsList() {
return Arrays.asList(labels.split("\\s+"));
return this.labels;
}

/**
Expand All @@ -176,26 +206,6 @@ public boolean hasLabel(String labelToFind) {
return this.labelsContain(labelToFind);
}

@Exported
public String getNote() {
return this.note;
}

@DataBoundSetter
public void setNote(String note) {
this.note = note;
}

@DataBoundSetter
public void setEphemeral(boolean ephemeral) {
this.ephemeral = ephemeral;
}

@Exported
public boolean isEphemeral() {
return ephemeral;
}

public boolean isValidLabel(String candidate, Map<String, Object> params) {
return labelsContain(candidate);
}
Expand Down Expand Up @@ -268,6 +278,25 @@ public boolean isReserved() {
return reservedBy != null;
}

@Restricted(NoExternalUse.class)
public static String getUserName() {
User current = User.current();
if (current != null) {
return current.getFullName();
} else {
return null;
}
}

/**
* Function check if the resources is reserved by currently logged user
* @return true when reserved by current user, false otherwise.
*/
@Restricted(NoExternalUse.class) // called by jelly
public boolean isReservedByCurrentUser() {
return (this.reservedBy != null && getUserName().equals(this.reservedBy));
}

@Exported
public String getReservedByEmail() {
if (isReserved()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import hudson.Extension;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.Util;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -147,7 +147,11 @@ public Boolean isValidLabel(String label) {
public Set<String> getAllLabels() {
Set<String> labels = new HashSet<>();
for (LockableResource r : this.resources) {
labels.addAll(r.getLabelsAsList());
List<String> toAdd = r.getLabelsAsList();
if (toAdd.isEmpty()) {
continue;
}
labels.addAll(toAdd);
}
return labels;
}
Expand Down Expand Up @@ -672,6 +676,7 @@ private QueuedContextStruct getNextQueuedContext(

/** Creates the resource if it does not exist. */
public synchronized boolean createResource(String name) {
name = Util.fixEmptyAndTrim(name);
if (name != null) {
LockableResource existent = fromName(name);
if (existent == null) {
Expand All @@ -686,6 +691,7 @@ public synchronized boolean createResource(String name) {
}

public synchronized boolean createResourceWithLabel(String name, String label) {
name = Util.fixEmptyAndTrim(name);
if (name != null && label != null) {
LockableResource existent = fromName(name);
if (existent == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import hudson.Extension;
import hudson.model.Api;
import hudson.model.RootAction;
import hudson.model.User;
import hudson.security.AccessDeniedException3;
import hudson.security.Permission;
import hudson.security.PermissionGroup;
Expand Down Expand Up @@ -81,12 +80,7 @@ public Api getApi() {
}

public String getUserName() {
User current = User.current();
if (current != null) {
return current.getFullName();
} else {
return null;
}
return LockableResource.getUserName();
}

@Override
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit de5663d

Please sign in to comment.