New seed data for BIM-Edition

Extracted from another OP instance with a script
pull/7648/head
Wieland Lindenthal 5 years ago
parent b515f87444
commit 75a75bb24d
  1. 2
      modules/bim_seeder/app/seeders/bim_seeder/basic_data/status_seeder.rb
  2. 115
      modules/bim_seeder/aspects/extract_seed_data.rb
  3. 1259
      modules/bim_seeder/config/locales/en.seeders.bim.yml
  4. BIN
      modules/bim_seeder/files/seed.bcfzip
  5. 10
      modules/bim_seeder/spec/seeders/demo_data_seeder_spec.rb
  6. 15
      modules/overviews/config/locales/en.seeders.bim.yml

@ -36,7 +36,7 @@ module BimSeeder
'red-9', # new
'yellow-3', # in progress
'green-3', # resolved
'green-9' #closed
'green-9' # closed
]
# When selecting for an array of values, implicit order is applied

@ -0,0 +1,115 @@
##
# This file contains code that helps extracting seed data from real OP instances.
# It is meant to be copy & pasted into the rails console of the the instance from which you want
# to extract the data from.
# It is very unstable code. However, it should never change the instance it runs in. However, use it with caution.
## Before using it, make sure that all subjects are unique:
# project_identifiers = %w(construction-project bcf-management seed-daten creating-bim-model)
# projects = Project.where(identifier: project_identifiers)
# all_wps = projects.map(&:work_packages).flatten
# all_wps.group_by(&:subject).select { |subject, members| members.size > 1 }.each { |subject, members| puts "#{subject}\t#{members.map(&:id).join("\t")}" }
class Seedifier
attr_accessor :written_work_packages_ids, :project_identifiers, :projects, :base_date
def initialize(project_identifiers)
@project_identifiers = project_identifiers
@written_work_packages_ids = []
@projects = Project.where(identifier: @project_identifiers)
all_work_packages = @projects.map { |project| project.work_packages.to_a }.flatten.sort_by(&:start_date)
@base_date = all_work_packages.first.start_date.monday
end
def run
@projects.each do |project|
puts "=== PROJECT: #{project.identifier} ==="
work_packages = project.work_packages.reject { |work_package| work_package.parent && work_package.parent.project.identifier == project.identifier }.sort_by(&:start_date)
if work_packages.empty?
puts "No work packages for project with identifier #{project.identifier}... skipping."
next
end
puts work_packages.map { |work_package| seedify_work_package(work_package, project) }.compact.to_yaml
end
end
def calc_start_offset(work_package)
if work_package.start_date
(work_package.start_date - @base_date).to_i
else
0
end
end
def calc_duration(work_package)
if work_package.start_date && work_package.due_date
(work_package.due_date - work_package.start_date).to_i
end
end
def calc_status(work_package)
prefix = ''
if ["Resolved"].include?(work_package.status.name)
prefix = 'seeders.bim.'
end
"#{prefix}default_status_#{calc_low_dash(work_package.status.name.downcase)}"
end
def calc_type(work_package)
prefix = ''
if ["Issue", "Clash", "Remark", "Request"].include?(work_package.type.name)
prefix = 'seeders.bim.'
end
"#{prefix}default_type_#{calc_low_dash(work_package.type.name.downcase)}"
end
def calc_low_dash(name)
name.tr(" ", "_")
end
##
# Create a hash that only hold those properties that we would like to copy and paste into a seeder YAML file.
def seedify_work_package(work_package, project)
# Don't seed a WP twice. And don't seed WPs of other projects.
return nil if (@written_work_packages_ids.include?(work_package.id) || work_package.project_id != project.id)
@written_work_packages_ids << work_package.id
predecessors = work_package.follows.sort_by(&:start_date).map { |predecessor| { to: predecessor.subject, type: 'follows' } }
children = work_package.children.sort_by(&:start_date).map { |child| seedify_work_package(child, project) }.compact
assigned_to = work_package.assigned_to.try(:name)
duration = calc_duration(work_package)
seedified = {
start: calc_start_offset(work_package)
}
if work_package.bcf_issue
seedified[:bcf_issue_uuid] = work_package.bcf_issue.uuid
else
seedified[:subject] = work_package.subject
seedified[:description] = work_package.description
seedified[:status] = calc_status(work_package)
seedified[:type] = calc_type(work_package)
seedified[:estimated_hours] = work_package.estimated_hours if work_package.estimated_hours.present?
seedified[:children] = children if children.any?
end
seedified[:assigned_to] = assigned_to if assigned_to.present?
seedified[:duration] = duration if duration.present?
seedified[:parent] = work_package.parent.subject if work_package.parent.present? && (work_package.bcf_issue || work_package.project_id != project.id)
seedified[:relations] = predecessors if predecessors.any?
seedified
end
end
# project_identifiers = ['demo-project']
project_identifiers = %w(construction-project bcf-management seed-daten creating-bim-model)
Seedifier.new(project_identifiers).run

File diff suppressed because it is too large Load Diff

@ -56,11 +56,11 @@ describe 'seeds' do
expect { DemoDataSeeder.new.seed! }.not_to raise_error
expect(User.where(admin: true).count).to eq 1
expect(Project.count).to eq 2
expect(WorkPackage.count).to eq 18
expect(Wiki.count).to eq 1
expect(Query.count).to eq 12
expect(Group.count).to eq 7
expect(Project.count).to eq 4
expect(WorkPackage.count).to eq 75
expect(Wiki.count).to eq 3
expect(Query.count).to eq 18
expect(Group.count).to eq 8
expect(Type.count).to eq 7
expect(Status.count).to eq 4
expect(IssuePriority.count).to eq 4

@ -30,7 +30,7 @@ en:
bim:
demo_data:
projects:
demo-project:
demo-construction-project:
project-overview:
row_count: 4
column_count: 2
@ -55,16 +55,15 @@ en:
text: |
We are glad you joined! We suggest to try a few things to get started in OpenProject.
Discover the most important features with our [Guided Tour](%{base_url}/projects/demo-project/work_packages/?start_onboarding_tour=true).
Discover the most important features with our [Guided Tour](%{base_url}/projects/demo-construction-project/work_packages/?start_onboarding_tour=true).
_Try the following steps:_
1. *Invite new members to your project*: &rightarrow; Go to [Members](%{base_url}/projects/demo-project/members) in the project navigation.
2. *View the work in your project*: &rightarrow; Go to [Work packages](%{base_url}/projects/demo-project/work_packages) in the project navigation.
3. *Create a new work package*: &rightarrow; Go to [Work packages &rightarrow; Create](%{base_url}/projects/demo-project/work_packages/new).
4. *Create and update a project plan*: &rightarrow; Go to [Project plan](%{base_url}/projects/demo-project/work_packages?query_id=##query.id:"Project plan") in the project navigation.
5. *Activate further modules*: &rightarrow; Go to [Project settings &rightarrow; Modules](%{base_url}/projects/demo-project/settings/modules).
6. *Complete your tasks in the project*: &rightarrow; Go to [Work packages &rightarrow; Tasks](%{base_url}/projects/demo-project/work_packages/details/##wp.id:"Edit a work package"/overview?query_id=##query.id:"Tasks").
1. *Invite new members to your project*: &rightarrow; Go to [Members](%{base_url}/projects/demo-construction-project/members) in the project navigation.
2. *View the work in your project*: &rightarrow; Go to [Work packages](%{base_url}/projects/demo-construction-project/work_packages) in the project navigation.
3. *Create a new work package*: &rightarrow; Go to [Work packages &rightarrow; Create](%{base_url}/projects/demo-construction-project/work_packages/new).
4. *Create and update a project plan*: &rightarrow; Go to [Project plan](%{base_url}/projects/demo-construction-project/work_packages?query_id=##query.id:"Project plan") in the project navigation.
5. *Activate further modules*: &rightarrow; Go to [Project settings &rightarrow; Modules](%{base_url}/projects/demo-construction-project/settings/modules).
Here you will find our [User Guides](https://www.openproject.org/help/).
Please let us know if you have any questions or need support. Contact us: [support[at]openproject.com](mailto:support@openproject.com).

Loading…
Cancel
Save