Eliminate manual emtpy to none conversion. This may close #1396

This commit is contained in:
Istvan Meszaros
2017-06-12 06:52:49 +02:00
parent 9ffae4241d
commit 9799735420
4 changed files with 11 additions and 13 deletions

View File

@@ -16,11 +16,11 @@ trait PrioritiesControllerBase extends ControllerBase {
self: PrioritiesService with IssuesService with RepositoryService
with ReferrerAuthenticator with WritableUsersAuthenticator =>
case class PriorityForm(priorityName: String, description: String, color: String)
case class PriorityForm(priorityName: String, description: Option[String], color: String)
val priorityForm = mapping(
"priorityName" -> trim(label("Priority name", text(required, priorityName, uniquePriorityName, maxlength(100)))),
"description" -> trim(label("Description", text(maxlength(255)))),
"description" -> trim(label("Description", optional(text(maxlength(255))))),
"priorityColor" -> trim(label("Color", text(required, color)))
)(PriorityForm.apply)

View File

@@ -16,7 +16,7 @@ trait PrioritiesService {
def getPriority(owner: String, repository: String, priorityName: String)(implicit s: Session): Option[Priority] =
Priorities.filter(_.byPriority(owner, repository, priorityName)).firstOption
def createPriority(owner: String, repository: String, priorityName: String, description: String, color: String)(implicit s: Session): Int = {
def createPriority(owner: String, repository: String, priorityName: String, description: Option[String], color: String)(implicit s: Session): Int = {
val ordering = Priorities.filter(_.byRepository(owner, repository))
.list
.map(p => p.ordering)
@@ -28,18 +28,18 @@ trait PrioritiesService {
userName = owner,
repositoryName = repository,
priorityName = priorityName,
description = StringUtil.emptyToNone(description),
description = description,
isDefault = false,
ordering = ordering,
color = color
)
}
def updatePriority(owner: String, repository: String, priorityId: Int, priorityName: String, description: String, color: String)
def updatePriority(owner: String, repository: String, priorityId: Int, priorityName: String, description: Option[String], color: String)
(implicit s: Session): Unit =
Priorities.filter(_.byPrimaryKey(owner, repository, priorityId))
.map(t => (t.priorityName, t.description.?, t.color))
.update(priorityName, StringUtil.emptyToNone(description), color)
.update(priorityName, description, color)
def reorderPriorities(owner: String, repository: String, order: Map[Int, Int])
(implicit s: Session): Unit = {

View File

@@ -78,11 +78,11 @@ trait RepositoryCreationService {
}
def insertDefaultPriorities(userName: String, repositoryName: String)(implicit s: Session): Unit = {
createPriority(userName, repositoryName, "highest", "All defects at this priority must be fixed before any public product is delivered.", "fc2929")
createPriority(userName, repositoryName, "very high", "Issues must be addressed before a final product is delivered.", "fc5629")
createPriority(userName, repositoryName, "high", "Issues should be addressed before a final product is delivered. If the issue cannot be resolved before delivery, it should be prioritized for the next release.", "fc9629")
createPriority(userName, repositoryName, "important", "Issues can be shipped with a final product, but should be reviewed before the next release.", "fccd29")
createPriority(userName, repositoryName, "default", "Default.", "acacac")
createPriority(userName, repositoryName, "highest", Some("All defects at this priority must be fixed before any public product is delivered."), "fc2929")
createPriority(userName, repositoryName, "very high", Some("Issues must be addressed before a final product is delivered."), "fc5629")
createPriority(userName, repositoryName, "high", Some("Issues should be addressed before a final product is delivered. If the issue cannot be resolved before delivery, it should be prioritized for the next release."), "fc9629")
createPriority(userName, repositoryName, "important", Some("Issues can be shipped with a final product, but should be reviewed before the next release."), "fccd29")
createPriority(userName, repositoryName, "default", Some("Default."), "acacac")
setDefaultPriority(userName, repositoryName, getPriority(userName, repositoryName, "default").map(_.priorityId))
}

View File

@@ -136,6 +136,4 @@ object StringUtil {
// }
// b.toString
// }
def emptyToNone(str: String): Option[String] = Option(str).map(_.trim).flatMap(s => if (s.isEmpty) None else Some(s));
}