Save repository options.

This commit is contained in:
takezoe
2013-06-04 18:23:51 +09:00
parent 118e32662d
commit 79a0ba5630
3 changed files with 48 additions and 14 deletions

View File

@@ -5,12 +5,19 @@ import jp.sf.amateras.scalatra.forms._
class SettingsController extends SettingsControllerBase with RepositoryService with AccountService class SettingsController extends SettingsControllerBase with RepositoryService with AccountService
trait SettingsControllerBase extends ControllerBase { self: RepositoryService with AccountService => trait SettingsControllerBase extends ControllerBase { self: RepositoryService with AccountService =>
case class OptionsForm(description: Option[String], defaultBranch: String, repositoryType: Int)
val optionsForm = mapping(
"description" -> trim(label("Description" , optional(text()))),
"defaultBranch" -> trim(label("Default Branch" , text(required, maxlength(100)))),
"repositoryType" -> trim(label("Repository Type", number()))
)(OptionsForm.apply)
case class CollaboratorForm(userName: String) case class CollaboratorForm(userName: String)
val form = mapping( val collaboratorForm = mapping(
"userName" -> trim(label("Username", text(required, collaborator))) "userName" -> trim(label("Username", text(required, collaborator)))
)(CollaboratorForm.apply) )(CollaboratorForm.apply)
@@ -27,6 +34,16 @@ trait SettingsControllerBase extends ControllerBase { self: RepositoryService wi
settings.html.options(getRepository(owner, repository, servletContext).get) settings.html.options(getRepository(owner, repository, servletContext).get)
}) })
post("/:owner/:repository/settings/options", optionsForm){ form =>
val owner = params("owner")
val repository = params("repository")
// save repository options
saveRepositoryOptions(owner, repository, form.description, form.defaultBranch, form.repositoryType)
redirect("%s/%s/settings/options".format(owner, repository))
}
get("/:owner/:repository/settings/collaborators")(ownerOnly { get("/:owner/:repository/settings/collaborators")(ownerOnly {
val owner = params("owner") val owner = params("owner")
val repository = params("repository") val repository = params("repository")
@@ -34,7 +51,7 @@ trait SettingsControllerBase extends ControllerBase { self: RepositoryService wi
settings.html.collaborators(getCollaborators(owner, repository), getRepository(owner, repository, servletContext).get) settings.html.collaborators(getCollaborators(owner, repository), getRepository(owner, repository, servletContext).get)
}) })
post("/:owner/:repository/settings/collaborators/_add", form)(ownerOnly { form => post("/:owner/:repository/settings/collaborators/_add", collaboratorForm)(ownerOnly { form =>
val owner = params("owner") val owner = params("owner")
val repository = params("repository") val repository = params("repository")
addCollaborator(owner, repository, form.userName) addCollaborator(owner, repository, form.userName)

View File

@@ -106,13 +106,21 @@ trait RepositoryService { self: AccountService =>
/** /**
* Updates the last activity date of the repository. * Updates the last activity date of the repository.
*/ */
def updateLastActivityDate(userName: String, repositoryName: String): Unit = { def updateLastActivityDate(userName: String, repositoryName: String): Unit =
val q = for { Query(Repositories)
r <- Repositories if (r.userName is userName.bind) && (r.repositoryName is repositoryName.bind) .filter { r => (r.userName is userName.bind) && (r.repositoryName is repositoryName.bind) }
} yield r.lastActivityDate .map { _.lastActivityDate }
.update (new java.sql.Date(System.currentTimeMillis))
q.update(new java.sql.Date(System.currentTimeMillis))
} /**
* Save repository options.
*/
def saveRepositoryOptions(userName: String, repositoryName: String,
description: Option[String], defaultBranch: String, repositoryType: Int): Unit =
Query(Repositories)
.filter { r => (r.userName is userName.bind) && (r.repositoryName is repositoryName.bind) }
.map { r => r.description.? ~ r.defaultBranch ~ r.repositoryType ~ r.updatedDate }
.update (description, defaultBranch, repositoryType, new java.sql.Date(System.currentTimeMillis))
/** /**
* Add collaborator to the repository. * Add collaborator to the repository.

View File

@@ -3,30 +3,38 @@
@html.main("Settings"){ @html.main("Settings"){
@html.header("settings", repository) @html.header("settings", repository)
@menu("options", repository){ @menu("options", repository){
<form id="form" method="post" action="@path/new" validate="true"> <form id="form" method="post" action="@path/@repository.owner/@repository.name/settings/options" validate="true">
<div class="box"> <div class="box">
<div class="box-header">Settings</div> <div class="box-header">Settings</div>
<div class="box-content"> <div class="box-content">
<fieldset>
<label for="description"><strong>Description</strong></label>
<input type="text" name="description" id="description" style="width: 600px;" value="@repository.repository.description"/>
</fieldset>
<hr>
<fieldset> <fieldset>
<label for="defaultBranch"><strong>Default Branch</strong></label> <label for="defaultBranch"><strong>Default Branch</strong></label>
<select name="defaultBranch" id="defaultBranch"> <select name="defaultBranch" id="defaultBranch">
<option value="master">master</option> @repository.branchList.map { branch =>
<option value="@branch"@if(branch==repository.repository.defaultBranch){ selected}>@branch</option>
}
</select> </select>
</fieldset> </fieldset>
<hr> <hr>
<fieldset> <fieldset>
<label><strong>Repository Type</strong></label> <label><strong>Repository Type</strong></label>
<label> <label>
<input type="radio" name="repositoryType" value="0" checked> <input type="radio" name="repositoryType" value="0"@if(repository.repository.repositoryType==0){ checked}>
<strong>Public</strong> - All users and guests can read this repository. <strong>Public</strong> - All users and guests can read this repository.
</label> </label>
<label> <label>
<input type="radio" name="repositoryType" value="1"> <input type="radio" name="repositoryType" value="1"@if(repository.repository.repositoryType==1){ checked}>
<strong>Private</strong> - Only collaborators can read this repository. <strong>Private</strong> - Only collaborators can read this repository.
</label> </label>
</fieldset> </fieldset>
</div> </div>
</div> </div>
<!--
<div class="box"> <div class="box">
<div class="box-header">Features</div> <div class="box-header">Features</div>
<div class="box-content"> <div class="box-content">
@@ -56,6 +64,7 @@
</dl> </dl>
</div> </div>
</div> </div>
-->
<fieldset> <fieldset>
<input type="submit" class="btn btn-primary" value="Apply changes"/> <input type="submit" class="btn btn-primary" value="Apply changes"/>
<!-- <!--