You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.3 KiB

4 years ago
require "json"
require "./src/project.cr"
require "option_parser"
require "./altsrc/common.cr"
require "./altsrc/main.cr"
4 years ago
new_storage_dir = "./new-storage"
old_storage_dir = "./old-storage"
user_id = 1001
OptionParser.parse do |parser|
parser.on "-n new-storage-directory",
"--new-directory storage-directory",
"The new directory where to put converted files." do |opt|
new_storage_dir = opt
end
parser.on "-u user-id",
"--user-id user-id",
"User id of the author of all lists." do |opt|
user_id = opt.to_i
end
parser.on "-o old-storage-directory",
"--old-storage-directory directory",
"Old storage directory, to convert." do |opt|
old_storage_dir = opt
end
parser.on "-h", "--help", "Show this help" do
puts parser
puts "Default values are:"
pp! new_storage_dir
pp! old_storage_dir
pp! user_id
exit 0
end
end
4 years ago
# 1. get the old list of projects
old_storage = Project.all old_storage_dir
4 years ago
# PROJECT: JSON.mapping({
# PROJECT: id: String,
# PROJECT: name: String,
# PROJECT: columns: Array(Column),
# PROJECT: tasks: Array(Task),
# PROJECT: })
# TASKS: JSON.mapping({
# TASKS: id: String,
# TASKS: author: Int32,
# TASKS: title: String,
# TASKS: description: String,
# TASKS: column: String,
# TASKS: assigned_to: Int32?,
# TASKS: color: {
# TASKS: type: String,
# TASKS: default: "dark"
# TASKS: }
# TASKS: })
# 2. create the new storage
new_storage = TodoD::Storage.new new_storage_dir
# 3. for each project (old name for "list")
# 3.1. get list properties
# 3.2. get tasks, create new tasks and store them
# 3.3. create and store the new list
class User
property uid : Int32 = 1001
end
4 years ago
4 years ago
old_storage.each do |old_project|
puts ""
puts ""
puts ""
4 years ago
puts "projet #{old_project.name}"
# 3.1. get list properties
4 years ago
extra_properties = Hash(String, JSON::Any).new
# columns = JSON.parse(old_project.columns.to_json)
columns = Array(Hash(String, String)).new
old_project.columns.each do |col|
column = { "id" => col.id, "title" => col.name }
columns << column
puts "column :"
pp! column
end
extra_properties["columns"] = JSON.parse(columns.to_json)
4 years ago
# 3.2. get tasks, create new tasks and store them
4 years ago
tasks = Array(TodoD::Task).new
old_project.tasks.each do |t|
# pp! t
# 1. get informations about the task
# 2. create a task in the new format
4 years ago
task_extra_properties = Hash(String, JSON::Any).new
task_extra_properties["column"] = JSON.parse(t.column.to_json)
# change the default color of the task, to match the new default list background color
if t.color == "dark"
task_extra_properties["backgroundColor"] = JSON.parse("white".to_json)
else
task_extra_properties["backgroundColor"] = JSON.parse(t.color.to_json)
end
task_extra_properties["assigneeId"] = JSON.parse(t.assigned_to.to_json)
4 years ago
newtask = ::TodoD::Task.new old_project.id, t.title, t.author,
4 years ago
description: (t.description || ""),
assigned_to: t.assigned_to,
extra_properties: task_extra_properties
# pp! newtask
4 years ago
# 3. store the new task
tasks << newtask
new_storage.tasks << newtask
4 years ago
end
# finally, create the list with all the parameters
u = User.new
u.uid = user_id
list = TodoD::List.new old_project.name, u, extra_properties
list.id = old_project.id
list.tasks = tasks.map &.id
4 years ago
# puts ""
pp! list
4 years ago
# finally, store the new list
new_storage.lists << list
4 years ago
end