Skip to content

Commit ab78c39

Browse files
denyskonsilverwind
andauthored
Refactor project templates (#26448)
This PR refactors a bunch of projects-related code, mostly the templates. The following things were done: - rename boards to columns in frontend code - use the new `ctx.Locale.Tr` method - cleanup template, remove useless newlines, classes, comments - merge org-/user and repo level project template together - move "new column" button into project toolbar - move issue card (shared by projects and pinned issues) to shared template, remove useless duplicated styles - add search function to projects (to make the layout more similar to milestones list where it is inherited from 😆) - maybe more changes I forgot I've done 😆 Closes #24893 After: ![Bildschirmfoto vom 2023-08-10 23-02-00](https://github.com/go-gitea/gitea/assets/47871822/cab61456-1d23-4373-8163-e567f1b3b5f9) ![Bildschirmfoto vom 2023-08-10 23-02-26](https://github.com/go-gitea/gitea/assets/47871822/94b55d60-5572-48eb-8111-538a52d8bcc6) ![Bildschirmfoto vom 2023-08-10 23-02-46](https://github.com/go-gitea/gitea/assets/47871822/a0358f4b-4e05-4194-a7bc-6e0ecba5a9b6) --------- Co-authored-by: silverwind <[email protected]>
1 parent 74930b1 commit ab78c39

File tree

16 files changed

+339
-662
lines changed

16 files changed

+339
-662
lines changed

models/project/project.go

+5
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ type SearchOptions struct {
198198
IsClosed util.OptionalBool
199199
OrderBy db.SearchOrderBy
200200
Type Type
201+
Title string
201202
}
202203

203204
func (opts *SearchOptions) toConds() builder.Cond {
@@ -218,6 +219,10 @@ func (opts *SearchOptions) toConds() builder.Cond {
218219
if opts.OwnerID > 0 {
219220
cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
220221
}
222+
223+
if len(opts.Title) != 0 {
224+
cond = cond.And(db.BuildCaseInsensitiveLike("title", opts.Title))
225+
}
221226
return cond
222227
}
223228

routers/web/org/projects.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func Projects(ctx *context.Context) {
4747
sortType := ctx.FormTrim("sort")
4848

4949
isShowClosed := strings.ToLower(ctx.FormTrim("state")) == "closed"
50+
keyword := ctx.FormTrim("q")
5051
page := ctx.FormInt("page")
5152
if page <= 1 {
5253
page = 1
@@ -64,6 +65,7 @@ func Projects(ctx *context.Context) {
6465
IsClosed: util.OptionalBoolOf(isShowClosed),
6566
OrderBy: project_model.GetSearchOrderByBySortType(sortType),
6667
Type: projectType,
68+
Title: keyword,
6769
})
6870
if err != nil {
6971
ctx.ServerError("FindProjects", err)
@@ -395,7 +397,7 @@ func ViewProject(ctx *context.Context) {
395397
ctx.Data["CanWriteProjects"] = canWriteProjects(ctx)
396398
ctx.Data["Project"] = project
397399
ctx.Data["IssuesMap"] = issuesMap
398-
ctx.Data["Boards"] = boards
400+
ctx.Data["Columns"] = boards // TODO: rename boards to columns in backend
399401
shared_user.RenderUserHeader(ctx)
400402

401403
err = shared_user.LoadHeaderCount(ctx)

routers/web/repo/projects.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func Projects(ctx *context.Context) {
5454
sortType := ctx.FormTrim("sort")
5555

5656
isShowClosed := strings.ToLower(ctx.FormTrim("state")) == "closed"
57+
keyword := ctx.FormTrim("q")
5758
repo := ctx.Repo.Repository
5859
page := ctx.FormInt("page")
5960
if page <= 1 {
@@ -76,6 +77,7 @@ func Projects(ctx *context.Context) {
7677
IsClosed: util.OptionalBoolOf(isShowClosed),
7778
OrderBy: project_model.GetSearchOrderByBySortType(sortType),
7879
Type: project_model.TypeRepository,
80+
Title: keyword,
7981
})
8082
if err != nil {
8183
ctx.ServerError("GetProjects", err)
@@ -364,7 +366,7 @@ func ViewProject(ctx *context.Context) {
364366
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
365367
ctx.Data["Project"] = project
366368
ctx.Data["IssuesMap"] = issuesMap
367-
ctx.Data["Boards"] = boards
369+
ctx.Data["Columns"] = boards // TODO: rename boards to columns in backend
368370

369371
ctx.HTML(http.StatusOK, tplProjectsView)
370372
}

templates/projects/list.tmpl

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
{{if and $.CanWriteProjects (not $.Repository.IsArchived)}}
2-
<div class="gt-text-right">
3-
<a class="ui small green button" href="{{$.Link}}/new">{{.locale.Tr "repo.projects.new"}}</a>
2+
<div class="gt-df gt-sb gt-mb-4">
3+
<div class="small-menu-items ui compact tiny menu list-header-toggle">
4+
<a class="item{{if not .IsShowClosed}} active{{end}}" href="{{$.Link}}?state=open&q={{$.Keyword}}">
5+
{{svg "octicon-project-symlink" 16 "gt-mr-3"}}
6+
{{.locale.PrettyNumber .OpenCount}}&nbsp;{{.locale.Tr "repo.issues.open_title"}}
7+
</a>
8+
<a class="item{{if .IsShowClosed}} active{{end}}" href="{{$.Link}}?state=closed&q={{$.Keyword}}">
9+
{{svg "octicon-check" 16 "gt-mr-3"}}
10+
{{.locale.PrettyNumber .ClosedCount}}&nbsp;{{.locale.Tr "repo.issues.closed_title"}}
11+
</a>
12+
</div>
13+
<div class="gt-text-right">
14+
<a class="ui small green button" href="{{$.Link}}/new">{{.locale.Tr "repo.projects.new"}}</a>
15+
</div>
416
</div>
5-
<div class="divider"></div>
617
{{end}}
718

819
{{template "base/alert" .}}
9-
<div class="small-menu-items ui compact tiny menu">
10-
<a class="item{{if not .IsShowClosed}} active{{end}}" href="{{$.Link}}?state=open">
11-
{{svg "octicon-project-symlink" 16 "gt-mr-3"}}
12-
{{.locale.PrettyNumber .OpenCount}}&nbsp;{{.locale.Tr "repo.issues.open_title"}}
13-
</a>
14-
<a class="item{{if .IsShowClosed}} active{{end}}" href="{{$.Link}}?state=closed">
15-
{{svg "octicon-check" 16 "gt-mr-3"}}
16-
{{.locale.PrettyNumber .ClosedCount}}&nbsp;{{.locale.Tr "repo.issues.closed_title"}}
17-
</a>
18-
</div>
1920

20-
<div class="ui right floated secondary filter menu">
21+
<div class="list-header">
22+
<!-- Search -->
23+
<form class="list-header-search ui form ignore-dirty">
24+
<div class="ui small search fluid action input">
25+
<input type="hidden" name="state" value="{{$.State}}">
26+
{{template "shared/searchinput" dict "locale" .locale "Value" .Keyword}}
27+
<button class="ui small icon button" type="submit" aria-label="{{.locale.Tr "explore.search"}}">
28+
{{svg "octicon-search"}}
29+
</button>
30+
</div>
31+
</form>
2132
<!-- Sort -->
22-
<div class="ui dropdown type jump item">
33+
<div class="list-header-sort ui small dropdown type jump item">
2334
<span class="text">
2435
{{.locale.Tr "repo.issues.filter_sort"}}
2536
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
@@ -31,6 +42,7 @@
3142
</div>
3243
</div>
3344
</div>
45+
3446
<div class="milestone-list">
3547
{{range .Projects}}
3648
<li class="milestone-card">

templates/projects/new.tmpl

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<h2 class="ui dividing header">
22
{{if .PageIsEditProjects}}
3-
{{.locale.Tr "repo.projects.edit"}}
4-
<div class="sub header">{{.locale.Tr "repo.projects.edit_subheader"}}</div>
3+
{{ctx.Locale.Tr "repo.projects.edit"}}
4+
<div class="sub header">{{ctx.Locale.Tr "repo.projects.edit_subheader"}}</div>
55
{{else}}
6-
{{.locale.Tr "repo.projects.new"}}
7-
<div class="sub header">{{.locale.Tr "repo.projects.new_subheader"}}</div>
6+
{{ctx.Locale.Tr "repo.projects.new"}}
7+
<div class="sub header">{{ctx.Locale.Tr "repo.projects.new_subheader"}}</div>
88
{{end}}
99
</h2>
1010
{{template "base/alert" .}}
@@ -13,42 +13,42 @@
1313
<div>
1414
<input type="hidden" id="redirect" name="redirect" value="{{.redirect}}">
1515
<div class="field {{if .Err_Title}}error{{end}}">
16-
<label>{{.locale.Tr "repo.projects.title"}}</label>
17-
<input name="title" placeholder="{{.locale.Tr "repo.projects.title"}}" value="{{.title}}" autofocus required>
16+
<label>{{ctx.Locale.Tr "repo.projects.title"}}</label>
17+
<input name="title" placeholder="{{ctx.Locale.Tr "repo.projects.title"}}" value="{{.title}}" autofocus required>
1818
</div>
1919
<div class="field">
20-
<label>{{.locale.Tr "repo.projects.description"}}</label>
21-
<textarea name="content" placeholder="{{.locale.Tr "repo.projects.description_placeholder"}}">{{.content}}</textarea>
20+
<label>{{ctx.Locale.Tr "repo.projects.description"}}</label>
21+
<textarea name="content" placeholder="{{ctx.Locale.Tr "repo.projects.description_placeholder"}}">{{.content}}</textarea>
2222
</div>
2323

2424
{{if not .PageIsEditProjects}}
2525
<div class="field">
26-
<label>{{.locale.Tr "repo.projects.template.desc"}}</label>
26+
<label>{{ctx.Locale.Tr "repo.projects.template.desc"}}</label>
2727
<div class="ui selection dropdown">
2828
<input type="hidden" name="board_type" value="{{.type}}">
29-
<div class="default text">{{.locale.Tr "repo.projects.template.desc_helper"}}</div>
29+
<div class="default text">{{ctx.Locale.Tr "repo.projects.template.desc_helper"}}</div>
3030
<div class="menu">
3131
{{range $element := .BoardTypes}}
32-
<div class="item" data-id="{{$element.BoardType}}" data-value="{{$element.BoardType}}">{{$.locale.Tr $element.Translation}}</div>
32+
<div class="item" data-id="{{$element.BoardType}}" data-value="{{$element.BoardType}}">{{ctx.Locale.Tr $element.Translation}}</div>
3333
{{end}}
3434
</div>
3535
</div>
3636
</div>
3737
{{end}}
3838

3939
<div class="field">
40-
<label>{{.locale.Tr "repo.projects.card_type.desc"}}</label>
40+
<label>{{ctx.Locale.Tr "repo.projects.card_type.desc"}}</label>
4141
<div class="ui selection dropdown">
4242
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
4343
{{range $element := .CardTypes}}
4444
{{if or (eq $.card_type $element.CardType) (and (not $.PageIsEditProjects) (eq $element.CardType 1))}}
4545
<input type="hidden" name="card_type" value="{{$element.CardType}}">
46-
<div class="default text">{{$.locale.Tr $element.Translation}}</div>
46+
<div class="default text">{{ctx.Locale.Tr $element.Translation}}</div>
4747
{{end}}
4848
{{end}}
4949
<div class="menu">
5050
{{range $element := .CardTypes}}
51-
<div class="item" data-id="{{$element.CardType}}" data-value="{{$element.CardType}}">{{$.locale.Tr $element.Translation}}</div>
51+
<div class="item" data-id="{{$element.CardType}}" data-value="{{$element.CardType}}">{{ctx.Locale.Tr $element.Translation}}</div>
5252
{{end}}
5353
</div>
5454
</div>
@@ -57,10 +57,10 @@
5757
<div class="divider"></div>
5858
<div class="gt-text-right">
5959
<a class="ui cancel button" href="{{$.CancelLink}}">
60-
{{.locale.Tr "repo.milestones.cancel"}}
60+
{{ctx.Locale.Tr "repo.milestones.cancel"}}
6161
</a>
6262
<button class="ui primary button">
63-
{{if .PageIsEditProjects}}{{.locale.Tr "repo.projects.modify"}}{{else}}{{.locale.Tr "repo.projects.create"}}{{end}}
63+
{{if .PageIsEditProjects}}{{ctx.Locale.Tr "repo.projects.modify"}}{{else}}{{ctx.Locale.Tr "repo.projects.create"}}{{end}}
6464
</button>
6565
</div>
6666
</form>

0 commit comments

Comments
 (0)