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
This commit is contained in:
Patrick Hiesel 2017-02-27 16:26:33 +01:00
parent d64dd9968c
commit 006578f7da
8 changed files with 75 additions and 1 deletions

View File

@ -644,6 +644,20 @@ on comments that you write yourself.
+
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

View File

@ -22,6 +22,7 @@ import com.google.gerrit.extensions.client.GeneralPreferencesInfo.DateFormat;
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 @@ public class GeneralPreferences extends JavaScriptObject {
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 @@ public class GeneralPreferences extends JavaScriptObject {
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 @@ public class GeneralPreferences extends JavaScriptObject {
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);
}

View File

@ -287,6 +287,12 @@ public interface AccountConstants extends Constants {
String emailFieldLabel();
String emailFormatFieldLabel();
String messagePlaintextOnly();
String messageHtmlPlaintext();
String defaultBaseForMerges();
String autoMerge();

View File

@ -19,6 +19,10 @@ messageCCMeOnMyComments = Every Comment
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

View File

@ -61,6 +61,7 @@ public class MyPreferencesScreen extends SettingsScreen {
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 @@ public class MyPreferencesScreen extends SettingsScreen {
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 @@ public class MyPreferencesScreen extends SettingsScreen {
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 @@ public class MyPreferencesScreen extends SettingsScreen {
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 @@ public class MyPreferencesScreen extends SettingsScreen {
e.listenTo(diffView);
e.listenTo(reviewCategoryStrategy);
e.listenTo(emailStrategy);
e.listenTo(emailFormat);
e.listenTo(defaultBaseForMerges);
}
@ -287,6 +299,7 @@ public class MyPreferencesScreen extends SettingsScreen {
reviewCategoryStrategy.setEnabled(on);
diffView.setEnabled(on);
emailStrategy.setEnabled(on);
emailFormat.setEnabled(on);
defaultBaseForMerges.setEnabled(on);
}
@ -314,6 +327,7 @@ public class MyPreferencesScreen extends SettingsScreen {
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 @@ public class MyPreferencesScreen extends SettingsScreen {
GeneralPreferencesInfo.EmailStrategy.ENABLED,
GeneralPreferencesInfo.EmailStrategy.values()));
p.emailFormat(
getListBox(
emailFormat,
GeneralPreferencesInfo.EmailFormat.HTML_PLAINTEXT,
GeneralPreferencesInfo.EmailFormat.values()));
p.defaultBaseForMerges(
getListBox(
defaultBaseForMerges,

View File

@ -174,6 +174,17 @@ limitations under the License.
</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">

View File

@ -21,6 +21,7 @@
'email_strategy',
'diff_view',
'expand_inline_diffs',
'email_format',
];
Polymer({

View File

@ -85,6 +85,7 @@ limitations under the License.
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 @@ limitations under the License.
.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')