mirror of
				https://github.com/gitbucket/gitbucket.git
				synced 2025-10-31 18:46:28 +01:00 
			
		
		
		
	Fix the index page.
This commit is contained in:
		| @@ -84,7 +84,7 @@ trait CreateRepositoryControllerBase extends ControllerBase { self: ProjectServi | ||||
|     def validate(name: String, value: String): Option[String] = { | ||||
|       if(!value.matches("^[a-zA-Z0-9\\-_]+$")){ | ||||
|         Some("Repository name contains invalid character.") | ||||
|       } else if(getRepositories(context.loginAccount.get.userName, servletContext).contains(value)){ | ||||
|       } else if(getRepositoriesOfUser(context.loginAccount.get.userName, servletContext).contains(value)){ | ||||
|         Some("Repository already exists.") | ||||
|       } else { | ||||
|         None | ||||
|   | ||||
| @@ -1,9 +1,13 @@ | ||||
| package app | ||||
|  | ||||
| class IndexController extends ControllerBase { | ||||
| import service._ | ||||
|  | ||||
| class IndexController extends IndexControllerBase with ProjectService with AccountService | ||||
|  | ||||
| trait IndexControllerBase extends ControllerBase { self: ProjectService => | ||||
|    | ||||
|   get("/"){ | ||||
|     html.index() | ||||
|     html.index(getAccessibleRepositories(context.loginAccount, servletContext)) | ||||
|   } | ||||
|  | ||||
| } | ||||
| @@ -25,7 +25,7 @@ trait RepositoryViewerControllerBase extends ControllerBase { self: ProjectServi | ||||
|   get("/:owner") { | ||||
|     val owner = params("owner") | ||||
|  | ||||
|     html.user(getAccountByUserName(owner).get, getRepositories(owner, servletContext)) | ||||
|     html.user(getAccountByUserName(owner).get, getRepositoriesOfUser(owner, servletContext)) | ||||
|   } | ||||
|    | ||||
|   /** | ||||
|   | ||||
| @@ -6,6 +6,10 @@ import Database.threadLocalSession | ||||
|  | ||||
| trait AccountService { | ||||
|  | ||||
|   def getAccountByUserId(userId: Long): Option[Account] = | ||||
|     Query(Accounts) filter(_.userId is userId.bind) firstOption | ||||
|  | ||||
|  | ||||
|   def getAccountByUserName(userName: String): Option[Account] = | ||||
|     Query(Accounts) filter(_.userName is userName.bind) firstOption | ||||
|  | ||||
|   | ||||
| @@ -44,10 +44,10 @@ trait ProjectService { self: AccountService => | ||||
|    * @param userName the user name | ||||
|    * @return the project list which is sorted in descending order of lastActivityDate. | ||||
|    */ | ||||
|   def getRepositories(userName: String, servletContext: ServletContext): List[RepositoryInfo] = { | ||||
|   def getRepositoriesOfUser(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, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags) | ||||
|       RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags) | ||||
|     } | ||||
|   } | ||||
|  | ||||
| @@ -56,10 +56,31 @@ trait ProjectService { self: AccountService => | ||||
|       (project.userId is getUserId(userName).bind) && (project.projectName is projectName.bind) | ||||
|     } firstOption) map { project => | ||||
|       val repositoryInfo = JGitUtil.getRepositoryInfo(userName, project.projectName, servletContext) | ||||
|       RepositoryInfo(userName, project.projectName, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags) | ||||
|       RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   def getAccessibleRepositories(account: Option[Account], servletContext: ServletContext): List[RepositoryInfo] = { | ||||
|     account match { | ||||
|       case Some(x) => { | ||||
|         (Query(Projects) sortBy(_.lastActivityDate desc) list) map { project => | ||||
|           // TODO ユーザ名はジョインして取得する? | ||||
|           val repositoryInfo = JGitUtil.getRepositoryInfo(getUserName(project.userId), project.projectName, servletContext) | ||||
|           RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags) | ||||
|         } | ||||
|       } | ||||
|       case None => { | ||||
|         (Query(Projects) filter(_.projectType is 0.bind) sortBy(_.lastActivityDate desc) list) map { project => | ||||
|           // TODO ユーザ名はジョインして取得する? | ||||
|           val repositoryInfo = JGitUtil.getRepositoryInfo(getUserName(project.userId), project.projectName, servletContext) | ||||
|           RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, project, repositoryInfo.branchList, repositoryInfo.tags) | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   private def getUserName(userId: Long): String = getAccountByUserId(userId).get.userName | ||||
|  | ||||
|   private def getUserId(userName: String): Long = getAccountByUserName(userName).get.userId.get | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,9 +1,12 @@ | ||||
| @()(implicit context: app.Context) | ||||
| @(repositories: List[service.ProjectService.RepositoryInfo])(implicit context: app.Context) | ||||
| @import context._ | ||||
| @main("GitBucket"){ | ||||
|   <h1>GitBucket</h1> | ||||
|   <ul> | ||||
|     <li><a href="@path/@context.loginAccount.get.userName">User page</a></li> | ||||
|     <li><a href="@path/new">Create new repository</a></li> | ||||
|   </ul> | ||||
|   <h3>Recent updated repositories</h3> | ||||
|   @repositories.map { repository => | ||||
|     <div class="block"> | ||||
|       <div class="block-header-2"><a href="@path/@repository.owner/@repository.name">@repository.owner/@repository.name</a></div> | ||||
|       <div>@repository.project.description</div> | ||||
|       <div><span class="description small">Last updated: @repository.project.lastActivityDate</span></div> | ||||
|     </div> | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user