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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
406cd5a
Started adding deadline to ui
kolaente Mar 22, 2018
859cd47
Implemented basic issue due date managing
kolaente Mar 23, 2018
02415f7
Improved UI for due date managing
kolaente Mar 23, 2018
bfef995
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Mar 25, 2018
74c9e07
Added at least write access to the repo in order to modify issue due …
kolaente Mar 25, 2018
aeb3db9
Ui improvements
kolaente Mar 25, 2018
211b2ed
Added issue comments creation when adding/modifying/removing a due date
kolaente Mar 25, 2018
82d7bf0
Show due date in issue list
kolaente Apr 14, 2018
13a12c3
merge with master
kolaente Apr 14, 2018
c1ada01
Added api support for issue due dates
kolaente Apr 14, 2018
6663012
Fixed lint suggestions
kolaente Apr 14, 2018
f4baf19
Added deadline to sdk
kolaente Apr 14, 2018
06d9649
Updated css
kolaente Apr 14, 2018
3bf2227
Added support for adding/modifiying deadlines for pull requests via api
kolaente Apr 14, 2018
60bbb23
Fixed comments not created when updating or removing a deadline
kolaente Apr 14, 2018
192f31e
update sdk (will do properly once go-gitea/go-sdk#103 is merged)
kolaente Apr 14, 2018
f766101
enhanced updateIssueDeadline
kolaente Apr 15, 2018
a1b79fe
Removed unnessecary Issue.DeadlineString
kolaente Apr 15, 2018
e659699
UI improvements
kolaente Apr 15, 2018
bdec65a
Small improvments to comment creation
kolaente Apr 16, 2018
38e1180
merge with gitea-master
kolaente Apr 16, 2018
51d3e4f
merge with gitea-master
kolaente Apr 16, 2018
5c93fe0
Check if an issue is overdue is now a seperate function
kolaente Apr 17, 2018
7292c30
Updated go-sdk with govendor as it was merged
kolaente Apr 17, 2018
6fb31d6
fmt
kolaente Apr 17, 2018
3ae5b7a
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 17, 2018
0b18607
Simplified isOverdue method
kolaente Apr 18, 2018
2efba88
removed unessecary deadline to 0 set
kolaente Apr 18, 2018
d8ba5ab
Merge with gitea-master
kolaente Apr 20, 2018
674d2ed
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 21, 2018
b8760ba
Update swagger definitions
kolaente Apr 21, 2018
c88a59d
Added missing return
kolaente Apr 22, 2018
7c0e537
Added an explanary comment
kolaente Apr 23, 2018
30a2c70
Improved updateIssueDeadline method so it'll only update `deadline_unix`
kolaente Apr 23, 2018
bf2d849
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 23, 2018
30dbda4
Small changes and improvements
kolaente Apr 27, 2018
b9f193a
Added check if a deadline was modified before updating it
kolaente Apr 27, 2018
3c8216f
Moved comment creating logic into its own function
kolaente Apr 27, 2018
fb7463f
Code cleanup for creating deadline comment
kolaente Apr 27, 2018
1c47d90
locale improvement
kolaente Apr 27, 2018
81c93d6
When modifying a deadline, the old deadline is saved with the comment
kolaente Apr 27, 2018
d02d09c
fmt
kolaente Apr 27, 2018
253d48f
Merge branch 'master' into issue-due-date
lunny Apr 29, 2018
c17c95b
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 29, 2018
d7f4798
small improvments to xorm session handling when updating an issue dea…
kolaente Apr 29, 2018
f35fec0
small improvments to xorm session handling when updating an issue dea…
kolaente Apr 29, 2018
1412580
style nitpicks
kolaente Apr 29, 2018
fe68965
Moved checking for if the user has write acces to middleware
kolaente Apr 29, 2018
65e841d
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 29, 2018
311dc73
Merge with gitea-master
kolaente May 1, 2018
8d3fff2
Merge with gitea-master
kolaente May 1, 2018
3f570d4
renamed remove deadline url
kolaente May 1, 2018
a7a9529
Deleting a deadline is now possible via get
kolaente May 1, 2018
d49dd2f
Reverted deleting a deadline back to using a post request
kolaente May 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Member

Choose a reason for hiding this comment

The 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:

Multiple operations in one go routine, no transation here but resue session memory

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 need that session to create the comment.

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

Choose a reason for hiding this comment

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

If you want transaction, you have to call Begin() first (from xorm doc):

if err := session.Begin(); err != nil {
    // if returned then will rollback automatically
    return err
}

If not, this is not needed and you can just return nil.

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'll add that.

}
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"
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.

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