mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
4.6 KiB
120 lines
4.6 KiB
3 years ago
|
import $ from 'jquery';
|
||
2 years ago
|
import {minimatch} from 'minimatch';
|
||
5 months ago
|
import {createMonaco} from './codeeditor.ts';
|
||
|
import {onInputDebounce, queryElems, toggleElem} from '../utils/dom.ts';
|
||
|
import {POST} from '../modules/fetch.ts';
|
||
3 years ago
|
|
||
3 years ago
|
const {appSubUrl, csrfToken} = window.config;
|
||
3 years ago
|
|
||
|
export function initRepoSettingsCollaboration() {
|
||
|
// Change collaborator access mode
|
||
6 months ago
|
for (const dropdownEl of queryElems('.page-content.repository .ui.dropdown.access-mode')) {
|
||
|
const textEl = dropdownEl.querySelector(':scope > .text');
|
||
|
$(dropdownEl).dropdown({
|
||
|
async action(text, value) {
|
||
|
dropdownEl.classList.add('is-loading', 'loading-icon-2px');
|
||
|
const lastValue = dropdownEl.getAttribute('data-last-value');
|
||
|
$(dropdownEl).dropdown('hide');
|
||
9 months ago
|
try {
|
||
6 months ago
|
const uid = dropdownEl.getAttribute('data-uid');
|
||
|
await POST(dropdownEl.getAttribute('data-url'), {data: new URLSearchParams({uid, 'mode': value})});
|
||
|
textEl.textContent = text;
|
||
|
dropdownEl.setAttribute('data-last-value', value);
|
||
9 months ago
|
} catch {
|
||
6 months ago
|
textEl.textContent = '(error)'; // prevent from misleading users when error occurs
|
||
|
dropdownEl.setAttribute('data-last-value', lastValue);
|
||
|
} finally {
|
||
|
dropdownEl.classList.remove('is-loading');
|
||
9 months ago
|
}
|
||
3 years ago
|
},
|
||
|
onHide() {
|
||
6 months ago
|
// set to the really selected value, defer to next tick to make sure `action` has finished
|
||
|
// its work because the calling order might be onHide -> action
|
||
3 years ago
|
setTimeout(() => {
|
||
6 months ago
|
const $item = $(dropdownEl).dropdown('get item', dropdownEl.getAttribute('data-last-value'));
|
||
3 years ago
|
if ($item) {
|
||
6 months ago
|
$(dropdownEl).dropdown('set selected', dropdownEl.getAttribute('data-last-value'));
|
||
3 years ago
|
} else {
|
||
6 months ago
|
textEl.textContent = '(none)'; // prevent from misleading users when the access mode is undefined
|
||
3 years ago
|
}
|
||
|
}, 0);
|
||
8 months ago
|
},
|
||
3 years ago
|
});
|
||
6 months ago
|
}
|
||
3 years ago
|
}
|
||
|
|
||
|
export function initRepoSettingSearchTeamBox() {
|
||
6 months ago
|
const searchTeamBox = document.querySelector('#search-team-box');
|
||
8 months ago
|
if (!searchTeamBox) return;
|
||
|
|
||
|
$(searchTeamBox).search({
|
||
3 years ago
|
minCharacters: 2,
|
||
|
apiSettings: {
|
||
8 months ago
|
url: `${appSubUrl}/org/${searchTeamBox.getAttribute('data-org-name')}/teams/-/search?q={query}`,
|
||
3 years ago
|
headers: {'X-Csrf-Token': csrfToken},
|
||
3 years ago
|
onResponse(response) {
|
||
|
const items = [];
|
||
|
$.each(response.data, (_i, item) => {
|
||
|
items.push({
|
||
10 months ago
|
title: item.name,
|
||
8 months ago
|
description: `${item.permission} access`, // TODO: translate this string
|
||
3 years ago
|
});
|
||
|
});
|
||
|
|
||
|
return {results: items};
|
||
8 months ago
|
},
|
||
3 years ago
|
},
|
||
|
searchFields: ['name', 'description'],
|
||
8 months ago
|
showNoResults: false,
|
||
3 years ago
|
});
|
||
|
}
|
||
|
|
||
3 years ago
|
export function initRepoSettingGitHook() {
|
||
8 months ago
|
if (!$('.edit.githook').length) return;
|
||
3 years ago
|
const filename = document.querySelector('.hook-filename').textContent;
|
||
3 years ago
|
const _promise = createMonaco($('#content')[0], filename, {language: 'shell'});
|
||
3 years ago
|
}
|
||
|
|
||
|
export function initRepoSettingBranches() {
|
||
8 months ago
|
if (!document.querySelector('.repository.settings.branches')) return;
|
||
|
|
||
6 months ago
|
for (const el of document.querySelectorAll('.toggle-target-enabled')) {
|
||
8 months ago
|
el.addEventListener('change', function () {
|
||
|
const target = document.querySelector(this.getAttribute('data-target'));
|
||
|
target?.classList.toggle('disabled', !this.checked);
|
||
|
});
|
||
|
}
|
||
|
|
||
6 months ago
|
for (const el of document.querySelectorAll('.toggle-target-disabled')) {
|
||
8 months ago
|
el.addEventListener('change', function () {
|
||
|
const target = document.querySelector(this.getAttribute('data-target'));
|
||
|
if (this.checked) target?.classList.add('disabled'); // only disable, do not auto enable
|
||
|
});
|
||
|
}
|
||
|
|
||
6 months ago
|
document.querySelector('#dismiss_stale_approvals')?.addEventListener('change', function () {
|
||
|
document.querySelector('#ignore_stale_approvals_box')?.classList.toggle('disabled', this.checked);
|
||
10 months ago
|
});
|
||
2 years ago
|
|
||
|
// show the `Matched` mark for the status checks that match the pattern
|
||
|
const markMatchedStatusChecks = () => {
|
||
6 months ago
|
const patterns = (document.querySelector('#status_check_contexts').value || '').split(/[\r\n]+/);
|
||
2 years ago
|
const validPatterns = patterns.map((item) => item.trim()).filter(Boolean);
|
||
6 months ago
|
const marks = document.querySelectorAll('.status-check-matched-mark');
|
||
2 years ago
|
|
||
|
for (const el of marks) {
|
||
|
let matched = false;
|
||
|
const statusCheck = el.getAttribute('data-status-check');
|
||
|
for (const pattern of validPatterns) {
|
||
|
if (minimatch(statusCheck, pattern)) {
|
||
|
matched = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
toggleElem(el, matched);
|
||
|
}
|
||
|
};
|
||
|
markMatchedStatusChecks();
|
||
6 months ago
|
document.querySelector('#status_check_contexts').addEventListener('input', onInputDebounce(markMatchedStatusChecks));
|
||
3 years ago
|
}
|