Seed demo work packages using locales

pull/3726/head
Peter Lehwess 9 years ago committed by Markus Kahl
parent 88b52a3fec
commit 67de87cd5b
  1. 72
      app/seeders/sample_data/work_package_seeder.rb
  2. 126
      config/locales/en.seeders.yml
  3. 16
      config/locales/en.yml

@ -38,11 +38,15 @@ module SampleData
self.types = project.types.all.reject(&:is_milestone?)
end
def seed!
def seed!(random: true)
puts ''
print ' ↳ Creating work_packages'
seed_random_work_packages
if random
seed_random_work_packages
else
seed_demo_work_packages
end
end
private
@ -68,17 +72,37 @@ module SampleData
make_changes(work_package)
end
# Using the attribute values passed in or random ones
def new_work_package(subject: nil, status: nil, type: nil, start_date: nil, due_date: nil)
WorkPackage.create(
project: project,
author: user,
subject: subject || Faker::Lorem.words(8).join(' '),
status: status || statuses.sample,
type: type || types.sample,
start_date: start_date || s = Date.today - (25 - rand(50)).days,
due_date: due_date || s + (1 + rand(120)).days
)
def seed_demo_work_packages
work_packages_data = I18n.t('seeders.sample_data.work_packages')
work_packages_data.each do |attributes|
start_date = calculate_start_date(attributes[:start])
print '.'
work_package = new_work_package(
subject: attributes[:subject],
status: Status.find_by!(name: attributes[:status_name]),
type: Type.find_by!(name: attributes[:type_name]),
start_date: start_date,
due_date: calculate_due_date(start_date, attributes[:duration])
)
attributes[:children].each do |child_attributes|
start_date = calculate_start_date(child_attributes[:start])
print '.'
child = new_work_package(
subject: child_attributes[:subject],
status: Status.find_by!(name: child_attributes[:status_name]),
type: Type.find_by!(name: child_attributes[:type_name]),
start_date: start_date,
due_date: calculate_due_date(start_date, child_attributes[:duration])
)
child.parent = work_package
child.save!
end
end
end
def add_changeset(work_package)
@ -193,5 +217,27 @@ module SampleData
end
end
# Using the attribute values passed in or random onesbb
def new_work_package(subject: nil, status: nil, type: nil, start_date: nil, due_date: nil)
WorkPackage.create!(
project: project,
author: user,
subject: subject || Faker::Lorem.words(8).join(' '),
status: status || statuses.sample,
type: type || types.sample,
start_date: start_date || s = Date.today - (25 - rand(50)).days,
due_date: due_date || s + (1 + rand(120)).days
)
end
def calculate_start_date(days_ahead)
monday = Date.today.monday
days_ahead > 0 ? monday + days_ahead : monday
end
def calculate_due_date(date, duration)
duration > 1 ? date + duration : date
end
end
end

@ -0,0 +1,126 @@
#-- 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.
#++
en:
seeders:
sample_data:
board:
name: Demo Board
description: General discussion on various topics for the project.
custom_fields:
names:
- Company
- City
project:
name: Demo project
identifier: demo-project
description: 'This is a description for your project. You can edit the description in the Project settings -> Description'
timeline:
name: Timeline
work_packages:
- subject: Project kick-off
status_name: Closed
type_name: Milestone
start: 0
duration: 1
children: []
- subject: Project planning
status_name: In progress
type_name: Phase
start: 1
duration: 10
children:
- subject: Collect ideas
status_name: Closed
type_name: Task
start: 1
duration: 3
- subject: Ensure financing
status_name: Closed
type_name: Task
start: 1
duration: 3
- subject: Build a project team
status_name: In progress
type_name: Task
start: 7
duration: 4
- subject: Development
status_name: Scheduled
type_name: Phase
start: 14
duration: 26
children:
- subject: Nice feature
status_name: In development
type_name: Feature
start: 14
duration: 26
- subject: Great feature
status_name: Developed
type_name: Feature
start: 14
duration: 11
- subject: Best feature
status_name: Specified
type_name: Feature
start: 29
duration: 11
- subject: Release public beta
status_name: Scheduled
type_name: Milestone
start: 41
duration: 1
children: []
- subject: Documentation and help resources
status_name: New
type_name: Phase
start: 43
duration: 16
children: []
- subject: Testing and bugfixing
status_name: New
type_name: Phase
start: 43
duration: 16
children: []
- subject: Go-Live
status_name: To be scheduled
type_name: Milestone
start: 60
duration: 1
children: []

@ -1727,22 +1727,6 @@ en:
sentence_connector: "and"
skip_last_comma: "false"
seeders:
sample_data:
board:
name: Demo Board
description: General discussion on various topics for the project.
custom_fields:
names:
- Company
- City
project:
name: Demo project
identifier: demo-project
description: 'This is a description for your project. You can edit the description in the Project settings -> Description'
timeline:
name: Timeline
text_access_token_hint: "Access tokens allow you to grant external applications access to resources in OpenProject."
text_analyze: "Further analyze: %{subject}"
text_are_you_sure: "Are you sure?"

Loading…
Cancel
Save