mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 15:05:50 +01:00
Retrieve project information from DB at the repository list.
This commit is contained in:
@@ -3,6 +3,8 @@ package app
|
||||
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.api.Git
|
||||
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 ContentInfo(viewType: String, content: Option[String])
|
||||
*/
|
||||
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?
|
||||
/**
|
||||
@@ -82,7 +84,7 @@ class RepositoryViewerController extends ControllerBase {
|
||||
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 @@ class RepositoryViewerController extends ControllerBase {
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
@@ -3,8 +3,11 @@ package service
|
||||
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 @@ trait ProjectService { self: AccountService =>
|
||||
* @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])
|
||||
}
|
||||
@@ -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){
|
||||
<div class="container-fluid">
|
||||
@@ -26,8 +26,8 @@
|
||||
@repositories.map { repository =>
|
||||
<div class="block">
|
||||
<div class="block-header-2"><a href="@path/@user/@repository.name">@repository.name</a></div>
|
||||
<div>xxxxxxxxxxxxxxxxxxxx</div>
|
||||
<div><span class="description small">Last updated: yyyy/mm/dd</span></div>
|
||||
<div>@repository.project.description</div>
|
||||
<div><span class="description small">Last updated: @repository.project.lastActivityDate</span></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user