Retrieve project information from DB at the repository list.

This commit is contained in:
takezoe
2013-06-02 15:02:53 +09:00
parent 8c41dc3396
commit 2e61598a57
3 changed files with 24 additions and 12 deletions

View File

@@ -3,6 +3,8 @@ package app
import util.Directory._ import util.Directory._
import util.Implicits._ import util.Implicits._
import util.{JGitUtil, FileTypeUtil, CompressUtil} import util.{JGitUtil, FileTypeUtil, CompressUtil}
import model._
import service._
import org.scalatra._ import org.scalatra._
import java.io.File import java.io.File
import java.util.Date import java.util.Date
@@ -10,16 +12,14 @@ import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib._ import org.eclipse.jgit.lib._
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import org.eclipse.jgit.treewalk._ import org.eclipse.jgit.treewalk._
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.diff.DiffEntry.ChangeType import org.eclipse.jgit.diff.DiffEntry.ChangeType
import org.eclipse.jgit.revwalk.RevWalk
// TODO Should models move to other package? // TODO Should models move to other package?
/** /**
* The repository data. * The repository data.
* *
* @param owner the user name of the repository owner * @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 url the repository URL
* @param branchList the list of branch names * @param branchList the list of branch names
* @param tags the list of tags * @param tags the list of tags
@@ -70,10 +70,12 @@ case class ContentInfo(viewType: String, content: Option[String])
*/ */
case class TagInfo(name: String, time: Date, id: String) case class TagInfo(name: String, time: Date, id: String)
class RepositoryViewerController extends RepositoryViewerControllerBase with ProjectService with AccountService
/** /**
* The repository viewer. * The repository viewer.
*/ */
class RepositoryViewerController extends ControllerBase { trait RepositoryViewerControllerBase extends ControllerBase { self: ProjectService =>
// TODO separate to AccountController? // TODO separate to AccountController?
/** /**
@@ -82,7 +84,7 @@ class RepositoryViewerController extends ControllerBase {
get("/:owner") { get("/:owner") {
val owner = params("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 @@ class RepositoryViewerController extends ControllerBase {
* *
* @param owner the repository owner * @param owner the repository owner
* @param repository the repository name * @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) * @param path the directory path (optional)
* @return HTML of the file list * @return HTML of the file list
*/ */

View File

@@ -3,8 +3,11 @@ package service
import model._ import model._
import scala.slick.driver.H2Driver.simple._ import scala.slick.driver.H2Driver.simple._
import Database.threadLocalSession import Database.threadLocalSession
import util.JGitUtil
import javax.servlet.ServletContext
trait ProjectService { self: AccountService => trait ProjectService { self: AccountService =>
import ProjectService._
/** /**
* Creates a new project. * Creates a new project.
@@ -41,10 +44,17 @@ trait ProjectService { self: AccountService =>
* @param userName the user name * @param userName the user name
* @return the project list which is sorted in descending order of lastActivityDate. * @return the project list which is sorted in descending order of lastActivityDate.
*/ */
def getProjects(userName: String): List[Project] = { def getProjects(userName: String, servletContext: ServletContext): List[RepositoryInfo] = {
Query(Projects) filter(_.userId is getUserId(userName).bind) sortBy(_.lastActivityDate desc) list (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 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])
}

View File

@@ -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._ @import context._
@main(user){ @main(user){
<div class="container-fluid"> <div class="container-fluid">
@@ -26,8 +26,8 @@
@repositories.map { repository => @repositories.map { repository =>
<div class="block"> <div class="block">
<div class="block-header-2"><a href="@path/@user/@repository.name">@repository.name</a></div> <div class="block-header-2"><a href="@path/@user/@repository.name">@repository.name</a></div>
<div>xxxxxxxxxxxxxxxxxxxx</div> <div>@repository.project.description</div>
<div><span class="description small">Last updated: yyyy/mm/dd</span></div> <div><span class="description small">Last updated: @repository.project.lastActivityDate</span></div>
</div> </div>
} }
</div> </div>