2022-01-28 21:00:11 +00:00
|
|
|
import $ from 'jquery';
|
2021-10-16 17:28:04 +00:00
|
|
|
import {htmlEscape} from 'escape-goat';
|
2024-07-07 15:32:30 +00:00
|
|
|
import {hideElem, showElem} from '../utils/dom.ts';
|
2021-10-16 17:28:04 +00:00
|
|
|
|
2021-10-21 07:37:43 +00:00
|
|
|
const {appSubUrl} = window.config;
|
2021-10-16 17:28:04 +00:00
|
|
|
|
|
|
|
export function initRepoTemplateSearch() {
|
|
|
|
const $repoTemplate = $('#repo_template');
|
|
|
|
const checkTemplate = function () {
|
|
|
|
const $templateUnits = $('#template_units');
|
|
|
|
const $nonTemplate = $('#non_template');
|
|
|
|
if ($repoTemplate.val() !== '' && $repoTemplate.val() !== '0') {
|
2023-02-19 04:06:14 +00:00
|
|
|
showElem($templateUnits);
|
|
|
|
hideElem($nonTemplate);
|
2021-10-16 17:28:04 +00:00
|
|
|
} else {
|
2023-02-19 04:06:14 +00:00
|
|
|
hideElem($templateUnits);
|
|
|
|
showElem($nonTemplate);
|
2021-10-16 17:28:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
$repoTemplate.on('change', checkTemplate);
|
|
|
|
checkTemplate();
|
|
|
|
|
|
|
|
const changeOwner = function () {
|
|
|
|
$('#repo_template_search')
|
|
|
|
.dropdown({
|
|
|
|
apiSettings: {
|
2022-04-07 18:59:56 +00:00
|
|
|
url: `${appSubUrl}/repo/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
|
2021-10-16 17:28:04 +00:00
|
|
|
onResponse(response) {
|
|
|
|
const filteredResponse = {success: true, results: []};
|
|
|
|
filteredResponse.results.push({
|
|
|
|
name: '',
|
2024-03-22 14:06:53 +00:00
|
|
|
value: '',
|
2021-10-16 17:28:04 +00:00
|
|
|
});
|
|
|
|
// Parse the response from the api to work with our dropdown
|
|
|
|
$.each(response.data, (_r, repo) => {
|
|
|
|
filteredResponse.results.push({
|
2023-05-13 21:59:01 +00:00
|
|
|
name: htmlEscape(repo.repository.full_name),
|
2024-03-22 14:06:53 +00:00
|
|
|
value: repo.repository.id,
|
2021-10-16 17:28:04 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return filteredResponse;
|
|
|
|
},
|
|
|
|
cache: false,
|
|
|
|
},
|
|
|
|
|
2024-03-22 14:06:53 +00:00
|
|
|
fullTextSearch: true,
|
2021-10-16 17:28:04 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
$('#uid').on('change', changeOwner);
|
|
|
|
changeOwner();
|
|
|
|
}
|