Merge "Add preference for dashboard columns in preferences"
This commit is contained in:
@@ -75,8 +75,9 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
|
|||||||
GeneralPreferencesInfo o = gApi.accounts()
|
GeneralPreferencesInfo o = gApi.accounts()
|
||||||
.id(user42.id.toString())
|
.id(user42.id.toString())
|
||||||
.getPreferences();
|
.getPreferences();
|
||||||
assertPrefs(o, GeneralPreferencesInfo.defaults(), "my");
|
assertPrefs(o, GeneralPreferencesInfo.defaults(), "my", "changeTable");
|
||||||
assertThat(o.my).hasSize(7);
|
assertThat(o.my).hasSize(7);
|
||||||
|
assertThat(o.changeTable).isEmpty();
|
||||||
|
|
||||||
GeneralPreferencesInfo i = GeneralPreferencesInfo.defaults();
|
GeneralPreferencesInfo i = GeneralPreferencesInfo.defaults();
|
||||||
|
|
||||||
@@ -99,6 +100,8 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
|
|||||||
i.diffView = DiffView.UNIFIED_DIFF;
|
i.diffView = DiffView.UNIFIED_DIFF;
|
||||||
i.my = new ArrayList<>();
|
i.my = new ArrayList<>();
|
||||||
i.my.add(new MenuItem("name", "url"));
|
i.my.add(new MenuItem("name", "url"));
|
||||||
|
i.changeTable = new ArrayList<>();
|
||||||
|
i.changeTable.add("Status");
|
||||||
i.urlAliases = new HashMap<>();
|
i.urlAliases = new HashMap<>();
|
||||||
i.urlAliases.put("foo", "bar");
|
i.urlAliases.put("foo", "bar");
|
||||||
|
|
||||||
@@ -107,6 +110,7 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
|
|||||||
.setPreferences(i);
|
.setPreferences(i);
|
||||||
assertPrefs(o, i, "my");
|
assertPrefs(o, i, "my");
|
||||||
assertThat(o.my).hasSize(1);
|
assertThat(o.my).hasSize(1);
|
||||||
|
assertThat(o.changeTable).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -125,6 +129,6 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
|
|||||||
assertThat(o.changesPerPage).isEqualTo(newChangesPerPage);
|
assertThat(o.changesPerPage).isEqualTo(newChangesPerPage);
|
||||||
|
|
||||||
// assert hard-coded defaults
|
// assert hard-coded defaults
|
||||||
assertPrefs(o, d, "my", "changesPerPage");
|
assertPrefs(o, d, "my", "changeTable", "changesPerPage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -141,6 +141,7 @@ public class GeneralPreferencesInfo {
|
|||||||
public Boolean muteCommonPathPrefixes;
|
public Boolean muteCommonPathPrefixes;
|
||||||
public Boolean signedOffBy;
|
public Boolean signedOffBy;
|
||||||
public List<MenuItem> my;
|
public List<MenuItem> my;
|
||||||
|
public List<String> changeTable;
|
||||||
public Map<String, String> urlAliases;
|
public Map<String, String> urlAliases;
|
||||||
public EmailStrategy emailStrategy;
|
public EmailStrategy emailStrategy;
|
||||||
public DefaultBase defaultBaseForMerges;
|
public DefaultBase defaultBaseForMerges;
|
||||||
|
@@ -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_TOKEN;
|
||||||
import static com.google.gerrit.server.git.UserConfigSections.KEY_URL;
|
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.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.base.Strings;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.client.MenuItem;
|
import com.google.gerrit.extensions.client.MenuItem;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
@@ -91,7 +95,7 @@ public class GeneralPreferencesLoader {
|
|||||||
loadSection(p.getConfig(), UserConfigSections.GENERAL, null,
|
loadSection(p.getConfig(), UserConfigSections.GENERAL, null,
|
||||||
new GeneralPreferencesInfo(),
|
new GeneralPreferencesInfo(),
|
||||||
updateDefaults(allUserPrefs), in);
|
updateDefaults(allUserPrefs), in);
|
||||||
|
loadChangeTableColumns(r, p, dp);
|
||||||
return loadMyMenusAndUrlAliases(r, p, dp);
|
return loadMyMenusAndUrlAliases(r, p, dp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,6 +165,22 @@ public class GeneralPreferencesLoader {
|
|||||||
return !Strings.isNullOrEmpty(val) ? val : defaultValue;
|
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) {
|
private static Map<String, String> urlAliases(VersionedAccountPreferences v) {
|
||||||
HashMap<String, String> urlAliases = new HashMap<>();
|
HashMap<String, String> urlAliases = new HashMap<>();
|
||||||
Config cfg = v.getConfig();
|
Config cfg = v.getConfig();
|
||||||
|
@@ -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_TOKEN;
|
||||||
import static com.google.gerrit.server.git.UserConfigSections.KEY_URL;
|
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.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.base.Strings;
|
||||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||||
@@ -87,6 +89,7 @@ public class SetPreferences implements
|
|||||||
Account.Id id = rsrc.getUser().getAccountId();
|
Account.Id id = rsrc.getUser().getAccountId();
|
||||||
GeneralPreferencesInfo n = loader.merge(id, i);
|
GeneralPreferencesInfo n = loader.merge(id, i);
|
||||||
|
|
||||||
|
n.changeTable = i.changeTable;
|
||||||
n.my = i.my;
|
n.my = i.my;
|
||||||
n.urlAliases = i.urlAliases;
|
n.urlAliases = i.urlAliases;
|
||||||
|
|
||||||
@@ -105,6 +108,7 @@ public class SetPreferences implements
|
|||||||
storeSection(prefs.getConfig(), UserConfigSections.GENERAL, null, i,
|
storeSection(prefs.getConfig(), UserConfigSections.GENERAL, null, i,
|
||||||
GeneralPreferencesInfo.defaults());
|
GeneralPreferencesInfo.defaults());
|
||||||
|
|
||||||
|
storeMyChangeTableColumns(prefs, i.changeTable);
|
||||||
storeMyMenus(prefs, i.my);
|
storeMyMenus(prefs, i.my);
|
||||||
storeUrlAliases(prefs, i.urlAliases);
|
storeUrlAliases(prefs, i.urlAliases);
|
||||||
prefs.commit(md);
|
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) {
|
private static void set(Config cfg, String section, String key, String val) {
|
||||||
if (Strings.isNullOrEmpty(val)) {
|
if (Strings.isNullOrEmpty(val)) {
|
||||||
cfg.unset(UserConfigSections.MY, section, key);
|
cfg.unset(UserConfigSections.MY, section, key);
|
||||||
|
@@ -29,6 +29,10 @@ public class UserConfigSections {
|
|||||||
public static final String KEY_MATCH = "match";
|
public static final String KEY_MATCH = "match";
|
||||||
public static final String KEY_TOKEN = "token";
|
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. */
|
/** The edit user preferences. */
|
||||||
public static final String EDIT = "edit";
|
public static final String EDIT = "edit";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user