Skip to content

Commit

Permalink
Issue due date (go-gitea#3794)
Browse files Browse the repository at this point in the history
* Started adding deadline to ui

* Implemented basic issue due date managing

* Improved UI for due date managing

* Added at least write access to the repo in order to modify issue due dates

* Ui improvements

* Added issue comments creation when adding/modifying/removing a due date

* Show due date in issue list

* Added api support for issue due dates

* Fixed lint suggestions

* Added deadline to sdk

* Updated css

* Added support for adding/modifiying deadlines for pull requests via api

* Fixed comments not created when updating or removing a deadline

* update sdk (will do properly once go-gitea/go-sdk#103 is merged)

* enhanced updateIssueDeadline

* Removed unnessecary Issue.DeadlineString

* UI improvements

* Small improvments to comment creation
+ ui & validation improvements

* Check if an issue is overdue is now a seperate function

* Updated go-sdk with govendor as it was merged

* Simplified isOverdue method

* removed unessecary deadline to 0 set

* Update swagger definitions

* Added missing return

* Added an explanary comment

* Improved updateIssueDeadline method so it'll only update `deadline_unix`

* Small changes and improvements
* no need to explicitly load the issue when updating a deadline, just use whats already there
* small optimisations

* Added check if a deadline was modified before updating it

* Moved comment creating logic into its own function

* Code cleanup for creating deadline comment

* locale improvement

* When modifying a deadline, the old deadline is saved with the comment

* small improvments to xorm session handling when updating an issue deadline
+ style nitpicks

* style nitpicks

* Moved checking for if the user has write acces to middleware
  • Loading branch information
kolaente authored and lafriks committed May 1, 2018
1 parent 85d14cc commit 1a97030
Show file tree
Hide file tree
Showing 22 changed files with 416 additions and 45 deletions.
42 changes: 39 additions & 3 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ type Issue struct {
Ref string

DeadlineUnix util.TimeStamp `xorm:"INDEX"`
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
ClosedUnix util.TimeStamp `xorm:"INDEX"`

CreatedUnix util.TimeStamp `xorm:"INDEX created"`
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
ClosedUnix util.TimeStamp `xorm:"INDEX"`

Attachments []*Attachment `xorm:"-"`
Comments []*Comment `xorm:"-"`
Expand Down Expand Up @@ -79,6 +80,11 @@ func (issue *Issue) loadTotalTimes(e Engine) (err error) {
return nil
}

// IsOverdue checks if the issue is overdue
func (issue *Issue) IsOverdue() bool {
return util.TimeStampNow() >= issue.DeadlineUnix
}

func (issue *Issue) loadRepo(e Engine) (err error) {
if issue.Repo == nil {
issue.Repo, err = getRepositoryByID(e, issue.RepoID)
Expand Down Expand Up @@ -348,6 +354,9 @@ func (issue *Issue) APIFormat() *api.Issue {
apiIssue.PullRequest.Merged = issue.PullRequest.MergedUnix.AsTimePtr()
}
}
if issue.DeadlineUnix != 0 {
apiIssue.Deadline = issue.DeadlineUnix.AsTimePtr()
}

return apiIssue
}
Expand Down Expand Up @@ -1522,3 +1531,30 @@ func updateIssue(e Engine, issue *Issue) error {
func UpdateIssue(issue *Issue) error {
return updateIssue(x, issue)
}

// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
func UpdateIssueDeadline(issue *Issue, deadlineUnix util.TimeStamp, doer *User) (err error) {

// if the deadline hasn't changed do nothing
if issue.DeadlineUnix == deadlineUnix {
return nil
}

sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}

// Update the deadline
if err = updateIssueCols(sess, &Issue{ID: issue.ID, DeadlineUnix: deadlineUnix}, "deadline_unix"); err != nil {
return err
}

// Make the comment
if _, err = createDeadlineComment(sess, doer, issue, deadlineUnix); err != nil {
return fmt.Errorf("createRemovedDueDateComment: %v", err)
}

return sess.Commit()
}
34 changes: 34 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const (
CommentTypeAddTimeManual
// Cancel a stopwatch for time tracking
CommentTypeCancelTracking
// Added a due date
CommentTypeAddedDeadline
// Modified the due date
CommentTypeModifiedDeadline
// Removed a due date
CommentTypeRemovedDeadline
)

// CommentTag defines comment tag type
Expand Down Expand Up @@ -485,6 +491,34 @@ func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue
})
}

func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlineUnix util.TimeStamp) (*Comment, error) {

var content string
var commentType CommentType

// newDeadline = 0 means deleting
if newDeadlineUnix == 0 {
commentType = CommentTypeRemovedDeadline
content = issue.DeadlineUnix.Format("2006-01-02")
} else if issue.DeadlineUnix == 0 {
// Check if the new date was added or modified
// If the actual deadline is 0 => deadline added
commentType = CommentTypeAddedDeadline
content = newDeadlineUnix.Format("2006-01-02")
} else { // Otherwise modified
commentType = CommentTypeModifiedDeadline
content = newDeadlineUnix.Format("2006-01-02") + "|" + issue.DeadlineUnix.Format("2006-01-02")
}

return createComment(e, &CreateCommentOptions{
Type: commentType,
Doer: doer,
Repo: issue.Repo,
Issue: issue,
Content: content,
})
}

func createChangeTitleComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldTitle, newTitle string) (*Comment, error) {
return createComment(e, &CreateCommentOptions{
Type: CommentTypeChangeTitle,
Expand Down
1 change: 1 addition & 0 deletions models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (pr *PullRequest) APIFormat() *api.PullRequest {
Base: apiBaseBranchInfo,
Head: apiHeadBranchInfo,
MergeBase: pr.MergeBase,
Deadline: apiIssue.Deadline,
Created: pr.Issue.CreatedUnix.AsTimePtr(),
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
}
Expand Down
10 changes: 10 additions & 0 deletions modules/auth/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,13 @@ func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors
type SaveTopicForm struct {
Topics []string `binding:"topics;Required;"`
}

// DeadlineForm hold the validation rules for deadlines
type DeadlineForm struct {
DateString string `form:"date" binding:"Required;Size(10)"`
}

// Validate validates the fields
func (f *DeadlineForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
return validate(errs, ctx.Data, f, ctx.Locale)
}
3 changes: 3 additions & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ func NewFuncMap() []template.FuncMap {
"Printf": fmt.Sprintf,
"Escape": Escape,
"Sec2Time": models.SecToTime,
"ParseDeadline": func(deadline string) []string {
return strings.Split(deadline, "|")
},
}}
}

Expand Down
16 changes: 15 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,22 @@ issues.add_time_minutes = Minutes
issues.add_time_sum_to_small = No time was entered.
issues.cancel_tracking = Cancel
issues.cancel_tracking_history = `cancelled time tracking %s`
issues.time_spent_total = Total Time Spent
issues.time_spent_from_all_authors = `Total Time Spent: %s`
issues.due_date = Due date
issues.invalid_due_date_format = "Due date format is invalid, must be 'yyyy-mm-dd'."
issues.error_modifying_due_date = "An error occured while modifying the due date."
issues.error_removing_due_date = "An error occured while remvoing the due date."
issues.due_date_form = "Due date, format yyyy-mm-dd"
issues.due_date_form_add = "Add due date"
issues.due_date_form_update = "Update due date"
issues.due_date_form_remove = "Remove due date"
issues.due_date_not_writer = "You need to have at least write access to this repository in order to update the due date for this issue."
issues.due_date_not_set = "No due date set."
issues.due_date_added = "added the due date %s %s"
issues.due_date_modified = "modified the due date to %s from %s %s"
issues.due_date_remove = "removed the due date %s %s"
issues.due_date_overdue = "Overdue"
pulls.desc = Enable merge requests and code reviews.
pulls.new = New Pull Request
Expand Down
2 changes: 1 addition & 1 deletion public/css/index.css

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2193,4 +2193,15 @@ function initTopicbar() {
},
},
});
}
}
function toggleDuedateForm() {
$('#add_deadline_form').fadeToggle(150);
}

function deleteDueDate(url) {
$.post(url, {
'_csrf': csrf,
},function( data ) {
window.location.reload();
});
}
3 changes: 3 additions & 0 deletions public/less/_repository.less
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,9 @@
margin-top: -5px;
margin-right: 5px;
}
.overdue{
color: red;
}
}
}
}
Expand Down
82 changes: 82 additions & 0 deletions public/swagger.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -5579,6 +5579,13 @@
"type": "string",
"x-go-name": "Assignee"
},
"assignees": {
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "Assignees"
},
"body": {
"type": "string",
"x-go-name": "Body"
Expand All @@ -5587,6 +5594,11 @@
"type": "boolean",
"x-go-name": "Closed"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"labels": {
"description": "list of label ids",
"type": "array",
Expand Down Expand Up @@ -5715,6 +5727,13 @@
"type": "string",
"x-go-name": "Assignee"
},
"assignees": {
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "Assignees"
},
"base": {
"type": "string",
"x-go-name": "Base"
Expand All @@ -5723,6 +5742,11 @@
"type": "string",
"x-go-name": "Body"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"head": {
"type": "string",
"x-go-name": "Head"
Expand Down Expand Up @@ -6024,10 +6048,22 @@
"type": "string",
"x-go-name": "Assignee"
},
"assignees": {
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "Assignees"
},
"body": {
"type": "string",
"x-go-name": "Body"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"milestone": {
"type": "integer",
"format": "int64",
Expand Down Expand Up @@ -6114,10 +6150,22 @@
"type": "string",
"x-go-name": "Assignee"
},
"assignees": {
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "Assignees"
},
"body": {
"type": "string",
"x-go-name": "Body"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"labels": {
"type": "array",
"items": {
Expand Down Expand Up @@ -6367,10 +6415,22 @@
"assignee": {
"$ref": "#/definitions/User"
},
"assignees": {
"type": "array",
"items": {
"$ref": "#/definitions/User"
},
"x-go-name": "Assignees"
},
"body": {
"type": "string",
"x-go-name": "Body"
},
"closed_at": {
"type": "string",
"format": "date-time",
"x-go-name": "Closed"
},
"comments": {
"type": "integer",
"format": "int64",
Expand All @@ -6381,6 +6441,11 @@
"format": "date-time",
"x-go-name": "Created"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"id": {
"type": "integer",
"format": "int64",
Expand Down Expand Up @@ -6778,13 +6843,25 @@
"assignee": {
"$ref": "#/definitions/User"
},
"assignees": {
"type": "array",
"items": {
"$ref": "#/definitions/User"
},
"x-go-name": "Assignees"
},
"base": {
"$ref": "#/definitions/PRBranchInfo"
},
"body": {
"type": "string",
"x-go-name": "Body"
},
"closed_at": {
"type": "string",
"format": "date-time",
"x-go-name": "Closed"
},
"comments": {
"type": "integer",
"format": "int64",
Expand All @@ -6799,6 +6876,11 @@
"type": "string",
"x-go-name": "DiffURL"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"head": {
"$ref": "#/definitions/PRBranchInfo"
},
Expand Down
Loading

0 comments on commit 1a97030

Please sign in to comment.