private void addPreferences(UserModel user) { // add preferences Form<Void> prefs = new Form<Void>("prefsForm"); List<Language> languages = Arrays.asList( new Language("Deutsch", "de"), new Language("English", "en"), new Language("Español", "es"), new Language("Français", "fr"), new Language("Italiano", "it"), new Language("日本語", "ja"), new Language("한국말", "ko"), new Language("Nederlands", "nl"), new Language("Norsk", "no"), new Language("Język Polski", "pl"), new Language("Português", "pt_BR"), new Language("簡體中文", "zh_CN"), new Language("正體中文", "zh_TW")); Locale locale = user.getPreferences().getLocale(); if (locale == null) { // user has not specified language preference // try server default preference String lc = app().settings().getString(Keys.web.forceDefaultLocale, null); if (StringUtils.isEmpty(lc)) { // server default language is not configured // try browser preference Locale sessionLocale = GitBlitWebSession.get().getLocale(); if (sessionLocale != null) { locale = sessionLocale; } } else { } } Language preferredLanguage = null; if (locale != null) { String localeCode = locale.getLanguage(); if (!StringUtils.isEmpty(locale.getCountry())) { localeCode += "_" + locale.getCountry(); } for (Language language : languages) { if (language.code.equals(localeCode)) { // language_COUNTRY match preferredLanguage = language; } else if (preferredLanguage != null && language.code.startsWith(locale.getLanguage())) { // language match preferredLanguage = language; } } } final IModel<String> displayName = Model.of(user.getDisplayName()); final IModel<String> emailAddress = Model.of(user.emailAddress == null ? "" : user.emailAddress); final IModel<Language> language = Model.of(preferredLanguage); final IModel<Boolean> emailMeOnMyTicketChanges = Model.of(user.getPreferences().isEmailMeOnMyTicketChanges()); final IModel<Transport> transport = Model.of(user.getPreferences().getTransport()); prefs.add( new TextOption( "displayName", getString("gb.displayName"), getString("gb.displayNameDescription"), displayName) .setVisible(app().authentication().supportsDisplayNameChanges(user))); prefs.add( new TextOption( "emailAddress", getString("gb.emailAddress"), getString("gb.emailAddressDescription"), emailAddress) .setVisible(app().authentication().supportsEmailAddressChanges(user))); prefs.add( new ChoiceOption<Language>( "language", getString("gb.languagePreference"), getString("gb.languagePreferenceDescription"), language, languages)); prefs.add( new BooleanOption( "emailMeOnMyTicketChanges", getString("gb.emailMeOnMyTicketChanges"), getString("gb.emailMeOnMyTicketChangesDescription"), emailMeOnMyTicketChanges) .setVisible(app().notifier().isSendingMail())); List<Transport> availableTransports = new ArrayList<>(); if (app().services().isServingSSH()) { availableTransports.add(Transport.SSH); } if (app().services().isServingHTTP()) { availableTransports.add(Transport.HTTP); } if (app().services().isServingHTTPS()) { availableTransports.add(Transport.HTTPS); } if (app().services().isServingGIT()) { availableTransports.add(Transport.GIT); } prefs.add( new ChoiceOption<Transport>( "transport", getString("gb.transportPreference"), getString("gb.transportPreferenceDescription"), transport, availableTransports)); prefs.add( new AjaxButton("save") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { UserModel user = GitBlitWebSession.get().getUser(); user.displayName = displayName.getObject(); user.emailAddress = emailAddress.getObject(); Language lang = language.getObject(); if (lang != null) { user.getPreferences().setLocale(lang.code); } user.getPreferences().setEmailMeOnMyTicketChanges(emailMeOnMyTicketChanges.getObject()); user.getPreferences().setTransport(transport.getObject()); try { app().gitblit().reviseUser(user.username, user); setRedirect(true); setResponsePage(UserPage.class, WicketUtils.newUsernameParameter(user.username)); } catch (GitBlitException e) { // logger.error("Failed to update user " + user.username, e); // error(getString("gb.failedToUpdateUser"), false); } } }); // add the preferences tab add(new Fragment("preferencesLink", "preferencesLinkFragment", this).setRenderBodyOnly(true)); Fragment fragment = new Fragment("preferencesTab", "preferencesTabFragment", this); fragment.add(prefs); add(fragment.setRenderBodyOnly(true)); }
private void setup(PageParameters params) { setupPage("", ""); // check to see if we should display a login message boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, true); if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) { String messageSource = GitBlit.getString(Keys.web.loginMessage, "gitblit"); String message = readMarkdown(messageSource, "login.mkd"); Component repositoriesMessage = new Label("repositoriesMessage", message); add(repositoriesMessage.setEscapeModelStrings(false)); add(new Label("activity").setVisible(false)); add(new Label("repositoryTabs").setVisible(false)); return; } // Load the markdown welcome message String messageSource = GitBlit.getString(Keys.web.repositoriesMessage, "gitblit"); String message = readMarkdown(messageSource, "welcome.mkd"); Component repositoriesMessage = new Label("repositoriesMessage", message) .setEscapeModelStrings(false) .setVisible(message.length() > 0); add(repositoriesMessage); UserModel user = GitBlitWebSession.get().getUser(); if (user == null) { user = UserModel.ANONYMOUS; } // parameters int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params); if (daysBack < 1) { daysBack = GitBlit.getInteger(Keys.web.activityDuration, 7); } Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, -1 * daysBack); Date minimumDate = c.getTime(); // build repo lists List<RepositoryModel> starred = new ArrayList<RepositoryModel>(); List<RepositoryModel> owned = new ArrayList<RepositoryModel>(); List<RepositoryModel> active = new ArrayList<RepositoryModel>(); for (RepositoryModel model : getRepositoryModels()) { if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) { owned.add(model); } if (user.getPreferences().isStarredRepository(model.name)) { starred.add(model); } if (model.isShowActivity() && model.lastChange.after(minimumDate)) { active.add(model); } } Comparator<RepositoryModel> lastUpdateSort = new Comparator<RepositoryModel>() { @Override public int compare(RepositoryModel o1, RepositoryModel o2) { return o2.lastChange.compareTo(o1.lastChange); } }; Collections.sort(owned, lastUpdateSort); Collections.sort(starred, lastUpdateSort); Collections.sort(active, lastUpdateSort); String activityTitle; Set<RepositoryModel> feed = new HashSet<RepositoryModel>(); feed.addAll(starred); feed.addAll(owned); if (feed.isEmpty()) { // no starred or owned, go with recent activity activityTitle = getString("gb.recentActivity"); feed.addAll(active); } else if (starred.isEmpty()) { // no starred, owned repos feed activityTitle = getString("gb.owned"); } else if (owned.isEmpty()) { // no owned, starred repos feed activityTitle = getString("gb.starred"); } else { // starred and owned repositories activityTitle = getString("gb.starredAndOwned"); } addActivity(user, feed, activityTitle, daysBack); Fragment repositoryTabs; if (UserModel.ANONYMOUS.equals(user)) { repositoryTabs = new Fragment("repositoryTabs", "anonymousTabsFragment", this); } else { repositoryTabs = new Fragment("repositoryTabs", "authenticatedTabsFragment", this); } add(repositoryTabs); // projects list List<ProjectModel> projects = GitBlit.self().getProjectModels(getRepositoryModels(), false); repositoryTabs.add(new FilterableProjectList("projects", projects)); // active repository list if (active.isEmpty()) { repositoryTabs.add(new Label("active").setVisible(false)); } else { FilterableRepositoryList repoList = new FilterableRepositoryList("active", active); repoList.setTitle(getString("gb.activeRepositories"), "icon-time"); repositoryTabs.add(repoList); } // starred repository list if (ArrayUtils.isEmpty(starred)) { repositoryTabs.add(new Label("starred").setVisible(false)); } else { FilterableRepositoryList repoList = new FilterableRepositoryList("starred", starred); repoList.setTitle(getString("gb.starredRepositories"), "icon-star"); repositoryTabs.add(repoList); } // owned repository list if (ArrayUtils.isEmpty(owned)) { repositoryTabs.add(new Label("owned").setVisible(false)); } else { FilterableRepositoryList repoList = new FilterableRepositoryList("owned", owned); repoList.setTitle(getString("gb.myRepositories"), "icon-user"); repoList.setAllowCreate(user.canCreate() || user.canAdmin()); repositoryTabs.add(repoList); } }