Skip to content
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

Merged
merged 54 commits into from
May 1, 2018
Merged

Issue due date #3794

merged 54 commits into from
May 1, 2018

Conversation

kolaente
Copy link
Member

@kolaente kolaente commented Apr 14, 2018

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

bildschirmfoto von 2018-04-14 17-19-43
bildschirmfoto von 2018-04-14 17-19-55
bildschirmfoto von 2018-04-14 17-21-12

TODO

  • Update go-sdk once its merged

models/issue.go Outdated
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
ClosedUnix util.TimeStamp `xorm:"INDEX"`
DeadlineUnix util.TimeStamp `xorm:"INDEX"`
DeadlineString string `xorm:"-"`
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@bkcsoft bkcsoft added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 15, 2018
@lunny lunny added the type/enhancement An improvement of existing functionality label Apr 15, 2018
@@ -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) {
Copy link
Member

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, good idea!


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

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.

Copy link
Member Author

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}}
Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do that, it looks like that:
bildschirmfoto von 2018-04-16 18-47-55

So I'm leaving it. (same for the other ones)

Copy link
Member

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}}
Copy link
Member

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}}
Copy link
Member

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;">
Copy link
Member

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"
Copy link
Member

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)

Copy link
Member Author

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:

Firefox:
bildschirmfoto von 2018-04-16 18-42-51

Chromium:
bildschirmfoto von 2018-04-16 18-43-22

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.

Copy link
Member

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.

Copy link
Member Author

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.

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
Copy link
Member

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?

Copy link
Member Author

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()
Copy link
Member

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()

Copy link
Member Author

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
Copy link
Member

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).

Copy link
Member Author

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.

}

// Check if the user has at least write access to the repo
if !ctx.Repo.IsWriter() {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jonasfranz
Copy link
Member

@lunny I already approved it here: #3794 (comment)

Copy link
Member

@Morlinest Morlinest left a 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).

@@ -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)
Copy link
Member

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.

Copy link
Member Author

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>
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@Morlinest Morlinest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gj

@kolaente
Copy link
Member Author

kolaente commented May 1, 2018

@Morlinest thanks!

Copy link
Member

@lafriks lafriks left a 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)

@kolaente
Copy link
Member Author

kolaente commented May 1, 2018

@lafriks OK, I'll change it back to how it was before.

@kolaente
Copy link
Member Author

kolaente commented May 1, 2018

@lafriks Done.

@lafriks lafriks merged commit 1a97030 into go-gitea:master May 1, 2018
@lafriks lafriks added the type/changelog Adds the changelog for a new Gitea version label May 1, 2018
@Morlinest
Copy link
Member

Just for info, I don't like this halfway solution.

@lafriks
Copy link
Member

lafriks commented May 1, 2018

@Morlinest about doing post for removing due date?

@kolaente kolaente mentioned this pull request May 2, 2018
@kolaente kolaente deleted the issue-due-date branch January 24, 2019 18:16
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
@delvh delvh removed the type/changelog Adds the changelog for a new Gitea version label Oct 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Due Date for issues
8 participants