From 1be31659e7e92c0fdc32e629d059d2aed5fe3a63 Mon Sep 17 00:00:00 2001
From: Rafael Cavazin <rafaelcavazin@gmail.com>
Date: Sun, 21 Jul 2013 11:12:11 -0400
Subject: [PATCH] Translation of lastest Strings up-do-date. Tradução das últimas Strings até a data atual.

---
 src/main/java/com/gitblit/wicket/pages/RepositoryPage.java |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 101 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
index 94adf56..f5b8c96 100644
--- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
@@ -19,6 +19,7 @@
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -28,6 +29,7 @@
 
 import org.apache.wicket.Component;
 import org.apache.wicket.PageParameters;
+import org.apache.wicket.behavior.SimpleAttributeModifier;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.form.DropDownChoice;
 import org.apache.wicket.markup.html.form.TextField;
@@ -41,9 +43,12 @@
 import org.eclipse.jgit.lib.PersonIdent;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.gitblit.Constants;
 import com.gitblit.GitBlit;
+import com.gitblit.GitBlitException;
 import com.gitblit.Keys;
 import com.gitblit.PagesServlet;
 import com.gitblit.SyndicationServlet;
@@ -52,11 +57,14 @@
 import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.SubmoduleModel;
 import com.gitblit.models.UserModel;
+import com.gitblit.models.UserRepositoryPreferences;
 import com.gitblit.utils.ArrayUtils;
+import com.gitblit.utils.DeepCopier;
 import com.gitblit.utils.JGitUtils;
-import com.gitblit.utils.PushLogUtils;
+import com.gitblit.utils.RefLogUtils;
 import com.gitblit.utils.StringUtils;
 import com.gitblit.utils.TicgitUtils;
+import com.gitblit.wicket.CacheControl;
 import com.gitblit.wicket.GitBlitWebSession;
 import com.gitblit.wicket.PageRegistration;
 import com.gitblit.wicket.PageRegistration.OtherPageLink;
@@ -67,7 +75,11 @@
 import com.gitblit.wicket.panels.RefsPanel;
 
 public abstract class RepositoryPage extends RootPage {
+	
+	private final Logger logger = LoggerFactory.getLogger(getClass());
 
+	private final String PARAM_STAR = "star";
+	
 	protected final String projectName;
 	protected final String repositoryName;
 	protected final String objectId;
@@ -104,7 +116,7 @@
 		if (getRepositoryModel().isCollectingGarbage) {
 			error(MessageFormat.format(getString("gb.busyCollectingGarbage"), getRepositoryModel().name), true);
 		}
-
+		
 		if (objectId != null) {
 			RefModel branch = null;
 			if ((branch = JGitUtils.getBranch(getRepository(), objectId)) != null) {
@@ -117,6 +129,22 @@
 								branch.reference.getName());
 				if (!canAccess) {
 					error(getString("gb.accessDenied"), true);
+				}
+			}
+		}
+		
+		if (params.containsKey(PARAM_STAR)) {
+			// set starred state
+			boolean star = params.getBoolean(PARAM_STAR);
+			UserModel user = GitBlitWebSession.get().getUser();
+			if (user != null && user.isAuthenticated) {
+				UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(getRepositoryModel().name);
+				prefs.starred = star;
+				try {
+					GitBlit.self().updateUserModel(user.username, user, false);
+				} catch (GitBlitException e) {
+					logger.error("Failed to update user " + user.username, e);
+					error(getString("gb.failedToUpdateUser"), false);
 				}
 			}
 		}
@@ -161,31 +189,31 @@
 		RepositoryModel model = getRepositoryModel();
 
 		// standard links
-		if (PushLogUtils.getPushLogBranch(r) == null) {
+		if (RefLogUtils.getRefLogBranch(r) == null) {
 			pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
 		} else {
 			pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
 //			pages.put("overview", new PageRegistration("gb.overview", OverviewPage.class, params));
-			pages.put("pushes", new PageRegistration("gb.pushes", PushesPage.class, params));
+			pages.put("reflog", new PageRegistration("gb.reflog", ReflogPage.class, params));
 		}		
 		pages.put("commits", new PageRegistration("gb.commits", LogPage.class, params));
 		pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params));
-		pages.put("compare", new PageRegistration("gb.compare", ComparePage.class, params));
+		pages.put("compare", new PageRegistration("gb.compare", ComparePage.class, params, true));
 		if (GitBlit.getBoolean(Keys.web.allowForking, true)) {
-			pages.put("forks", new PageRegistration("gb.forks", ForksPage.class, params));
+			pages.put("forks", new PageRegistration("gb.forks", ForksPage.class, params, true));
 		}
 
 		// conditional links
 		// per-repository extra page links
 		if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {
-			pages.put("tickets", new PageRegistration("gb.tickets", TicketsPage.class, params));
+			pages.put("tickets", new PageRegistration("gb.tickets", TicketsPage.class, params, true));
 		}
 		if (model.showReadme || model.useDocs) {
-			pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params));
+			pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params, true));
 		}
 		if (JGitUtils.getPagesBranch(r) != null) {
 			OtherPageLink pagesLink = new OtherPageLink("gb.pages", PagesServlet.asLink(
-					getRequest().getRelativePathPrefixToContextRoot(), repositoryName, null));
+					getRequest().getRelativePathPrefixToContextRoot(), repositoryName, null), true);
 			pages.put("pages", pagesLink);
 		}
 
@@ -200,9 +228,6 @@
 		isOwner = GitBlitWebSession.get().isLoggedIn()
 				&& (model.isOwner(GitBlitWebSession.get()
 						.getUsername()));
-		if (showAdmin || isOwner) {
-			pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));
-		}
 		return pages;
 	}
 	
@@ -260,6 +285,26 @@
 			}
 		}
 		
+		// (un)star link allows a user to star a repository
+		if (user.isAuthenticated) {
+			PageParameters starParams = DeepCopier.copy(getPageParameters());
+			starParams.put(PARAM_STAR, !user.getPreferences().isStarredRepository(model.name));
+			String toggleStarUrl = getRequestCycle().urlFor(getClass(), starParams).toString();
+			if (user.getPreferences().isStarredRepository(model.name)) {
+				// show unstar button
+				add(new Label("starLink").setVisible(false));
+				addToolbarButton("unstarLink", "icon-star-empty", getString("gb.unstar"), toggleStarUrl);
+			} else {
+				// show star button
+				addToolbarButton("starLink", "icon-star", getString("gb.star"), toggleStarUrl);
+				add(new Label("unstarLink").setVisible(false));
+			}
+		} else {
+			// anonymous user
+			add(new Label("starLink").setVisible(false));
+			add(new Label("unstarLink").setVisible(false));
+		}
+
 		// fork controls
 		if (!allowForkControls() || user == null || !user.isAuthenticated) {
 			// must be logged-in to fork, hide all fork controls
@@ -290,7 +335,24 @@
 			}
 		}
 		
+		if (showAdmin || isOwner) {
+			String url = getRequestCycle().urlFor(EditRepositoryPage.class, WicketUtils.newRepositoryParameter(model.name)).toString();
+			add(new ExternalLink("editLink", url)); 
+		} else {
+			add(new Label("editLink").setVisible(false));
+		}
+		
 		super.setupPage(repositoryName, pageName);
+	}
+	
+	protected void addToolbarButton(String wicketId, String iconClass, String label, String url) {
+		Fragment button = new Fragment(wicketId, "toolbarLinkFragment", this);
+		Label icon = new Label("icon");
+		WicketUtils.setCssClass(icon, iconClass);
+		button.add(icon);
+		button.add(new Label("label", label));
+		button.add(new SimpleAttributeModifier("href", url));
+		add(button);
 	}
 
 	protected void addSyndicationDiscoveryLink() {
@@ -334,7 +396,8 @@
 		RevCommit commit = JGitUtils.getCommit(r, objectId);
 		if (commit == null) {
 			error(MessageFormat.format(getString("gb.failedToFindCommit"),
-					objectId, repositoryName, getPageName()), true);
+					objectId, repositoryName, getPageName()), null, LogPage.class,
+					WicketUtils.newRepositoryParameter(repositoryName));
 		}
 		getSubmodules(commit);
 		return commit;
@@ -385,7 +448,7 @@
 			if (submoduleName.lastIndexOf('/') > -1) {
 				String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
 				candidates.add(currentPath + StringUtils.stripDotGit(name));
-				candidates.add(currentPath + candidates.get(candidates.size() - 1) + ".git");
+				candidates.add(candidates.get(candidates.size() - 1) + ".git");
 			}
 
 			// absolute
@@ -511,6 +574,30 @@
 		setupPage(repositoryName, "/ " + getPageName());
 		super.onBeforeRender();
 	}
+	
+	@Override
+	protected void setLastModified() {
+		if (getClass().isAnnotationPresent(CacheControl.class)) {
+			CacheControl cacheControl = getClass().getAnnotation(CacheControl.class);
+			switch (cacheControl.value()) {
+			case REPOSITORY:
+				RepositoryModel repository = getRepositoryModel();
+				if (repository != null) {
+					setLastModified(repository.lastChange);
+				}
+				break;
+			case COMMIT:
+				RevCommit commit = getCommit();
+				if (commit != null) {
+					Date commitDate = JGitUtils.getCommitDate(commit);
+					setLastModified(commitDate);
+				}
+				break;
+			default:
+				super.setLastModified();
+			}
+		}
+	}
 
 	protected PageParameters newRepositoryParameter() {
 		return WicketUtils.newRepositoryParameter(repositoryName);

--
Gitblit v1.9.1