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

Add unset default project column #23531

Merged
merged 14 commits into from
Apr 19, 2023
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,8 @@ projects.column.new_submit = "Create Column"
projects.column.new = "New Column"
projects.column.set_default = "Set Default"
projects.column.set_default_desc = "Set this column as default for uncategorized issues and pulls"
projects.column.unset_default = "Unset Default"
projects.column.unset_default_desc = "Unset this column as default"
projects.column.delete = "Delete Column"
projects.column.deletion_desc = "Deleting a project column moves all related issues to 'Uncategorized'. Continue?"
projects.column.color = "Color"
Expand Down
17 changes: 17 additions & 0 deletions routers/web/org/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,23 @@ func SetDefaultProjectBoard(ctx *context.Context) {
})
}

// UnsetDefaultProjectBoard unset default board for uncategorized issues/pulls
func UnsetDefaultProjectBoard(ctx *context.Context) {
project, _ := CheckProjectBoardChangePermissions(ctx)
if ctx.Written() {
return
}

if err := project_model.SetDefaultBoard(project.ID, 0); err != nil {
ctx.ServerError("SetDefaultBoard", err)
return
}

ctx.JSON(http.StatusOK, map[string]interface{}{
"ok": true,
})
}

// MoveIssues moves or keeps issues in a column and sorts them inside that column
func MoveIssues(ctx *context.Context) {
if ctx.Doer == nil {
Expand Down
17 changes: 17 additions & 0 deletions routers/web/repo/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,23 @@ func SetDefaultProjectBoard(ctx *context.Context) {
})
}

// UnSetDefaultProjectBoard unset default board for uncategorized issues/pulls
func UnSetDefaultProjectBoard(ctx *context.Context) {
project, _ := checkProjectBoardChangePermissions(ctx)
if ctx.Written() {
return
}

if err := project_model.SetDefaultBoard(project.ID, 0); err != nil {
ctx.ServerError("SetDefaultBoard", err)
return
}

ctx.JSON(http.StatusOK, map[string]interface{}{
"ok": true,
})
}

// MoveIssues moves or keeps issues in a column and sorts them inside that column
func MoveIssues(ctx *context.Context) {
if ctx.Doer == nil {
Expand Down
2 changes: 2 additions & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ func RegisterRoutes(m *web.Route) {
m.Put("", web.Bind(forms.EditProjectBoardForm{}), org.EditProjectBoard)
m.Delete("", org.DeleteProjectBoard)
m.Post("/default", org.SetDefaultProjectBoard)
m.Post("/unsetdefault", org.UnsetDefaultProjectBoard)

m.Post("/move", org.MoveIssues)
})
Expand Down Expand Up @@ -1296,6 +1297,7 @@ func RegisterRoutes(m *web.Route) {
m.Put("", web.Bind(forms.EditProjectBoardForm{}), repo.EditProjectBoard)
m.Delete("", repo.DeleteProjectBoard)
m.Post("/default", repo.SetDefaultProjectBoard)
m.Post("/unsetdefault", repo.UnSetDefaultProjectBoard)

m.Post("/move", repo.MoveIssues)
})
Expand Down
20 changes: 20 additions & 0 deletions templates/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
{{svg "octicon-pin"}}
{{$.locale.Tr "repo.projects.column.set_default"}}
</a>
{{else}}
<a class="item show-modal button" data-modal="#unset-default-project-board-modal-{{.ID}}">
{{svg "octicon-pin"}}
{{$.locale.Tr "repo.projects.column.unset_default"}}
</a>
{{end}}
<a class="item show-modal button" data-modal="#delete-board-modal-{{.ID}}">
{{svg "octicon-trash"}}
Expand Down Expand Up @@ -149,6 +154,21 @@
</div>
</div>

<div class="ui basic modal" id="unset-default-project-board-modal-{{.ID}}">
<div class="ui icon header">
{{$.locale.Tr "repo.projects.column.unset_default"}}
</div>
<div class="content center">
<label>
{{$.locale.Tr "repo.projects.column.unset_default_desc"}}
</label>
</div>
<div class="text right actions">
<button class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</button>
<button class="ui red button unset-default-project-board" data-url="{{$.Link}}/{{.ID}}/unsetdefault">{{$.locale.Tr "repo.projects.column.unset_default"}}</button>
</div>
</div>

<div class="ui basic modal" id="delete-board-modal-{{.ID}}">
<div class="ui icon header">
{{$.locale.Tr "repo.projects.column.delete"}}
Expand Down
20 changes: 20 additions & 0 deletions templates/repo/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
{{svg "octicon-pin"}}
{{$.locale.Tr "repo.projects.column.set_default"}}
</a>
{{else}}
<a class="item show-modal button" data-modal="#unset-default-project-board-modal-{{.ID}}">
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC there is a general method to pass variables to a model dialog, then there is no need to create a lot of model elements on the page?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, not blocker, if this is ready for merge, I will do following improvements in next PR

Copy link
Contributor Author

@yp05327 yp05327 Apr 13, 2023

Choose a reason for hiding this comment

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

I’m trying to improve the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you. Never mind, IMO no need to block as long as it works. The "project/board" pages have too much technical debt in history and might need some more improvements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried my best to improve the code here 😭
You are welcome to improve them later.
When you have finished the improvement, please mention me as I want to learn more about good frontend coding 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move on , maybe some maintainers could help to merge 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Waiting for unpin icon.

{{svg "octicon-pin"}}
{{$.locale.Tr "repo.projects.column.unset_default"}}
</a>
{{end}}
<a class="item show-modal button" data-modal="#delete-board-modal-{{.ID}}">
{{svg "octicon-trash"}}
Expand Down Expand Up @@ -153,6 +158,21 @@
</div>
</div>

<div class="ui basic modal" id="unset-default-project-board-modal-{{.ID}}">
<div class="ui icon header">
{{$.locale.Tr "repo.projects.column.unset_default"}}
</div>
<div class="content center">
<label>
{{$.locale.Tr "repo.projects.column.unset_default_desc"}}
</label>
</div>
<div class="text right actions">
<button class="ui cancel button">{{$.locale.Tr "settings.cancel"}}</button>
<button class="ui red button unset-default-project-board" data-url="{{$.Link}}/{{.ID}}/unsetdefault">{{$.locale.Tr "repo.projects.column.unset_default"}}</button>
</div>
</div>

<div class="ui basic modal" id="delete-board-modal-{{.ID}}">
<div class="ui icon header">
{{$.locale.Tr "repo.projects.column.delete"}}
Expand Down
15 changes: 15 additions & 0 deletions web_src/js/features/repo-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ export function initRepoProject() {
window.location.reload();
});

$(document).on('click', '.unset-default-project-board', async function (e) {
e.preventDefault();

await $.ajax({
method: 'POST',
url: $(this).data('url'),
silverwind marked this conversation as resolved.
Show resolved Hide resolved
headers: {
'X-Csrf-Token': csrfToken,
},
contentType: 'application/json',
});

window.location.reload();
});

$('.delete-project-board').each(function () {
$(this).click(function (e) {
e.preventDefault();
Expand Down