Add frontend code for email format user preference
This change adds all required frontend code for both GWT UI and
Polygerrit as well as docs for the user preferenced introduced by
Change I190644732.
Feature: Issue 5349
Change-Id: I94353380fbd5208cebb7fe8946fb4c4100c8d054
diff --git a/Documentation/intro-user.txt b/Documentation/intro-user.txt
index ac32656..0c5511e 100644
--- a/Documentation/intro-user.txt
+++ b/Documentation/intro-user.txt
@@ -644,6 +644,20 @@
+
Email notifications are disabled.
+- [[email-format]]`Email Format`:
++
+This setting controls the email format Gerrit sends. Note that this
+setting has no effect if the administrator has disabled HTML emails
+for the Gerrit instance.
++
+** `Plaintext Only`:
++
+Email notifications contain only plaintext content.
++
+** `HTML and Plaintext`:
++
+Email notifications contain both HTML and plaintext content.
+
- [[default-base-for-merges]]`Default Base For Merges`:
+
This setting controls which base should be pre-selected in the
diff --git a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/info/GeneralPreferences.java b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/info/GeneralPreferences.java
index 6f91440..23e1a93 100644
--- a/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/info/GeneralPreferences.java
+++ b/gerrit-gwtui-common/src/main/java/com/google/gerrit/client/info/GeneralPreferences.java
@@ -22,6 +22,7 @@
import com.google.gerrit.extensions.client.GeneralPreferencesInfo.DefaultBase;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo.DiffView;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo.DownloadCommand;
+import com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailFormat;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailStrategy;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo.ReviewCategoryStrategy;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo.TimeFormat;
@@ -52,6 +53,7 @@
p.legacycidInChangeTable(d.legacycidInChangeTable);
p.muteCommonPathPrefixes(d.muteCommonPathPrefixes);
p.signedOffBy(d.signedOffBy);
+ p.emailFormat(d.emailFormat);
p.reviewCategoryStrategy(d.getReviewCategoryStrategy());
p.diffView(d.getDiffView());
p.emailStrategy(d.emailStrategy);
@@ -132,6 +134,13 @@
private native String emailStrategyRaw() /*-{ return this.email_strategy }-*/;
+ public final EmailFormat emailFormat() {
+ String s = emailFormatRaw();
+ return s != null ? EmailFormat.valueOf(s) : null;
+ }
+
+ private native String emailFormatRaw() /*-{ return this.email_format }-*/;
+
public final DefaultBase defaultBaseForMerges() {
String s = defaultBaseForMergesRaw();
return s != null ? DefaultBase.valueOf(s) : null;
@@ -203,6 +212,12 @@
private native void emailStrategyRaw(String s) /*-{ this.email_strategy = s }-*/;
+ public final void emailFormat(EmailFormat f) {
+ emailFormatRaw(f != null ? f.toString() : null);
+ }
+
+ private native void emailFormatRaw(String s) /*-{ this.email_format = s }-*/;
+
public final void defaultBaseForMerges(DefaultBase b) {
defaultBaseForMergesRaw(b != null ? b.toString() : null);
}
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.java
index 8ad55e8..4a3a5f8 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.java
@@ -287,6 +287,12 @@
String emailFieldLabel();
+ String emailFormatFieldLabel();
+
+ String messagePlaintextOnly();
+
+ String messageHtmlPlaintext();
+
String defaultBaseForMerges();
String autoMerge();
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.properties
index 2479c87..9d87365 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.properties
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/AccountConstants.properties
@@ -19,6 +19,10 @@
messageEnabled = Only Comments Left By Others
messageDisabled = None
+emailFormatFieldLabel = Email Format:
+messagePlaintextOnly = Plaintext Only
+messageHtmlPlaintext = HTML and Plaintext
+
defaultBaseForMerges = Default Base For Merges:
autoMerge = Auto Merge
firstParent = First Parent
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/MyPreferencesScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/MyPreferencesScreen.java
index 1f20d8e..c597230 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/MyPreferencesScreen.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/MyPreferencesScreen.java
@@ -61,6 +61,7 @@
private ListBox reviewCategoryStrategy;
private ListBox diffView;
private ListBox emailStrategy;
+ private ListBox emailFormat;
private ListBox defaultBaseForMerges;
private StringListPanel myMenus;
private Button save;
@@ -102,6 +103,12 @@
emailStrategy.addItem(
Util.C.messageDisabled(), GeneralPreferencesInfo.EmailStrategy.DISABLED.name());
+ emailFormat = new ListBox();
+ emailFormat.addItem(
+ Util.C.messagePlaintextOnly(), GeneralPreferencesInfo.EmailFormat.PLAINTEXT.name());
+ emailFormat.addItem(
+ Util.C.messageHtmlPlaintext(), GeneralPreferencesInfo.EmailFormat.HTML_PLAINTEXT.name());
+
defaultBaseForMerges = new ListBox();
defaultBaseForMerges.addItem(
Util.C.autoMerge(), GeneralPreferencesInfo.DefaultBase.AUTO_MERGE.name());
@@ -157,7 +164,7 @@
signedOffBy = new CheckBox(Util.C.signedOffBy());
boolean flashClippy = !UserAgent.hasJavaScriptClipboard() && UserAgent.Flash.isInstalled();
- final Grid formGrid = new Grid(13 + (flashClippy ? 1 : 0), 2);
+ final Grid formGrid = new Grid(14 + (flashClippy ? 1 : 0), 2);
int row = 0;
@@ -177,6 +184,10 @@
formGrid.setWidget(row, fieldIdx, emailStrategy);
row++;
+ formGrid.setText(row, labelIdx, Util.C.emailFormatFieldLabel());
+ formGrid.setWidget(row, fieldIdx, emailFormat);
+ row++;
+
formGrid.setText(row, labelIdx, Util.C.defaultBaseForMerges());
formGrid.setWidget(row, fieldIdx, defaultBaseForMerges);
row++;
@@ -250,6 +261,7 @@
e.listenTo(diffView);
e.listenTo(reviewCategoryStrategy);
e.listenTo(emailStrategy);
+ e.listenTo(emailFormat);
e.listenTo(defaultBaseForMerges);
}
@@ -287,6 +299,7 @@
reviewCategoryStrategy.setEnabled(on);
diffView.setEnabled(on);
emailStrategy.setEnabled(on);
+ emailFormat.setEnabled(on);
defaultBaseForMerges.setEnabled(on);
}
@@ -314,6 +327,7 @@
p.reviewCategoryStrategy());
setListBox(diffView, GeneralPreferencesInfo.DiffView.SIDE_BY_SIDE, p.diffView());
setListBox(emailStrategy, GeneralPreferencesInfo.EmailStrategy.ENABLED, p.emailStrategy());
+ setListBox(emailFormat, GeneralPreferencesInfo.EmailFormat.HTML_PLAINTEXT, p.emailFormat());
setListBox(
defaultBaseForMerges,
GeneralPreferencesInfo.DefaultBase.FIRST_PARENT,
@@ -414,6 +428,12 @@
GeneralPreferencesInfo.EmailStrategy.ENABLED,
GeneralPreferencesInfo.EmailStrategy.values()));
+ p.emailFormat(
+ getListBox(
+ emailFormat,
+ GeneralPreferencesInfo.EmailFormat.HTML_PLAINTEXT,
+ GeneralPreferencesInfo.EmailFormat.values()));
+
p.defaultBaseForMerges(
getListBox(
defaultBaseForMerges,
diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html
index 8789580..c3542ba 100644
--- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html
+++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html
@@ -174,6 +174,17 @@
</select>
</span>
</section>
+ <section hidden$="[[!_localPrefs.email_format]]">
+ <span class="title">Email Format</span>
+ <span class="value">
+ <select
+ is="gr-select"
+ bind-value="{{_localPrefs.email_format}}">
+ <option value="HTML_PLAINTEXT">HTML and Plaintext</option>
+ <option value="PLAINTEXT">Plaintext Only</option>
+ </select>
+ </span>
+ </section>
<section>
<span class="title">Diff View</span>
<span class="value">
diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js
index 355105d..4c852b5 100644
--- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js
+++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js
@@ -21,6 +21,7 @@
'email_strategy',
'diff_view',
'expand_inline_diffs',
+ 'email_format',
];
Polymer({
diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_test.html b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_test.html
index 0d381cb..13ca254 100644
--- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_test.html
+++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_test.html
@@ -85,6 +85,7 @@
time_format: 'HHMM_12',
diff_view: 'UNIFIED_DIFF',
email_strategy: 'ENABLED',
+ email_format: 'HTML_PLAINTEXT',
my: [
{url: '/first/url', name: 'first name', target: '_blank'},
@@ -162,6 +163,8 @@
.lastElementChild.bindValue, preferences.time_format);
assert.equal(valueOf('Email Notifications', 'preferences')
.firstElementChild.bindValue, preferences.email_strategy);
+ assert.equal(valueOf('Email Format', 'preferences')
+ .firstElementChild.bindValue, preferences.email_format);
assert.equal(valueOf('Diff View', 'preferences')
.firstElementChild.bindValue, preferences.diff_view);
assert.equal(valueOf('Expand Inline Diffs', 'preferences')