-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue due date #3794
Issue due date #3794
Changes from 22 commits
406cd5a
859cd47
02415f7
bfef995
74c9e07
aeb3db9
211b2ed
82d7bf0
13a12c3
c1ada01
6663012
f4baf19
06d9649
3bf2227
60bbb23
192f31e
f766101
a1b79fe
e659699
bdec65a
38e1180
51d3e4f
5c93fe0
7292c30
6fb31d6
3ae5b7a
0b18607
2efba88
d8ba5ab
674d2ed
b8760ba
c88a59d
7c0e537
30a2c70
bf2d849
30dbda4
b9f193a
3c8216f
fb7463f
1c47d90
81c93d6
d02d09c
253d48f
c17c95b
d7f4798
f35fec0
1412580
fe68965
65e841d
311dc73
8d3fff2
3f570d4
a7a9529
d49dd2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,10 +46,12 @@ type Issue struct { | |
NumComments int | ||
Ref string | ||
|
||
DeadlineUnix util.TimeStamp `xorm:"INDEX"` | ||
CreatedUnix util.TimeStamp `xorm:"INDEX created"` | ||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` | ||
ClosedUnix util.TimeStamp `xorm:"INDEX"` | ||
DeadlineUnix util.TimeStamp `xorm:"INDEX"` | ||
IsOverDue bool `xorm:"-"` | ||
|
||
CreatedUnix util.TimeStamp `xorm:"INDEX created"` | ||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` | ||
ClosedUnix util.TimeStamp `xorm:"INDEX"` | ||
|
||
Attachments []*Attachment `xorm:"-"` | ||
Comments []*Comment `xorm:"-"` | ||
|
@@ -69,6 +71,13 @@ func init() { | |
issueTasksDonePat = regexp.MustCompile(issueTasksDoneRegexpStr) | ||
} | ||
|
||
// AfterLoad checks if the issue is overdue and sets the property | ||
func (issue *Issue) AfterLoad() { | ||
if util.TimeStampNow() >= issue.DeadlineUnix { | ||
issue.IsOverDue = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just change IsOverDue as a method of Issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I've changed it. |
||
} | ||
} | ||
|
||
func (issue *Issue) loadRepo(e Engine) (err error) { | ||
if issue.Repo == nil { | ||
issue.Repo, err = getRepositoryByID(e, issue.RepoID) | ||
|
@@ -324,6 +333,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 | ||
} | ||
|
@@ -1498,3 +1510,46 @@ func updateIssue(e Engine, issue *Issue) error { | |
func UpdateIssue(issue *Issue) error { | ||
return updateIssue(x, issue) | ||
} | ||
|
||
// UpdateIssueDeadline does what it says | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please correct comment... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How? Do you want me to write something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's better. And does it really update only deadline? I think it updates all given fields right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also creates comments. I am not sure if it is good. Maybe better to add comments directly in udate/remove deadline function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, it updates all fields to its old value + issueDeadline to the new value. Although I think xorm does some magic here and only updates the fields which did not change.
This is the function which updates/removes the deadline... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the only diff between this function and I don't think Xorm is so magical. As I know, it can ignore default values, but doesn't know what is updated. But you can check it by turning on sql logging so we can be sure about that. Sry, I should be more concrete about "update/remove" functions. I meant Edit: OK, you updated it in meanwhile so this comment is not 100% relevant now :) |
||
func UpdateIssueDeadline(issue *Issue, doer *User) (err error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can change this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But wouldn't that mean to get the actual deadline before calling the function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like IMO only issue deadline should be updated, not everything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe something like this?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I'd still need to check if the issue deadline hasn't changed meanwhile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe check if new deadline is different than old deadline? So we don't create comments nor update issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I haven't thought of that. |
||
|
||
// Check if the new date was added or modified | ||
var actualIssue Issue | ||
if _, err := x.ID(issue.ID).Get(&actualIssue); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed it to only get and update |
||
return fmt.Errorf("getActualIssue: %v", err) | ||
} | ||
|
||
sess := x.NewSession() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now, do we really need this session? What you want to achieve here? From xorm readme:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need that session to create the comment. |
||
defer sess.Close() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, fixed. |
||
|
||
if err = issue.loadRepo(sess); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed. |
||
return fmt.Errorf("loadRepo: %v", err) | ||
} | ||
|
||
// Make the comment | ||
if issue.DeadlineUnix == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can move this if/else to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if _, err = createDeadlineComment(sess, doer, issue.Repo, issue, actualIssue.DeadlineUnix, CommentTypeRemovedDeadline); err != nil { | ||
return fmt.Errorf("createRemovedDueDateComment: %v", err) | ||
} | ||
} else { | ||
// Check if the new date was added or modified | ||
// If the actual deadline is 0 => deadline added | ||
if actualIssue.DeadlineUnix == 0 { | ||
if _, err = createDeadlineComment(sess, doer, issue.Repo, issue, issue.DeadlineUnix, CommentTypeAddedDeadline); err != nil { | ||
return fmt.Errorf("createRemovedDueDateComment: %v", err) | ||
} | ||
} else { // Otherwise modified | ||
if _, err = createDeadlineComment(sess, doer, issue.Repo, issue, issue.DeadlineUnix, CommentTypeModifiedDeadline); err != nil { | ||
return fmt.Errorf("createRemovedDueDateComment: %v", err) | ||
} | ||
} | ||
} | ||
|
||
err = updateIssue(sess, issue) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return sess.Commit() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want transaction, you have to call
If not, this is not needed and you can just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll add that. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -485,6 +491,25 @@ func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue | |
}) | ||
} | ||
|
||
func createDeadlineComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, dateUnix util.TimeStamp, deadlineCommentType CommentType) (*Comment, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It would be great if content is more specific. When deadline is modified it should show both dates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but I rather won't add another row to the issue comment table as there are already too much. Someone said we should redo that some day, so I'll probably wait for that to do that... Or do you have an idea on how to add both dates in one field? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant if we can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, sure. I'll figure something out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if deadlineCommentType != CommentTypeAddedDeadline && | ||
deadlineCommentType != CommentTypeModifiedDeadline && | ||
deadlineCommentType != CommentTypeRemovedDeadline { | ||
return &Comment{}, fmt.Errorf("wrong comment type: %d", deadlineCommentType) | ||
} | ||
|
||
// Make string from unix date | ||
date := dateUnix.Format("2006-01-02") | ||
|
||
return createComment(e, &CreateCommentOptions{ | ||
Type: deadlineCommentType, | ||
Doer: doer, | ||
Repo: repo, | ||
Issue: issue, | ||
Content: date, | ||
}) | ||
} | ||
|
||
func createChangeTitleComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldTitle, newTitle string) (*Comment, error) { | ||
return createComment(e, &CreateCommentOptions{ | ||
Type: CommentTypeChangeTitle, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -737,6 +737,20 @@ 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.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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that
could be confusing for users from non-english countries (like Germany) because modern browsers use for the UI the local date format (in Germany: dd.mm.yyyy) and as value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but that value is used as a placeholder for the input. If the browser supports Some screenshots with an empty input: The format doesnt really seem to be an issue here. Also, currently the date is not localized anywhere, so if we'd start doing that here we should do it everywhere which is totally out of scope for this pr. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the placeholder isn't shown at all it could be removed to reduce translation effort. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is shown when the browser doesn't support the |
||
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 %s" | ||
issues.due_date_remove = "removed the due date %s %s" | ||
issues.due_date_overdue = "Overdue" | ||
|
||
pulls.desc = Pulls management your code review and merge requests | ||
pulls.new = New Pull Request | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1544,6 +1544,9 @@ | |
margin-top: -5px; | ||
margin-right: 5px; | ||
} | ||
.overdue{ | ||
color: red; | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,12 +163,20 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { | |
// responses: | ||
// "201": | ||
// "$ref": "#/responses/Issue" | ||
|
||
var deadline util.TimeStamp | ||
deadline = util.TimeStamp(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line could be removed I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems logic, I removed that. |
||
if form.Deadline != nil { | ||
deadline = util.TimeStamp(form.Deadline.Unix()) | ||
} | ||
|
||
issue := &models.Issue{ | ||
RepoID: ctx.Repo.Repository.ID, | ||
Title: form.Title, | ||
PosterID: ctx.User.ID, | ||
Poster: ctx.User, | ||
Content: form.Body, | ||
RepoID: ctx.Repo.Repository.ID, | ||
Title: form.Title, | ||
PosterID: ctx.User.ID, | ||
Poster: ctx.User, | ||
Content: form.Body, | ||
DeadlineUnix: deadline, | ||
} | ||
|
||
if ctx.Repo.IsWriter() { | ||
|
@@ -265,6 +273,15 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { | |
issue.Content = *form.Body | ||
} | ||
|
||
if form.Deadline != nil && !form.Deadline.IsZero() { | ||
issue.DeadlineUnix = util.TimeStamp(form.Deadline.Unix()) | ||
} else { | ||
issue.DeadlineUnix = util.TimeStamp(0) | ||
} | ||
if err := models.UpdateIssueDeadline(issue, ctx.User); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do I need the repo for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, but isn't the repo already available in |
||
ctx.Error(500, "UpdateIssueDeadline", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably. I've added one (same for pull.go). |
||
} | ||
|
||
if ctx.Repo.IsWriter() && form.Assignee != nil && | ||
(issue.Assignee == nil || issue.Assignee.LowerName != strings.ToLower(*form.Assignee)) { | ||
if len(*form.Assignee) == 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about
return util.TimeStampNow() >= issue.DeadlineUnix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.