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);
}
}
}));
}
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();
}
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;
}
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);
}
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);
}
}
Aggregations