mirror of
				https://github.com/gitbucket/gitbucket.git
				synced 2025-10-31 02:25:59 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Scala
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Scala
		
	
	
	
	
	
| package app
 | |
| 
 | |
| import jp.sf.amateras.scalatra.forms._
 | |
| import service._
 | |
| import util.CollaboratorsAuthenticator
 | |
| 
 | |
| class LabelsController extends LabelsControllerBase
 | |
|   with LabelsService with RepositoryService with AccountService with CollaboratorsAuthenticator
 | |
| 
 | |
| trait LabelsControllerBase extends ControllerBase {
 | |
|   self: LabelsService with RepositoryService with CollaboratorsAuthenticator =>
 | |
| 
 | |
|   case class LabelForm(labelName: String, color: String)
 | |
| 
 | |
|   val newForm = mapping(
 | |
|     "newLabelName" -> trim(label("Label name", text(required, identifier, maxlength(100)))),
 | |
|     "newColor"     -> trim(label("Color",      text(required, color)))
 | |
|   )(LabelForm.apply)
 | |
| 
 | |
|   val editForm = mapping(
 | |
|     "editLabelName" -> trim(label("Label name", text(required, identifier, maxlength(100)))),
 | |
|     "editColor"     -> trim(label("Color",      text(required, color)))
 | |
|   )(LabelForm.apply)
 | |
| 
 | |
|   post("/:owner/:repository/issues/label/new", newForm)(collaboratorsOnly { (form, repository) =>
 | |
|     createLabel(repository.owner, repository.name, form.labelName, form.color.substring(1))
 | |
|     redirect("/%s/%s/issues".format(repository.owner, repository.name))
 | |
|   })
 | |
| 
 | |
|   ajaxGet("/:owner/:repository/issues/label/edit")(collaboratorsOnly { repository =>
 | |
|     issues.labels.html.editlist(getLabels(repository.owner, repository.name), repository)
 | |
|   })
 | |
| 
 | |
|   ajaxGet("/:owner/:repository/issues/label/:labelId/edit")(collaboratorsOnly { repository =>
 | |
|     getLabel(repository.owner, repository.name, params("labelId").toInt).map { label =>
 | |
|       issues.labels.html.edit(Some(label), repository)
 | |
|     } getOrElse NotFound()
 | |
|   })
 | |
| 
 | |
|   ajaxPost("/:owner/:repository/issues/label/:labelId/edit", editForm)(collaboratorsOnly { (form, repository) =>
 | |
|     updateLabel(repository.owner, repository.name, params("labelId").toInt, form.labelName, form.color.substring(1))
 | |
|     issues.labels.html.editlist(getLabels(repository.owner, repository.name), repository)
 | |
|   })
 | |
| 
 | |
|   ajaxGet("/:owner/:repository/issues/label/:labelId/delete")(collaboratorsOnly { repository =>
 | |
|     deleteLabel(repository.owner, repository.name, params("labelId").toInt)
 | |
|     issues.labels.html.editlist(getLabels(repository.owner, repository.name), repository)
 | |
|   })
 | |
| 
 | |
| } |