diff --git a/src/main/scala/app/IssuesController.scala b/src/main/scala/app/IssuesController.scala index 8daa38e..ad52bb7 100644 --- a/src/main/scala/app/IssuesController.scala +++ b/src/main/scala/app/IssuesController.scala @@ -6,11 +6,11 @@ import util.{WritableRepositoryAuthenticator, ReadableRepositoryAuthenticator, UsersOnlyAuthenticator} class IssuesController extends IssuesControllerBase - with IssuesService with RepositoryService with AccountService + with IssuesService with RepositoryService with AccountService with LabelsService with UsersOnlyAuthenticator with ReadableRepositoryAuthenticator with WritableRepositoryAuthenticator trait IssuesControllerBase extends ControllerBase { - self: IssuesService with RepositoryService + self: IssuesService with RepositoryService with LabelsService with UsersOnlyAuthenticator with ReadableRepositoryAuthenticator with WritableRepositoryAuthenticator => case class IssueForm(title: String, content: Option[String]) @@ -37,8 +37,8 @@ case "closed" => true } getOrElse false - issues.html.issues(searchIssue(owner, repository, closed), - getRepository(params("owner"), params("repository"), baseUrl).get) + issues.html.issues(searchIssue(owner, repository, closed), getLabels(owner, repository), + getRepository(owner, repository, baseUrl).get) } get("/:owner/:repository/issues/:id"){ diff --git a/src/main/scala/app/LabelsController.scala b/src/main/scala/app/LabelsController.scala index bdaf2de..f281ea8 100644 --- a/src/main/scala/app/LabelsController.scala +++ b/src/main/scala/app/LabelsController.scala @@ -1,7 +1,29 @@ package app +import jp.sf.amateras.scalatra.forms._ +import service._ +import util.WritableRepositoryAuthenticator + class LabelsController extends LabelsControllerBase + with LabelsService with RepositoryService with AccountService with WritableRepositoryAuthenticator trait LabelsControllerBase extends ControllerBase { + self: LabelsService with WritableRepositoryAuthenticator => + + case class LabelForm(labelName: String, color: String) + + val labelForm = mapping( + "labelName" -> trim(label("Label name", text(required, maxlength(100)))), + "color" -> trim(label("Color", text(required, maxlength(7)))) + )(LabelForm.apply) + + post("/:owner/:repository/issues/label/new", labelForm)(writableRepository { form => + val owner = params("owner") + val repository = params("repository") + + createLabel(owner, repository, form.labelName, form.color.substring(1)) + + redirect("/%s/%s/issues".format(owner, repository)) + }) } \ No newline at end of file diff --git a/src/main/scala/service/LabelsService.scala b/src/main/scala/service/LabelsService.scala index ec7eb53..0c5b469 100644 --- a/src/main/scala/service/LabelsService.scala +++ b/src/main/scala/service/LabelsService.scala @@ -16,4 +16,7 @@ .sortBy(_.labelName asc) .list + def createLabel(owner: String, repository: String, labelName: String, color: String): Unit = + Labels.ins insert (owner, repository, labelName, color) + } diff --git a/src/main/twirl/issues/issues.scala.html b/src/main/twirl/issues/issues.scala.html index 01e2ea1..5942583 100644 --- a/src/main/twirl/issues/issues.scala.html +++ b/src/main/twirl/issues/issues.scala.html @@ -1,4 +1,4 @@ -@(issues: List[model.Issue], repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context) +@(issues: List[model.Issue], labels: List[model.Label], repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context) @import context._ @import view.helpers._ @html.main("Issues - " + repository.owner + "/" + repository.name){ @@ -15,11 +15,27 @@ No milestone selected