2018-03-17 18:26:18 +05:30
|
|
|
class ImporterStatus {
|
|
|
|
constructor(jobsUrl, importUrl) {
|
|
|
|
this.jobsUrl = jobsUrl;
|
|
|
|
this.importUrl = importUrl;
|
|
|
|
this.initStatusPage();
|
|
|
|
this.setAutoUpdate();
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
initStatusPage() {
|
|
|
|
$('.js-add-to-import')
|
|
|
|
.off('click')
|
|
|
|
.on('click', (event) => {
|
|
|
|
const $btn = $(event.currentTarget);
|
|
|
|
const $tr = $btn.closest('tr');
|
|
|
|
const $targetField = $tr.find('.import-target');
|
|
|
|
const $namespaceInput = $targetField.find('.js-select-namespace option:selected');
|
|
|
|
const id = $tr.attr('id').replace('repo_', '');
|
|
|
|
let targetNamespace;
|
|
|
|
let newName;
|
|
|
|
if ($namespaceInput.length > 0) {
|
|
|
|
targetNamespace = $namespaceInput[0].innerHTML;
|
|
|
|
newName = $targetField.find('#path').prop('value');
|
|
|
|
$targetField.empty().append(`${targetNamespace}/${newName}`);
|
|
|
|
}
|
|
|
|
$btn.disable().addClass('is-loading');
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
return $.post(this.importUrl, {
|
|
|
|
repo_id: id,
|
|
|
|
target_namespace: targetNamespace,
|
|
|
|
new_name: newName,
|
|
|
|
}, {
|
|
|
|
dataType: 'script',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.js-import-all')
|
|
|
|
.off('click')
|
|
|
|
.on('click', function onClickImportAll() {
|
|
|
|
const $btn = $(this);
|
2016-09-13 17:45:13 +05:30
|
|
|
$btn.disable().addClass('is-loading');
|
2018-03-17 18:26:18 +05:30
|
|
|
return $('.js-add-to-import').each(function triggerAddImport() {
|
2016-09-13 17:45:13 +05:30
|
|
|
return $(this).trigger('click');
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
setAutoUpdate() {
|
|
|
|
return setInterval(() => $.get(this.jobsUrl, data => $.each(data, (i, job) => {
|
|
|
|
const jobItem = $(`#project_${job.id}`);
|
|
|
|
const statusField = jobItem.find('.job-status');
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
const spinner = '<i class="fa fa-spinner fa-spin"></i>';
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
switch (job.import_status) {
|
|
|
|
case 'finished':
|
|
|
|
jobItem.removeClass('active').addClass('success');
|
|
|
|
statusField.html('<span><i class="fa fa-check"></i> done</span>');
|
|
|
|
break;
|
|
|
|
case 'scheduled':
|
|
|
|
statusField.html(`${spinner} scheduled`);
|
|
|
|
break;
|
|
|
|
case 'started':
|
|
|
|
statusField.html(`${spinner} started`);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
statusField.html(job.import_status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
})), 4000);
|
|
|
|
}
|
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
|
export default function initImporterStatus() {
|
|
|
|
const importerStatus = document.querySelector('.js-importer-status');
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if (importerStatus) {
|
|
|
|
const data = importerStatus.dataset;
|
|
|
|
return new ImporterStatus(data.jobsImportPath, data.importPath);
|
|
|
|
}
|
|
|
|
}
|