diff options
author | Fatih Acet <acetfatih@gmail.com> | 2016-07-24 23:45:11 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-07-24 23:45:11 +0300 |
commit | aaa9509d120524573085e94af9de5cdde83e3271 (patch) | |
tree | 3824cffd4cdd132ee9cf75a00a7624f5ccc0dabd /app/assets/javascripts/importer_status.js | |
parent | 56b79181adc0bd6e9abef97ea075c14be971a01a (diff) | |
download | gitlab-ce-aaa9509d120524573085e94af9de5cdde83e3271.tar.gz |
ES6ify all the things!
Diffstat (limited to 'app/assets/javascripts/importer_status.js')
-rw-r--r-- | app/assets/javascripts/importer_status.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/app/assets/javascripts/importer_status.js b/app/assets/javascripts/importer_status.js new file mode 100644 index 00000000000..55b6f132bab --- /dev/null +++ b/app/assets/javascripts/importer_status.js @@ -0,0 +1,69 @@ +(function() { + this.ImporterStatus = (function() { + function ImporterStatus(jobs_url, import_url) { + this.jobs_url = jobs_url; + this.import_url = import_url; + this.initStatusPage(); + this.setAutoUpdate(); + } + + ImporterStatus.prototype.initStatusPage = function() { + $('.js-add-to-import').off('click').on('click', (function(_this) { + return function(e) { + var $btn, $namespace_input, $target_field, $tr, id, new_namespace; + $btn = $(e.currentTarget); + $tr = $btn.closest('tr'); + $target_field = $tr.find('.import-target'); + $namespace_input = $target_field.find('input'); + id = $tr.attr('id').replace('repo_', ''); + new_namespace = null; + if ($namespace_input.length > 0) { + new_namespace = $namespace_input.prop('value'); + $target_field.empty().append(new_namespace + "/" + ($target_field.data('project_name'))); + } + $btn.disable().addClass('is-loading'); + return $.post(_this.import_url, { + repo_id: id, + new_namespace: new_namespace + }, { + dataType: 'script' + }); + }; + })(this)); + return $('.js-import-all').off('click').on('click', function(e) { + var $btn; + $btn = $(this); + $btn.disable().addClass('is-loading'); + return $('.js-add-to-import').each(function() { + return $(this).trigger('click'); + }); + }); + }; + + ImporterStatus.prototype.setAutoUpdate = function() { + return setInterval(((function(_this) { + return function() { + return $.get(_this.jobs_url, function(data) { + return $.each(data, function(i, job) { + var job_item, status_field; + job_item = $("#project_" + job.id); + status_field = job_item.find(".job-status"); + if (job.import_status === 'finished') { + job_item.removeClass("active").addClass("success"); + return status_field.html('<span><i class="fa fa-check"></i> done</span>'); + } else if (job.import_status === 'started') { + return status_field.html("<i class='fa fa-spinner fa-spin'></i> started"); + } else { + return status_field.html(job.import_status); + } + }); + }); + }; + })(this)), 4000); + }; + + return ImporterStatus; + + })(); + +}).call(this); |