mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Fix PR toggle WIP (#34920)
Fix #34919 --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -443,6 +443,10 @@ func ViewPullMergeBox(ctx *context.Context) { | ||||
| 	preparePullViewPullInfo(ctx, issue) | ||||
| 	preparePullViewReviewAndMerge(ctx, issue) | ||||
| 	ctx.Data["PullMergeBoxReloading"] = issue.PullRequest.IsChecking() | ||||
|  | ||||
| 	// TODO: it should use a dedicated struct to render the pull merge box, to make sure all data is prepared correctly | ||||
| 	ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.Doer.ID) | ||||
| 	ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) | ||||
| 	ctx.HTML(http.StatusOK, tplPullMergeBox) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| {{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .HasMerged) (not .Issue.IsClosed) (not .IsPullWorkInProgress)}} | ||||
| 	<a class="toggle-wip tw-block tw-mt-2" data-title="{{.Issue.Title}}" data-wip-prefix="{{index .PullRequestWorkInProgressPrefixes 0}}" data-update-url="{{.Issue.Link}}/title"> | ||||
| 	<a data-global-init="initPullRequestWipToggle" data-title="{{.Issue.Title}}" data-wip-prefix="{{index .PullRequestWorkInProgressPrefixes 0}}" data-update-url="{{.Issue.Link}}/title"> | ||||
| 		{{ctx.Locale.Tr "repo.pulls.still_in_progress"}} {{ctx.Locale.Tr "repo.pulls.add_prefix" (index .PullRequestWorkInProgressPrefixes 0)}} | ||||
| 	</a> | ||||
| {{end}} | ||||
|   | ||||
| @@ -95,7 +95,7 @@ | ||||
| 						{{ctx.Locale.Tr "repo.pulls.cannot_merge_work_in_progress"}} | ||||
| 					</div> | ||||
| 					{{if or .HasIssuesOrPullsWritePermission .IsIssuePoster}} | ||||
| 						<button class="ui compact button toggle-wip" data-title="{{.Issue.Title}}" data-wip-prefix="{{.WorkInProgressPrefix}}" data-update-url="{{.Issue.Link}}/title"> | ||||
| 						<button class="ui compact button" data-global-init="initPullRequestWipToggle" data-title="{{.Issue.Title}}" data-wip-prefix="{{.WorkInProgressPrefix}}" data-update-url="{{.Issue.Link}}/title"> | ||||
| 							{{ctx.Locale.Tr "repo.pulls.remove_prefix" .WorkInProgressPrefix}} | ||||
| 						</button> | ||||
| 					{{end}} | ||||
|   | ||||
| @@ -17,6 +17,7 @@ import {showErrorToast} from '../modules/toast.ts'; | ||||
| import {initRepoIssueSidebar} from './repo-issue-sidebar.ts'; | ||||
| import {fomanticQuery} from '../modules/fomantic/base.ts'; | ||||
| import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts'; | ||||
| import {registerGlobalInitFunc} from '../modules/observer.ts'; | ||||
|  | ||||
| const {appSubUrl} = window.config; | ||||
|  | ||||
| @@ -416,25 +417,20 @@ export function initRepoIssueWipNewTitle() { | ||||
|  | ||||
| export function initRepoIssueWipToggle() { | ||||
|   // Toggle WIP for existing PR | ||||
|   queryElems(document, '.toggle-wip', (el) => el.addEventListener('click', async (e) => { | ||||
|   registerGlobalInitFunc('initPullRequestWipToggle', (toggleWip) => toggleWip.addEventListener('click', async (e) => { | ||||
|     e.preventDefault(); | ||||
|     const toggleWip = el; | ||||
|     const title = toggleWip.getAttribute('data-title'); | ||||
|     const wipPrefix = toggleWip.getAttribute('data-wip-prefix'); | ||||
|     const updateUrl = toggleWip.getAttribute('data-update-url'); | ||||
|  | ||||
|     try { | ||||
|       const params = new URLSearchParams(); | ||||
|       params.append('title', title?.startsWith(wipPrefix) ? title.slice(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`); | ||||
|  | ||||
|       const response = await POST(updateUrl, {data: params}); | ||||
|       if (!response.ok) { | ||||
|         throw new Error('Failed to toggle WIP status'); | ||||
|       } | ||||
|       window.location.reload(); | ||||
|     } catch (error) { | ||||
|       console.error(error); | ||||
|     const params = new URLSearchParams(); | ||||
|     params.append('title', title?.startsWith(wipPrefix) ? title.slice(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`); | ||||
|     const response = await POST(updateUrl, {data: params}); | ||||
|     if (!response.ok) { | ||||
|       showErrorToast(`Failed to toggle 'work in progress' status`); | ||||
|       return; | ||||
|     } | ||||
|     window.location.reload(); | ||||
|   })); | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user