aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/features/repo-migrate.js
blob: 93d1390b4b4fc469f70bf2a88eb28e66e47217d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import $ from 'jquery';
import {hideElem, showElem} from '../utils/dom.js';

const {appSubUrl, csrfToken} = window.config;

export function initRepoMigrationStatusChecker() {
  const migrating = $('#repo_migrating');
  hideElem($('#repo_migrating_failed'));
  hideElem($('#repo_migrating_failed_image'));
  hideElem($('#repo_migrating_progress_message'));
  if (migrating) {
    const task = migrating.attr('task');
    if (task === undefined) {
      return;
    }
    $.ajax({
      type: 'GET',
      url: `${appSubUrl}/user/task/${task}`,
      data: {
        _csrf: csrfToken,
      },
      complete(xhr) {
        if (xhr.status === 200 && xhr.responseJSON) {
          if (xhr.responseJSON.status === 4) {
            window.location.reload();
            return;
          } else if (xhr.responseJSON.status === 3) {
            hideElem($('#repo_migrating_progress'));
            hideElem($('#repo_migrating'));
            showElem($('#repo_migrating_failed'));
            showElem($('#repo_migrating_failed_image'));
            $('#repo_migrating_failed_error').text(xhr.responseJSON.message);
            return;
          }
          if (xhr.responseJSON.message) {
            showElem($('#repo_migrating_progress_message'));
            $('#repo_migrating_progress_message').text(xhr.responseJSON.message);
          }
          setTimeout(() => {
            initRepoMigrationStatusChecker();
          }, 2000);
          return;
        }
        hideElem($('#repo_migrating_progress'));
        hideElem($('#repo_migrating'));
        showElem($('#repo_migrating_failed'));
        showElem($('#repo_migrating_failed_image'));
      }
    });
  }
}