Merge "Add preference for dashboard columns in preferences"

This commit is contained in:
Dave Borowitz
2016-11-28 22:14:24 +00:00
committed by Gerrit Code Review
5 changed files with 46 additions and 3 deletions

View File

@@ -75,8 +75,9 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
GeneralPreferencesInfo o = gApi.accounts()
.id(user42.id.toString())
.getPreferences();
assertPrefs(o, GeneralPreferencesInfo.defaults(), "my");
assertPrefs(o, GeneralPreferencesInfo.defaults(), "my", "changeTable");
assertThat(o.my).hasSize(7);
assertThat(o.changeTable).isEmpty();
GeneralPreferencesInfo i = GeneralPreferencesInfo.defaults();
@@ -99,6 +100,8 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
i.diffView = DiffView.UNIFIED_DIFF;
i.my = new ArrayList<>();
i.my.add(new MenuItem("name", "url"));
i.changeTable = new ArrayList<>();
i.changeTable.add("Status");
i.urlAliases = new HashMap<>();
i.urlAliases.put("foo", "bar");
@@ -107,6 +110,7 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
.setPreferences(i);
assertPrefs(o, i, "my");
assertThat(o.my).hasSize(1);
assertThat(o.changeTable).hasSize(1);
}
@Test
@@ -125,6 +129,6 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
assertThat(o.changesPerPage).isEqualTo(newChangesPerPage);
// assert hard-coded defaults
assertPrefs(o, d, "my", "changesPerPage");
assertPrefs(o, d, "my", "changeTable", "changesPerPage");
}
}

View File

@@ -141,6 +141,7 @@ public class GeneralPreferencesInfo {
public Boolean muteCommonPathPrefixes;
public Boolean signedOffBy;
public List<MenuItem> my;
public List<String> changeTable;
public Map<String, String> urlAliases;
public EmailStrategy emailStrategy;
public DefaultBase defaultBaseForMerges;

View File

@@ -22,8 +22,12 @@ import static com.google.gerrit.server.git.UserConfigSections.KEY_TARGET;
import static com.google.gerrit.server.git.UserConfigSections.KEY_TOKEN;
import static com.google.gerrit.server.git.UserConfigSections.KEY_URL;
import static com.google.gerrit.server.git.UserConfigSections.URL_ALIAS;
import static com.google.gerrit.server.git.UserConfigSections.CHANGE_TABLE;
import static com.google.gerrit.server.git.UserConfigSections.CHANGE_TABLE_COLUMN;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
import com.google.gerrit.extensions.client.MenuItem;
import com.google.gerrit.reviewdb.client.Account;
@@ -91,7 +95,7 @@ public class GeneralPreferencesLoader {
loadSection(p.getConfig(), UserConfigSections.GENERAL, null,
new GeneralPreferencesInfo(),
updateDefaults(allUserPrefs), in);
loadChangeTableColumns(r, p, dp);
return loadMyMenusAndUrlAliases(r, p, dp);
}
}
@@ -161,6 +165,22 @@ public class GeneralPreferencesLoader {
return !Strings.isNullOrEmpty(val) ? val : defaultValue;
}
public GeneralPreferencesInfo loadChangeTableColumns(GeneralPreferencesInfo r,
VersionedAccountPreferences v, VersionedAccountPreferences d) {
r.changeTable = changeTable(v);
Config cfg = v.getConfig();
if (r.changeTable.isEmpty() && !v.isDefaults()) {
r.changeTable = changeTable(d);
}
return r;
}
private static List<String> changeTable(VersionedAccountPreferences v) {
return Lists.newArrayList(v.getConfig().getStringList(
CHANGE_TABLE, null, CHANGE_TABLE_COLUMN));
}
private static Map<String, String> urlAliases(VersionedAccountPreferences v) {
HashMap<String, String> urlAliases = new HashMap<>();
Config cfg = v.getConfig();

View File

@@ -21,6 +21,8 @@ import static com.google.gerrit.server.git.UserConfigSections.KEY_TARGET;
import static com.google.gerrit.server.git.UserConfigSections.KEY_TOKEN;
import static com.google.gerrit.server.git.UserConfigSections.KEY_URL;
import static com.google.gerrit.server.git.UserConfigSections.URL_ALIAS;
import static com.google.gerrit.server.git.UserConfigSections.CHANGE_TABLE;
import static com.google.gerrit.server.git.UserConfigSections.CHANGE_TABLE_COLUMN;
import com.google.common.base.Strings;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
@@ -87,6 +89,7 @@ public class SetPreferences implements
Account.Id id = rsrc.getUser().getAccountId();
GeneralPreferencesInfo n = loader.merge(id, i);
n.changeTable = i.changeTable;
n.my = i.my;
n.urlAliases = i.urlAliases;
@@ -105,6 +108,7 @@ public class SetPreferences implements
storeSection(prefs.getConfig(), UserConfigSections.GENERAL, null, i,
GeneralPreferencesInfo.defaults());
storeMyChangeTableColumns(prefs, i.changeTable);
storeMyMenus(prefs, i.my);
storeUrlAliases(prefs, i.urlAliases);
prefs.commit(md);
@@ -125,6 +129,16 @@ public class SetPreferences implements
}
}
public static void storeMyChangeTableColumns(VersionedAccountPreferences
prefs, List<String> changeTable) {
Config cfg = prefs.getConfig();
if (changeTable != null) {
unsetSection(cfg, UserConfigSections.CHANGE_TABLE);
cfg.setStringList(UserConfigSections.CHANGE_TABLE, null,
CHANGE_TABLE_COLUMN, changeTable);
}
}
private static void set(Config cfg, String section, String key, String val) {
if (Strings.isNullOrEmpty(val)) {
cfg.unset(UserConfigSections.MY, section, key);

View File

@@ -29,6 +29,10 @@ public class UserConfigSections {
public static final String KEY_MATCH = "match";
public static final String KEY_TOKEN = "token";
/** The table column user preferences. */
public static final String CHANGE_TABLE = "changeTable";
public static final String CHANGE_TABLE_COLUMN = "column";
/** The edit user preferences. */
public static final String EDIT = "edit";