diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index e753bc0..627acda 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -3,6 +3,8 @@ import util.Directory._ import util.Implicits._ import util.{JGitUtil, FileTypeUtil, CompressUtil} +import model._ +import service._ import org.scalatra._ import java.io.File import java.util.Date @@ -10,16 +12,14 @@ import org.eclipse.jgit.lib._ import org.apache.commons.io.FileUtils import org.eclipse.jgit.treewalk._ -import org.eclipse.jgit.revwalk.RevCommit import org.eclipse.jgit.diff.DiffEntry.ChangeType -import org.eclipse.jgit.revwalk.RevWalk // TODO Should models move to other package? /** * The repository data. * * @param owner the user name of the repository owner - * @param repository the repository name + * @param name the repository name * @param url the repository URL * @param branchList the list of branch names * @param tags the list of tags @@ -70,10 +70,12 @@ */ case class TagInfo(name: String, time: Date, id: String) +class RepositoryViewerController extends RepositoryViewerControllerBase with ProjectService with AccountService + /** * The repository viewer. */ -class RepositoryViewerController extends ControllerBase { +trait RepositoryViewerControllerBase extends ControllerBase { self: ProjectService => // TODO separate to AccountController? /** @@ -81,8 +83,8 @@ */ get("/:owner") { val owner = params("owner") - - html.user(owner, getRepositories(owner).map(JGitUtil.getRepositoryInfo(owner, _, servletContext))) + + html.user(owner, getProjects(owner, servletContext)) } /** @@ -268,7 +270,7 @@ * * @param owner the repository owner * @param repository the repository name - * @param rev the branch name or commit id(optional) + * @param revstr the branch name or commit id(optional) * @param path the directory path (optional) * @return HTML of the file list */ diff --git a/src/main/scala/service/ProjectService.scala b/src/main/scala/service/ProjectService.scala index e6da3c7..9f0ac96 100644 --- a/src/main/scala/service/ProjectService.scala +++ b/src/main/scala/service/ProjectService.scala @@ -3,8 +3,11 @@ import model._ import scala.slick.driver.H2Driver.simple._ import Database.threadLocalSession +import util.JGitUtil +import javax.servlet.ServletContext trait ProjectService { self: AccountService => + import ProjectService._ /** * Creates a new project. @@ -41,10 +44,17 @@ * @param userName the user name * @return the project list which is sorted in descending order of lastActivityDate. */ - def getProjects(userName: String): List[Project] = { - Query(Projects) filter(_.userId is getUserId(userName).bind) sortBy(_.lastActivityDate desc) list + def getProjects(userName: String, servletContext: ServletContext): List[RepositoryInfo] = { + (Query(Projects) filter(_.userId is getUserId(userName).bind) sortBy(_.lastActivityDate desc) list).map { project => + val repositoryInfo = JGitUtil.getRepositoryInfo(userName, project.projectName, servletContext) + RepositoryInfo(userName, project.projectName, project, repositoryInfo.branchList, repositoryInfo.tags) + } } private def getUserId(userName: String): Long = getAccountByUserName(userName).get.userId.get } + +object ProjectService { + case class RepositoryInfo(owner: String, name: String, project: Project, branchList: List[String], tagInfo: List[app.TagInfo]) +} \ No newline at end of file diff --git a/src/main/twirl/user.scala.html b/src/main/twirl/user.scala.html index 2894d68..f2fa13b 100644 --- a/src/main/twirl/user.scala.html +++ b/src/main/twirl/user.scala.html @@ -1,4 +1,4 @@ -@(user: String, repositories: List[app.RepositoryInfo])(implicit context: app.Context) +@(user: String, repositories: List[service.ProjectService.RepositoryInfo])(implicit context: app.Context) @import context._ @main(user){