Skip to content

Commit

Permalink
Display custom field values
Browse files Browse the repository at this point in the history
  • Loading branch information
takezoe committed Apr 10, 2022
1 parent 5a33610 commit b5ba23d
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ trait IssuesControllerBase extends ControllerBase {
getMilestonesWithIssueCount(repository.owner, repository.name),
getPriorities(repository.owner, repository.name),
getLabels(repository.owner, repository.name),
getCustomFields(repository.owner, repository.name).filter(_.enableForIssues),
getCustomFieldsWithValue(repository.owner, repository.name, issueId.toInt).filter(_._1.enableForIssues),
isIssueEditable(repository),
isIssueManageable(repository),
isIssueCommentManageable(repository),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ trait PullRequestsControllerBase extends ControllerBase {
getMilestonesWithIssueCount(repository.owner, repository.name),
getPriorities(repository.owner, repository.name),
getLabels(repository.owner, repository.name),
getCustomFields(repository.owner, repository.name).filter(_.enableForPullRequests),
getCustomFieldsWithValue(repository.owner, repository.name, issueId).filter(_._1.enableForPullRequests),
isEditable(repository),
isManageable(repository),
hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount),
Expand Down
15 changes: 13 additions & 2 deletions src/main/scala/gitbucket/core/service/CustomFieldsService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ trait CustomFieldsService {
def getCustomFields(owner: String, repository: String)(implicit s: Session): List[CustomField] =
CustomFields.filter(_.byRepository(owner, repository)).sortBy(_.fieldId asc).list

def getCustomFieldsWithValue(owner: String, repository: String, issueId: Int)(
implicit s: Session
): List[(CustomField, Option[IssueCustomField])] = {
CustomFields
.filter(_.byRepository(owner, repository))
.joinLeft(IssueCustomFields)
.on { case (t1, t2) => t1.fieldId === t2.fieldId && t2.issueId === issueId.bind }
.sortBy { case (t1, t2) => t1.fieldId }
.list
}

def getCustomField(owner: String, repository: String, fieldId: Int)(implicit s: Session): Option[CustomField] =
CustomFields.filter(_.byPrimaryKey(owner, repository, fieldId)).firstOption

Expand Down Expand Up @@ -72,7 +83,7 @@ trait CustomFieldsService {
value: String
)(implicit s: Session): Unit = {
val customFieldValue = field.fieldType match {
case "text" =>
case "string" =>
Some(
IssueCustomField(
userName = userName,
Expand All @@ -85,7 +96,7 @@ trait CustomFieldsService {
dateValue = None
)
)
case "int" =>
case "number" =>
Some(
IssueCustomField(
userName = userName,
Expand Down
14 changes: 13 additions & 1 deletion src/main/twirl/gitbucket/core/issues/create.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@
</div>
</div>
<div class="col-md-3">
@gitbucket.core.issues.html.issueinfo(None, Nil, Nil, collaborators, milestones.map(x => (x, 0, 0)), priorities, defaultPriority, labels, customFields, isManageable, repository)
@gitbucket.core.issues.html.issueinfo(
issue = None,
comments = Nil,
issueLabels = Nil,
collaborators = collaborators,
milestones = milestones.map(x => (x, 0, 0)),
priorities= priorities,
defaultPriority = defaultPriority,
labels = labels,
customFields = customFields.map((_, None)),
isManageable = isManageable,
repository = repository
)
</div>
</div>
</form>
Expand Down
16 changes: 14 additions & 2 deletions src/main/twirl/gitbucket/core/issues/issue.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
milestones: List[(gitbucket.core.model.Milestone, Int, Int)],
priorities: List[gitbucket.core.model.Priority],
labels: List[gitbucket.core.model.Label],
customFields: List[gitbucket.core.model.CustomField],
customFields: List[(gitbucket.core.model.CustomField, Option[gitbucket.core.model.IssueCustomField])],
isEditable: Boolean,
isManageable: Boolean,
isCommentManageable: Boolean,
Expand Down Expand Up @@ -57,7 +57,19 @@ <h1 class="body-title">
@gitbucket.core.issues.html.commentform(issue, true, isEditable, isManageable, repository)
</div>
<div class="col-md-3">
@gitbucket.core.issues.html.issueinfo(Some(issue), comments, issueLabels, collaborators, milestones, priorities, None, labels, customFields, isManageable, repository)
@gitbucket.core.issues.html.issueinfo(
issue = Some(issue),
comments = comments,
issueLabels = issueLabels,
collaborators = collaborators,
milestones = milestones,
priorities = priorities,
defaultPriority = None,
labels = labels,
customFields = customFields,
isManageable = isManageable,
repository = repository
)
</div>
</div>
}
Expand Down
42 changes: 29 additions & 13 deletions src/main/twirl/gitbucket/core/issues/issueinfo.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
priorities: List[gitbucket.core.model.Priority],
defaultPriority: Option[gitbucket.core.model.Priority],
labels: List[gitbucket.core.model.Label],
customFields: List[gitbucket.core.model.CustomField],
customFields: List[(gitbucket.core.model.CustomField, Option[gitbucket.core.model.IssueCustomField])],
isManageable: Boolean,
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
Expand Down Expand Up @@ -149,22 +149,38 @@
<input type="hidden" name="assignedUserName" value=""/>
}

@customFields.map { customField =>
@customFields.map { case (field, value) =>
<hr/>
<div style="margin-bottom: 14px;">
<span class="muted small strong">@customField.fieldName</span>
<span class="muted small strong">@field.fieldName</span>
<div class="pull-right">
@if(customField.fieldType == "number") {
<input type="text" class="form-control input-sm" id="custom-field-@customField.fieldId" name="custom-field-@customField.fieldId" style="width: 120px;"/>
}
@if(customField.fieldType == "string") {
<input type="text" class="form-control input-sm" id="custom-field-@customField.fieldId" name="custom-field-@customField.fieldId" style="width: 120px;"/>
}
@if(customField.fieldType == "boolean") {
<input type="checkbox" id="custom-field-@customField.fieldId" name="custom-field-@customField.fieldId"/>
@if(issue.nonEmpty) {
@if(field.fieldType == "number") {
@value.map(_.intValue)
}
@if(field.fieldType == "string") {
@value.map(_.stringValue)
}
@if(field.fieldType == "boolean") {
@value.map(_.booleanValue)
}
@if(field.fieldType == "date") {
@value.flatMap(_.dateValue.map(helpers.date))
}
}
@if(customField.fieldType == "date") {
<input type="date" class="form-control input-sm" id="custom-field-@customField.fieldId" name="custom-field-@customField.fieldId" style="width: 120px;"/>
@if(issue.isEmpty) {
@if(field.fieldType == "number") {
<input type="text" class="form-control input-sm" id="custom-field-@field.fieldId" name="custom-field-@field.fieldId" style="width: 120px;"/>
}
@if(field.fieldType == "string") {
<input type="text" class="form-control input-sm" id="custom-field-@field.fieldId" name="custom-field-@field.fieldId" style="width: 120px;"/>
}
@if(field.fieldType == "boolean") {
<input type="checkbox" id="custom-field-@field.fieldId" name="custom-field-@field.fieldId"/>
}
@if(field.fieldType == "date") {
<input type="date" class="form-control input-sm" id="custom-field-@field.fieldId" name="custom-field-@field.fieldId" style="width: 120px;"/>
}
}
</div>
</div>
Expand Down
14 changes: 13 additions & 1 deletion src/main/twirl/gitbucket/core/pulls/compare.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,19 @@
</div>
</div>
<div class="col-md-3">
@gitbucket.core.issues.html.issueinfo(None, Nil, Nil, collaborators, milestones.map((_, 0, 0)), priorities, defaultPriority, labels, customFields, hasOriginWritePermission, repository)
@gitbucket.core.issues.html.issueinfo(
issue = None,
comments = Nil,
issueLabels = Nil,
collaborators = collaborators,
milestones = milestones.map((_, 0, 0)),
priorities = priorities,
defaultPriority = defaultPriority,
labels = labels,
customFields = customFields.map((_, None)),
isManageable = hasOriginWritePermission,
repository = repository
)
</div>
</div>
</form>
Expand Down
16 changes: 14 additions & 2 deletions src/main/twirl/gitbucket/core/pulls/conversation.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
milestones: List[(gitbucket.core.model.Milestone, Int, Int)],
priorities: List[gitbucket.core.model.Priority],
labels: List[gitbucket.core.model.Label],
customFields: List[gitbucket.core.model.CustomField],
customFields: List[(gitbucket.core.model.CustomField, Option[gitbucket.core.model.IssueCustomField])],
isEditable: Boolean,
isManageable: Boolean,
isManageableForkedRepository: Boolean,
Expand Down Expand Up @@ -51,7 +51,19 @@
}
</div>
<div class="col-md-3">
@gitbucket.core.issues.html.issueinfo(Some(issue), comments.toList, issueLabels, collaborators, milestones, priorities, None, labels, customFields, isManageable, repository)
@gitbucket.core.issues.html.issueinfo(
Some(issue),
comments.toList,
issueLabels,
collaborators,
milestones,
priorities,
None,
labels,
customFields,
isManageable,
repository
)
</div>
<script>
$(function(){
Expand Down

0 comments on commit b5ba23d

Please sign in to comment.