Search in sources :

Example 1 with EditPreferencesInfo

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

the class Gerrit method onModuleLoad.

@Override
public void onModuleLoad() {
    if (!canLoadInIFrame()) {
        UserAgent.assertNotInIFrame();
    }
    setXsrfToken();
    KeyUtil.setEncoderImpl(new KeyUtil.Encoder() {

        @Override
        public String encode(String e) {
            e = URL.encodeQueryString(e);
            e = fixPathImpl(e);
            e = fixColonImpl(e);
            e = fixDoubleQuote(e);
            return e;
        }

        @Override
        public String decode(final String e) {
            return URL.decodeQueryString(e);
        }

        private native String fixPathImpl(String path);

        private native String fixColonImpl(String path);

        private native String fixDoubleQuote(String path);
    });
    initHostname();
    Window.setTitle(M.windowTitle1(myHost));
    RpcStatus.INSTANCE = new RpcStatus();
    CallbackGroup cbg = new CallbackGroup();
    getDocIndex(cbg.add(new GerritCallback<DocInfo>() {

        @Override
        public void onSuccess(DocInfo indexInfo) {
            hasDocumentation = indexInfo != null;
            docUrl = selfRedirect("/Documentation/");
        }
    }));
    ConfigServerApi.serverInfo(cbg.add(new GerritCallback<ServerInfo>() {

        @Override
        public void onSuccess(ServerInfo info) {
            myServerInfo = info;
            urlAliasMatcher = new UrlAliasMatcher(info.urlAliases());
            String du = info.gerrit().docUrl();
            if (du != null && !du.isEmpty()) {
                hasDocumentation = true;
                docUrl = du;
            }
            docSearch = info.gerrit().docSearch();
        }
    }));
    HostPageDataService hpd = GWT.create(HostPageDataService.class);
    hpd.load(cbg.addFinal(new GerritCallback<HostPageData>() {

        @Override
        public void onSuccess(final HostPageData result) {
            Document.get().getElementById("gerrit_hostpagedata").removeFromParent();
            myTheme = result.theme;
            isNoteDbEnabled = result.isNoteDbEnabled;
            if (result.accountDiffPref != null) {
                myAccountDiffPref = result.accountDiffPref;
            }
            if (result.accountDiffPref != null) {
                // TODO: Support options on the GetDetail REST endpoint so that it can
                // also return the preferences. Then we can fetch everything with a
                // single request and we don't need the callback group anymore.
                CallbackGroup cbg = new CallbackGroup();
                AccountApi.self().view("detail").get(cbg.add(new GerritCallback<AccountInfo>() {

                    @Override
                    public void onSuccess(AccountInfo result) {
                        myAccount = result;
                    }
                }));
                AccountApi.self().view("preferences").get(cbg.add(new GerritCallback<GeneralPreferences>() {

                    @Override
                    public void onSuccess(GeneralPreferences prefs) {
                        myPrefs = prefs;
                        onModuleLoad2(result);
                    }
                }));
                AccountApi.getEditPreferences(cbg.addFinal(new GerritCallback<EditPreferences>() {

                    @Override
                    public void onSuccess(EditPreferences prefs) {
                        EditPreferencesInfo prefsInfo = new EditPreferencesInfo();
                        prefs.copyTo(prefsInfo);
                        editPrefs = prefsInfo;
                    }
                }));
            } else {
                myAccount = AccountInfo.create(0, null, null, null);
                myPrefs = GeneralPreferences.createDefault();
                editPrefs = null;
                onModuleLoad2(result);
            }
        }
    }));
}
Also used : DocInfo(com.google.gerrit.client.documentation.DocInfo) ServerInfo(com.google.gerrit.client.info.ServerInfo) GeneralPreferences(com.google.gerrit.client.info.GeneralPreferences) CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) EditPreferences(com.google.gerrit.client.account.EditPreferences) HostPageData(com.google.gerrit.common.data.HostPageData) GerritCallback(com.google.gerrit.client.rpc.GerritCallback) EditPreferencesInfo(com.google.gerrit.extensions.client.EditPreferencesInfo) AccountInfo(com.google.gerrit.client.info.AccountInfo) KeyUtil(com.google.gwtorm.client.KeyUtil)

Example 2 with EditPreferencesInfo

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

the class EditPreferencesBox method onSave.

@UiHandler("save")
void onSave(@SuppressWarnings("unused") ClickEvent e) {
    AccountApi.putEditPreferences(prefs, new GerritCallback<EditPreferences>() {

        @Override
        public void onSuccess(EditPreferences p) {
            Gerrit.setEditPreferences(p.copyTo(new EditPreferencesInfo()));
        }
    });
    close();
}
Also used : EditPreferences(com.google.gerrit.client.account.EditPreferences) EditPreferencesInfo(com.google.gerrit.extensions.client.EditPreferencesInfo) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 3 with EditPreferencesInfo

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

the class SetEditPreferences method apply.

@Override
public EditPreferencesInfo apply(AccountResource rsrc, EditPreferencesInfo in) throws AuthException, BadRequestException, RepositoryNotFoundException, IOException, ConfigInvalidException, PermissionBackendException {
    if (self.get() != rsrc.getUser()) {
        permissionBackend.user(self).check(GlobalPermission.MODIFY_ACCOUNT);
    }
    if (in == null) {
        throw new BadRequestException("input must be provided");
    }
    Account.Id accountId = rsrc.getUser().getAccountId();
    VersionedAccountPreferences prefs;
    EditPreferencesInfo out = new EditPreferencesInfo();
    try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
        prefs = VersionedAccountPreferences.forUser(accountId);
        prefs.load(md);
        storeSection(prefs.getConfig(), UserConfigSections.EDIT, null, readFromGit(accountId, gitMgr, allUsersName, in), EditPreferencesInfo.defaults());
        prefs.commit(md);
        out = loadSection(prefs.getConfig(), UserConfigSections.EDIT, null, out, EditPreferencesInfo.defaults(), null);
    }
    return out;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) EditPreferencesInfo(com.google.gerrit.extensions.client.EditPreferencesInfo) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 4 with EditPreferencesInfo

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

the class EditPreferencesIT method getSetEditPreferences.

@Test
public void getSetEditPreferences() throws Exception {
    EditPreferencesInfo out = gApi.accounts().id(admin.getId().toString()).getEditPreferences();
    assertThat(out.lineLength).isEqualTo(100);
    assertThat(out.indentUnit).isEqualTo(2);
    assertThat(out.tabSize).isEqualTo(8);
    assertThat(out.cursorBlinkRate).isEqualTo(0);
    assertThat(out.hideTopMenu).isNull();
    assertThat(out.showTabs).isTrue();
    assertThat(out.showWhitespaceErrors).isNull();
    assertThat(out.syntaxHighlighting).isTrue();
    assertThat(out.hideLineNumbers).isNull();
    assertThat(out.matchBrackets).isTrue();
    assertThat(out.lineWrapping).isNull();
    assertThat(out.autoCloseBrackets).isNull();
    assertThat(out.showBase).isNull();
    assertThat(out.theme).isEqualTo(Theme.DEFAULT);
    assertThat(out.keyMapType).isEqualTo(KeyMapType.DEFAULT);
    // change some default values
    out.lineLength = 80;
    out.indentUnit = 4;
    out.tabSize = 4;
    out.cursorBlinkRate = 500;
    out.hideTopMenu = true;
    out.showTabs = false;
    out.showWhitespaceErrors = true;
    out.syntaxHighlighting = false;
    out.hideLineNumbers = true;
    out.matchBrackets = false;
    out.lineWrapping = true;
    out.autoCloseBrackets = true;
    out.showBase = true;
    out.theme = Theme.TWILIGHT;
    out.keyMapType = KeyMapType.EMACS;
    EditPreferencesInfo info = gApi.accounts().id(admin.getId().toString()).setEditPreferences(out);
    assertEditPreferences(info, out);
    // Partially filled input record
    EditPreferencesInfo in = new EditPreferencesInfo();
    in.tabSize = 42;
    info = gApi.accounts().id(admin.getId().toString()).setEditPreferences(in);
    out.tabSize = in.tabSize;
    assertEditPreferences(info, out);
}
Also used : EditPreferencesInfo(com.google.gerrit.extensions.client.EditPreferencesInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with EditPreferencesInfo

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

the class GetEditPreferences method readFromGit.

static EditPreferencesInfo readFromGit(Account.Id id, GitRepositoryManager gitMgr, AllUsersName allUsersName, EditPreferencesInfo in) throws IOException, ConfigInvalidException, RepositoryNotFoundException {
    try (Repository git = gitMgr.openRepository(allUsersName)) {
        VersionedAccountPreferences p = VersionedAccountPreferences.forUser(id);
        p.load(git);
        return loadSection(p.getConfig(), UserConfigSections.EDIT, null, new EditPreferencesInfo(), EditPreferencesInfo.defaults(), in);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) EditPreferencesInfo(com.google.gerrit.extensions.client.EditPreferencesInfo)

Aggregations

EditPreferencesInfo (com.google.gerrit.extensions.client.EditPreferencesInfo)5 EditPreferences (com.google.gerrit.client.account.EditPreferences)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 DocInfo (com.google.gerrit.client.documentation.DocInfo)1 AccountInfo (com.google.gerrit.client.info.AccountInfo)1 GeneralPreferences (com.google.gerrit.client.info.GeneralPreferences)1 ServerInfo (com.google.gerrit.client.info.ServerInfo)1 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)1 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)1 HostPageData (com.google.gerrit.common.data.HostPageData)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 Account (com.google.gerrit.reviewdb.client.Account)1 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 KeyUtil (com.google.gwtorm.client.KeyUtil)1 Repository (org.eclipse.jgit.lib.Repository)1 Test (org.junit.Test)1