Skip to content

Commit 141d782

Browse files
silverwindGiteaBotwxiaoguang
authored
Refactor repo-projects.ts (#32892)
- Remove jQuery - Add types to all functions - Tested all modified functionality --------- Co-authored-by: Giteabot <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent dc8f59b commit 141d782

File tree

8 files changed

+152
-239
lines changed

8 files changed

+152
-239
lines changed

routers/web/web.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,14 +1020,15 @@ func registerRoutes(m *web.Router) {
10201020
m.Get("/new", org.RenderNewProject)
10211021
m.Post("/new", web.Bind(forms.CreateProjectForm{}), org.NewProjectPost)
10221022
m.Group("/{id}", func() {
1023-
m.Post("", web.Bind(forms.EditProjectColumnForm{}), org.AddColumnToProjectPost)
1024-
m.Post("/move", project.MoveColumns)
10251023
m.Post("/delete", org.DeleteProject)
10261024

10271025
m.Get("/edit", org.RenderEditProject)
10281026
m.Post("/edit", web.Bind(forms.CreateProjectForm{}), org.EditProjectPost)
10291027
m.Post("/{action:open|close}", org.ChangeProjectStatus)
10301028

1029+
// TODO: improper name. Others are "delete project", "edit project", but this one is "move columns"
1030+
m.Post("/move", project.MoveColumns)
1031+
m.Post("/columns/new", web.Bind(forms.EditProjectColumnForm{}), org.AddColumnToProjectPost)
10311032
m.Group("/{columnID}", func() {
10321033
m.Put("", web.Bind(forms.EditProjectColumnForm{}), org.EditProjectColumn)
10331034
m.Delete("", org.DeleteProjectColumn)
@@ -1387,14 +1388,15 @@ func registerRoutes(m *web.Router) {
13871388
m.Get("/new", repo.RenderNewProject)
13881389
m.Post("/new", web.Bind(forms.CreateProjectForm{}), repo.NewProjectPost)
13891390
m.Group("/{id}", func() {
1390-
m.Post("", web.Bind(forms.EditProjectColumnForm{}), repo.AddColumnToProjectPost)
1391-
m.Post("/move", project.MoveColumns)
13921391
m.Post("/delete", repo.DeleteProject)
13931392

13941393
m.Get("/edit", repo.RenderEditProject)
13951394
m.Post("/edit", web.Bind(forms.CreateProjectForm{}), repo.EditProjectPost)
13961395
m.Post("/{action:open|close}", repo.ChangeProjectStatus)
13971396

1397+
// TODO: improper name. Others are "delete project", "edit project", but this one is "move columns"
1398+
m.Post("/move", project.MoveColumns)
1399+
m.Post("/columns/new", web.Bind(forms.EditProjectColumnForm{}), repo.AddColumnToProjectPost)
13981400
m.Group("/{columnID}", func() {
13991401
m.Put("", web.Bind(forms.EditProjectColumnForm{}), repo.EditProjectColumn)
14001402
m.Delete("", repo.DeleteProjectColumn)

templates/projects/view.tmpl

Lines changed: 58 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,25 @@
3737
{{ctx.Locale.Tr "repo.projects.close"}}
3838
</button>
3939
{{end}}
40-
<button class="item btn delete-button" data-url="{{.Link}}/delete" data-id="{{.Project.ID}}">
40+
<button class="item btn link-action" data-url="{{.Link}}/delete?id={{.Project.ID}}"
41+
data-modal-confirm-header="{{ctx.Locale.Tr "repo.projects.deletion"}}"
42+
data-modal-confirm-content="{{ctx.Locale.Tr "repo.projects.deletion_desc"}}"
43+
>
4144
{{svg "octicon-trash"}}
4245
{{ctx.Locale.Tr "repo.issues.label_delete"}}
4346
</button>
44-
<button class="item btn show-modal" data-modal="#new-project-column-item">
47+
<button class="item btn show-modal show-project-column-modal-edit" data-modal="#project-column-modal-edit"
48+
data-modal-header="{{ctx.Locale.Tr "repo.projects.column.new"}}"
49+
data-modal-project-column-title-label="{{ctx.Locale.Tr "repo.projects.column.new_title"}}"
50+
data-modal-project-column-button-save="{{ctx.Locale.Tr "repo.projects.column.new_submit"}}"
51+
data-modal-project-column-id=""
52+
data-modal-project-column-title-input=""
53+
data-modal-project-column-color-input=""
54+
>
4555
{{svg "octicon-plus"}}
4656
{{ctx.Locale.Tr "new_project_column"}}
4757
</button>
4858
</div>
49-
<div class="ui small modal new-project-column-modal" id="new-project-column-item">
50-
<div class="header">
51-
{{ctx.Locale.Tr "repo.projects.column.new"}}
52-
</div>
53-
<div class="content">
54-
<form class="ui form">
55-
<div class="required field">
56-
<label for="new_project_column">{{ctx.Locale.Tr "repo.projects.column.new_title"}}</label>
57-
<input class="new-project-column" id="new_project_column" name="title" required>
58-
</div>
59-
60-
<div class="field color-field">
61-
<label for="new_project_column_color_picker">{{ctx.Locale.Tr "repo.projects.column.color"}}</label>
62-
<div class="js-color-picker-input column">
63-
<input maxlength="7" placeholder="#c320f6" id="new_project_column_color_picker" name="color">
64-
{{template "repo/issue/label_precolors"}}
65-
</div>
66-
</div>
67-
68-
<div class="text right actions">
69-
<button class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button>
70-
<button data-url="{{$.Link}}" class="ui primary button" id="new_project_column_submit">{{ctx.Locale.Tr "repo.projects.column.new_submit"}}</button>
71-
</div>
72-
</form>
73-
</div>
74-
</div>
7559
{{end}}
7660
</div>
7761

@@ -80,88 +64,43 @@
8064
<div class="divider"></div>
8165
</div>
8266

83-
<div id="project-board">
84-
<div class="board {{if .CanWriteProjects}}sortable{{end}}"{{if .CanWriteProjects}} data-url="{{$.Link}}/move"{{end}}>
67+
<div id="project-board" data-project-borad-writable="{{$canWriteProject}}">
68+
<div class="board {{if $canWriteProject}}sortable{{end}}" {{if $canWriteProject}}data-url="{{$.Link}}/move"{{end}}>
8569
{{range .Columns}}
86-
<div class="project-column"{{if .Color}} style="background: {{.Color}} !important; color: {{ContrastColor .Color}} !important"{{end}} data-id="{{.ID}}" data-sorting="{{.Sorting}}" data-url="{{$.Link}}/{{.ID}}">
70+
<div class="project-column" {{if .Color}}style="background: {{.Color}} !important; color: {{ContrastColor .Color}} !important"{{end}} data-id="{{.ID}}" data-sorting="{{.Sorting}}" data-url="{{$.Link}}/{{.ID}}">
8771
<div class="project-column-header{{if $canWriteProject}} tw-cursor-grab{{end}}">
8872
<div class="ui circular label project-column-issue-count">
8973
{{.NumIssues ctx}}
9074
</div>
91-
<div class="project-column-title-label gt-ellipsis">{{.Title}}</div>
75+
<div class="project-column-title-text gt-ellipsis">{{.Title}}</div>
9276
{{if $canWriteProject}}
9377
<div class="ui dropdown tw-p-1">
9478
{{svg "octicon-kebab-horizontal"}}
9579
<div class="menu">
96-
<a class="item show-modal button" data-modal="#edit-project-column-modal-{{.ID}}">
97-
{{svg "octicon-pencil"}}
98-
{{ctx.Locale.Tr "repo.projects.column.edit"}}
80+
<a class="item button show-modal show-project-column-modal-edit" data-modal="#project-column-modal-edit"
81+
data-modal-header="{{ctx.Locale.Tr "repo.projects.column.edit"}}"
82+
data-modal-project-column-title-label="{{ctx.Locale.Tr "repo.projects.column.edit_title"}}"
83+
data-modal-project-column-button-save="{{ctx.Locale.Tr "repo.projects.column.edit"}}"
84+
data-modal-project-column-id="{{.ID}}"
85+
data-modal-project-column-title-input="{{.Title}}"
86+
data-modal-project-column-color-input="{{.Color}}"
87+
>
88+
{{svg "octicon-pencil"}} {{ctx.Locale.Tr "repo.projects.column.edit"}}
9989
</a>
10090
{{if not .Default}}
101-
<a class="item show-modal button default-project-column-show"
102-
data-modal="#default-project-column-modal-{{.ID}}"
103-
data-modal-default-project-column-header="{{ctx.Locale.Tr "repo.projects.column.set_default"}}"
104-
data-modal-default-project-column-content="{{ctx.Locale.Tr "repo.projects.column.set_default_desc"}}"
105-
data-url="{{$.Link}}/{{.ID}}/default">
106-
{{svg "octicon-pin"}}
107-
{{ctx.Locale.Tr "repo.projects.column.set_default"}}
91+
<a class="item button link-action" data-url="{{$.Link}}/{{.ID}}/default"
92+
data-modal-confirm-header="{{ctx.Locale.Tr "repo.projects.column.set_default"}}"
93+
data-modal-confirm-content="{{ctx.Locale.Tr "repo.projects.column.set_default_desc"}}"
94+
>
95+
{{svg "octicon-pin"}} {{ctx.Locale.Tr "repo.projects.column.set_default"}}
10896
</a>
109-
<a class="item show-modal button show-delete-project-column-modal"
110-
data-modal="#delete-project-column-modal-{{.ID}}"
111-
data-url="{{$.Link}}/{{.ID}}">
112-
{{svg "octicon-trash"}}
113-
{{ctx.Locale.Tr "repo.projects.column.delete"}}
97+
<a class="item button link-action" data-url="{{$.Link}}/{{.ID}}" data-link-action-method="DELETE"
98+
data-modal-confirm-header="{{ctx.Locale.Tr "repo.projects.column.delete"}}"
99+
data-modal-confirm-content="{{ctx.Locale.Tr "repo.projects.column.deletion_desc"}}"
100+
>
101+
{{svg "octicon-trash"}} {{ctx.Locale.Tr "repo.projects.column.delete"}}
114102
</a>
115103
{{end}}
116-
117-
<div class="ui small modal edit-project-column-modal" id="edit-project-column-modal-{{.ID}}">
118-
<div class="header">
119-
{{ctx.Locale.Tr "repo.projects.column.edit"}}
120-
</div>
121-
<div class="content">
122-
<form class="ui form">
123-
<div class="required field">
124-
<label for="new_project_column_title">{{ctx.Locale.Tr "repo.projects.column.edit_title"}}</label>
125-
<input class="project-column-title-input" id="new_project_column_title" name="title" value="{{.Title}}" required>
126-
</div>
127-
128-
<div class="field color-field">
129-
<label for="new_project_column_color">{{ctx.Locale.Tr "repo.projects.column.color"}}</label>
130-
<div class="js-color-picker-input column">
131-
<input maxlength="7" placeholder="#c320f6" id="new_project_column_color" name="color" value="{{.Color}}">
132-
{{template "repo/issue/label_precolors"}}
133-
</div>
134-
</div>
135-
136-
<div class="text right actions">
137-
<button class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button>
138-
<button data-url="{{$.Link}}/{{.ID}}" class="ui primary button edit-project-column-button">{{ctx.Locale.Tr "repo.projects.column.edit"}}</button>
139-
</div>
140-
</form>
141-
</div>
142-
</div>
143-
144-
<div class="ui g-modal-confirm modal default-project-column-modal" id="default-project-column-modal-{{.ID}}">
145-
<div class="header">
146-
<span id="default-project-column-header"></span>
147-
</div>
148-
<div class="content">
149-
<label id="default-project-column-content"></label>
150-
</div>
151-
{{template "base/modal_actions_confirm" (dict "ModalButtonTypes" "confirm")}}
152-
</div>
153-
154-
<div class="ui g-modal-confirm modal" id="delete-project-column-modal-{{.ID}}">
155-
<div class="header">
156-
{{ctx.Locale.Tr "repo.projects.column.delete"}}
157-
</div>
158-
<div class="content">
159-
<label>
160-
{{ctx.Locale.Tr "repo.projects.column.deletion_desc"}}
161-
</label>
162-
</div>
163-
{{template "base/modal_actions_confirm" (dict "ModalButtonTypes" "confirm")}}
164-
</div>
165104
</div>
166105
</div>
167106
{{end}}
@@ -179,15 +118,28 @@
179118
</div>
180119
</div>
181120

182-
{{if .CanWriteProjects}}
183-
<div class="ui g-modal-confirm delete modal">
184-
<div class="header">
185-
{{svg "octicon-trash"}}
186-
{{ctx.Locale.Tr "repo.projects.deletion"}}
187-
</div>
188-
<div class="content">
189-
<p>{{ctx.Locale.Tr "repo.projects.deletion_desc"}}</p>
190-
</div>
191-
{{template "base/modal_actions_confirm" .}}
121+
{{if $canWriteProject}}
122+
<div class="ui small modal" id="project-column-modal-edit">
123+
<div class="header">edit</div>
124+
<div class="content">
125+
<form class="ui form ignore-dirty" method="post" data-action-base-link="{{$.Link}}">
126+
<input class="project-column-id" type="hidden" name="id">
127+
<div class="required field">
128+
<label class="project-column-title-label" for="project-column-title-input">title</label>
129+
<input id="project-column-title-input" name="title" value="{{.Title}}" required>
130+
</div>
131+
<div class="field">
132+
<label class="project-column-color-label" for="project-column-color-input">color</label>
133+
<div class="js-color-picker-input column">
134+
<input maxlength="7" placeholder="#c320f6" id="project-column-color-input" name="color" value="{{.Color}}">
135+
{{template "repo/issue/label_precolors"}}
136+
</div>
137+
</div>
138+
<div class="actions tw-text-right">
139+
<button class="ui cancel button">{{ctx.Locale.Tr "settings.cancel"}}</button>
140+
<button type="submit" class="ui primary button project-column-button-save">save</button>
141+
</div>
142+
</form>
192143
</div>
144+
</div>
193145
{{end}}

templates/repo/issue/labels/label_edit_modal.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<input class="label-desc-input" name="description" placeholder="{{ctx.Locale.Tr "repo.issues.new_label_desc_placeholder"}}" maxlength="200">
4242
</div>
4343
</div>
44-
<div class="field color-field">
44+
<div class="field">
4545
<label for="color">{{ctx.Locale.Tr "repo.issues.label_color"}}</label>
4646
<div class="column js-color-picker-input">
4747
<input name="color" value="#70c24a"placeholder="#c320f6" required maxlength="7">

web_src/css/features/projects.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@
5151
color: inherit;
5252
}
5353

54-
.project-column-title-label {
55-
flex: 1;
56-
}
57-
5854
.project-column > .cards {
5955
flex: 1;
6056
display: flex;

web_src/js/features/common-fetch-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async function linkAction(el: HTMLElement, e: Event) {
100100
const url = el.getAttribute('data-url');
101101
const doRequest = async () => {
102102
if ('disabled' in el) el.disabled = true; // el could be A or BUTTON, but A doesn't have disabled attribute
103-
await fetchActionDoRequest(el, url, {method: 'POST'});
103+
await fetchActionDoRequest(el, url, {method: el.getAttribute('data-link-action-method') || 'POST'});
104104
if ('disabled' in el) el.disabled = false;
105105
};
106106

0 commit comments

Comments
 (0)