Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-39580 Allow the user to configure a preferred provider (#5)
- Loading branch information
James William Dumay
committed
Dec 9, 2016
1 parent
ffadcca
commit 4f280c2
Showing
9 changed files
with
156 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/org/jenkinsci/plugins/displayurlapi/user/PreferredProviderUserProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.jenkinsci.plugins.displayurlapi.user; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Iterables; | ||
import com.google.common.collect.Lists; | ||
import hudson.Extension; | ||
import hudson.model.UserProperty; | ||
import hudson.model.UserPropertyDescriptor; | ||
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
public class PreferredProviderUserProperty extends UserProperty { | ||
|
||
@Extension | ||
public static final UserPropertyDescriptor DESCRIPTOR = new PreferredProviderUserPropertyDescriptor(); | ||
|
||
@Nullable | ||
private String providerId; | ||
|
||
@DataBoundConstructor | ||
public PreferredProviderUserProperty(@Nullable String providerId) { | ||
this.providerId = providerId; | ||
} | ||
|
||
public ProviderOption getProvider() { | ||
final DisplayURLProvider provider = getConfiguredProvider(); | ||
return provider == null ? ProviderOption.DEFAULT_OPTION : new ProviderOption(provider.getClass().getName(), provider.getDisplayName()); | ||
} | ||
|
||
public DisplayURLProvider getConfiguredProvider() { | ||
return Iterables.find(DisplayURLProvider.all(), new Predicate<DisplayURLProvider>() { | ||
@Override | ||
public boolean apply(DisplayURLProvider input) { | ||
return input.getClass().getName().equals(providerId); | ||
} | ||
}, null); | ||
} | ||
|
||
public List<ProviderOption> getAll() { | ||
Iterable<ProviderOption> options = Iterables.transform(DisplayURLProvider.all(), new Function<DisplayURLProvider, ProviderOption>() { | ||
@Override | ||
public ProviderOption apply(DisplayURLProvider input) { | ||
return new ProviderOption(input.getClass().getName(), input.getDisplayName()); | ||
} | ||
}); | ||
return ImmutableList.copyOf(Iterables.concat(Lists.newArrayList(ProviderOption.DEFAULT_OPTION), options)); | ||
} | ||
|
||
public boolean isSelected(String providerId) { | ||
return getProvider().getId().equals(providerId); | ||
} | ||
|
||
public static class ProviderOption { | ||
|
||
public static final ProviderOption DEFAULT_OPTION = new ProviderOption("default", "Default"); | ||
|
||
private final String id; | ||
private final String name; | ||
|
||
public ProviderOption(String id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ava/org/jenkinsci/plugins/displayurlapi/user/PreferredProviderUserPropertyDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.jenkinsci.plugins.displayurlapi.user; | ||
|
||
import hudson.model.User; | ||
import hudson.model.UserProperty; | ||
import hudson.model.UserPropertyDescriptor; | ||
import org.jenkinsci.plugins.displayurlapi.Messages; | ||
import org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty.ProviderOption; | ||
|
||
public class PreferredProviderUserPropertyDescriptor extends UserPropertyDescriptor { | ||
|
||
public PreferredProviderUserPropertyDescriptor() { | ||
super(PreferredProviderUserProperty.class); | ||
} | ||
|
||
@Override | ||
public UserProperty newInstance(User user) { | ||
return new PreferredProviderUserProperty(ProviderOption.DEFAULT_OPTION.getId()); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.display_url(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/resources/org/jenkinsci/plugins/displayurlapi/Messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
display.url = Notification URL | ||
classic.name = Jenkins Classic |
20 changes: 20 additions & 0 deletions
20
...urces/org/jenkinsci/plugins/displayurlapi/user/PreferredProviderUserProperty/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" | ||
xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
<f:block> | ||
<f:entry name="providerId" field="providerId"> | ||
<select name="providerId"> | ||
<j:forEach var="provider" items="${instance.all}"> | ||
<j:choose> | ||
<j:when test="${instance.isSelected(provider.getId())}"> | ||
<option value="${provider.getId()}" selected="true">${provider.getName()}</option> | ||
</j:when> | ||
<j:otherwise> | ||
<option value="${provider.getId()}">${provider.getName()}</option> | ||
</j:otherwise> | ||
</j:choose> | ||
</j:forEach> | ||
</select> | ||
</f:entry> | ||
</f:block> | ||
</j:jelly> |
1 change: 1 addition & 0 deletions
1
...g/jenkinsci/plugins/displayurlapi/user/PreferredProviderUserProperty/help-providerId.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allows the user to select their preferred user interface when clicking links to Jenkins from notifications (e.g. Email, Slack or Github) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters