0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-04-04 03:35:05 +02:00

revert frontend change

This commit is contained in:
wxiaoguang 2026-03-30 16:01:52 +08:00
parent 02a328ae89
commit 198d13de4c
3 changed files with 27 additions and 92 deletions

View File

@ -32,9 +32,6 @@ export class IssueSidebarComboList {
elComboValue: HTMLInputElement;
initialValues: string[];
container: HTMLElement;
// Optional callback invoked after the backend update completes.
// If it returns true, the page reload is skipped.
onAfterUpdate?: (response: Response, changedValues: string[]) => Promise<boolean>;
constructor(container: HTMLElement) {
this.container = container;
@ -66,33 +63,38 @@ export class IssueSidebarComboList {
toggleElem(elEmptyTip, !hasItems);
}
async updateToBackend(changedValues: Array<string>) {
let resp: Response | undefined;
try {
if (this.updateAlgo === 'diff') {
for (const value of this.initialValues) {
if (!changedValues.includes(value)) {
await POST(this.updateUrl, {data: new URLSearchParams({action: 'detach', id: value})});
}
async sendRequestToBackend(changedValues: Array<string>): Promise<Response> {
if (!changedValues.length) throw new Error('No changed values to update');
let lastResp: Response | null = null;
if (this.updateAlgo === 'diff') {
for (const value of this.initialValues) {
if (!changedValues.includes(value)) {
lastResp = await POST(this.updateUrl, {data: new URLSearchParams({action: 'detach', id: value})});
}
for (const value of changedValues) {
if (!this.initialValues.includes(value)) {
resp = await POST(this.updateUrl, {data: new URLSearchParams({action: 'attach', id: value})});
}
}
} else {
resp = await POST(this.updateUrl, {data: new URLSearchParams({id: changedValues.join(',')})});
}
if (resp && !resp.ok) {
showErrorToast(`Failed to update: ${resp.statusText}`);
for (const value of changedValues) {
if (!this.initialValues.includes(value)) {
lastResp = await POST(this.updateUrl, {data: new URLSearchParams({action: 'attach', id: value})});
}
}
} else {
lastResp = await POST(this.updateUrl, {data: new URLSearchParams({id: changedValues.join(',')})});
}
return lastResp!;
}
async updateToBackend(changedValues: Array<string>) {
if (!changedValues.length) return;
try {
const resp = await this.sendRequestToBackend(changedValues);
if (!resp.ok) {
showErrorToast(`Failed to update to backend: ${resp.statusText}`);
return;
}
} catch {
showErrorToast('Failed to update');
return;
issueSidebarReloadConfirmDraftComment();
} catch (e) {
showErrorToast(`Failed to update to backend: ${e}`);
}
if (this.onAfterUpdate && resp && await this.onAfterUpdate(resp, changedValues)) return;
issueSidebarReloadConfirmDraftComment();
}
async doUpdate() {
@ -147,31 +149,7 @@ export class IssueSidebarComboList {
if (this.selectionMode === 'multiple') this.doUpdate();
}
rerender(items: {value: string; text: string}[], selectedValue: string) {
const menu = this.elDropdown.querySelector('.menu')!;
menu.innerHTML = '';
for (const item of items) {
const el = document.createElement('div');
el.className = `item${item.value === selectedValue ? ' checked' : ''}`;
el.setAttribute('data-value', item.value);
el.textContent = item.text;
menu.append(el);
}
this.elComboValue.value = selectedValue;
this.initialValues = selectedValue ? [selectedValue] : [];
this.updateUiList(this.initialValues);
addDelegatedEventListener(this.elDropdown, 'click', '.item', (el, e) => this.onItemClick(el, e));
fomanticQuery(this.elDropdown).dropdown('destroy');
fomanticQuery(this.elDropdown).dropdown({
action: 'nothing',
fullTextSearch: 'exact',
hideDividers: 'empty',
onHide: () => this.onHide(),
});
}
init() {
(this.container as any)._comboList = this;
// init the checked items from initial value
if (this.elComboValue.value && this.elComboValue.value !== '0' && !queryElems(this.elDropdown, `.menu > .item.checked`).length) {
const values = this.elComboValue.value.split(',');

View File

@ -1,39 +0,0 @@
import type {IssueSidebarComboList} from './repo-issue-sidebar-combolist.ts';
type ColumnInfo = {
id: number;
title: string;
};
export function initProjectColumnPicker() {
const projectCombo = document.querySelector<HTMLElement>('.issue-sidebar-combo[data-update-url*="/issues/projects?"]');
if (!projectCombo) return;
const comboList = (projectCombo as any)._comboList as IssueSidebarComboList | undefined;
if (!comboList) return;
const columnComboEl = document.querySelector<HTMLElement>('#sidebar-project-column');
if (!columnComboEl) return;
const columnComboList = (columnComboEl as any)._comboList as IssueSidebarComboList | undefined;
if (!columnComboList) return;
comboList.onAfterUpdate = async (response: Response, _changedValues: string[]): Promise<boolean> => {
const data = await response.json();
const columns: ColumnInfo[] = data.columns || [];
const selectedColumnID: number = data.selected_column_id || 0;
comboList.updateUiList(comboList.collectCheckedValues());
if (columns.length > 1) {
columnComboList.rerender(
columns.map((c) => ({value: String(c.id), text: c.title})),
String(selectedColumnID),
);
columnComboEl.classList.remove('tw-hidden');
} else {
columnComboEl.classList.add('tw-hidden');
}
return true;
};
}

View File

@ -1,7 +1,6 @@
import {POST} from '../modules/fetch.ts';
import {queryElems, toggleElem} from '../utils/dom.ts';
import {IssueSidebarComboList} from './repo-issue-sidebar-combolist.ts';
import {initProjectColumnPicker} from './repo-issue-sidebar-project.ts';
function initBranchSelector() {
// TODO: RemoveIssueRef: see "repo/issue/branch_selector_field.tmpl"
@ -50,7 +49,4 @@ export function initRepoIssueSidebar() {
// init the combo list: a dropdown for selecting items, and a list for showing selected items and related actions
queryElems<HTMLElement>(document, '.issue-sidebar-combo', (el) => new IssueSidebarComboList(el).init());
// hook up the project column picker (must run after combo list init)
initProjectColumnPicker();
}