-
-
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
Conversation
models/issue.go
Outdated
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` | ||
ClosedUnix util.TimeStamp `xorm:"INDEX"` | ||
DeadlineUnix util.TimeStamp `xorm:"INDEX"` | ||
DeadlineString string `xorm:"-"` |
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.
It seems this field is unnecessary.
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.
No, it is needed to show the deadline in templates.
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.
You could use something like .DeadlineUnix.FormatShort
.
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.
Thanks, I didn't know that function exists.
On another note, what do you think about putting date formats in the corresponding locale files meaning we could have different date formats for every locale?
models/issue.go
Outdated
} | ||
} | ||
|
||
return UpdateIssue(issue) |
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.
this should be err = updateIssue(sess, issue)
and need sess.Commit()
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.
models/issue_comment.go
Outdated
@@ -485,6 +491,45 @@ func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue | |||
}) | |||
} | |||
|
|||
func createAddedDeadlineComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, dateUnix util.TimeStamp) (*Comment, error) { |
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.
I think that you could pack all of these create...DeadlineComment
functions into one function with an additional parameter type
(please also check if the type is a valid deadline type).
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.
Done, good idea!
modules/auth/repo_form.go
Outdated
|
||
// DeadlineForm hold the validation rules for deadlines | ||
type DeadlineForm struct { | ||
DateString string `form:"date" binding:"Required;MaxSize(10)"` |
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.
Replace MaxSize
with Size
since a yyyy-mm-dd
date has always 10 characters.
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.
Thanks, I didn't know Size
exists.
<img src="{{.Poster.RelAvatarLink}}"> | ||
</a> | ||
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a> | ||
{{$.i18n.Tr "repo.issues.due_date_added" .Content $createdStr | Safe}} |
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.
Please remove |Safe
since it is not required (no safe HTML content inside)
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.
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.
Fair enough
<img src="{{.Poster.RelAvatarLink}}"> | ||
</a> | ||
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a> | ||
{{$.i18n.Tr "repo.issues.due_date_modified" .Content $createdStr | Safe}} |
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.
Please remove |Safe
since it is not required (no safe HTML content inside)
<img src="{{.Poster.RelAvatarLink}}"> | ||
</a> | ||
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a> | ||
{{$.i18n.Tr "repo.issues.due_date_remove" .Content $createdStr | Safe}} |
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.
Please remove |Safe
since it is not required (no safe HTML content inside)
<form method="POST"{{if gt .Issue.DeadlineUnix 0}}style="display: none;"{{end}}} id="add_deadline_form" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/deadline/update" class="ui action input fluid"> | ||
{{$.CsrfTokenHtml}} | ||
<div class="ui fluid action input"> | ||
<input required placeholder='{{.i18n.Tr "repo.issues.due_date_form"}}' {{if gt .Issue.DeadlineUnix 0}}value="{{.Issue.DeadlineUnix.Format "2006-01-02"}}"{{end}} type="date" name="date" style="min-width: 13.9rem;border-radius: 4px 0 0 4px;border-right: 0;white-space: nowrap;"> |
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.
Replace placeholder='...'
with placeholder="..."
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think that
format yyyy-mm-dd
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 yyyy-mm-dd
. (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#Value)
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.
Yes, but that value is used as a placeholder for the input. If the browser supports input type date
, the browser does what you described thus not showing the placeholder at all (because there's already something inside that field).
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
It is shown when the browser doesn't support the <input type="date"/>
tag, so I'd leave that.
+ ui & validation improvements
models/issue.go
Outdated
// 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, I've changed it.
models/issue.go
Outdated
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
defer sess.Close() |
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.
defer sess.Close()
should be after sess := x.NewSession()
and before sess.Begin()
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.
Sure, fixed.
@@ -265,6 +272,16 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { | |||
issue.Content = *form.Body | |||
} | |||
|
|||
var deadlineUnix util.TimeStamp |
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.
nit: Use var deadlineUnix util.TimeStamp
or var deadline util.TimeStamp
, not both as it has same meaning (same in repo/issue.go and repo/pull.go).
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.
Sure, I fixed that as well.
…dline + style nitpicks
routers/repo/issue.go
Outdated
} | ||
|
||
// Check if the user has at least write access to the repo | ||
if !ctx.Repo.IsWriter() { |
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.
I found there is authorization middleware, can you use that instead? Like in m.Post("/status", reqRepoWriter, repo.UpdateIssueStatus)
. It calls RequireRepoWriter()
func.
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.
Done.
@lunny I already approved it here: #3794 (comment) |
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.
Should be last changes. There are another two things I don' like. But one is not related directly only to this issue (usage of ctx.Writen()
and ctx.HasError()
) and second is about better UI (but that can be updated in future, right now I have not better idea).
routers/routes/routes.go
Outdated
@@ -496,6 +496,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
}) | |||
}) | |||
m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction) | |||
m.Post("/deadline/update", reqRepoWriter, bindIgnErr(auth.DeadlineForm{}), repo.UpdateDeadline) | |||
m.Post("/deadline/remove", reqRepoWriter, repo.RemoveDeadline) |
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.
For consistency, this endpoint should be called /delete
.
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 that.
{{end}} | ||
<br/> | ||
<a style="cursor:pointer;" onclick="toggleDuedateForm();"><i class="edit icon"></i>Edit</a> - | ||
<a style="cursor:pointer;" onclick="deleteDueDate('{{$.RepoLink}}/issues/{{.Issue.Index}}/deadline/remove');"><i class="remove icon"></i>Remove</a> |
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.
This can/should be standard link (<a href="{{$.RepoLink}}/issues/{{.Issue.Index}}/deadline/remove">
), right?
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.
No, the js function sends a post request.
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.
I'll send a seperate pr after this one is merged which will add a seperate api endpoint for deadlines which then will be used for the update the deadline from the UI.
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.
Good to know you will improve this solution and add api endpoint. Until then, you should not simulate api endpoint by using js and standard page, ignoring anything it can return. For now, there is not reason to use js, you can add it later, in another PR when api would be ready for it.
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.
I've modifed the endpoint, deleting a deadline is now done via GET.
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.
gj
@Morlinest thanks! |
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.
@Morlinest @kolaente Wanted to already merge but there one thing needs to be changed back as it was in previous commits. For security reasons all actions that update database must be done using post method, so that CSRF can be verified and user could not be fooled into actions that he did not want (either by giving him url or redirecting him to such url)
@lafriks OK, I'll change it back to how it was before. |
@lafriks Done. |
Just for info, I don't like this halfway solution. |
@Morlinest about doing |
Fixes #2533.
Blocked by go-gitea/go-sdk#103.This PR adds the ability to add due dates to issues. This works similar to milestones, but for single issues. Due date can be managed via the api.
Due dates are shown in the issue list, overdue issues are marked in red.
Screenshots
TODO
go-sdk
once its merged