BigW Consortium Gitlab

importer_status.js.coffee 1.56 KB
Newer Older
1 2 3 4 5 6
class @ImporterStatus
  constructor: (@jobs_url, @import_url) ->
    this.initStatusPage()
    this.setAutoUpdate()

  initStatusPage: ->
7
    $('.js-add-to-import')
8
      .off 'click'
Phil Hughes committed
9
      .on 'click', (e) =>
10
        new_namespace = null
Phil Hughes committed
11
        $btn = $(e.currentTarget)
12 13 14 15 16
        $tr = $btn.closest('tr')
        id = $tr.attr('id').replace('repo_', '')
        if $tr.find('.import-target input').length > 0
          new_namespace = $tr.find('.import-target input').prop('value')
          $tr.find('.import-target').empty().append("#{new_namespace} / #{$tr.find('.import-target').data('project_name')}")
17 18 19 20 21 22 23

        $btn
          .disable()
          .addClass 'is-loading'

        $.post @import_url, {repo_id: id, new_namespace: new_namespace}, dataType: 'script'

24
    $('.js-import-all')
25
      .off 'click'
Phil Hughes committed
26 27
      .on 'click', (e) ->
        $btn = $(@)
28 29 30 31
        $btn
          .disable()
          .addClass 'is-loading'

32
        $('.js-add-to-import').each ->
Phil Hughes committed
33
          $(this).trigger('click')
34

35 36 37 38 39 40
  setAutoUpdate: ->
    setInterval (=>
      $.get @jobs_url, (data) =>
        $.each data, (i, job) =>
          job_item = $("#project_" + job.id)
          status_field = job_item.find(".job-status")
41

42 43
          if job.import_status == 'finished'
            job_item.removeClass("active").addClass("success")
44
            status_field.html('<span><i class="fa fa-check"></i> done</span>')
45 46 47 48
          else if job.import_status == 'started'
            status_field.html("<i class='fa fa-spinner fa-spin'></i> started")
          else
            status_field.html(job.import_status)
49 50

    ), 4000