Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Adding optional confirmation text to buttons #57
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Dec 26, 2016
1 parent 0957957 commit e643e48
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 78 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Changelog of Pull Request Notifier for Bitbucket.
* Adjusting textarea size in GUI.
* Supplying form as JSON to GUI, instead of escaped JSON string.

[c1c0dc0cc2b382b](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/c1c0dc0cc2b382b) Tomas Bjerre *2016-12-26 19:36:32*
[095795704b8e580](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/095795704b8e580) Tomas Bjerre *2016-12-26 20:13:35*

Adjustments after merge of

Expand All @@ -22,6 +22,11 @@ Changelog of Pull Request Notifier for Bitbucket.

[649638d30d2d32c](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/649638d30d2d32c) Tomas Bjerre *2016-12-25 21:46:25*

### GitHub [#57](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/57) Trigger button: confirmation dialog
Adding optional confirmation text to buttons

[b14d86ed8b986ea](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/b14d86ed8b986ea) Tomas Bjerre *2016-12-26 21:10:45*

### No issue
Add interactive forms to buttons

Expand Down
31 changes: 30 additions & 1 deletion src/main/java/se/bjurr/prnfb/presentation/dto/ButtonDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public class ButtonDTO implements Comparable<ButtonDTO> {
private String repositorySlug;
private USER_LEVEL userLevel;
private UUID uuid;
private String confirmationText;

public void setConfirmationText(String confirmationText) {
this.confirmationText = confirmationText;
}

public String getConfirmationText() {
return confirmationText;
}

@Override
public int compareTo(ButtonDTO o) {
Expand All @@ -60,9 +69,23 @@ public boolean equals(Object obj) {
} else if (!buttonFormList.equals(other.buttonFormList)) {
return false;
}
if (buttonFormListString == null) {
if (other.buttonFormListString != null) {
return false;
}
} else if (!buttonFormListString.equals(other.buttonFormListString)) {
return false;
}
if (confirmation != other.confirmation) {
return false;
}
if (confirmationText == null) {
if (other.confirmationText != null) {
return false;
}
} else if (!confirmationText.equals(other.confirmationText)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
Expand Down Expand Up @@ -134,7 +157,9 @@ public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (buttonFormList == null ? 0 : buttonFormList.hashCode());
result = prime * result + (buttonFormListString == null ? 0 : buttonFormListString.hashCode());
result = prime * result + (confirmation == null ? 0 : confirmation.hashCode());
result = prime * result + (confirmationText == null ? 0 : confirmationText.hashCode());
result = prime * result + (name == null ? 0 : name.hashCode());
result = prime * result + (projectKey == null ? 0 : projectKey.hashCode());
result = prime * result + (repositorySlug == null ? 0 : repositorySlug.hashCode());
Expand Down Expand Up @@ -181,8 +206,10 @@ public void setUuid(UUID uuid) {

@Override
public String toString() {
return "ButtonDTO [buttonFormDtoList="
return "ButtonDTO [buttonFormList="
+ buttonFormList
+ ", buttonFormListString="
+ buttonFormListString
+ ", confirmation="
+ confirmation
+ ", name="
Expand All @@ -195,6 +222,8 @@ public String toString() {
+ userLevel
+ ", uuid="
+ uuid
+ ", confirmationText="
+ confirmationText
+ "]";
}
}
33 changes: 20 additions & 13 deletions src/main/java/se/bjurr/prnfb/service/SettingsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.atlassian.bitbucket.pull.PullRequestState;
import com.atlassian.bitbucket.user.SecurityService;
import com.atlassian.bitbucket.util.Operation;
import com.atlassian.sal.api.pluginsettings.PluginSettings;
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
import com.atlassian.sal.api.transaction.TransactionCallback;
import com.atlassian.sal.api.transaction.TransactionTemplate;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.gson.Gson;

import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
import se.bjurr.prnfb.presentation.dto.ON_OR_OFF;
import se.bjurr.prnfb.settings.HasUuid;
Expand All @@ -33,18 +45,6 @@
import se.bjurr.prnfb.settings.legacy.Header;
import se.bjurr.prnfb.settings.legacy.SettingsStorage;

import com.atlassian.bitbucket.pull.PullRequestState;
import com.atlassian.bitbucket.user.SecurityService;
import com.atlassian.bitbucket.util.Operation;
import com.atlassian.sal.api.pluginsettings.PluginSettings;
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
import com.atlassian.sal.api.transaction.TransactionCallback;
import com.atlassian.sal.api.transaction.TransactionTemplate;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.gson.Gson;

public class SettingsService {

public static final String STORAGE_KEY = "se.bjurr.prnfb.pull-request-notifier-for-bitbucket-3";
Expand Down Expand Up @@ -346,7 +346,14 @@ private PrnfbSettings settingsFromLegacy(
}
newButtons.add(
new PrnfbButton(
UUID.randomUUID(), oldButton.getTitle(), userLevel, ON_OR_OFF.off, null, null, null));
UUID.randomUUID(),
oldButton.getTitle(),
userLevel,
ON_OR_OFF.off,
null,
null,
"confirmationText",
null));
}

List<PrnfbNotification> newNotifications = newArrayList();
Expand Down
75 changes: 46 additions & 29 deletions src/main/java/se/bjurr/prnfb/settings/PrnfbButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PrnfbButton implements HasUuid {
private final List<PrnfbButtonFormElement> buttonFormElementList;
private final USER_LEVEL userLevel;
private final UUID uuid;
private final String confirmationText;

public PrnfbButton(
UUID uuid,
Expand All @@ -30,17 +31,52 @@ public PrnfbButton(
ON_OR_OFF confirmation,
String projectKey,
String repositorySlug,
String confirmationText,
List<PrnfbButtonFormElement> buttonFormElementList) {
this.uuid = firstNonNull(uuid, randomUUID());
this.name = name;
this.userLevel = userLevel;
this.confirmation = confirmation;
this.repositorySlug = emptyToNull(repositorySlug);
this.projectKey = emptyToNull(projectKey);
this.confirmationText = emptyToNull(confirmationText);
this.buttonFormElementList =
firstNonNull(buttonFormElementList, new ArrayList<PrnfbButtonFormElement>());
}

public String getConfirmationText() {
return confirmationText;
}

public ON_OR_OFF getConfirmation() {
return this.confirmation;
}

public String getName() {
return this.name;
}

public List<PrnfbButtonFormElement> getButtonFormElementList() {
return buttonFormElementList;
}

public Optional<String> getProjectKey() {
return fromNullable(this.projectKey);
}

public Optional<String> getRepositorySlug() {
return fromNullable(this.repositorySlug);
}

public USER_LEVEL getUserLevel() {
return this.userLevel;
}

@Override
public UUID getUuid() {
return this.uuid;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand All @@ -63,6 +99,13 @@ public boolean equals(Object obj) {
if (confirmation != other.confirmation) {
return false;
}
if (confirmationText == null) {
if (other.confirmationText != null) {
return false;
}
} else if (!confirmationText.equals(other.confirmationText)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
Expand Down Expand Up @@ -97,42 +140,14 @@ public boolean equals(Object obj) {
return true;
}

public ON_OR_OFF getConfirmation() {
return this.confirmation;
}

public String getName() {
return this.name;
}

public List<PrnfbButtonFormElement> getButtonFormElementList() {
return buttonFormElementList;
}

public Optional<String> getProjectKey() {
return fromNullable(this.projectKey);
}

public Optional<String> getRepositorySlug() {
return fromNullable(this.repositorySlug);
}

public USER_LEVEL getUserLevel() {
return this.userLevel;
}

@Override
public UUID getUuid() {
return this.uuid;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result =
prime * result + (buttonFormElementList == null ? 0 : buttonFormElementList.hashCode());
result = prime * result + (confirmation == null ? 0 : confirmation.hashCode());
result = prime * result + (confirmationText == null ? 0 : confirmationText.hashCode());
result = prime * result + (name == null ? 0 : name.hashCode());
result = prime * result + (projectKey == null ? 0 : projectKey.hashCode());
result = prime * result + (repositorySlug == null ? 0 : repositorySlug.hashCode());
Expand All @@ -157,6 +172,8 @@ public String toString() {
+ userLevel
+ ", uuid="
+ uuid
+ ", confirmationText="
+ confirmationText
+ "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static ButtonDTO toButtonDto(PrnfbButton from) {
to.setProjectKey(from.getProjectKey().orNull());
to.setRepositorySlug(from.getRepositorySlug().orNull());
to.setConfirmation(from.getConfirmation());
to.setConfirmationText(from.getConfirmationText());
to.setButtonFormList(toButtonFormDtoList(from.getButtonFormElementList()));
String buttonFormDtoListString = gson.toJson(to.getButtonFormList());
to.setButtonFormListString(buttonFormDtoListString);
Expand Down Expand Up @@ -106,6 +107,7 @@ public static PrnfbButton toPrnfbButton(ButtonDTO buttonDto) {
buttonDto.getConfirmation(), //
buttonDto.getProjectKey().orNull(), //
buttonDto.getRepositorySlug().orNull(), //
buttonDto.getConfirmationText(), //
buttonFormElement); //
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/admin.vm
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@
<div class="description">Whether to show a confirmation dialog.</div>
</div>

<div class="field-group">
<label>Confirmation message </label>
<input class="text long-field" type="text" name="confirmationText">
<div class="description">If not empty, a confirmation dialog will be shown with this message, before any notification is triggered.</div>
</div>

<div class="field-group">
<label>Button Form</label>
<textarea class="textarea" rows="6" name="buttonFormListString"></textarea>
Expand Down
16 changes: 13 additions & 3 deletions src/main/resources/pr-triggerbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,18 @@ define('plugin/prnfb/pr-triggerbutton', [
return $("<fieldset class='group'/>").append(radioItems);
};

var confirmationTextTemplate = function(confirmationText) {
if (!confirmationText) {
return '';
}

var confirmationDiv = '<div class="description">' + confirmationText + '</div>';
return confirmationDiv;
};

var formTemplate = function(formDescription) {
if (!formDescription || formDescription.length === 0) {
return null;
return '';
}

var formItems = [];
Expand Down Expand Up @@ -244,10 +253,11 @@ define('plugin/prnfb/pr-triggerbutton', [
});
};

if (item.buttonFormList && item.buttonFormList.length > 0) {
if (item.confirmationText || item.buttonFormList && item.buttonFormList.length > 0) {
// Create the form and dialog
var confirmationText = confirmationTextTemplate(item.confirmationText);
var form = formTemplate(item.buttonFormList);
var formHtml = $("<div/>").append(form).html();
var formHtml = $("<div/>").append(confirmationText).append(form).html();
var $dialog = $(dialogTemplate(item.name, formHtml));
$dialog.appendTo($("body"));

Expand Down
Loading

0 comments on commit e643e48

Please sign in to comment.