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

Commit e643e48

Browse files
committed
Adding optional confirmation text to buttons #57
1 parent 0957957 commit e643e48

File tree

12 files changed

+193
-78
lines changed

12 files changed

+193
-78
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Changelog of Pull Request Notifier for Bitbucket.
1212
* Adjusting textarea size in GUI.
1313
* Supplying form as JSON to GUI, instead of escaped JSON string.
1414

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

1717
Adjustments after merge of
1818

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

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

25+
### GitHub [#57](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/57) Trigger button: confirmation dialog
26+
Adding optional confirmation text to buttons
27+
28+
[b14d86ed8b986ea](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/b14d86ed8b986ea) Tomas Bjerre *2016-12-26 21:10:45*
29+
2530
### No issue
2631
Add interactive forms to buttons
2732

src/main/java/se/bjurr/prnfb/presentation/dto/ButtonDTO.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public class ButtonDTO implements Comparable<ButtonDTO> {
3535
private String repositorySlug;
3636
private USER_LEVEL userLevel;
3737
private UUID uuid;
38+
private String confirmationText;
39+
40+
public void setConfirmationText(String confirmationText) {
41+
this.confirmationText = confirmationText;
42+
}
43+
44+
public String getConfirmationText() {
45+
return confirmationText;
46+
}
3847

3948
@Override
4049
public int compareTo(ButtonDTO o) {
@@ -60,9 +69,23 @@ public boolean equals(Object obj) {
6069
} else if (!buttonFormList.equals(other.buttonFormList)) {
6170
return false;
6271
}
72+
if (buttonFormListString == null) {
73+
if (other.buttonFormListString != null) {
74+
return false;
75+
}
76+
} else if (!buttonFormListString.equals(other.buttonFormListString)) {
77+
return false;
78+
}
6379
if (confirmation != other.confirmation) {
6480
return false;
6581
}
82+
if (confirmationText == null) {
83+
if (other.confirmationText != null) {
84+
return false;
85+
}
86+
} else if (!confirmationText.equals(other.confirmationText)) {
87+
return false;
88+
}
6689
if (name == null) {
6790
if (other.name != null) {
6891
return false;
@@ -134,7 +157,9 @@ public int hashCode() {
134157
final int prime = 31;
135158
int result = 1;
136159
result = prime * result + (buttonFormList == null ? 0 : buttonFormList.hashCode());
160+
result = prime * result + (buttonFormListString == null ? 0 : buttonFormListString.hashCode());
137161
result = prime * result + (confirmation == null ? 0 : confirmation.hashCode());
162+
result = prime * result + (confirmationText == null ? 0 : confirmationText.hashCode());
138163
result = prime * result + (name == null ? 0 : name.hashCode());
139164
result = prime * result + (projectKey == null ? 0 : projectKey.hashCode());
140165
result = prime * result + (repositorySlug == null ? 0 : repositorySlug.hashCode());
@@ -181,8 +206,10 @@ public void setUuid(UUID uuid) {
181206

182207
@Override
183208
public String toString() {
184-
return "ButtonDTO [buttonFormDtoList="
209+
return "ButtonDTO [buttonFormList="
185210
+ buttonFormList
211+
+ ", buttonFormListString="
212+
+ buttonFormListString
186213
+ ", confirmation="
187214
+ confirmation
188215
+ ", name="
@@ -195,6 +222,8 @@ public String toString() {
195222
+ userLevel
196223
+ ", uuid="
197224
+ uuid
225+
+ ", confirmationText="
226+
+ confirmationText
198227
+ "]";
199228
}
200229
}

src/main/java/se/bjurr/prnfb/service/SettingsService.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

21+
import com.atlassian.bitbucket.pull.PullRequestState;
22+
import com.atlassian.bitbucket.user.SecurityService;
23+
import com.atlassian.bitbucket.util.Operation;
24+
import com.atlassian.sal.api.pluginsettings.PluginSettings;
25+
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
26+
import com.atlassian.sal.api.transaction.TransactionCallback;
27+
import com.atlassian.sal.api.transaction.TransactionTemplate;
28+
import com.google.common.annotations.VisibleForTesting;
29+
import com.google.common.base.Optional;
30+
import com.google.common.base.Predicate;
31+
import com.google.gson.Gson;
32+
2133
import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
2234
import se.bjurr.prnfb.presentation.dto.ON_OR_OFF;
2335
import se.bjurr.prnfb.settings.HasUuid;
@@ -33,18 +45,6 @@
3345
import se.bjurr.prnfb.settings.legacy.Header;
3446
import se.bjurr.prnfb.settings.legacy.SettingsStorage;
3547

36-
import com.atlassian.bitbucket.pull.PullRequestState;
37-
import com.atlassian.bitbucket.user.SecurityService;
38-
import com.atlassian.bitbucket.util.Operation;
39-
import com.atlassian.sal.api.pluginsettings.PluginSettings;
40-
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
41-
import com.atlassian.sal.api.transaction.TransactionCallback;
42-
import com.atlassian.sal.api.transaction.TransactionTemplate;
43-
import com.google.common.annotations.VisibleForTesting;
44-
import com.google.common.base.Optional;
45-
import com.google.common.base.Predicate;
46-
import com.google.gson.Gson;
47-
4848
public class SettingsService {
4949

5050
public static final String STORAGE_KEY = "se.bjurr.prnfb.pull-request-notifier-for-bitbucket-3";
@@ -346,7 +346,14 @@ private PrnfbSettings settingsFromLegacy(
346346
}
347347
newButtons.add(
348348
new PrnfbButton(
349-
UUID.randomUUID(), oldButton.getTitle(), userLevel, ON_OR_OFF.off, null, null, null));
349+
UUID.randomUUID(),
350+
oldButton.getTitle(),
351+
userLevel,
352+
ON_OR_OFF.off,
353+
null,
354+
null,
355+
"confirmationText",
356+
null));
350357
}
351358

352359
List<PrnfbNotification> newNotifications = newArrayList();

src/main/java/se/bjurr/prnfb/settings/PrnfbButton.java

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class PrnfbButton implements HasUuid {
2222
private final List<PrnfbButtonFormElement> buttonFormElementList;
2323
private final USER_LEVEL userLevel;
2424
private final UUID uuid;
25+
private final String confirmationText;
2526

2627
public PrnfbButton(
2728
UUID uuid,
@@ -30,17 +31,52 @@ public PrnfbButton(
3031
ON_OR_OFF confirmation,
3132
String projectKey,
3233
String repositorySlug,
34+
String confirmationText,
3335
List<PrnfbButtonFormElement> buttonFormElementList) {
3436
this.uuid = firstNonNull(uuid, randomUUID());
3537
this.name = name;
3638
this.userLevel = userLevel;
3739
this.confirmation = confirmation;
3840
this.repositorySlug = emptyToNull(repositorySlug);
3941
this.projectKey = emptyToNull(projectKey);
42+
this.confirmationText = emptyToNull(confirmationText);
4043
this.buttonFormElementList =
4144
firstNonNull(buttonFormElementList, new ArrayList<PrnfbButtonFormElement>());
4245
}
4346

47+
public String getConfirmationText() {
48+
return confirmationText;
49+
}
50+
51+
public ON_OR_OFF getConfirmation() {
52+
return this.confirmation;
53+
}
54+
55+
public String getName() {
56+
return this.name;
57+
}
58+
59+
public List<PrnfbButtonFormElement> getButtonFormElementList() {
60+
return buttonFormElementList;
61+
}
62+
63+
public Optional<String> getProjectKey() {
64+
return fromNullable(this.projectKey);
65+
}
66+
67+
public Optional<String> getRepositorySlug() {
68+
return fromNullable(this.repositorySlug);
69+
}
70+
71+
public USER_LEVEL getUserLevel() {
72+
return this.userLevel;
73+
}
74+
75+
@Override
76+
public UUID getUuid() {
77+
return this.uuid;
78+
}
79+
4480
@Override
4581
public boolean equals(Object obj) {
4682
if (this == obj) {
@@ -63,6 +99,13 @@ public boolean equals(Object obj) {
6399
if (confirmation != other.confirmation) {
64100
return false;
65101
}
102+
if (confirmationText == null) {
103+
if (other.confirmationText != null) {
104+
return false;
105+
}
106+
} else if (!confirmationText.equals(other.confirmationText)) {
107+
return false;
108+
}
66109
if (name == null) {
67110
if (other.name != null) {
68111
return false;
@@ -97,42 +140,14 @@ public boolean equals(Object obj) {
97140
return true;
98141
}
99142

100-
public ON_OR_OFF getConfirmation() {
101-
return this.confirmation;
102-
}
103-
104-
public String getName() {
105-
return this.name;
106-
}
107-
108-
public List<PrnfbButtonFormElement> getButtonFormElementList() {
109-
return buttonFormElementList;
110-
}
111-
112-
public Optional<String> getProjectKey() {
113-
return fromNullable(this.projectKey);
114-
}
115-
116-
public Optional<String> getRepositorySlug() {
117-
return fromNullable(this.repositorySlug);
118-
}
119-
120-
public USER_LEVEL getUserLevel() {
121-
return this.userLevel;
122-
}
123-
124-
@Override
125-
public UUID getUuid() {
126-
return this.uuid;
127-
}
128-
129143
@Override
130144
public int hashCode() {
131145
final int prime = 31;
132146
int result = 1;
133147
result =
134148
prime * result + (buttonFormElementList == null ? 0 : buttonFormElementList.hashCode());
135149
result = prime * result + (confirmation == null ? 0 : confirmation.hashCode());
150+
result = prime * result + (confirmationText == null ? 0 : confirmationText.hashCode());
136151
result = prime * result + (name == null ? 0 : name.hashCode());
137152
result = prime * result + (projectKey == null ? 0 : projectKey.hashCode());
138153
result = prime * result + (repositorySlug == null ? 0 : repositorySlug.hashCode());
@@ -157,6 +172,8 @@ public String toString() {
157172
+ userLevel
158173
+ ", uuid="
159174
+ uuid
175+
+ ", confirmationText="
176+
+ confirmationText
160177
+ "]";
161178
}
162179
}

src/main/java/se/bjurr/prnfb/transformer/ButtonTransformer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static ButtonDTO toButtonDto(PrnfbButton from) {
3636
to.setProjectKey(from.getProjectKey().orNull());
3737
to.setRepositorySlug(from.getRepositorySlug().orNull());
3838
to.setConfirmation(from.getConfirmation());
39+
to.setConfirmationText(from.getConfirmationText());
3940
to.setButtonFormList(toButtonFormDtoList(from.getButtonFormElementList()));
4041
String buttonFormDtoListString = gson.toJson(to.getButtonFormList());
4142
to.setButtonFormListString(buttonFormDtoListString);
@@ -106,6 +107,7 @@ public static PrnfbButton toPrnfbButton(ButtonDTO buttonDto) {
106107
buttonDto.getConfirmation(), //
107108
buttonDto.getProjectKey().orNull(), //
108109
buttonDto.getRepositorySlug().orNull(), //
110+
buttonDto.getConfirmationText(), //
109111
buttonFormElement); //
110112
}
111113

src/main/resources/admin.vm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@
245245
<div class="description">Whether to show a confirmation dialog.</div>
246246
</div>
247247

248+
<div class="field-group">
249+
<label>Confirmation message </label>
250+
<input class="text long-field" type="text" name="confirmationText">
251+
<div class="description">If not empty, a confirmation dialog will be shown with this message, before any notification is triggered.</div>
252+
</div>
253+
248254
<div class="field-group">
249255
<label>Button Form</label>
250256
<textarea class="textarea" rows="6" name="buttonFormListString"></textarea>

src/main/resources/pr-triggerbutton.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,18 @@ define('plugin/prnfb/pr-triggerbutton', [
116116
return $("<fieldset class='group'/>").append(radioItems);
117117
};
118118

119+
var confirmationTextTemplate = function(confirmationText) {
120+
if (!confirmationText) {
121+
return '';
122+
}
123+
124+
var confirmationDiv = '<div class="description">' + confirmationText + '</div>';
125+
return confirmationDiv;
126+
};
127+
119128
var formTemplate = function(formDescription) {
120129
if (!formDescription || formDescription.length === 0) {
121-
return null;
130+
return '';
122131
}
123132

124133
var formItems = [];
@@ -244,10 +253,11 @@ define('plugin/prnfb/pr-triggerbutton', [
244253
});
245254
};
246255

247-
if (item.buttonFormList && item.buttonFormList.length > 0) {
256+
if (item.confirmationText || item.buttonFormList && item.buttonFormList.length > 0) {
248257
// Create the form and dialog
258+
var confirmationText = confirmationTextTemplate(item.confirmationText);
249259
var form = formTemplate(item.buttonFormList);
250-
var formHtml = $("<div/>").append(form).html();
260+
var formHtml = $("<div/>").append(confirmationText).append(form).html();
251261
var $dialog = $(dialogTemplate(item.name, formHtml));
252262
$dialog.appendTo($("body"));
253263

0 commit comments

Comments
 (0)