Merge pull request #7616 from opf/feature/30882-Extend-seeder-to-handle-default-type-descriptions

[30882] Extend seeder to handle default type descriptions and queries in form configuration
pull/7626/head
Wieland Lindenthal 5 years ago committed by GitHub
commit d25ade0f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      app/seeders/basic_data/type_seeder.rb
  2. 50
      app/seeders/demo_data/global_query_seeder.rb
  3. 9
      app/seeders/demo_data/project_seeder.rb
  4. 19
      app/seeders/demo_data/query_builder.rb
  5. 1
      app/seeders/demo_data_seeder.rb
  6. 21
      config/locales/en.seeders.standard.yml.example
  7. 20
      modules/bim_seeder/config/locales/en.seeders.bim.yml

@ -61,7 +61,8 @@ module BasicData
is_default: values[1],
color_id: color_id,
is_in_roadmap: values[3],
is_milestone: values[4]
is_milestone: values[4],
description: type_description(values[5])
}
end
end
@ -73,5 +74,42 @@ module BasicData
def type_table
raise NotImplementedError
end
def type_description(type_name)
return '' if demo_data_for('type_configuration').nil?
demo_data_for('type_configuration').each do |entry|
if entry[:type] && I18n.t(entry[:type]) === I18n.t(type_name)
return entry[:description] ? entry[:description] : ''
else
return ''
end
end
end
def set_attribute_groups_for_type(type)
return if demo_data_for('type_configuration').nil?
demo_data_for('type_configuration').each do |entry|
if entry[:form_configuration] && I18n.t(entry[:type]) === type.name
entry[:form_configuration].each do |form_config_attr|
groups = type.default_attribute_groups
query_association = 'query_' + find_query_by_name(form_config_attr[:query_name]).to_s
groups.unshift([form_config_attr[:group_name], [query_association.to_sym]])
type.attribute_groups = groups
end
type.save!
end
end
end
private
def find_query_by_name(name)
Query.find_by(name: name).id
end
end
end

@ -0,0 +1,50 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# 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.
#
# See doc/COPYRIGHT.rdoc for more details.
module DemoData
class GlobalQuerySeeder < Seeder
def initialize; end
def seed_data!
print ' ↳ Creating global queries'
seed_global_queries
puts
end
private
def seed_global_queries
Array(demo_data_for('global_queries')).each do |config|
DemoData::QueryBuilder.new(config, nil).create!
end
end
end
end

@ -69,6 +69,9 @@ module DemoData
puts ' ↳ Assign groups to projects'
set_groups
puts ' ↳ Update form configuration with global queries'
set_form_configuration
puts ' ↳ Updating settings'
seed_settings
end
@ -128,6 +131,12 @@ module DemoData
DemoData::GroupSeeder.new.add_projects_to_groups
end
def set_form_configuration
Type.all.each do |type|
BasicData::TypeSeeder.new.set_attribute_groups_for_type(type)
end
end
def set_types(project, key)
project.types.clear
Array(project_data_for(key, 'types')).each do |type_name|

@ -49,10 +49,10 @@ module DemoData
def base_attributes
{
project: project,
name: config[:name],
user: User.admin.first,
is_public: true,
is_public: config[:is_public] != false,
hidden: config[:hidden] == true,
show_hierarchies: config[:hierarchy] == true,
timeline_visible: config[:timeline] == true
}
@ -61,6 +61,7 @@ module DemoData
def create_query
attr = base_attributes
set_project! attr
set_columns! attr
set_sort_by! attr
set_group_by! attr
@ -81,6 +82,10 @@ module DemoData
)
end
def set_project!(attr)
attr[:project] = project unless project.nil?
end
def set_columns!(attr)
attr[:column_names] = columns unless columns.empty?
end
@ -113,6 +118,7 @@ module DemoData
set_status_filter! filters
set_version_filter! filters
set_type_filter! filters
set_parent_filter! filters
filters
end
@ -145,6 +151,15 @@ module DemoData
end
end
def set_parent_filter!(filters)
if parent_filter_value = config[:parent].presence
filters[:parent] = {
operator: "=",
values: [parent_filter_value]
}
end
end
def backlogs_present?
@backlogs_present = defined? OpenProject::Backlogs if @backlogs_present.nil?

@ -30,6 +30,7 @@ class DemoDataSeeder < CompositeSeeder
[
DemoData::GroupSeeder,
DemoData::AttributeHelpTextSeeder,
DemoData::GlobalQuerySeeder,
DemoData::ProjectSeeder
]
end

@ -29,6 +29,7 @@ en:
seeders:
standard:
demo_data:
<<<<<<< HEAD
attribute_help_texts:
- attribute_name: 'assignee'
help_text: |
@ -37,6 +38,26 @@ en:
* Doing the job
* Tracking the time
* Update ticket status
default_description_for_types:
- type: :default_type_bug
description: |
### Steps to reproduce
global_queries:
- name: My cool query
status: open
timeline: false
sort_by: id
hidden: true
is_public: false
type_configuration:
- type: :default_type_bug
description: |
### Steps to reproduce
### Actual behavior
form_configuration:
- group_name: Custom query
query_name: My cool query
groups:
- name: 'Project Admins'
projects:

@ -35,6 +35,26 @@ en:
default_status_resolved: Resolved
default_priority_critical: Critical
demo_data:
global_queries:
- name: "Embedded table: Children"
parent: '{id}'
timeline: false
sort_by: id
hidden: true
is_public: false
columns:
- type
- id
- subject
- status
- assigned_to
- priority
- project
type_configuration:
- type: :default_type_phase
form_configuration:
- group_name: "Children"
query_name: "Embedded table: Children"
groups:
- name: Architects
- name: BIM Coordinators

Loading…
Cancel
Save