diff options
author | modmew8 <modmew8@gmail.com> | 2018-01-03 09:34:13 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2018-01-03 02:34:13 -0600 |
commit | d996da6babf505c56802bb2a9afe530dca940d7a (patch) | |
tree | 8c6d314ce74e9910bc8f6331b4eee2370be8eb87 /models/issue.go | |
parent | 22a7a7ec9b94aad6c689b7e61bee09c2e322fd57 (diff) | |
download | gitea-d996da6babf505c56802bb2a9afe530dca940d7a.tar.gz gitea-d996da6babf505c56802bb2a9afe530dca940d7a.zip |
Added progressbar for issues (#1146). (#3171)
* Added progressbar for issues (#1146).
* Updated the generated index.css.
Signed-off-by: modmew8 <modmew8@gmail.com>
* Removed stored progress percentage and changed it to css calc. Also added the issue task progress to the user/dashboard/issues.
Signed-off-by: modmew8 <modmew8@gmail.com>
* Removed unnecessary blanks.
Signed-off-by: modmew8 <modmew8@gmail.com>
* Formatted the files correctly, fmt-check terminates now without errors.
Signed-off-by: modmew8 <modmew8@gmail.com>
* Removed variables, made computing the tasks on demand with precompiled regexp.
Signed-off-by: modmew8 <modmew8@gmail.com>
Diffstat (limited to 'models/issue.go')
-rw-r--r-- | models/issue.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/models/issue.go b/models/issue.go index 13973b7d1c..052ebf90c0 100644 --- a/models/issue.go +++ b/models/issue.go @@ -7,6 +7,7 @@ package models import ( "fmt" "path" + "regexp" "sort" "strings" @@ -54,6 +55,19 @@ type Issue struct { Reactions ReactionList `xorm:"-"` } +var ( + issueTasksPat *regexp.Regexp + issueTasksDonePat *regexp.Regexp +) + +const issueTasksRegexpStr = `(^\s*-\s\[[\sx]\]\s)|(\n\s*-\s\[[\sx]\]\s)` +const issueTasksDoneRegexpStr = `(^\s*-\s\[[x]\]\s)|(\n\s*-\s\[[x]\]\s)` + +func init() { + issueTasksPat = regexp.MustCompile(issueTasksRegexpStr) + issueTasksDonePat = regexp.MustCompile(issueTasksDoneRegexpStr) +} + func (issue *Issue) loadRepo(e Engine) (err error) { if issue.Repo == nil { issue.Repo, err = getRepositoryByID(e, issue.RepoID) @@ -741,6 +755,7 @@ func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branc func (issue *Issue) ChangeContent(doer *User, content string) (err error) { oldContent := issue.Content issue.Content = content + if err = UpdateIssueCols(issue, "content"); err != nil { return fmt.Errorf("UpdateIssueCols: %v", err) } @@ -818,6 +833,16 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) { return nil } +// GetTasks returns the amount of tasks in the issues content +func (issue *Issue) GetTasks() int { + return len(issueTasksPat.FindAllStringIndex(issue.Content, -1)) +} + +// GetTasksDone returns the amount of completed tasks in the issues content +func (issue *Issue) GetTasksDone() int { + return len(issueTasksDonePat.FindAllStringIndex(issue.Content, -1)) +} + // NewIssueOptions represents the options of a new issue. type NewIssueOptions struct { Repo *Repository |