Search in sources :

Example 1 with MenuItem

use of com.google.gerrit.extensions.client.MenuItem in project gerrit by GerritCodeReview.

the class GeneralPreferencesIT method getAndSetPreferences.

@Test
public void getAndSetPreferences() throws Exception {
    GeneralPreferencesInfo o = gApi.accounts().id(user42.id.toString()).getPreferences();
    assertPrefs(o, GeneralPreferencesInfo.defaults(), "my", "changeTable");
    assertThat(o.my).hasSize(7);
    assertThat(o.changeTable).isEmpty();
    GeneralPreferencesInfo i = GeneralPreferencesInfo.defaults();
    // change all default values
    i.changesPerPage *= -1;
    i.showSiteHeader ^= true;
    i.useFlashClipboard ^= true;
    i.downloadCommand = DownloadCommand.REPO_DOWNLOAD;
    i.dateFormat = DateFormat.US;
    i.timeFormat = TimeFormat.HHMM_24;
    i.emailStrategy = EmailStrategy.DISABLED;
    i.emailFormat = EmailFormat.PLAINTEXT;
    i.defaultBaseForMerges = DefaultBase.AUTO_MERGE;
    i.expandInlineDiffs ^= true;
    i.highlightAssigneeInChangeTable ^= true;
    i.relativeDateInChangeTable ^= true;
    i.sizeBarInChangeTable ^= true;
    i.legacycidInChangeTable ^= true;
    i.muteCommonPathPrefixes ^= true;
    i.signedOffBy ^= true;
    i.reviewCategoryStrategy = ReviewCategoryStrategy.ABBREV;
    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");
    o = gApi.accounts().id(user42.getId().toString()).setPreferences(i);
    assertPrefs(o, i, "my");
    assertThat(o.my).hasSize(1);
    assertThat(o.changeTable).hasSize(1);
}
Also used : GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) MenuItem(com.google.gerrit.extensions.client.MenuItem) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with MenuItem

use of com.google.gerrit.extensions.client.MenuItem in project gerrit by GerritCodeReview.

the class SetPreferences method storeMyMenus.

public static void storeMyMenus(VersionedAccountPreferences prefs, List<MenuItem> my) {
    Config cfg = prefs.getConfig();
    if (my != null) {
        unsetSection(cfg, UserConfigSections.MY);
        for (MenuItem item : my) {
            set(cfg, item.name, KEY_URL, item.url);
            set(cfg, item.name, KEY_TARGET, item.target);
            set(cfg, item.name, KEY_ID, item.id);
        }
    }
}
Also used : Config(org.eclipse.jgit.lib.Config) MenuItem(com.google.gerrit.extensions.client.MenuItem)

Example 3 with MenuItem

use of com.google.gerrit.extensions.client.MenuItem in project gerrit by GerritCodeReview.

the class GeneralPreferencesLoader method my.

private static List<MenuItem> my(VersionedAccountPreferences v) {
    List<MenuItem> my = new ArrayList<>();
    Config cfg = v.getConfig();
    for (String subsection : cfg.getSubsections(UserConfigSections.MY)) {
        String url = my(cfg, subsection, KEY_URL, "#/");
        String target = my(cfg, subsection, KEY_TARGET, url.startsWith("#") ? null : "_blank");
        my.add(new MenuItem(subsection, url, target, my(cfg, subsection, KEY_ID, null)));
    }
    return my;
}
Also used : Config(org.eclipse.jgit.lib.Config) ArrayList(java.util.ArrayList) MenuItem(com.google.gerrit.extensions.client.MenuItem)

Example 4 with MenuItem

use of com.google.gerrit.extensions.client.MenuItem in project gerrit by GerritCodeReview.

the class GeneralPreferencesLoader method loadMyMenusAndUrlAliases.

public GeneralPreferencesInfo loadMyMenusAndUrlAliases(GeneralPreferencesInfo r, VersionedAccountPreferences v, VersionedAccountPreferences d) {
    r.my = my(v);
    if (r.my.isEmpty() && !v.isDefaults()) {
        r.my = my(d);
    }
    if (r.my.isEmpty()) {
        r.my.add(new MenuItem("Changes", "#/dashboard/self", null));
        r.my.add(new MenuItem("Drafts", "#/q/owner:self+is:draft", null));
        r.my.add(new MenuItem("Draft Comments", "#/q/has:draft", null));
        r.my.add(new MenuItem("Edits", "#/q/has:edit", null));
        r.my.add(new MenuItem("Watched Changes", "#/q/is:watched+is:open", null));
        r.my.add(new MenuItem("Starred Changes", "#/q/is:starred", null));
        r.my.add(new MenuItem("Groups", "#/groups/self", null));
    }
    r.urlAliases = urlAliases(v);
    if (r.urlAliases == null && !v.isDefaults()) {
        r.urlAliases = urlAliases(d);
    }
    return r;
}
Also used : MenuItem(com.google.gerrit.extensions.client.MenuItem)

Aggregations

MenuItem (com.google.gerrit.extensions.client.MenuItem)4 Config (org.eclipse.jgit.lib.Config)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 GeneralPreferencesInfo (com.google.gerrit.extensions.client.GeneralPreferencesInfo)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1