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
|
||||
51
db/schema.rb
51
db/schema.rb
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130715233410) do
|
||||
ActiveRecord::Schema.define(:version => 20130718183101) do
|
||||
|
||||
create_table "article_categories", :force => true do |t|
|
||||
t.string "name", :default => "", :null => false
|
||||
|
|
@ -66,18 +66,6 @@ ActiveRecord::Schema.define(:version => 20130715233410) do
|
|||
|
||||
add_index "assignments", ["user_id", "task_id"], :name => "index_assignments_on_user_id_and_task_id", :unique => true
|
||||
|
||||
create_table "configurable_settings", :force => true do |t|
|
||||
t.integer "configurable_id"
|
||||
t.string "configurable_type"
|
||||
t.integer "targetable_id"
|
||||
t.string "targetable_type"
|
||||
t.string "name", :default => "", :null => false
|
||||
t.string "value_type"
|
||||
t.text "value"
|
||||
end
|
||||
|
||||
add_index "configurable_settings", ["name"], :name => "index_configurable_settings_on_name"
|
||||
|
||||
create_table "deliveries", :force => true do |t|
|
||||
t.integer "supplier_id"
|
||||
t.date "delivered_on"
|
||||
|
|
@ -143,17 +131,11 @@ ActiveRecord::Schema.define(:version => 20130715233410) do
|
|||
t.boolean "role_article_meta", :default => false, :null => false
|
||||
t.boolean "role_finance", :default => false, :null => false
|
||||
t.boolean "role_orders", :default => false, :null => false
|
||||
t.boolean "weekly_task", :default => false
|
||||
t.integer "weekday"
|
||||
t.string "task_name"
|
||||
t.string "task_description"
|
||||
t.integer "task_required_users", :default => 1
|
||||
t.datetime "deleted_at"
|
||||
t.string "contact_person"
|
||||
t.string "contact_phone"
|
||||
t.string "contact_address"
|
||||
t.text "stats"
|
||||
t.integer "task_duration", :default => 1
|
||||
t.integer "next_weekly_tasks_number", :default => 8
|
||||
t.boolean "ignore_apple_restriction", :default => false
|
||||
end
|
||||
|
|
@ -268,6 +250,23 @@ ActiveRecord::Schema.define(:version => 20130715233410) do
|
|||
add_index "pages", ["permalink"], :name => "index_pages_on_permalink"
|
||||
add_index "pages", ["title"], :name => "index_pages_on_title"
|
||||
|
||||
create_table "periodic_task_groups", :force => true do |t|
|
||||
t.date "next_task_date"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "settings", :force => true do |t|
|
||||
t.string "var", :null => false
|
||||
t.text "value"
|
||||
t.integer "thing_id"
|
||||
t.string "thing_type", :limit => 30
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "settings", ["thing_type", "thing_id", "var"], :name => "index_settings_on_thing_type_and_thing_id_and_var", :unique => true
|
||||
|
||||
create_table "stock_changes", :force => true do |t|
|
||||
t.integer "delivery_id"
|
||||
t.integer "order_id"
|
||||
|
|
@ -308,16 +307,16 @@ ActiveRecord::Schema.define(:version => 20130715233410) do
|
|||
add_index "suppliers", ["name"], :name => "index_suppliers_on_name", :unique => true
|
||||
|
||||
create_table "tasks", :force => true do |t|
|
||||
t.string "name", :default => "", :null => false
|
||||
t.string "name", :default => "", :null => false
|
||||
t.string "description"
|
||||
t.date "due_date"
|
||||
t.boolean "done", :default => false
|
||||
t.boolean "done", :default => false
|
||||
t.integer "workgroup_id"
|
||||
t.datetime "created_on", :null => false
|
||||
t.datetime "updated_on", :null => false
|
||||
t.integer "required_users", :default => 1
|
||||
t.boolean "weekly"
|
||||
t.integer "duration", :default => 1
|
||||
t.datetime "created_on", :null => false
|
||||
t.datetime "updated_on", :null => false
|
||||
t.integer "required_users", :default => 1
|
||||
t.integer "duration", :default => 1
|
||||
t.integer "periodic_task_group_id"
|
||||
end
|
||||
|
||||
add_index "tasks", ["due_date"], :name => "index_tasks_on_due_date"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue