Refactor code

pull/10947/head
Christophe Bliard 2 years ago
parent 39cc95a2a4
commit 136a34e7ab
No known key found for this signature in database
GPG Key ID: 2BC07603210C3FA4
  1. 21
      app/seeders/basic_data/type_seeder.rb
  2. 2
      app/seeders/standard_seeder/basic_data/type_seeder.rb
  3. 25
      modules/bim/app/seeders/bim/basic_data/type_seeder.rb

@ -48,20 +48,17 @@ module BasicData
#
# @return [Array<Hash>] List of attributes for each type.
def data
colors = Color.all
colors = colors.map { |c| { c.name => c.id } }.reduce({}, :merge)
type_table.map do |_name, values|
color_id = colors[values[2]] || values[2]
colors = Color.pluck(:name, :id).to_h
type_table.map do |_name, (position, is_default, color_name, is_in_roadmap, is_milestone, type_name)|
{
name: I18n.t(values[5]),
position: values[0],
is_default: values[1],
color_id:,
is_in_roadmap: values[3],
is_milestone: values[4],
description: type_description(values[5])
name: I18n.t(type_name),
position:,
is_default:,
color_id: colors.fetch(color_name),
is_in_roadmap:,
is_milestone:,
description: type_description(type_name)
}
end
end

@ -33,7 +33,7 @@ module StandardSeeder
end
def type_table
{ # position is_default color_id is_in_roadmap is_milestone
{ # position is_default color_name is_in_roadmap is_milestone type_name
task: [1, true, I18n.t(:default_color_blue), true, false, :default_type_task],
milestone: [2, true, I18n.t(:default_color_green_light), false, true, :default_type_milestone],
phase: [3, true, 'orange-5', false, false, :default_type_phase],

@ -33,27 +33,14 @@ module Bim
end
def type_table
color_names = [
'blue-6',
'indigo-7',
'orange-6',
'cyan-7',
'red-8'
]
# When selecting for an array of values, implicit order is applied
# so we need to restore values by their name.
colors_by_name = Color.where(name: color_names).index_by(&:name)
colors = color_names.collect { |name| colors_by_name[name].id }
{ # position is_default color_id is_in_roadmap is_milestone
task: [1, true, colors[0], true, false, :default_type_task],
milestone: [2, true, colors[2], false, true, :default_type_milestone],
{ # position is_default color_name is_in_roadmap is_milestone type_name
task: [1, true, 'blue-6', true, false, :default_type_task],
milestone: [2, true, 'orange-6', false, true, :default_type_milestone],
phase: [3, true, I18n.t(:default_color_grey), false, false, :default_type_phase],
issue: [4, true, colors[1], true, false, 'seeders.bim.default_type_issue'],
issue: [4, true, 'indigo-7', true, false, 'seeders.bim.default_type_issue'],
remark: [5, true, I18n.t(:default_color_green_dark), true, false, 'seeders.bim.default_type_remark'],
request: [6, true, colors[3], true, false, 'seeders.bim.default_type_request'],
clash: [7, true, colors[4], true, false, 'seeders.bim.default_type_clash']
request: [6, true, 'cyan-7', true, false, 'seeders.bim.default_type_request'],
clash: [7, true, 'red-8', true, false, 'seeders.bim.default_type_clash']
}
end
end

Loading…
Cancel
Save