todod/conversion.cr

110 lines
2.6 KiB
Crystal
Raw Normal View History

2019-12-12 06:26:17 +01:00
require "json"
require "./src/project.cr"
2019-12-13 05:47:45 +01:00
require "./altsrc/common.cr"
require "./altsrc/main.cr"
2019-12-12 06:26:17 +01:00
# 1. get the old list of projects
old_storage = Project.all "../storage/"
2019-12-13 05:47:45 +01:00
# 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/"
# 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 = 1002
end
2019-12-12 06:26:17 +01:00
old_storage.each do |old_project|
2019-12-13 05:47:45 +01:00
puts ""
puts ""
puts ""
2019-12-12 06:26:17 +01:00
puts "projet #{old_project.name}"
2019-12-13 05:47:45 +01:00
# 3.1. get list properties
2019-12-12 06:26:17 +01:00
extra_properties = Hash(String, JSON::Any).new
2019-12-17 04:44:53 +01:00
# 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)
2019-12-12 06:26:17 +01:00
2019-12-13 05:47:45 +01:00
# 3.2. get tasks, create new tasks and store them
2019-12-12 06:26:17 +01:00
tasks = Array(TodoD::Task).new
old_project.tasks.each do |t|
2019-12-13 05:47:45 +01:00
# pp! t
# 1. get informations about the task
# 2. create a task in the new format
2019-12-12 06:26:17 +01:00
task_extra_properties = Hash(String, JSON::Any).new
2019-12-17 04:44:53 +01:00
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)
2019-12-12 06:26:17 +01:00
2019-12-13 05:47:45 +01:00
newtask = ::TodoD::Task.new old_project.id, t.title, t.author,
2019-12-12 06:26:17 +01:00
description: (t.description || ""),
assigned_to: t.assigned_to,
extra_properties: task_extra_properties
2019-12-13 05:47:45 +01:00
# pp! newtask
2019-12-12 06:26:17 +01:00
# 3. store the new task
2019-12-13 05:47:45 +01:00
tasks << newtask
new_storage.tasks[newtask.id] = newtask
2019-12-12 06:26:17 +01:00
end
# finally, create the list with all the parameters
2019-12-13 05:47:45 +01:00
u = User.new
list = TodoD::List.new old_project.name, u, extra_properties
2019-12-17 04:44:53 +01:00
list.id = old_project.id
2019-12-13 05:47:45 +01:00
list.tasks = tasks.map &.id
2019-12-12 06:26:17 +01:00
2019-12-13 05:47:45 +01:00
# puts ""
pp! list
2019-12-12 06:26:17 +01:00
2019-12-13 05:47:45 +01:00
# finally, store the new list
new_storage.lists[list.id] = list
2019-12-12 06:26:17 +01:00
end