diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-01-20 21:07:37 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-01-20 21:07:37 +0000 |
commit | 148740cc6769b0faf7ee564552143ccd0a18768b (patch) | |
tree | 36df01c89082a64332fd926e0eec5bc6e20d126b | |
parent | 5ade3a6b781413c62df2ce44f6b79ba8ef3c3d62 (diff) | |
parent | 6da0ab7d60ecdf189190ac095aecdf174e73a03e (diff) | |
download | gitlab-ce-148740cc6769b0faf7ee564552143ccd0a18768b.tar.gz |
Merge branch 'github_importer' into 'master'
Github importer: AJAX update status
#1907
See merge request !1417
-rw-r--r-- | app/controllers/github_imports_controller.rb | 7 | ||||
-rw-r--r-- | app/views/github_imports/create.js.haml | 6 | ||||
-rw-r--r-- | app/views/github_imports/status.html.haml | 27 | ||||
-rw-r--r-- | config/routes.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/github/project_creator.rb | 2 |
5 files changed, 34 insertions, 9 deletions
diff --git a/app/controllers/github_imports_controller.rb b/app/controllers/github_imports_controller.rb index c96bef598be..ac5cfd8d45d 100644 --- a/app/controllers/github_imports_controller.rb +++ b/app/controllers/github_imports_controller.rb @@ -22,6 +22,11 @@ class GithubImportsController < ApplicationController @repos.reject!{|repo| already_added_projects_names.include? repo.full_name} end + def jobs + jobs = current_user.created_projects.where(import_type: "github").to_json(:only => [:id, :import_status]) + render json: jobs + end + def create @repo_id = params[:repo_id].to_i repo = octo_client.repo(@repo_id) @@ -42,7 +47,7 @@ class GithubImportsController < ApplicationController namespace.add_owner(current_user) end - Gitlab::Github::ProjectCreator.new(repo, namespace, current_user).execute + @project = Gitlab::Github::ProjectCreator.new(repo, namespace, current_user).execute end private diff --git a/app/views/github_imports/create.js.haml b/app/views/github_imports/create.js.haml index 363dfeb4f54..cd4c9fbf360 100644 --- a/app/views/github_imports/create.js.haml +++ b/app/views/github_imports/create.js.haml @@ -12,5 +12,7 @@ target_field.find('input').prop("value", origin_namespace) - else :plain - $("table.import-jobs tbody").prepend($("tr#repo_#{@repo_id}")) - $("tr#repo_#{@repo_id}").addClass("active").find(".import-actions").html("<i class='fa fa-spinner fa-spin'></i> started") + job = $("tr#repo_#{@repo_id}") + job.attr("id", "project_#{@project.id}") + $("table.import-jobs tbody").prepend(job) + job.addClass("active").find(".import-actions").html("<i class='fa fa-spinner fa-spin'></i> started") diff --git a/app/views/github_imports/status.html.haml b/app/views/github_imports/status.html.haml index 47c60e4d45f..52a1e16cd04 100644 --- a/app/views/github_imports/status.html.haml +++ b/app/views/github_imports/status.html.haml @@ -3,9 +3,7 @@ Import repositories from GitHub.com %p.light - Select projects you want to import. - %span.pull-right - Reload to see the progress. + Select projects you want to import. %hr %table.table.import-jobs @@ -16,11 +14,11 @@ %th Status %tbody - @already_added_projects.each do |project| - %tr{id: "repo_#{project.id}", class: "#{project_status_css_class(project.import_status)}"} + %tr{id: "project_#{project.id}", class: "#{project_status_css_class(project.import_status)}"} %td= project.import_source %td %strong= link_to project.name_with_namespace, project - %td + %td.job-status - if project.import_status == 'finished' %span.cgreen %i.fa.fa-check @@ -33,7 +31,7 @@ %td= repo.full_name %td.import-target = repo.full_name - %td.import-actions + %td.import-actions.job-status = button_tag "Add", class: "btn btn-add-to-import" @@ -46,3 +44,20 @@ 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 "#{github_import_url}", {repo_id: id, new_namespace: new_namespace}, dataType: 'script' + + + setInterval (-> + $.get "#{jobs_github_import_path}", (data)-> + $.each data, (i, job) -> + job_item = $("#project_" + job.id) + status_field = job_item.find(".job-status") + + if job.import_status == 'finished' + job_item.removeClass("active").addClass("success") + status_field.html('<span class="cgreen"><i class="fa fa-check"></i> done</span>') + 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) + + ), 4000 diff --git a/config/routes.rb b/config/routes.rb index 648ab53926d..ef3c5aedfcb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,6 +57,7 @@ Gitlab::Application.routes.draw do resource :github_import, only: [:create, :new] do get :status get :callback + get :jobs end # diff --git a/lib/gitlab/github/project_creator.rb b/lib/gitlab/github/project_creator.rb index 682ef389e44..7b04926071f 100644 --- a/lib/gitlab/github/project_creator.rb +++ b/lib/gitlab/github/project_creator.rb @@ -31,6 +31,8 @@ module Gitlab @project.import_start end end + + @project end end end |