From 751441fdfaf1b7b9e494118018bc1b798bd29118 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Fri, 30 Jan 2015 15:54:52 +0900 Subject: [PATCH] ChangeScreen: Allow to disable muting of common paths in file table In the file table, parts of the file path that are common to the file previously listed are muted. The purpose of this is to make it easier to see files that all belong under the same path, but some users find it annoying. Add a new user preference to control this feature. When it is disabled, the entire path is shown in the same color for all files. The default setting for the new preference is enabled, meaning the default behavior is the same as now, and the user must explicitly disable it. Bug: Issue 3147 Change-Id: Id9bf7270e3eb65c22c4d44f5ef6717c952aeeb2a --- Documentation/rest-api-accounts.txt | 4 ++ .../client/account/AccountConstants.java | 1 + .../account/AccountConstants.properties | 1 + .../client/account/MyPreferencesScreen.java | 12 +++++- .../gerrit/client/account/Preferences.java | 7 ++++ .../gerrit/client/change/FileTable.java | 5 ++- .../client/AccountGeneralPreferences.java | 13 ++++++ .../gerrit/server/account/GetPreferences.java | 2 + .../gerrit/server/account/SetPreferences.java | 4 ++ .../gerrit/server/config/SetPreferences.java | 1 + .../gerrit/server/schema/SchemaVersion.java | 2 +- .../gerrit/server/schema/Schema_107.java | 41 +++++++++++++++++++ 12 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_107.java diff --git a/Documentation/rest-api-accounts.txt b/Documentation/rest-api-accounts.txt index 9966c8e320..b5c155725e 100644 --- a/Documentation/rest-api-accounts.txt +++ b/Documentation/rest-api-accounts.txt @@ -1550,6 +1550,8 @@ Whether to show relative dates in the changes table. Whether to show the change sizes as colored bars in the change table. |`legacycid_in_change_table` |not set if `false`| Whether to show change number in the change table. +|`mute_common_path_prefixes` |not set if `false`| +Whether to mute common path prefixes in file names in the file table. |`review_category_strategy` || The strategy used to displayed info in the review category column. Allowed values are `NONE`, `NAME`, `EMAIL`, `USERNAME`, `ABBREV`. @@ -1591,6 +1593,8 @@ Whether to show relative dates in the changes table. Whether to show the change sizes as colored bars in the change table. |`legacycid_in_change_table` |optional| Whether to show change number in the change table. +|`mute_common_path_prefixes` |optional| +Whether to mute common path prefixes in file names in the file table. |`review_category_strategy` |optional| The strategy used to displayed info in the review category column. Allowed values are `NONE`, `NAME`, `EMAIL`, `USERNAME`, `ABBREV`. 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 abcfa0cace..4c3cc29a0d 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 @@ -42,6 +42,7 @@ public interface AccountConstants extends Constants { String showRelativeDateInChangeTable(); String showSizeBarInChangeTable(); String showLegacycidInChangeTable(); + String muteCommonPathPrefixes(); String myMenu(); String myMenuInfo(); String myMenuName(); 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 8f151a97cd..5596aceb00 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 @@ -23,6 +23,7 @@ buttonSaveChanges = Save Changes showRelativeDateInChangeTable = Show Relative Dates In Changes Table showSizeBarInChangeTable = Show Change Sizes As Colored Bars In Changes Table showLegacycidInChangeTable = Show Change Number In Changes Table +muteCommonPathPrefixes = Mute Common Path Prefixes In File List myMenu = My Menu myMenuInfo = \ Menu items for the 'My' top level menu. \ 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 25c21bfbd4..5cee76709f 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 @@ -50,6 +50,7 @@ public class MyPreferencesScreen extends SettingsScreen { private CheckBox relativeDateInChangeTable; private CheckBox sizeBarInChangeTable; private CheckBox legacycidInChangeTable; + private CheckBox muteCommonPathPrefixes; private ListBox maximumPageSize; private ListBox dateFormat; private ListBox timeFormat; @@ -132,8 +133,9 @@ public class MyPreferencesScreen extends SettingsScreen { relativeDateInChangeTable = new CheckBox(Util.C.showRelativeDateInChangeTable()); sizeBarInChangeTable = new CheckBox(Util.C.showSizeBarInChangeTable()); legacycidInChangeTable = new CheckBox(Util.C.showLegacycidInChangeTable()); + muteCommonPathPrefixes = new CheckBox(Util.C.muteCommonPathPrefixes()); - final Grid formGrid = new Grid(10, 2); + final Grid formGrid = new Grid(11, 2); int row = 0; formGrid.setText(row, labelIdx, ""); @@ -172,6 +174,10 @@ public class MyPreferencesScreen extends SettingsScreen { formGrid.setWidget(row, fieldIdx, legacycidInChangeTable); row++; + formGrid.setText(row, labelIdx, ""); + formGrid.setWidget(row, fieldIdx, muteCommonPathPrefixes); + row++; + formGrid.setText(row, labelIdx, Util.C.diffViewLabel()); formGrid.setWidget(row, fieldIdx, diffView); @@ -201,6 +207,7 @@ public class MyPreferencesScreen extends SettingsScreen { e.listenTo(relativeDateInChangeTable); e.listenTo(sizeBarInChangeTable); e.listenTo(legacycidInChangeTable); + e.listenTo(muteCommonPathPrefixes); e.listenTo(diffView); } @@ -226,6 +233,7 @@ public class MyPreferencesScreen extends SettingsScreen { relativeDateInChangeTable.setEnabled(on); sizeBarInChangeTable.setEnabled(on); legacycidInChangeTable.setEnabled(on); + muteCommonPathPrefixes.setEnabled(on); reviewCategoryStrategy.setEnabled(on); diffView.setEnabled(on); } @@ -242,6 +250,7 @@ public class MyPreferencesScreen extends SettingsScreen { relativeDateInChangeTable.setValue(p.relativeDateInChangeTable()); sizeBarInChangeTable.setValue(p.sizeBarInChangeTable()); legacycidInChangeTable.setValue(p.legacycidInChangeTable()); + muteCommonPathPrefixes.setValue(p.muteCommonPathPrefixes()); setListBox(reviewCategoryStrategy, AccountGeneralPreferences.ReviewCategoryStrategy.NONE, p.reviewCategoryStrategy()); @@ -325,6 +334,7 @@ public class MyPreferencesScreen extends SettingsScreen { p.setRelativeDateInChangeTable(relativeDateInChangeTable.getValue()); p.setSizeBarInChangeTable(sizeBarInChangeTable.getValue()); p.setLegacycidInChangeTable(legacycidInChangeTable.getValue()); + p.setMuteCommonPathPrefixes(muteCommonPathPrefixes.getValue()); p.setReviewCategoryStrategy(getListBox(reviewCategoryStrategy, ReviewCategoryStrategy.NONE, ReviewCategoryStrategy.values())); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/Preferences.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/Preferences.java index aec679c8cc..e9bd5f1e2e 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/Preferences.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/account/Preferences.java @@ -44,6 +44,7 @@ public class Preferences extends JavaScriptObject { p.relativeDateInChangeTable(in.isRelativeDateInChangeTable()); p.sizeBarInChangeTable(in.isSizeBarInChangeTable()); p.legacycidInChangeTable(in.isLegacycidInChangeTable()); + p.muteCommonPathPrefixes(in.isMuteCommonPathPrefixes()); p.reviewCategoryStrategy(in.getReviewCategoryStrategy()); p.diffView(in.getDiffView()); p.setMyMenus(myMenus); @@ -102,6 +103,9 @@ public class Preferences extends JavaScriptObject { public final native boolean legacycidInChangeTable() /*-{ return this.legacycid_in_change_table || false }-*/; + public final native boolean muteCommonPathPrefixes() + /*-{ return this.mute_common_path_prefixes || false }-*/; + public final ReviewCategoryStrategy reviewCategoryStrategy() { String s = reviewCategeoryStrategyRaw(); return s != null ? ReviewCategoryStrategy.valueOf(s) : ReviewCategoryStrategy.NONE; @@ -164,6 +168,9 @@ public class Preferences extends JavaScriptObject { public final native void legacycidInChangeTable(boolean s) /*-{ this.legacycid_in_change_table = s }-*/; + public final native void muteCommonPathPrefixes(boolean s) + /*-{ this.mute_common_path_prefixes = s }-*/; + public final void reviewCategoryStrategy(ReviewCategoryStrategy s) { reviewCategoryStrategyRaw(s != null ? s.toString() : null); } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/FileTable.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/FileTable.java index aa50f02d03..5dab3ac3b9 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/FileTable.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/FileTable.java @@ -630,7 +630,8 @@ public class FileTable extends FlowPanel { if (Patch.COMMIT_MSG.equals(path)) { sb.append(Util.C.commitMessage()); - } else { + } else if (!hasUser || Gerrit.getUserAccount().getGeneralPreferences() + .isMuteCommonPathPrefixes()) { int commonPrefixLen = commonPrefix(path); if (commonPrefixLen > 0) { sb.openSpan().setStyleName(R.css().commonPrefix()) @@ -639,6 +640,8 @@ public class FileTable extends FlowPanel { } sb.append(path.substring(commonPrefixLen)); lastPath = path; + } else { + sb.append(path); } sb.closeAnchor(); diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/AccountGeneralPreferences.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/AccountGeneralPreferences.java index a0cc2bfb99..31494bac8a 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/AccountGeneralPreferences.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/AccountGeneralPreferences.java @@ -157,6 +157,9 @@ public final class AccountGeneralPreferences { @Column(id = 18, length = 20, notNull = false) protected String reviewCategoryStrategy; + @Column(id = 19) + protected boolean muteCommonPathPrefixes; + public AccountGeneralPreferences() { } @@ -295,6 +298,15 @@ public final class AccountGeneralPreferences { this.legacycidInChangeTable = legacycidInChangeTable; } + public boolean isMuteCommonPathPrefixes() { + return muteCommonPathPrefixes; + } + + public void setMuteCommonPathPrefixes( + boolean muteCommonPathPrefixes) { + this.muteCommonPathPrefixes = muteCommonPathPrefixes; + } + public void resetToDefaults() { maximumPageSize = DEFAULT_PAGESIZE; showSiteHeader = true; @@ -309,5 +321,6 @@ public final class AccountGeneralPreferences { diffView = null; sizeBarInChangeTable = true; legacycidInChangeTable = false; + muteCommonPathPrefixes = true; } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/GetPreferences.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/GetPreferences.java index 8983013eba..e45e7ccb06 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/GetPreferences.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/GetPreferences.java @@ -109,6 +109,7 @@ public class GetPreferences implements RestReadView { Boolean relativeDateInChangeTable; Boolean sizeBarInChangeTable; Boolean legacycidInChangeTable; + Boolean muteCommonPathPrefixes; ReviewCategoryStrategy reviewCategoryStrategy; DiffView diffView; List my; @@ -127,6 +128,7 @@ public class GetPreferences implements RestReadView { relativeDateInChangeTable = p.isRelativeDateInChangeTable() ? true : null; sizeBarInChangeTable = p.isSizeBarInChangeTable() ? true : null; legacycidInChangeTable = p.isLegacycidInChangeTable() ? true : null; + muteCommonPathPrefixes = p.isMuteCommonPathPrefixes() ? true : null; reviewCategoryStrategy = p.getReviewCategoryStrategy(); diffView = p.getDiffView(); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/SetPreferences.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/SetPreferences.java index 08450f37e5..d75c5a2f63 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/SetPreferences.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/SetPreferences.java @@ -63,6 +63,7 @@ public class SetPreferences implements RestModifyView { public Boolean relativeDateInChangeTable; public Boolean sizeBarInChangeTable; public Boolean legacycidInChangeTable; + public Boolean muteCommonPathPrefixes; public ReviewCategoryStrategy reviewCategoryStrategy; public DiffView diffView; public List my; @@ -150,6 +151,9 @@ public class SetPreferences implements RestModifyView { if (i.legacycidInChangeTable != null) { p.setLegacycidInChangeTable(i.legacycidInChangeTable); } + if (i.muteCommonPathPrefixes != null) { + p.setMuteCommonPathPrefixes(i.muteCommonPathPrefixes); + } if (i.reviewCategoryStrategy != null) { p.setReviewCategoryStrategy(i.reviewCategoryStrategy); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/SetPreferences.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/SetPreferences.java index 0044ebd98b..d97499cee5 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/SetPreferences.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/SetPreferences.java @@ -52,6 +52,7 @@ public class SetPreferences implements RestModifyView { || i.relativeDateInChangeTable != null || i.sizeBarInChangeTable != null || i.legacycidInChangeTable != null + || i.muteCommonPathPrefixes != null || i.reviewCategoryStrategy != null) { throw new BadRequestException("unsupported option"); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaVersion.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaVersion.java index 50b3d88cc8..4e9e096f24 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaVersion.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/SchemaVersion.java @@ -32,7 +32,7 @@ import java.util.List; /** A version of the database schema. */ public abstract class SchemaVersion { /** The current schema version. */ - public static final Class C = Schema_106.class; + public static final Class C = Schema_107.class; public static int getBinaryVersion() { return guessVersion(C); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_107.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_107.java new file mode 100644 index 0000000000..13ab09aa40 --- /dev/null +++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_107.java @@ -0,0 +1,41 @@ +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.server.schema; + +import com.google.gerrit.reviewdb.server.ReviewDb; +import com.google.gwtorm.jdbc.JdbcSchema; +import com.google.inject.Inject; +import com.google.inject.Provider; + +import java.sql.SQLException; +import java.sql.Statement; + +public class Schema_107 extends SchemaVersion { + + @Inject + Schema_107(Provider prior) { + super(prior); + } + + @Override + protected void migrateData(ReviewDb db, UpdateUI ui) throws SQLException { + Statement stmt = ((JdbcSchema) db).getConnection().createStatement(); + try { + stmt.executeUpdate("UPDATE accounts set mute_common_path_prefixes = 'Y'"); + } finally { + stmt.close(); + } + } +}