Skip to content

Commit

Permalink
Merge pull request #7 from tmerten/experimental-configurable-relation…
Browse files Browse the repository at this point in the history
…ships

Experimental configurable relationships
  • Loading branch information
tmerten committed Jan 8, 2015
2 parents fbf7a62 + 826ba37 commit c18d5a4
Show file tree
Hide file tree
Showing 48 changed files with 932 additions and 1,303 deletions.
6 changes: 3 additions & 3 deletions app/controllers/re_artifact_properties_controller.rb
Expand Up @@ -399,8 +399,8 @@ def how_to_delete

@children = gather_children(@re_artifact_properties)

@relationships_incoming.delete_if { |x| x.relation_type.eql? ReArtifactRelationship::RELATION_TYPES[:pch] }
@relationships_outgoing.delete_if { |x| x.relation_type.eql? ReArtifactRelationship::RELATION_TYPES[:pch] }
@relationships_incoming.delete_if { |x| x.relation_type.eql? "parentchild" }
@relationships_outgoing.delete_if { |x| x.relation_type.eql? "parentchild" }

initialize_tree_data

Expand Down Expand Up @@ -488,4 +488,4 @@ def gather_children(artifact)
children
end

end
end
358 changes: 165 additions & 193 deletions app/controllers/re_artifact_relationship_controller.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/controllers/re_queries_controller.rb
Expand Up @@ -201,7 +201,7 @@ def load_selectable_collections
@project_artifacts = ReArtifactProperties.of_project(@project).without_projects
@artifacts = []
@artifact_types = @project_artifacts.available_artifact_types
@relation_types = ReArtifactRelationship::RELATION_TYPES.values
@relation_types = ReRelationtype.relation_types(@project.id, false)
@issues = []
@users = User.all(:conditions => ['status = ?', User::STATUS_ACTIVE],
:order => 'firstname ASC, lastname ASC, login ASC')
Expand Down
111 changes: 55 additions & 56 deletions app/controllers/re_settings_controller.rb
Expand Up @@ -4,15 +4,10 @@ class ReSettingsController < RedmineReController

def configure
initialize_artifact_order(@project.id)
initialize_relation_order(@project.id)

name = @project.name
if name.length < 3
name = name+" Project"
end
if name.length > 50
name = name[0..49]
end
name = "#{name} Project" if name.length < 3
name = name[0..49] if name.length > 50

@project_artifact = ReArtifactProperties.where({
:project_id => @project.id,
Expand Down Expand Up @@ -45,29 +40,15 @@ def configure
configured_artifact = {}
configured_artifact['in_use'] = true
configured_artifact['alias'] = artifact_type.gsub(/^re_/, '').humanize
configured_artifact['color'] = artifact_type.to_s.classify.constantize::INITIAL_COLOR #"%06x" % (rand * 0xffffff)

configured_artifact['color'] = artifact_type.to_s.classify.constantize::INITIAL_COLOR
ReSetting.set_serialized(artifact_type, @project.id, configured_artifact)
end
@re_artifact_configs[artifact_type] = configured_artifact
end

@re_relation_configs = {}
@re_relation_order.each do |relation_type|
configured_relation = ReSetting.get_serialized(relation_type, @project.id)
if configured_relation.nil?
logger.debug("##### found an unconfigured relation of type '" + relation_type.to_s + "', creating an initial configuration")
configured_relation = {}
configured_relation['in_use'] = true
configured_relation['alias'] = relation_type.humanize

configured_relation['color'] = ReArtifactRelationship::INITIAL_COLORS[ReArtifactRelationship::ALL_RELATION_TYPES.index(relation_type)]
configured_relation['show_in_visualization'] = true
ReSetting.set_serialized(relation_type, @project.id, configured_relation)
end
@re_relation_configs[relation_type] = configured_relation
end

@re_relation_types = ReRelationtype.find_all_by_project_id(@project.id)
logger.debug @re_relation_types.inspect
@re_settings = {}
@re_settings["visualization_size"] = ReSetting.get_plain("visualization_size", @project.id)
@re_settings["visualization_size"] ||= 800
Expand All @@ -80,7 +61,6 @@ def configure
else
@re_visualization_setting["issue"] = false
end

end

def self.for(artifact_type, project_id)
Expand All @@ -106,7 +86,6 @@ def edit_artifact_type_description
@description = configured_artifact['description']
@hide_default_description = configured_artifact['hide_default_description']
end

end

private
Expand All @@ -124,15 +103,7 @@ def initialize_artifact_order(project_id)
# Put it into the empty configured_artifact_types array
configured_artifact_types.concat(stored_settings) if stored_settings

# Search for artifact types (all models containing "acts_as_re_artifact" are used)
all_artifact_types = Dir["#{Rails.root}/plugins/redmine_re/app/models/re_*.rb"].map do |f|
fd = File.open(f, 'r')
File.basename(f, '.rb') if fd.read.include? "acts_as_re_artifact"
end

all_artifact_types.delete_if { |x| x.nil? }
all_artifact_types.delete(:ReArtifactProperties)
all_artifact_types.delete(:ReArtifactsConfig)
all_artifact_types = ReSetting::ARTIFACT_TYPES
all_artifact_types.delete_if { |v| configured_artifact_types.include? v }
configured_artifact_types.concat(all_artifact_types)

Expand All @@ -141,21 +112,6 @@ def initialize_artifact_order(project_id)
@re_artifact_order = configured_artifact_types
end

def initialize_relation_order(project_id)
configured_relation_types = Array.new
stored_settings = ReSetting.get_serialized("relation_order", project_id)
configured_relation_types.concat(stored_settings) if stored_settings

all_relation_types = []
ReArtifactRelationship::RELATION_TYPES.values.each { |k| all_relation_types << k.to_s }
ReArtifactRelationship::SYSTEM_RELATION_TYPES.values.each { |k| all_relation_types << k.to_s }

all_relation_types.delete_if { |v| configured_relation_types.include? v }
configured_relation_types.concat(all_relation_types)

@re_relation_order = configured_relation_types
end

def save_user_config
#store new settings and configurations
new_settings = params[:re_settings]
Expand Down Expand Up @@ -188,22 +144,65 @@ def save_user_config
ReSetting.set_serialized(k, @project.id, v)
end

# Get existing
new_relation_configs = params[:re_relation_configs]

# Add new relations
unless params[:config].nil?
params[:config][:re_relationtypes].each_pair do |k, new_relation|
new_relation_configs = new_relation_configs.merge({ k => new_relation })
end
end

new_relation_configs.each_pair do |k, v|
v['in_use'] = v.has_key? 'in_use'
v['show_in_visualization'] = v.has_key? 'show_in_visualization'
ReSetting.set_serialized(k, @project.id, v)
logger.debug v.to_yaml
if v['id'].blank?
r = ReRelationtype.new
r.relation_type = v[:alias_name] # on i the type was created the alias name will be set
r.is_system_relation = 0
else
r = ReRelationtype.find_or_create_by_id(v['id'])
end

logger.debug "before: #{r.inspect}"
if r.is_system_relation == 0
r.in_use = (v[:in_use] == "1" || v[:in_use] == "yes")
r.is_directed = (v[:is_directed] == "1" || v[:is_directed] == "yes")
end
r.alias_name = v[:alias_name]
r.color = v[:color]
r.project_id = @project.id

logger.debug "after: #{r.inspect}"

if r.is_system_relation == "1"
r.save
else
if v[:destroy] == "1"

n = ReArtifactRelationship.find_all_by_relation_type(r.relation_type)
n.each do |relation|
artifact = ReArtifactProperties.find(relation.source_id)
if (artifact.project_id == r.project_id)
ReArtifactRelationship.destroy(relation.id)
end
end

ReRelationtype.destroy(r.id)
else
r.save
end
end
end

@re_artifact_order = ReSetting.get_serialized("artifact_order", @project.id)
@re_relation_order = ReSetting.get_serialized("relation_order", @project.id)
ReSetting.set_serialized("unconfirmed", @project.id, false)


flash[:notice] = t(:re_configs_saved)

redirect_to :controller => "requirements", :action => "index", :project_id => @project.id
#redirect_to :controller => "requirements", :action => "index", :project_id => @project.id

end

end
end
38 changes: 20 additions & 18 deletions app/controllers/redmine_re_controller.rb
Expand Up @@ -49,7 +49,8 @@ def load_settings
ReSetting.check_cache
session[:expanded_nodes] ||= Set.new
@re_artifact_order = ReSetting.get_serialized("artifact_order", @project.id)
@re_relation_order = ReSetting.get_serialized("relation_order", @project.id)
@re_relation_types = ReRelationtype.relation_types(@project.id, false)
@re_used_relation_types = ReRelationtype.relation_types(@project.id, false, true)
@re_artifact_settings = ReSetting.active_re_artifact_settings(@project.id)
@re_relation_settings = ReSetting.active_re_relation_settings(@project.id)
end
Expand Down Expand Up @@ -116,7 +117,7 @@ def create
@artifact.updated_by = User.current.id
@artifact.created_by = User.current.id if @artifact.new_record?

# realtion related attributes
# relation related attributes
unless params[:sibling_id].blank?
@sibling = ReArtifactProperties.find(params[:sibling_id])
@parent = @sibling.parent
Expand Down Expand Up @@ -193,24 +194,24 @@ def edit
end

def new_hook(paramsparams)
logger.debug("#############: new_hook not called")
logger.debug("#############: new_hook not called")
end

def edit_hook_after_artifact_initialized(params)
logger.debug("#############: edit_hook_after_artifact_initialized not called")
logger.debug("#############: edit_hook_after_artifact_initialized not called")
end

def edit_hook_validate_before_save(params, artifact_valid)
logger.debug("#############: edit_validate_before_save_hook not called")
logger.debug("#############: edit_validate_before_save_hook not called")
return true
end

def edit_hook_valid_artifact_after_save(params)
logger.debug("#############: edit_valid_artifact_after_save_hook not called")
logger.debug("#############: edit_valid_artifact_after_save_hook not called")
end

def edit_hook_invalid_artifact_cleanup(params)
logger.debug("#############: edit_invalid_artifact_cleanup_hook not called")
logger.debug("#############: edit_invalid_artifact_cleanup_hook not called")
end

# filtering of re_artifacts. If request is post, filter was used already
Expand Down Expand Up @@ -308,17 +309,18 @@ def render_autocomplete_artifact_list_entry(artifact)

def create_tree(re_artifact_properties)
# creates a hash containing re_artifact_properties and all its children
# until a certain tree depth (BFS)
# the result is a hash in the form
#
# example format
# 'data' : [
# {
# 'id' : 'node_2',
# 'text' : 'Root node with options',
# 'state' : { 'opened' : true, 'selected' : true },
# 'children' : [ { 'text' : 'Child 1' }, .........]
# }
# {
# 'id' : 'node_2',
# 'text' : 'Root node with options',
# 'state' : { 'opened' : true, 'selected' : true },
# 'children' : [ { 'text' : 'Child 1' }, .........]
# }
# ]
#
# to be rendered as json or xml. Used together with JStree right now
session[:expanded_nodes].delete(re_artifact_properties.id) if re_artifact_properties.children.empty?
expanded = session[:expanded_nodes].include?(re_artifact_properties.id)
Expand All @@ -327,22 +329,21 @@ def create_tree(re_artifact_properties)
artifact_name = re_artifact_properties.name.to_s
artifact_id = re_artifact_properties.id.to_s
has_children = !re_artifact_properties.children.empty?

node = {}
node['id'] = "node_" + artifact_id.to_s
node['text'] = artifact_name
node['type'] = artifact_type

state = {}
if expanded
state['opened'] = true
end
node['state'] = state

a_attr = {}
a_attr['data-id'] = artifact_id.to_s
unless artifact_type.eql?('project')
a_attr['data-href'] = url_for(:controller => 're_artifact_properties', :action => 'show', :id => artifact_id)
a_attr['data-href'] = url_for(:controller => 're_artifact_properties', :action => 'show', :id => artifact_id)
a_attr['data-delete-href'] = url_for(:controller => 're_artifact_properties', :action => 'destroy', :id => artifact_id)
end
node['a_attr'] = a_attr
Expand All @@ -363,6 +364,7 @@ def create_tree(re_artifact_properties)

def get_children(re_artifact_properties)
children = []

for child in re_artifact_properties.children
children << create_tree(child)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/requirements_controller.rb
Expand Up @@ -76,7 +76,7 @@ def tree
session[:expanded_nodes].delete(node_id)
render :text => "node #{node_id} closed"
end
logger.debug("Expended nodes: #{session[:expanded_nodes].inspect}")
logger.debug("Expended nodes: #{session[:expanded_nodes].inspect}")
end

def sendDiagramPreviewImage
Expand Down
17 changes: 14 additions & 3 deletions app/helpers/re_application_helper.rb
@@ -1,10 +1,11 @@
module ReApplicationHelper
def rendered_relation_type(relation_type)
relation_type_alias = @re_relation_settings[relation_type]['alias']
#relation_type_alias = @re_relation_settings[relation_type]['alias']
relation_type_alias = relation_type
relation_type_humanized = relation_type.humanize

if relation_type_alias.blank? or relation_type_humanized.eql?(relation_type_alias)
return t('re_' + relation_type)
return relation_type_humanized
else
return relation_type_alias
end
Expand Down Expand Up @@ -164,4 +165,14 @@ def get_escaped_subtask_html(f, sub_type)
end
escape_javascript(fields)
end
end


# renders a link to javascript to add an empty object into a forms
def get_escaped_relationtype_html(f)
new_object = ReRelationtype.new(:is_system_relation => 0, :is_directed => 1, :in_use => 1, :color => "#000000")
fields = f.fields_for("re_relationtypes", new_object, :index => "new_re_relationtype") do |builder|
render("re_settings/add_relation", :f => builder)
end
escape_javascript(fields)
end
end

0 comments on commit c18d5a4

Please sign in to comment.