Merge branch 'master' into fix-closed-group_order-totals
Conflicts: db/schema.rb
This commit is contained in:
commit
ebb22ccb53
137 changed files with 4484 additions and 1507 deletions
13
db/migrate/20130615073715_create_periodic_task_groups.rb
Normal file
13
db/migrate/20130615073715_create_periodic_task_groups.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class CreatePeriodicTaskGroups < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :periodic_task_groups do |t|
|
||||
t.date :next_task_date
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
change_table :tasks do |t|
|
||||
t.references :periodic_task_group
|
||||
end
|
||||
end
|
||||
end
|
||||
62
db/migrate/20130622095040_move_weekly_tasks.rb
Normal file
62
db/migrate/20130622095040_move_weekly_tasks.rb
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
class MoveWeeklyTasks < ActiveRecord::Migration
|
||||
def up
|
||||
Workgroup.where(weekly_task: true).each do |workgroup|
|
||||
task_group = PeriodicTaskGroup.create
|
||||
puts "Moving weekly task for workgroup #{workgroup.name} to group #{task_group.id}"
|
||||
workgroup.tasks.undone.each do |task|
|
||||
task.update_column(:periodic_task_group_id, task_group.id) if weekly_task?(workgroup, task)
|
||||
end
|
||||
tasks = task_group.tasks.order(:due_date)
|
||||
task_group.next_task_date = tasks.last.due_date + PeriodicTaskGroup::PeriodDays unless tasks.empty?
|
||||
task_group.save!
|
||||
puts "Associated #{tasks.count} tasks with group and set next_task_date to #{task_group.next_task_date}"
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
PeriodicTaskGroup.all.each do |task_group|
|
||||
unless task_group.tasks.empty?
|
||||
task = task_group.tasks.first
|
||||
workgroup = task.workgroup
|
||||
puts "Writing task data of group #{task_group.id} to workgroup #{workgroup.name}"
|
||||
workgroup_attributes = {
|
||||
weekly_task: true,
|
||||
weekday: task.due_date.days_to_week_start(:sunday),
|
||||
task_name: task.name,
|
||||
task_description: task.description,
|
||||
task_required_users: task.required_users,
|
||||
task_duration: task.duration
|
||||
}
|
||||
workgroup.update_attributes workgroup_attributes
|
||||
task_group.tasks.update_all weekly: true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def weekly_task?(workgroup, task)
|
||||
return false if task.due_date.nil?
|
||||
|
||||
group_task = {
|
||||
weekday: workgroup.weekday,
|
||||
name: workgroup.task_name,
|
||||
description: workgroup.task_description,
|
||||
required_users: workgroup.task_required_users,
|
||||
duration: workgroup.task_duration,
|
||||
weekly: true,
|
||||
done: false,
|
||||
workgroup_id: workgroup.id
|
||||
}
|
||||
task_task = {
|
||||
weekday: task.due_date.days_to_week_start(:sunday),
|
||||
name: task.name,
|
||||
description: task.description,
|
||||
required_users: task.required_users,
|
||||
duration: task.duration,
|
||||
weekly: task.weekly,
|
||||
done: task.done,
|
||||
workgroup_id: task.workgroup_id
|
||||
}
|
||||
group_task == task_task
|
||||
end
|
||||
end
|
||||
9
db/migrate/20130624084223_remove_weekly_from_tasks.rb
Normal file
9
db/migrate/20130624084223_remove_weekly_from_tasks.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class RemoveWeeklyFromTasks < ActiveRecord::Migration
|
||||
def up
|
||||
remove_column :tasks, :weekly
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :tasks, :weekly, :boolean
|
||||
end
|
||||
end
|
||||
19
db/migrate/20130624085246_remove_weekly_task_from_groups.rb
Normal file
19
db/migrate/20130624085246_remove_weekly_task_from_groups.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class RemoveWeeklyTaskFromGroups < ActiveRecord::Migration
|
||||
def up
|
||||
remove_column :groups, :weekly_task
|
||||
remove_column :groups, :weekday
|
||||
remove_column :groups, :task_name
|
||||
remove_column :groups, :task_description
|
||||
remove_column :groups, :task_required_users
|
||||
remove_column :groups, :task_duration
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :groups, :task_duration, :integer
|
||||
add_column :groups, :task_required_users, :integer
|
||||
add_column :groups, :task_description, :string
|
||||
add_column :groups, :task_name, :string
|
||||
add_column :groups, :weekday, :integer
|
||||
add_column :groups, :weekly_task, :boolean
|
||||
end
|
||||
end
|
||||
17
db/migrate/20130718183100_create_settings.rb
Normal file
17
db/migrate/20130718183100_create_settings.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class CreateSettings < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :settings do |t|
|
||||
t.string :var, null: false
|
||||
t.text :value, null: true
|
||||
t.integer :thing_id, null: true
|
||||
t.string :thing_type, limit: 30, null: true
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :settings, [ :thing_type, :thing_id, :var ], unique: true
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :settings
|
||||
end
|
||||
end
|
||||
55
db/migrate/20130718183101_migrate_user_settings.rb
Normal file
55
db/migrate/20130718183101_migrate_user_settings.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
class MigrateUserSettings < ActiveRecord::Migration
|
||||
def up
|
||||
say_with_time 'Save old user settings in new RailsSettings module' do
|
||||
|
||||
# Allow setting default locale via env parameter
|
||||
# This is used, when setting users language settings
|
||||
default_locale = I18n.default_locale
|
||||
tmp_locale = ENV['DEFAULT_LOCALE'].present? ? ENV['DEFAULT_LOCALE'].to_sym : default_locale
|
||||
I18n.default_locale = tmp_locale
|
||||
|
||||
old_settings = ConfigurableSetting.all
|
||||
|
||||
old_settings.each do |old_setting|
|
||||
# get target (user)
|
||||
type = old_setting.configurable_type
|
||||
id = old_setting.configurable_id
|
||||
begin
|
||||
user = type.constantize.find(id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
Rails.logger.debug "Can't find configurable object with type: #{type.inspect}, id: #{id.inspect}"
|
||||
next
|
||||
end
|
||||
|
||||
# get the data (settings)
|
||||
name = old_setting.name
|
||||
namespace = name.split('.')[0]
|
||||
key = name.split('.')[1].underscore # Camelcase to underscore
|
||||
|
||||
# prepare value
|
||||
value = YAML.load(old_setting.value)
|
||||
value = value.nil? ? false : value
|
||||
|
||||
# set the settings_attributes (thanks to settings.merge! we can set them one by one)
|
||||
user.settings_attributes = {
|
||||
"#{namespace}" => {
|
||||
"#{key}" => value
|
||||
}
|
||||
}
|
||||
|
||||
# save the user to apply after_save callback
|
||||
user.save
|
||||
end
|
||||
|
||||
I18n.default_locale = default_locale
|
||||
end
|
||||
|
||||
drop_table :configurable_settings
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
||||
|
||||
# this is the base class of all configurable settings
|
||||
class ConfigurableSetting < ActiveRecord::Base; end
|
||||
Loading…
Add table
Add a link
Reference in a new issue