2022-01-29 02:30:11 +05:30
|
|
|
import $ from 'jquery';
|
2021-10-16 22:58:04 +05:30
|
|
|
import {htmlEscape} from 'escape-goat';
|
2023-02-19 09:36:14 +05:30
|
|
|
import {hideElem, showElem} from '../utils/dom.js';
|
2021-10-16 22:58:04 +05:30
|
|
|
|
2021-10-21 13:07:43 +05:30
|
|
|
const {appSubUrl} = window.config;
|
2021-10-16 22:58:04 +05:30
|
|
|
|
|
|
|
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 09:36:14 +05:30
|
|
|
showElem($templateUnits);
|
|
|
|
hideElem($nonTemplate);
|
2021-10-16 22:58:04 +05:30
|
|
|
} else {
|
2023-02-19 09:36:14 +05:30
|
|
|
hideElem($templateUnits);
|
|
|
|
showElem($nonTemplate);
|
2021-10-16 22:58:04 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
$repoTemplate.on('change', checkTemplate);
|
|
|
|
checkTemplate();
|
|
|
|
|
|
|
|
const changeOwner = function () {
|
|
|
|
$('#repo_template_search')
|
|
|
|
.dropdown({
|
|
|
|
apiSettings: {
|
2022-04-08 00:29:56 +05:30
|
|
|
url: `${appSubUrl}/repo/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
|
2021-10-16 22:58:04 +05:30
|
|
|
onResponse(response) {
|
|
|
|
const filteredResponse = {success: true, results: []};
|
|
|
|
filteredResponse.results.push({
|
|
|
|
name: '',
|
2024-03-22 19:36:53 +05:30
|
|
|
value: '',
|
2021-10-16 22:58:04 +05:30
|
|
|
});
|
|
|
|
// Parse the response from the api to work with our dropdown
|
|
|
|
$.each(response.data, (_r, repo) => {
|
|
|
|
filteredResponse.results.push({
|
2023-05-14 03:29:01 +05:30
|
|
|
name: htmlEscape(repo.repository.full_name),
|
2024-03-22 19:36:53 +05:30
|
|
|
value: repo.repository.id,
|
2021-10-16 22:58:04 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
return filteredResponse;
|
|
|
|
},
|
|
|
|
cache: false,
|
|
|
|
},
|
|
|
|
|
2024-03-22 19:36:53 +05:30
|
|
|
fullTextSearch: true,
|
2021-10-16 22:58:04 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
$('#uid').on('change', changeOwner);
|
|
|
|
changeOwner();
|
|
|
|
}
|