[closed #20] Changed adding collaborators to project
Changed collaborators page of project: * Added form to input group and/or project nickname. * In tables show only projects/groups that already added to project
This commit is contained in:
parent
2edf0ad172
commit
1b3e473b94
|
@ -81,6 +81,41 @@ class CollaboratorsController < ApplicationController
|
|||
def destroy
|
||||
end
|
||||
|
||||
def add
|
||||
# TODO: Here is used Chelyabinsk method to display Flash messages.
|
||||
|
||||
member = User.find_by_uname(params['member_uname']) if params['member_uname'] && !params['member_uname'].empty?
|
||||
group = Group.find_by_uname(params['group_uname']) if params['group_uname'] && !params['group_uname'].empty?
|
||||
|
||||
flash[:notice], flash[:error], flash[:warning] = [], [], []
|
||||
|
||||
[member, group].compact.each do |mem|
|
||||
if mem and @project.relations.exists?(:object_id => mem.id, :object_type => mem.class.to_s)
|
||||
flash[:warning] << [t('flash.collaborators.member_already_added'), mem.uname]
|
||||
end
|
||||
unless @project.relations.exists?(:object_id => mem.id, :object_type => mem.class.to_s)
|
||||
rel = @project.relations.build(:role => 'reader')
|
||||
rel.object = mem
|
||||
if rel.save
|
||||
flash[:notice] << [t('flash.collaborators.successfully_added'), mem.uname]
|
||||
else
|
||||
flash[:notice] << [t('flash.collaborators.error_in_adding'), mem.uname]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[:notice, :warning, :error].each do |k|
|
||||
if flash[k].size > 0
|
||||
flash[k] = flash[k].map{|i| (i.is_a? Array) ? sprintf(i.first, i.last) : i}.join('; ')
|
||||
else
|
||||
flash[k] = nil
|
||||
end
|
||||
end
|
||||
flash.delete_if{|k, v| v.nil?}
|
||||
|
||||
redirect_to(edit_project_collaborators_path(@project))
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_project
|
||||
|
@ -88,10 +123,10 @@ class CollaboratorsController < ApplicationController
|
|||
end
|
||||
|
||||
def find_users
|
||||
@users = User.all
|
||||
@users = @project.collaborators#User.all
|
||||
end
|
||||
|
||||
def find_groups
|
||||
@groups = Group.all
|
||||
@groups = @project.groups#Group.all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ class GroupsController < ApplicationController
|
|||
before_filter :find_group, :only => [:show, :edit, :update, :destroy]
|
||||
|
||||
load_and_authorize_resource
|
||||
autocomplete :group, :uname
|
||||
|
||||
def index
|
||||
puts parent.inspect
|
||||
|
|
|
@ -5,6 +5,23 @@
|
|||
%li.active= link_to t("layout.collaborators.edit"), edit_project_collaborators_path(@project)
|
||||
.content
|
||||
.inner
|
||||
= form_tag add_project_collaborators_path(@project) do
|
||||
= javascript_include_tag 'autocomplete-rails.js'
|
||||
.group
|
||||
%h2.title= t("layout.collaborators.add")
|
||||
= label_tag "member_uname", t("layout.collaborators.input_username")
|
||||
= autocomplete_field_tag 'member_uname', params[:member_uname], autocomplete_user_uname_users_path
|
||||
|
||||
= t('layout.or')
|
||||
|
||||
= label_tag "group_uname", t("layout.collaborators.input_groupname")
|
||||
= autocomplete_field_tag 'group_uname', params[:group_uname], autocomplete_group_uname_groups_path
|
||||
%br
|
||||
.group.navform.wat-cf
|
||||
%button.button{:type => "submit"}
|
||||
= image_tag("web-app-theme/icons/tick.png", :alt => t("layout.add"))
|
||||
= t("layout.add")
|
||||
|
||||
= form_tag project_collaborators_path(@project) do
|
||||
%h2.title= t("layout.users.list_header")
|
||||
%table.table
|
||||
|
@ -31,8 +48,8 @@
|
|||
%tr
|
||||
%th.first ID
|
||||
%th= t("activerecord.attributes.group.name")
|
||||
%th= t("activerecord.attributes.group.roles")
|
||||
%th= t("activerecord.attributes.group.uname")
|
||||
%th.last= t("layout.collaborators.add")
|
||||
- @groups.each do |group|
|
||||
%tr{:class => cycle("odd", "even")}
|
||||
%td
|
||||
|
|
|
@ -223,6 +223,8 @@ ru:
|
|||
edit_roles: Редактировать роли
|
||||
roles_header: Роли для
|
||||
add_role: Добавить/Удалить роль
|
||||
input_username: Введите псевдоним пользователя
|
||||
input_groupname: Введите псевдоним группы
|
||||
|
||||
members:
|
||||
back_to_group: Вернуться к группе
|
||||
|
@ -333,6 +335,10 @@ ru:
|
|||
collaborators:
|
||||
successfully_changed: Список коллабораторов успешно изменен
|
||||
error_in_changing: Ошибка изменения списка коллабораторов
|
||||
member_already_added: Участник %s уже добавлен
|
||||
group_already_added: Группа уже добавлена
|
||||
successfully_added: Участник %s успешно добавлен
|
||||
error_in_adding: Ошибка при добавлении участника %s
|
||||
|
||||
members:
|
||||
successfully_changed: Список участников успешно изменен
|
||||
|
|
|
@ -8,9 +8,7 @@ Rosa::Application.routes.draw do
|
|||
|
||||
resources :users do
|
||||
resources :groups, :only => [:new, :create, :index]
|
||||
collection do
|
||||
get :autocomplete_user_uname
|
||||
end
|
||||
get :autocomplete_user_uname, :on => :collection
|
||||
end
|
||||
|
||||
resources :event_logs, :only => :index
|
||||
|
@ -81,10 +79,11 @@ Rosa::Application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :collaborators, :only => [:index, :edit, :update] do
|
||||
resources :collaborators, :only => [:index, :edit, :update, :add] do
|
||||
collection do
|
||||
get :edit
|
||||
post :update
|
||||
post :add
|
||||
end
|
||||
member do
|
||||
post :update
|
||||
|
@ -111,6 +110,7 @@ Rosa::Application.routes.draw do
|
|||
end
|
||||
|
||||
resources :groups do
|
||||
get :autocomplete_group_uname, :on => :collection
|
||||
resources :members, :only => [:index, :edit, :update, :add] do
|
||||
collection do
|
||||
get :edit
|
||||
|
|
Loading…
Reference in New Issue