#321: added UI for mass_import
This commit is contained in:
parent
2899728a33
commit
dbf3f24b21
|
@ -3,6 +3,7 @@ class Projects::ProjectsController < Projects::BaseController
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
load_and_authorize_resource :id_param => :project_name # to force member actions load
|
load_and_authorize_resource :id_param => :project_name # to force member actions load
|
||||||
|
before_filter :who_owns, :only => [:new, :create, :mass_import, :run_mass_import]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@projects = Project.accessible_by(current_ability, :membered)
|
@projects = Project.accessible_by(current_ability, :membered)
|
||||||
|
@ -24,7 +25,26 @@ class Projects::ProjectsController < Projects::BaseController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@project = Project.new
|
@project = Project.new
|
||||||
@who_owns = :me
|
end
|
||||||
|
|
||||||
|
def mass_import
|
||||||
|
@project = Project.new(:mass_import => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_mass_import
|
||||||
|
@project = Project.new params[:project]
|
||||||
|
@project.owner = choose_owner
|
||||||
|
authorize! :write, @project.owner if @project.owner.class == Group
|
||||||
|
@project.valid?
|
||||||
|
@project.errors.messages.slice! :url
|
||||||
|
if @project.errors.messages.blank? # We need only url validation
|
||||||
|
@project.mass_import
|
||||||
|
flash[:notice] = t('flash.project.mass_import_added_to_queue')
|
||||||
|
redirect_to projects_path
|
||||||
|
else
|
||||||
|
flash[:warning] = @project.errors.full_messages.join('. ')
|
||||||
|
render :mass_import
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@ -33,7 +53,6 @@ class Projects::ProjectsController < Projects::BaseController
|
||||||
def create
|
def create
|
||||||
@project = Project.new params[:project]
|
@project = Project.new params[:project]
|
||||||
@project.owner = choose_owner
|
@project.owner = choose_owner
|
||||||
@who_owns = (@project.owner_type == 'User' ? :me : :group)
|
|
||||||
authorize! :write, @project.owner if @project.owner.class == Group
|
authorize! :write, @project.owner if @project.owner.class == Group
|
||||||
|
|
||||||
if @project.save
|
if @project.save
|
||||||
|
@ -115,6 +134,10 @@ class Projects::ProjectsController < Projects::BaseController
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def who_owns
|
||||||
|
@who_owns = (@project.try(:owner_type) == 'User' ? :me : :group)
|
||||||
|
end
|
||||||
|
|
||||||
def prepare_list(projects, groups, owners)
|
def prepare_list(projects, groups, owners)
|
||||||
res = {}
|
res = {}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,10 @@ class Project < ActiveRecord::Base
|
||||||
|
|
||||||
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false},
|
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false},
|
||||||
:presence => true,
|
:presence => true,
|
||||||
:format => {:with => /\A#{NAME_REGEXP}\z/, :message => I18n.t("activerecord.errors.project.uname")}
|
:format => {:with => /\A#{NAME_REGEXP}\z/,
|
||||||
|
:message => I18n.t("activerecord.errors.project.uname")}
|
||||||
validates :maintainer_id, :presence => true, :unless => :new_record?
|
validates :maintainer_id, :presence => true, :unless => :new_record?
|
||||||
|
validates :url, :presence => true, :format => {:with => /\Ahttps?:\/\/[\S]+\z/}, :if => :mass_import
|
||||||
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
|
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES}
|
||||||
validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS }
|
validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS }
|
||||||
validate :check_default_branch
|
validate :check_default_branch
|
||||||
|
@ -43,7 +45,9 @@ class Project < ActiveRecord::Base
|
||||||
errors.delete :project_to_repositories
|
errors.delete :project_to_repositories
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessible :name, :description, :visibility, :srpm, :is_package, :default_branch, :has_issues, :has_wiki, :maintainer_id, :publish_i686_into_x86_64
|
attr_accessible :name, :description, :visibility, :srpm, :is_package, :default_branch,
|
||||||
|
:has_issues, :has_wiki, :maintainer_id, :publish_i686_into_x86_64,
|
||||||
|
:url, :srpms_list, :mass_import
|
||||||
attr_readonly :owner_id, :owner_type
|
attr_readonly :owner_id, :owner_type
|
||||||
|
|
||||||
scope :recent, order("lower(#{table_name}.name) ASC")
|
scope :recent, order("lower(#{table_name}.name) ASC")
|
||||||
|
@ -82,6 +86,8 @@ class Project < ActiveRecord::Base
|
||||||
|
|
||||||
has_ancestry :orphan_strategy => :rootify #:adopt not available yet
|
has_ancestry :orphan_strategy => :rootify #:adopt not available yet
|
||||||
|
|
||||||
|
attr_accessor :url, :srpms_list, :mass_import
|
||||||
|
|
||||||
include Modules::Models::Owner
|
include Modules::Models::Owner
|
||||||
include Modules::Models::Git
|
include Modules::Models::Git
|
||||||
include Modules::Models::Wiki
|
include Modules::Models::Wiki
|
||||||
|
@ -96,6 +102,16 @@ class Project < ActiveRecord::Base
|
||||||
def find_by_owner_and_name!(owner_name, project_name)
|
def find_by_owner_and_name!(owner_name, project_name)
|
||||||
find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound
|
find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.run_mass_import(url, srpms_list, visibility, owner)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def mass_import
|
||||||
|
Project.perform_later :clone_build, :run_mass_import, url, srpms_list, visibility, owner
|
||||||
end
|
end
|
||||||
|
|
||||||
def name_with_owner
|
def name_with_owner
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
- if can?(:create, Project)
|
- if can?(:create, Project)
|
||||||
.bordered.bpadding20
|
.bordered.bpadding20
|
||||||
= link_to t('layout.projects.new'), new_project_path, :class => 'button'
|
= link_to t('layout.projects.new'), new_project_path, :class => 'button'
|
||||||
|
.both
|
||||||
|
%br
|
||||||
|
= link_to t('layout.projects.mass_import'), mass_import_projects_path, :class => 'button'
|
||||||
.bordered.bpadding20
|
.bordered.bpadding20
|
||||||
%h3=t('layout.relations.filters')
|
%h3=t('layout.relations.filters')
|
||||||
- options_for_filters(@all_projects, @groups, @owners).each do |options|
|
- options_for_filters(@all_projects, @groups, @owners).each do |options|
|
||||||
|
|
|
@ -7,22 +7,10 @@
|
||||||
.rightlist= f.text_area :description, :class => 'text_field', :cols => 80
|
.rightlist= f.text_area :description, :class => 'text_field', :cols => 80
|
||||||
.both
|
.both
|
||||||
- if [:new, :create].include? act
|
- if [:new, :create].include? act
|
||||||
.leftlist= f.label :owner
|
= render 'owner', :f => f
|
||||||
.rightlist
|
|
||||||
= label_tag t("activerecord.attributes.project.who_owns.me")
|
|
||||||
- if Group.can_own_project(current_user).count > 0
|
|
||||||
= radio_button_tag :who_owns, 'me', @who_owns == :me #{}.merge( (@who_owns == :me) ? {:checked => 'checked'} : {} )
|
|
||||||
= label_tag t("activerecord.attributes.project.who_owns.group")
|
|
||||||
= radio_button_tag :who_owns, 'group', @who_owns == :group #{}.merge( (@who_owns == :group) ? {:checked => 'checked'} : {} )
|
|
||||||
-# TODO: Make our own select_box helper with new design, blackjack and bitches!
|
|
||||||
= select_tag :owner_id, options_from_collection_for_select( Group.can_own_project(current_user), :id, :name )
|
|
||||||
- else
|
|
||||||
= hidden_field_tag :who_owns, :me
|
|
||||||
.both
|
|
||||||
|
|
||||||
.leftlist= f.label :visibility
|
.leftlist= f.label :visibility
|
||||||
.rightlist
|
.rightlist
|
||||||
=# f.select :visibility, Project::VISIBILITIES
|
|
||||||
- Project::VISIBILITIES.each do |visibility|
|
- Project::VISIBILITIES.each do |visibility|
|
||||||
= f.radio_button :visibility, visibility, :class => 'niceRadio'
|
= f.radio_button :visibility, visibility, :class => 'niceRadio'
|
||||||
- if visibility == 'open'
|
- if visibility == 'open'
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
.leftlist= f.label :owner
|
||||||
|
.rightlist
|
||||||
|
= label_tag t("activerecord.attributes.project.who_owns.me")
|
||||||
|
- if Group.can_own_project(current_user).count > 0
|
||||||
|
= radio_button_tag :who_owns, 'me', @who_owns == :me #{}.merge( (@who_owns == :me) ? {:checked => 'checked'} : {} )
|
||||||
|
= label_tag t("activerecord.attributes.project.who_owns.group")
|
||||||
|
= radio_button_tag :who_owns, 'group', @who_owns == :group #{}.merge( (@who_owns == :group) ? {:checked => 'checked'} : {} )
|
||||||
|
-# TODO: Make our own select_box helper with new design, blackjack and bitches!
|
||||||
|
= select_tag :owner_id, options_from_collection_for_select( Group.can_own_project(current_user), :id, :name )
|
||||||
|
- else
|
||||||
|
= hidden_field_tag :who_owns, :me
|
||||||
|
.both
|
|
@ -0,0 +1,24 @@
|
||||||
|
%h3.bpadding10= title t("layout.projects.mass_import")
|
||||||
|
= form_for @project, :url => run_mass_import_projects_path, :html => { :class => :form } do |f|
|
||||||
|
= f.hidden_field :mass_import
|
||||||
|
.leftlist= f.label :url
|
||||||
|
.rightlist= f.text_field :url
|
||||||
|
.both
|
||||||
|
.leftlist= f.label :srpms_list
|
||||||
|
.rightlist= f.text_area :srpms_list
|
||||||
|
.both
|
||||||
|
= render 'owner', :f => f
|
||||||
|
|
||||||
|
.leftlist= f.label :visibility
|
||||||
|
.rightlist
|
||||||
|
- Project::VISIBILITIES.each do |visibility|
|
||||||
|
= f.radio_button :visibility, visibility, :class => 'niceRadio'
|
||||||
|
- if visibility == 'open'
|
||||||
|
= image_tag("unlock.png")
|
||||||
|
- else
|
||||||
|
= image_tag("lock.png")
|
||||||
|
= t("activerecord.attributes.project.visibilities.#{visibility}")
|
||||||
|
.both
|
||||||
|
.hr
|
||||||
|
.button_block
|
||||||
|
= f.submit t('layout.add'), :data => {'disable-with' => t('layout.saving')}
|
|
@ -1,6 +1,7 @@
|
||||||
en:
|
en:
|
||||||
layout:
|
layout:
|
||||||
projects:
|
projects:
|
||||||
|
mass_import: Mass import
|
||||||
branches: Branches
|
branches: Branches
|
||||||
delete_branch: Delete branch
|
delete_branch: Delete branch
|
||||||
restore_branch: Restore branch
|
restore_branch: Restore branch
|
||||||
|
@ -89,6 +90,8 @@ en:
|
||||||
project: Project
|
project: Project
|
||||||
attributes:
|
attributes:
|
||||||
project:
|
project:
|
||||||
|
url: URL
|
||||||
|
srpms_list: SRPMs list
|
||||||
name: Name
|
name: Name
|
||||||
description: Descripton
|
description: Descripton
|
||||||
owner: Owner
|
owner: Owner
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
ru:
|
ru:
|
||||||
layout:
|
layout:
|
||||||
projects:
|
projects:
|
||||||
|
mass_import: Массовый импорт
|
||||||
branches: Ветки
|
branches: Ветки
|
||||||
delete_branch: Удалить ветку
|
delete_branch: Удалить ветку
|
||||||
restore_branch: Восстановить ветку
|
restore_branch: Восстановить ветку
|
||||||
|
@ -89,6 +90,8 @@ ru:
|
||||||
project: Проект
|
project: Проект
|
||||||
attributes:
|
attributes:
|
||||||
project:
|
project:
|
||||||
|
url: URL
|
||||||
|
srpms_list: Список SRPMs
|
||||||
name: Название
|
name: Название
|
||||||
description: Описание
|
description: Описание
|
||||||
owner: Владелец
|
owner: Владелец
|
||||||
|
|
|
@ -284,7 +284,12 @@ Rosa::Application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :projects, :only => [:index, :new, :create]
|
resources :projects, :only => [:index, :new, :create] do
|
||||||
|
collection do
|
||||||
|
post :run_mass_import
|
||||||
|
get :mass_import
|
||||||
|
end
|
||||||
|
end
|
||||||
scope ':owner_name/:project_name', :constraints => {:project_name => Project::NAME_REGEXP} do # project
|
scope ':owner_name/:project_name', :constraints => {:project_name => Project::NAME_REGEXP} do # project
|
||||||
scope :as => 'project' do
|
scope :as => 'project' do
|
||||||
resources :wiki do
|
resources :wiki do
|
||||||
|
|
Loading…
Reference in New Issue