BigW Consortium Gitlab

importer_status.js.coffee 1.3 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").click (event) =>
8 9 10 11 12 13 14
      new_namespace = null
      tr = $(event.currentTarget).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"))
      $.post @import_url, {repo_id: id, new_namespace: new_namespace}, dataType: 'script'
15 16 17 18

    $(".js-import-all").click (event) =>
      $(".js-add-to-import").each ->
        $(this).click()
19

20 21 22 23 24 25
  setAutoUpdate: ->
    setInterval (=>
      $.get @jobs_url, (data) =>
        $.each data, (i, job) =>
          job_item = $("#project_" + job.id)
          status_field = job_item.find(".job-status")
26

27 28
          if job.import_status == 'finished'
            job_item.removeClass("active").addClass("success")
29
            status_field.html('<span><i class="fa fa-check"></i> done</span>')
30 31 32 33
          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)
34 35

    ), 4000