Project

General

Profile

Patch #20384 » 0004-Add-workspace-functionality-to-reuse-roles-and-track.patch

for Redmine 4.0 (1/2) - Frederico Camara, 2019-11-21 13:20

View differences:

app/controllers/admin_controller.rb
@project_pages = Paginator.new @project_count, per_page_option, params['page']
@projects = scope.limit(@project_pages.per_page).offset(@project_pages.offset).to_a
@workspaces = Hash[Workspace.pluck(:id, :name)]
render :action => "projects", :layout => false if request.xhr?
end
app/controllers/workflows_controller.rb
def index
@roles = Role.sorted.select(&:consider_workflow?)
@trackers = Tracker.sorted
@workflow_counts = WorkflowTransition.group(:tracker_id, :role_id).count
@workspaces = Workspace.sorted
@workflow_counts = WorkflowTransition.group(:tracker_id, :role_id, :workspace_id).count
end
def edit
find_trackers_roles_and_statuses_for_edit
if request.post? && @roles && @trackers && params[:transitions]
if request.post? && @roles && @trackers && @workspaces && params[:transitions]
transitions = params[:transitions].deep_dup
transitions.each do |old_status_id, transitions_by_new_status|
transitions_by_new_status.each do |new_status_id, transition_by_rule|
transition_by_rule.reject! {|rule, transition| transition == 'no_change'}
end
end
WorkflowTransition.replace_transitions(@trackers, @roles, transitions)
WorkflowTransition.replace_transitions(@trackers, @roles, transitions, @workspaces)
flash[:notice] = l(:notice_successful_update)
redirect_to_referer_or workflows_edit_path
return
end
if @trackers && @roles && @statuses.any?
if @trackers && @roles && @workspaces && @statuses.any?
workflows = WorkflowTransition.
where(:role_id => @roles.map(&:id), :tracker_id => @trackers.map(&:id)).
where(:role_id => @roles.map(&:id), :tracker_id => @trackers.map(&:id), :workspace_id => @workspaces.map(&:id)).
preload(:old_status, :new_status)
@workflows = {}
@workflows['always'] = workflows.select {|w| !w.author && !w.assignee}
......
def permissions
find_trackers_roles_and_statuses_for_edit
if request.post? && @roles && @trackers && params[:permissions]
if request.post? && @roles && @trackers && @workspaces && params[:permissions]
permissions = params[:permissions].deep_dup
permissions.each { |field, rule_by_status_id|
rule_by_status_id.reject! {|status_id, rule| rule == 'no_change'}
}
WorkflowPermission.replace_permissions(@trackers, @roles, permissions)
WorkflowPermission.replace_permissions(@trackers, @roles, permissions, @workspaces)
flash[:notice] = l(:notice_successful_update)
redirect_to_referer_or workflows_permissions_path
return
end
if @roles && @trackers
if @roles && @trackers && @workspaces
@fields = (Tracker::CORE_FIELDS_ALL - @trackers.map(&:disabled_core_fields).reduce(:&)).map {|field| [field, l("field_"+field.sub(/_id$/, ''))]}
@custom_fields = @trackers.map(&:custom_fields).flatten.uniq.sort
@permissions = WorkflowPermission.rules_by_status_id(@trackers, @roles)
@permissions = WorkflowPermission.rules_by_status_id(@trackers, @roles, @workspaces)
@statuses.each {|status| @permissions[status.id] ||= {}}
end
end
......
def copy
@roles = Role.sorted.select(&:consider_workflow?)
@trackers = Tracker.sorted
@workspaces = Workspace.sorted
if params[:source_tracker_id].blank? || params[:source_tracker_id] == 'any'
@source_tracker = nil
......
else
@source_role = Role.find_by_id(params[:source_role_id].to_i)
end
if params[:source_workspace_id].blank? || params[:source_workspace_id] == 'any'
@source_workspace = nil
else
@source_workspace = Workspace.find_by_id(params[:source_workspace_id].to_i)
end
@target_trackers = params[:target_tracker_ids].blank? ?
nil : Tracker.where(:id => params[:target_tracker_ids]).to_a
@target_roles = params[:target_role_ids].blank? ?
nil : Role.where(:id => params[:target_role_ids]).to_a
@target_workspaces = params[:target_workspace_ids].blank? ?
nil : Workspace.where(:id => params[:target_workspace_ids]).to_a
if request.post?
if params[:source_tracker_id].blank? || params[:source_role_id].blank? || (@source_tracker.nil? && @source_role.nil?)
if params[:source_tracker_id].blank? || params[:source_role_id].blank? || params[:source_workspace_id].blank? || (@source_tracker.nil? && @source_role.nil? && @source_workspace.nil?)
flash.now[:error] = l(:error_workflow_copy_source)
elsif @target_trackers.blank? || @target_roles.blank?
elsif @target_trackers.blank? || @target_roles.blank? || @target_workspaces.blank?
flash.now[:error] = l(:error_workflow_copy_target)
else
WorkflowRule.copy(@source_tracker, @source_role, @target_trackers, @target_roles)
WorkflowRule.copy(@source_tracker, @source_role, @source_workspace, @target_trackers, @target_roles, @target_workspaces)
flash[:notice] = l(:notice_successful_update)
redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role)
redirect_to workflows_copy_path(:source_tracker_id => @source_tracker, :source_role_id => @source_role, :source_workspace_id => @source_workspace)
end
end
end
......
def find_trackers_roles_and_statuses_for_edit
find_roles
find_trackers
find_workspaces
find_statuses
end
......
@trackers = nil if @trackers.blank?
end
def find_workspaces
ids = Array.wrap(params[:workspace_id])
if ids == ['all']
@workspaces = Workspace.sorted.to_a
elsif ids.present?
@workspaces = Workspace.where(:id => ids).to_a
end
@workspaces = nil if @workspaces.blank?
end
def find_statuses
@used_statuses_only = (params[:used_statuses_only] == '0' ? false : true)
if @trackers && @used_statuses_only
app/controllers/workspaces_controller.rb
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class WorkspacesController < ApplicationController
layout 'admin'
self.main_menu = false
before_action :require_admin, :except => :index
before_action :require_admin_or_api_request, :only => :index
accept_api_auth :index
def index
@workspaces = Workspace.sorted.to_a
respond_to do |format|
format.html { render :layout => false if request.xhr? }
format.api
end
end
def new
@workspace = Workspace.new
end
def create
@workspace = Workspace.new
@workspace.safe_attributes = params[:workspace]
if @workspace.save
flash[:notice] = l(:notice_successful_create)
redirect_to workspaces_path
else
render :action => 'new'
end
end
def edit
@workspace = Workspace.find(params[:id])
end
def update
@workspace = Workspace.find(params[:id])
@workspace.safe_attributes = params[:workspace]
if @workspace.save
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
redirect_to workspaces_path(:page => params[:page])
}
format.js { head 200 }
end
else
respond_to do |format|
format.html { render :action => 'edit' }
format.js { head 422 }
end
end
end
def destroy
unless Project.where(:workspace_id => params[:id]).any? || params[:id] == "1"
Workspace.find(params[:id]).destroy
else
flash[:error] = l(:error_unable_delete_workspace)
end
redirect_to workspaces_path
end
end
app/helpers/projects_helper.rb
principals_options_for_select(assignable_users, project.default_assigned_to)
end
def project_workspace_options(project)
grouped = Hash.new {|h,k| h[k] = []}
Workspace.all.sorted.each do |workspace|
grouped[workspace.name] = workspace.id
end
options_for_select(grouped, project.workspace_id)
end
def format_version_sharing(sharing)
sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
l("label_version_sharing_#{sharing}")
app/helpers/workflows_helper.rb
def options_for_workflow_select(name, objects, selected, options={})
option_tags = ''.html_safe
multiple = false
if selected
if selected
if selected.size == objects.size
selected = 'all'
else
......
options = [["", ""], [l(:label_readonly), "readonly"]]
options << [l(:label_required), "required"] unless field_required?(field)
html_options = {}
if perm = permissions[status.id][name]
if perm.uniq.size > 1 || perm.size < @roles.size * @trackers.size
if perm.uniq.size > 1 || perm.size < @roles.size * @trackers.size * @workspaces.size
options << [l(:label_no_change_option), "no_change"]
selected = 'no_change'
else
......
def transition_tag(workflows, old_status, new_status, name)
w = workflows.select {|w| w.old_status == old_status && w.new_status == new_status}.size
tag_name = "transitions[#{ old_status.try(:id) || 0 }][#{new_status.id}][#{name}]"
if old_status == new_status
check_box_tag(tag_name, "1", true,
{:disabled => true, :class => "old-status-#{old_status.try(:id) || 0} new-status-#{new_status.id}"})
elsif w == 0 || w == @roles.size * @trackers.size
elsif w == 0 || w == @roles.size * @trackers.size * @workspaces.size
hidden_field_tag(tag_name, "0", :id => nil) +
check_box_tag(tag_name, "1", w != 0,
:class => "old-status-#{old_status.try(:id) || 0} new-status-#{new_status.id}")
app/models/issue.rb
return {} if roles.empty?
result = {}
workflow_permissions = WorkflowPermission.where(:tracker_id => tracker_id, :old_status_id => status_id, :role_id => roles.map(&:id)).to_a
workflow_permissions = WorkflowPermission.where(:tracker_id => tracker_id, :old_status_id => status_id, :role_id => roles.map(&:id), :workspace_id => project.workspace_id).to_a
if workflow_permissions.any?
workflow_rules = workflow_permissions.inject({}) do |h, wp|
h[wp.field_name] ||= {}
......
initial_status,
user.admin ? Role.all.to_a : user.roles_for_project(project),
tracker,
project.workspace_id,
author == user,
assignee_transitions_allowed
)
app/models/issue_status.rb
end
# Returns an array of all statuses the given role can switch to
def new_statuses_allowed_to(roles, tracker, author=false, assignee=false)
self.class.new_statuses_allowed(self, roles, tracker, author, assignee)
def new_statuses_allowed_to(roles, tracker, workspace_id, author=false, assignee=false)
self.class.new_statuses_allowed(self, roles, tracker, workspace_id, author, assignee)
end
alias :find_new_statuses_allowed_to :new_statuses_allowed_to
def self.new_statuses_allowed(status, roles, tracker, author=false, assignee=false)
if roles.present? && tracker
def self.new_statuses_allowed(status, roles, tracker, workspace_id, author=false, assignee=false)
if roles.present? && tracker && workspace_id
status_id = status.try(:id) || 0
scope = IssueStatus.
joins(:workflow_transitions_as_new_status).
where(:workflows => {:old_status_id => status_id, :role_id => roles.map(&:id), :tracker_id => tracker.id})
where(:workflows => {:old_status_id => status_id, :role_id => roles.map(&:id), :tracker_id => tracker.id, :workspace_id => workspace_id})
unless author && assignee
if author || assignee
app/models/project.rb
has_many :versions, :dependent => :destroy
belongs_to :default_version, :class_name => 'Version'
belongs_to :default_assigned_to, :class_name => 'Principal'
belongs_to :workspace
has_many :time_entries, :dependent => :destroy
has_many :queries, :dependent => :delete_all
has_many :documents, :dependent => :destroy
......
'issue_custom_field_ids',
'parent_id',
'default_version_id',
'workspace_id',
'default_assigned_to_id'
safe_attributes 'enabled_module_names',
app/models/role.rb
end
def copy_workflow_rules(source_role)
WorkflowRule.copy(nil, source_role, nil, self)
WorkflowRule.copy(nil, source_role, nil, nil, self, nil)
end
# Find all the roles that can be given to a project member
app/models/tracker.rb
end
def copy_workflow_rules(source_tracker)
WorkflowRule.copy(source_tracker, nil, self, nil)
WorkflowRule.copy(source_tracker, nil, nil, self, nil, nil)
end
# Returns the fields that are disabled for all the given trackers
app/models/workflow_permission.rb
validates_presence_of :old_status
validate :validate_field_name
# Returns the workflow permissions for the given trackers and roles
# Returns the workflow permissions for the given trackers, roles and workspaces
# grouped by status_id
#
# Example:
# WorkflowPermission.rules_by_status_id trackers, roles
# WorkflowPermission.rules_by_status_id trackers, roles, workspaces
# # => {1 => {'start_date' => 'required', 'due_date' => 'readonly'}}
def self.rules_by_status_id(trackers, roles)
WorkflowPermission.where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id)).inject({}) do |h, w|
def self.rules_by_status_id(trackers, roles, workspaces)
WorkflowPermission.where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id), :workspace_id => workspaces.map(&:id)).inject({}) do |h, w|
h[w.old_status_id] ||= {}
h[w.old_status_id][w.field_name] ||= []
h[w.old_status_id][w.field_name] << w.rule
......
end
end
# Replaces the workflow permissions for the given trackers and roles
# Replaces the workflow permissions for the given trackers, roles and workspaces
#
# Example:
# WorkflowPermission.replace_permissions trackers, roles, {'1' => {'start_date' => 'required', 'due_date' => 'readonly'}}
def self.replace_permissions(trackers, roles, permissions)
# WorkflowPermission.replace_permissions trackers, roles, {'1' => {'start_date' => 'required', 'due_date' => 'readonly'}}, workspaces
def self.replace_permissions(trackers, roles, permissions, workspaces)
trackers = Array.wrap trackers
roles = Array.wrap roles
workspaces = Array.wrap workspaces
transaction do
permissions.each { |status_id, rule_by_field|
rule_by_field.each { |field, rule|
where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id), :old_status_id => status_id, :field_name => field).destroy_all
where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id), :old_status_id => status_id, :field_name => field, :workspace_id => workspaces.map(&:id)).destroy_all
if rule.present?
trackers.each do |tracker|
roles.each do |role|
WorkflowPermission.create(:role_id => role.id, :tracker_id => tracker.id, :old_status_id => status_id, :field_name => field, :rule => rule)
workspaces.each do |workspace|
WorkflowPermission.create(:role_id => role.id, :tracker_id => tracker.id, :old_status_id => status_id, :field_name => field, :rule => rule, :workspace_id => workspace.id)
end
end
end
end
app/models/workflow_rule.rb
belongs_to :tracker
belongs_to :old_status, :class_name => 'IssueStatus'
belongs_to :new_status, :class_name => 'IssueStatus'
belongs_to :workspace
validates_presence_of :role, :tracker
validates_presence_of :role, :tracker, :workspace
# Copies workflows from source to targets
def self.copy(source_tracker, source_role, target_trackers, target_roles)
unless source_tracker.is_a?(Tracker) || source_role.is_a?(Role)
raise ArgumentError.new("source_tracker or source_role must be specified, given: #{source_tracker.class.name} and #{source_role.class.name}")
def self.copy(source_tracker, source_role, source_workspace, target_trackers, target_roles, target_workspaces)
unless source_tracker.is_a?(Tracker) || source_role.is_a?(Role) || source_workspace.is_a?(Workspace)
raise ArgumentError.new("source_tracker, source_role or source_workspace must be specified, given: #{source_tracker.class.name}, #{source_role.class.name} and #{source_workspace.class.name}")
end
target_trackers = [target_trackers].flatten.compact
target_roles = [target_roles].flatten.compact
target_workspaces = [target_workspaces].flatten.compact
target_trackers = Tracker.sorted.to_a if target_trackers.empty?
target_roles = Role.all.select(&:consider_workflow?) if target_roles.empty?
target_workspaces = Workspace.sorted.to_a if target_workspaces.empty?
target_trackers.each do |target_tracker|
target_roles.each do |target_role|
copy_one(source_tracker || target_tracker,
source_role || target_role,
target_tracker,
target_role)
target_workspaces.each do |target_workspace|
copy_one(source_tracker || target_tracker,
source_role || target_role,
source_workspace || target_workspace,
target_tracker,
target_role,
target_workspace)
end
end
end
end
# Copies a single set of workflows from source to target
def self.copy_one(source_tracker, source_role, target_tracker, target_role)
def self.copy_one(source_tracker, source_role, source_workspace, target_tracker, target_role, target_workspace)
unless source_tracker.is_a?(Tracker) && !source_tracker.new_record? &&
source_role.is_a?(Role) && !source_role.new_record? &&
source_workspace.is_a?(Workspace) && !source_workspace.new_record? &&
target_tracker.is_a?(Tracker) && !target_tracker.new_record? &&
target_role.is_a?(Role) && !target_role.new_record?
target_role.is_a?(Role) && !target_role.new_record? &&
target_workspace.is_a?(Workspace) && !target_workspace.new_record?
raise ArgumentError.new("arguments can not be nil or unsaved objects")
end
if source_tracker == target_tracker && source_role == target_role
if source_tracker == target_tracker && source_role == target_role && source_workspace == target_workspace
false
else
transaction do
where(:tracker_id => target_tracker.id, :role_id => target_role.id).delete_all
connection.insert "INSERT INTO #{WorkflowRule.table_name} (tracker_id, role_id, old_status_id, new_status_id, author, assignee, field_name, #{connection.quote_column_name 'rule'}, type)" +
" SELECT #{target_tracker.id}, #{target_role.id}, old_status_id, new_status_id, author, assignee, field_name, #{connection.quote_column_name 'rule'}, type" +
where(:tracker_id => target_tracker.id, :role_id => target_role.id, :workspace_id => target_workspace.id).delete_all
connection.insert "INSERT INTO #{WorkflowRule.table_name} (tracker_id, role_id, old_status_id, new_status_id, author, assignee, field_name, #{connection.quote_column_name 'rule'}, type, workspace_id)" +
" SELECT #{target_tracker.id}, #{target_role.id}, old_status_id, new_status_id, author, assignee, field_name, #{connection.quote_column_name 'rule'}, type, #{target_workspace.id}" +
" FROM #{WorkflowRule.table_name}" +
" WHERE tracker_id = #{source_tracker.id} AND role_id = #{source_role.id}"
" WHERE tracker_id = #{source_tracker.id} AND role_id = #{source_role.id} AND workspace_id = #{source_workspace.id}"
end
true
end
app/models/workflow_transition.rb
class WorkflowTransition < WorkflowRule
validates_presence_of :new_status
def self.replace_transitions(trackers, roles, transitions)
def self.replace_transitions(trackers, roles, transitions, workspaces)
trackers = Array.wrap trackers
roles = Array.wrap roles
workspaces = Array.wrap workspaces
transaction do
records = WorkflowTransition.where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id)).to_a
records = WorkflowTransition.where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id), :workspace_id => workspaces.map(&:id)).to_a
transitions.each do |old_status_id, transitions_by_new_status|
transitions_by_new_status.each do |new_status_id, transition_by_rule|
transition_by_rule.each do |rule, transition|
trackers.each do |tracker|
roles.each do |role|
w = records.select {|r|
r.old_status_id == old_status_id.to_i &&
r.new_status_id == new_status_id.to_i &&
r.tracker_id == tracker.id &&
r.role_id == role.id &&
!r.destroyed?
}
workspaces.each do |workspace|
w = records.select {|r|
r.old_status_id == old_status_id.to_i &&
r.new_status_id == new_status_id.to_i &&
r.tracker_id == tracker.id &&
r.role_id == role.id &&
r.workspace_id == workspace.id &&
!r.destroyed?
}
if rule == 'always'
w = w.select {|r| !r.author && !r.assignee}
else
w = w.select {|r| r.author || r.assignee}
end
if w.size > 1
w[1..-1].each(&:destroy)
end
w = w.first
if transition == "1" || transition == true
unless w
w = WorkflowTransition.new(:old_status_id => old_status_id, :new_status_id => new_status_id, :tracker_id => tracker.id, :role_id => role.id)
records << w
end
w.author = true if rule == "author"
w.assignee = true if rule == "assignee"
w.save if w.changed?
elsif w
if rule == 'always'
w.destroy
elsif rule == 'author'
if w.assignee
w.author = false
w.save if w.changed?
else
w.destroy
w = w.select {|r| !r.author && !r.assignee}
else
w = w.select {|r| r.author || r.assignee}
end
if w.size > 1
w[1..-1].each(&:destroy)
end
w = w.first
if transition == "1" || transition == true
unless w
w = WorkflowTransition.new(:old_status_id => old_status_id, :new_status_id => new_status_id, :tracker_id => tracker.id, :role_id => role.id, :workspace_id => workspace.id)
records << w
end
elsif rule == 'assignee'
if w.author
w.assignee = false
w.save if w.changed?
else
w.author = true if rule == "author"
w.assignee = true if rule == "assignee"
w.save if w.changed?
elsif w
if rule == 'always'
w.destroy
elsif rule == 'author'
if w.assignee
w.author = false
w.save if w.changed?
else
w.destroy
end
elsif rule == 'assignee'
if w.author
w.assignee = false
w.save if w.changed?
else
w.destroy
end
end
end
end
app/models/workspace.rb
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Workspace < ActiveRecord::Base
include Redmine::SafeAttributes
before_destroy :check_integrity
has_many :projects
has_many :workflow_rules, :dependent => :delete_all
acts_as_positioned
validates_presence_of :name
validates_uniqueness_of :name
validates_length_of :name, :maximum => 30
scope :sorted, lambda { order(:position) }
safe_attributes 'name',
'description',
'position'
def <=>(workspace)
position <=> workspace.position
end
def to_s; name end
private
def check_integrity
raise Exception.new("Cannot delete workspace") if Project.where(:workspace_id => self.id).any?
end
end
app/views/admin/projects.html.erb
<th><%=l(:label_project)%></th>
<th><%=l(:field_is_public)%></th>
<th><%=l(:field_created_on)%></th>
<th><%=l(:field_workspace)%></th>
<th></th>
</tr></thead>
<tbody>
......
<td class="name"><span><%= link_to_project_settings(project, {}, :title => project.short_description) %></span></td>
<td><%= checked_image project.is_public? %></td>
<td><%= format_date(project.created_on) %></td>
<td><%= @workspaces[project.workspace_id] %></td>
<td class="buttons">
<%= link_to(l(:button_archive), archive_project_path(project, :status => params[:status]), :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock') unless project.archived? %>
<%= link_to(l(:button_unarchive), unarchive_project_path(project, :status => params[:status]), :method => :post, :class => 'icon icon-unlock') if project.archived? %>
app/views/projects/_form.html.erb
<p><%= label(:project, :parent_id, l(:field_parent)) %><%= parent_project_select_tag(@project) %></p>
<% end %>
<% if @project.safe_attribute? 'workspace_id' %>
<p><%= f.select :workspace_id, project_workspace_options(@project) %></p>
<% end %>
<% if @project.safe_attribute? 'inherit_members' %>
<p><%= f.check_box :inherit_members %></p>
<% end %>
app/views/workflows/copy.html.erb
<%= form_tag({}, :id => 'workflow_copy_form') do %>
<fieldset class="tabular box">
<legend><%= l(:label_copy_source) %></legend>
<p>
<label><%= l(:label_role) %></label>
<%= select_tag('source_role_id',
content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '') +
content_tag('option', "--- #{ l(:label_copy_same_as_target) } ---", :value => 'any') +
options_from_collection_for_select(@roles, 'id', 'name', @source_role && @source_role.id)) %>
</p>
<p>
<label><%= l(:label_tracker) %></label>
<%= select_tag('source_tracker_id',
......
options_from_collection_for_select(@trackers, 'id', 'name', @source_tracker && @source_tracker.id)) %>
</p>
<p>
<label><%= l(:label_role) %></label>
<%= select_tag('source_role_id',
<label><%= l(:label_workspace) %></label>
<%= select_tag('source_workspace_id',
content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '') +
content_tag('option', "--- #{ l(:label_copy_same_as_target) } ---", :value => 'any') +
options_from_collection_for_select(@roles, 'id', 'name', @source_role && @source_role.id)) %>
options_from_collection_for_select(@workspaces, 'id', 'name', @source_workspace && @source_workspace.id)) %>
</p>
</fieldset>
<fieldset class="tabular box">
<legend><%= l(:label_copy_target) %></legend>
<p>
<label><%= l(:label_role) %></label>
<%= select_tag 'target_role_ids',
content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '', :disabled => true) +
options_from_collection_for_select(@roles, 'id', 'name', @target_roles && @target_roles.map(&:id)), :multiple => true %>
</p>
<p>
<label><%= l(:label_tracker) %></label>
<%= select_tag 'target_tracker_ids',
......
options_from_collection_for_select(@trackers, 'id', 'name', @target_trackers && @target_trackers.map(&:id)), :multiple => true %>
</p>
<p>
<label><%= l(:label_role) %></label>
<%= select_tag 'target_role_ids',
<label><%= l(:label_workspace) %></label>
<%= select_tag 'target_workspace_ids',
content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '', :disabled => true) +
options_from_collection_for_select(@roles, 'id', 'name', @target_roles && @target_roles.map(&:id)), :multiple => true %>
options_from_collection_for_select(@workspaces, 'id', 'name', @target_workspaces && @target_workspaces.map(&:id)), :multiple => true %>
</p>
</fieldset>
<%= submit_tag l(:button_copy) %>
app/views/workflows/edit.html.erb
<div class="tabs">
<ul>
<li><%= link_to l(:label_status_transitions), workflows_edit_path(:role_id => @roles, :tracker_id => @trackers), :class => 'selected' %></li>
<li><%= link_to l(:label_fields_permissions), workflows_permissions_path(:role_id => @roles, :tracker_id => @trackers) %></li>
<li><%= link_to l(:label_status_transitions), workflows_edit_path(:role_id => @roles, :tracker_id => @trackers, :workspace_id => @workspaces, :used_statuses_only => @used_statuses_only ? 1 : 0), :class => 'selected' %></li>
<li><%= link_to l(:label_fields_permissions), workflows_permissions_path(:role_id => @roles, :tracker_id => @trackers, :workspace_id => @workspaces, :used_statuses_only => @used_statuses_only ? 1 : 0) %></li>
</ul>
</div>
......
</label>
<a href="#" data-expands="#tracker_id"><span class="toggle-multiselect"></span></a>
<label><%=l(:label_workspace)%>:
<%= options_for_workflow_select 'workspace_id[]', Workspace.sorted, @workspaces, :id => 'workspace_id', :class => 'expandable' %>
</label>
<a href="#" data-expands="#workspace_id"><span class="toggle-multiselect"></span></a>
<%= submit_tag l(:button_edit), :name => nil %>
<%= hidden_field_tag 'used_statuses_only', '0', :id => nil %>
......
</p>
<% end %>
<% if @trackers && @roles && @statuses.any? %>
<% if @trackers && @roles && @workspaces && @statuses.any? %>
<%= form_tag({}, :id => 'workflow_form' ) do %>
<%= @trackers.map {|tracker| hidden_field_tag 'tracker_id[]', tracker.id, :id => nil}.join.html_safe %>
<%= @roles.map {|role| hidden_field_tag 'role_id[]', role.id, :id => nil}.join.html_safe %>
<%= @workspaces.map {|workspace| hidden_field_tag 'workspace_id[]', workspace.id, :id => nil}.join.html_safe %>
<%= hidden_field_tag 'used_statuses_only', params[:used_statuses_only], :id => nil %>
<div class="autoscroll">
<%= render :partial => 'form', :locals => {:name => 'always', :workflows => @workflows['always']} %>
app/views/workflows/index.html.erb
<% if @roles.empty? || @trackers.empty? %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% else %>
<p><label><%=l(:label_workspace)%>:
<%= options_for_workflow_select 'workspace_id[]', Workspace.sorted, @workspaces, :id => 'workspace_id', :class => 'expandable', :onchange=>'refresh_table(this.value);' %>
</label></p>
<div class="autoscroll">
<table class="list">
<table class="list collapsed">
<thead>
<tr>
<th></th>
<th onclick='expand_table();'><i><span class='tip_exp_off'><%= l(:button_expand_all) %></span><span class='tip_exp_on'><%= l(:button_collapse_all) %></span></i></th>
<% @roles.each do |role| %>
<th>
<%= content_tag(role.builtin? ? 'em' : 'span', role.name) %>
......
<tr>
<td class="name"><%= tracker.name %></td>
<% @roles.each do |role| -%>
<% count = @workflow_counts[[tracker.id, role.id]] || 0 %>
<td>
<% countall = 0 %>
<% @workspaces.each do |workspace| %>
<% count = @workflow_counts[[tracker.id, role.id, workspace.id]] || 0 %>
<% countall += count %>
<span class="ws ws<%= workspace.id%>" style="display: none;">
<%= link_to((count > 0 ? count : content_tag(:span, nil, :class => 'icon-only icon-not-ok')),
{:action => 'edit', :role_id => role, :tracker_id => tracker, :workspace_id => workspace},
:title => l(:button_edit)) %>
</span>
<% end %>
<span class="ws wsall" style="display: none;">
<%= link_to((countall > 0 ? countall : content_tag(:span, nil, :class => 'icon-only icon-not-ok')),
{:action => 'edit', :role_id => role, :tracker_id => tracker, :workspace_id => 'all'},
:title => l(:button_edit)) %>
</span>
<%= link_to((count > 0 ? count : content_tag(:span, nil, :class => 'icon-only icon-not-ok')),
{:action => 'edit', :role_id => role, :tracker_id => tracker},
:title => l(:button_edit)) %>
</td>
<% end -%>
</tr>
......
</tbody>
</table>
</div>
<script>
function refresh_table(value) {
$('.ws').css("display","none");
$('.ws' + value).css("display","inline");
collapse_table();
}
function expand_table() {
$('table').toggleClass("collapsed");
collapse_table();
}
function collapse_table() {
i = $('#workspace_id').val();
var x = !$('table').hasClass("collapsed");
if (x) {
$('.tip_exp_on').css("display", "");
$('.tip_exp_off').css("display", "none");
} else {
$('.tip_exp_on').css("display", "none");
$('.tip_exp_off').css("display", "");
}
$('th, td, tr').toggle(true);
for (var j = 2; j <= $('thead > tr > th').length; j++) {
if ($('tbody > tr > td:nth-child(' + j + ') > span:visible > a:not(:has(span))').length == 0) {
$('tbody > tr > td:nth-child(' + j + ')').toggle(x);
$('thead > tr > th:nth-child(' + j + ')').toggle(x);
}
}
for (var j = 1; j <= $('tbody > tr').length; j++) {
if ($('tbody > tr:nth-child(' + j + ') > td > span:visible > a:not(:has(span))').length == 0) {
$('tbody > tr:nth-child(' + j + ')').toggle(x);
}
}
}
refresh_table($('#workspace_id').val());
</script>
<% end %>
app/views/workflows/permissions.html.erb
<div class="tabs">
<ul>
<li><%= link_to l(:label_status_transitions), workflows_edit_path(:role_id => @roles, :tracker_id => @trackers) %></li>
<li><%= link_to l(:label_fields_permissions), workflows_permissions_path(:role_id => @roles, :tracker_id => @trackers), :class => 'selected' %></li>
<li><%= link_to l(:label_status_transitions), workflows_edit_path(:role_id => @roles, :tracker_id => @trackers, :workspace_id => @workspaces, :used_statuses_only => @used_statuses_only ? 1 : 0) %></li>
<li><%= link_to l(:label_fields_permissions), workflows_permissions_path(:role_id => @roles, :tracker_id => @trackers, :workspace_id => @workspaces, :used_statuses_only => @used_statuses_only ? 1 : 0), :class => 'selected' %></li>
</ul>
</div>
......
<%= options_for_workflow_select 'tracker_id[]', Tracker.sorted, @trackers, :id => 'tracker_id', :class => 'expandable' %>
</label>
<a href="#" data-expands="#tracker_id"><span class="toggle-multiselect"></a>
<label><%=l(:label_workspace)%>:
<%= options_for_workflow_select 'workspace_id[]', Workspace.sorted, @workspaces, :id => 'workspace_id', :class => 'expandable' %>
</label>
<a href="#" data-expands="#workspace_id"><span class="toggle-multiselect"></span></a>
<%= submit_tag l(:button_edit), :name => nil %>
......
</p>
<% end %>
<% if @trackers && @roles && @statuses.any? %>
<% if @trackers && @roles && @workspaces && @statuses.any? %>
<%= form_tag({}, :id => 'workflow_form' ) do %>
<%= @trackers.map {|tracker| hidden_field_tag 'tracker_id[]', tracker.id, :id => nil}.join.html_safe %>
<%= @roles.map {|role| hidden_field_tag 'role_id[]', role.id, :id => nil}.join.html_safe %>
<%= @workspaces.map {|workspace| hidden_field_tag 'workspace_id[]', workspace.id, :id => nil}.join.html_safe %>
<%= hidden_field_tag 'used_statuses_only', params[:used_statuses_only], :id => nil %>
<div class="autoscroll">
<table class="list workflows fields_permissions">
app/views/workspaces/_form.html.erb
<%= error_messages_for 'workspace' %>
<div class="box tabular">
<p><%= f.text_field :name, :required => true %></p>
<p><%= f.text_field :description %></p>
<%= call_hook(:view_workspaces_form, :workspace => @workspace) %>
</div>
app/views/workspaces/edit.html.erb
<%= title [l(:label_workspace_plural), workspaces_path], @workspace.name %>
<%= labelled_form_for @workspace do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_save) %>
<% end %>
app/views/workspaces/index.api.rsb
api.array :workspaces do
@workspaces.each do |workspace|
api.workspace do
api.id status.id
api.name status.name
api.description status.description
end
end
end
app/views/workspaces/index.html.erb
<div class="contextual">
<%= link_to l(:label_workspace_new), new_workspace_path, :class => 'icon icon-add' %>
</div>
<h2><%=l(:label_workspace_plural)%></h2>
<table class="list workspaces">
<thead><tr>
<th><%=l(:field_name)%></th>
<th><%=l(:field_description)%></th>
<th></th>
</tr></thead>
<tbody>
<% for workspace in @workspaces %>
<tr class="<%= workspace.id == 1 ? "builtin" : "givable" %>">
<td class="name"><%= link_to workspace.name, edit_workspace_path(workspace) %></td>
<td class="description"><%= link_to workspace.description, edit_workspace_path(workspace) %></td>
<td class="buttons">
<%= reorder_handle(workspace) unless workspace.id == 1 %>
<%= delete_link workspace_path(workspace) unless workspace.id == 1 %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% html_title(l(:label_workspace_plural)) -%>
<%= javascript_tag do %>
$(function() { $("table.workspaces tbody").positionedItems({items: ".givable"}); });
<% end %>
app/views/workspaces/new.html.erb
<%= title [l(:label_workspace_plural), workspaces_path], l(:label_workspace_new) %>
<%= labelled_form_for @workspace do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_create) %>
<% end %>
config/locales/en.yml
label_tracker_plural: Trackers
label_tracker_all: All trackers
label_tracker_new: New tracker
label_workspace: Workspace
label_workspace_plural: Workspaces
label_workspace_new: New workspace
error_unable_delete_workspace: Unable to delete workspace
field_workspace: Workspace
label_workflow: Workflow
label_issue_status: Issue status
label_issue_status_plural: Issue statuses
config/locales/pt-BR.yml
label_tracker: Tipo de tarefa
label_tracker_plural: Tipos de tarefas
label_tracker_new: Novo tipo
label_workspace: Espaço de trabalho
label_workspace_plural: Espaços de trabalho
label_workspace_new: Novo espaço de trabalho
error_unable_delete_workspace: Não foi possível excluir espaço de trabalho
field_workspace: Espaço de trabalho
label_workflow: Fluxo de trabalho
label_issue_status: Situação da tarefa
label_issue_status_plural: Situação das tarefas
config/routes.rb
end
end
resources :workspaces, :except => :show
match 'workflows', :controller => 'workflows', :action => 'index', :via => :get
match 'workflows/edit', :controller => 'workflows', :action => 'edit', :via => [:get, :post]
match 'workflows/permissions', :controller => 'workflows', :action => 'permissions', :via => [:get, :post]
db/migrate/20160314174310_add_workspace_to_projects.rb
class AddWorkspaceToProjects < ActiveRecord::Migration[4.2]
def self.up
add_column :projects, :workspace_id, :integer, :default => 1
end
def self.down
remove_column :projects, :workspace_id
end
end
db/migrate/20160314174311_add_workspace_to_workflows.rb
class AddWorkspaceToWorkflows < ActiveRecord::Migration[4.2]
def self.up
add_column :workflows, :workspace_id, :integer, :default => 1
end
def self.down
remove_column :workflows, :workspace_id
end
end
db/migrate/20160314174312_create_workspaces.rb
class CreateWorkspaces < ActiveRecord::Migration[4.2]
def self.up
create_table :workspaces do |t|
t.string :name
t.string :description
t.integer :position, :default => nil, :null => true
end
# create default workspace
unless Workspace.exists?(1)
Workspace.create(:name => "Default", :description => "Default workspace", :position => 1)
end
end
def self.down
drop_table :workspaces
end
end
lib/redmine.rb
:html => {:class => 'icon icon-issue'}
menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural,
:html => {:class => 'icon icon-issue-edit'}
menu.push :workspaces, {:controller => 'workspaces'}, :caption => :label_workspace_plural,
:html => {:class => 'icon icon-multiple'}
menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow,
:html => {:class => 'icon icon-workflows'}
menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural,
public/stylesheets/application.css
div#roadmap .wiki h2 { font-size: 110%; }
body.controller-versions.action-show div#roadmap .related-issues {width:70%;}
span.tip_exp_on {font-weight:bold; position:relative; color:#fff; background:#9DB9D5; padding:0px 6px 1px 6px; border-radius:3px; margin-left:4px;}
span.tip_exp_off {font-weight:bold; position:relative; color:#fff; background:#9DB9D5; padding:0px 6px 1px 6px; border-radius:3px; margin-left:4px;}
div#version-summary { float:right; width:28%; margin-left: 16px; margin-bottom: 16px; background-color: #fff; }
div#version-summary fieldset { margin-bottom: 1em; }
div#version-summary fieldset.time-tracking table { width:100%; }
(3-3/5)