conversion 0.1
This commit is contained in:
parent
10891d193d
commit
5e2295ae9a
70
altsrc/common.cr
Normal file
70
altsrc/common.cr
Normal file
@ -0,0 +1,70 @@
|
||||
require "uuid"
|
||||
require "uuid/json"
|
||||
|
||||
class TodoD
|
||||
end
|
||||
|
||||
class TodoD::List
|
||||
enum PermissionLevel
|
||||
None = -1
|
||||
Read
|
||||
Post
|
||||
Edit
|
||||
Admin
|
||||
|
||||
def to_json(o)
|
||||
to_s.downcase.to_json(o)
|
||||
end
|
||||
end
|
||||
|
||||
JSON.mapping({
|
||||
id: String,
|
||||
title: String,
|
||||
permissions: Hash(String, Array(Int32)),
|
||||
extra_properties: Hash(String, JSON::Any),
|
||||
tasks: {
|
||||
type: Array(String),
|
||||
default: [] of String
|
||||
}
|
||||
})
|
||||
|
||||
def initialize(@title, user, @extra_properties = Hash(String, JSON::Any).new)
|
||||
@id = UUID.random.to_s
|
||||
@permissions = {
|
||||
"admin" => [user.uid],
|
||||
"edit" => [] of Int32,
|
||||
"post" => [] of Int32,
|
||||
"read" => [] of Int32
|
||||
}
|
||||
@tasks = [] of String
|
||||
end
|
||||
end
|
||||
|
||||
class TodoD::Task
|
||||
# Should we hardcode more properties here?
|
||||
JSON.mapping({
|
||||
id: String,
|
||||
list: String,
|
||||
title: String,
|
||||
description: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
creator: Int32,
|
||||
assigned_to: Int32?,
|
||||
priority: String?,
|
||||
tags: {
|
||||
type: Array(String),
|
||||
default: [] of String
|
||||
},
|
||||
extra_properties: {
|
||||
type: Hash(String, JSON::Any),
|
||||
default: {} of String => JSON::Any
|
||||
}
|
||||
})
|
||||
|
||||
def initialize(@list, @title, @creator, @description = "", @assigned_to = nil, @priority = nil, @tags = [] of String, @extra_properties = {} of String => JSON::Any)
|
||||
@id = UUID.random.to_s
|
||||
end
|
||||
end
|
||||
|
25
altsrc/main.cr
Normal file
25
altsrc/main.cr
Normal file
@ -0,0 +1,25 @@
|
||||
require "option_parser"
|
||||
require "uuid"
|
||||
require "uuid/json"
|
||||
|
||||
require "fs"
|
||||
|
||||
class TodoD::Storage
|
||||
getter root : String
|
||||
|
||||
getter lists : FS::Hash(String, List)
|
||||
getter tasks : FS::Hash(String, Task)
|
||||
|
||||
def initialize(@root)
|
||||
@lists = FS::Hash(String, List).new("#{@root}/lists").tap do |lists|
|
||||
lists.new_nn_partition "user", &.users_with_read_permissions.map(&.to_s)
|
||||
end
|
||||
|
||||
@tasks = FS::Hash(String, Task).new("#{@root}/tasks").tap do |tasks|
|
||||
end
|
||||
end
|
||||
|
||||
def new_list(list)
|
||||
@lists[list.id] = list
|
||||
end
|
||||
end
|
0
altsrc/todod.cr
Normal file
0
altsrc/todod.cr
Normal file
132
conversion.cr
Normal file
132
conversion.cr
Normal file
@ -0,0 +1,132 @@
|
||||
|
||||
require "json"
|
||||
require "./src/project.cr"
|
||||
|
||||
# require "./altsrc/common.cr"
|
||||
# require "./altsrc/main.cr"
|
||||
|
||||
|
||||
# 1. get the old list of projects
|
||||
old_storage = Project.all "../storage/"
|
||||
|
||||
# JSON.mapping({
|
||||
# id: String,
|
||||
# name: String,
|
||||
# columns: Array(Column),
|
||||
# tasks: Array(Task),
|
||||
# })
|
||||
|
||||
# 2. for each project
|
||||
# pp! old_storage
|
||||
old_storage.each do |old_project|
|
||||
puts "projet #{old_project.name}"
|
||||
|
||||
extra_properties = Hash(String, JSON::Any).new
|
||||
extra_properties["columns"] = JSON.parse(old_project.columns.to_json)
|
||||
pp! extra_properties["columns"]
|
||||
|
||||
# 1. create a new list an copy all properties
|
||||
|
||||
tasks = Array(TodoD::Task).new
|
||||
|
||||
old_project.tasks.each do |t|
|
||||
pp! t
|
||||
|
||||
task_extra_properties = Hash(String, JSON::Any).new
|
||||
task_extra_properties["column"] = JSON.parse(t.column.to_json)
|
||||
task_extra_properties["backgroundColor"] = JSON.parse(t.column.to_json)
|
||||
task_extra_properties["assigneeId"] = JSON.parse(t.column.to_json)
|
||||
|
||||
newtask = ::TodoD::Task.new old_project.id, old_project.name, t.author,
|
||||
description: (t.description || ""),
|
||||
assigned_to: t.assigned_to,
|
||||
extra_properties: task_extra_properties
|
||||
|
||||
|
||||
# TASK
|
||||
|
||||
# @color="dark",
|
||||
# @description="",
|
||||
# @id="9808dcf2-1064-4b55-a39a-e402b477d60e",
|
||||
# @title="fsdb automatic tests">
|
||||
|
||||
|
||||
# 1. get the task in the old storage
|
||||
# TODO
|
||||
# 2. create a task in the new format
|
||||
|
||||
# task = ::TodoD::Task.new @list.to_s, @title, user.uid,
|
||||
# description: (@description || ""),
|
||||
# assigned_to: @assigned_to,
|
||||
# extra_properties: @extra_properties || {} of String => JSON::Any
|
||||
|
||||
# 3. store the new task
|
||||
# list.tasks << task.id
|
||||
# service.storage.tasks[task.id] = task
|
||||
end
|
||||
|
||||
# finally, create the list with all the parameters
|
||||
|
||||
# list = List.new old_project.name, user, extra_properties
|
||||
# list.tasks = tasks.map &.id
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
####### service.storage.lists.delete list.id
|
||||
|
||||
# Store the new list
|
||||
# service.storage.lists[list.id] = list
|
||||
|
||||
# EDIT TASK
|
||||
# task = service.storage.tasks[@task.to_s]?
|
||||
# list = service.storage.lists[task.list.to_s]?
|
||||
|
||||
# @title.try { |x| task.title = x }
|
||||
# @description.try { |x| task.description = x }
|
||||
# @tags.try { |x| task.tags = x }
|
||||
# @assigned_to.try { |x| task.assigned_to = x }
|
||||
# @extra_properties.try { |x| task.extra_properties = x }
|
||||
|
||||
# service.storage.tasks.delete task.id
|
||||
# service.storage.tasks[task.id] = task
|
||||
# EDIT LIST
|
||||
|
||||
# list = service.storage.lists[@list.to_s]
|
||||
|
||||
# # Updating our list copy.
|
||||
# @title.try do |title|
|
||||
# list.title = title
|
||||
# end
|
||||
|
||||
# @permissions.try do |permissions|
|
||||
# permissions.each do |key, value|
|
||||
# list.permissions[key] = value
|
||||
# end
|
||||
# end
|
||||
|
||||
# @extra_properties.try do |properties|
|
||||
# properties.each do |key, value|
|
||||
# list.extra_properties[key] = value
|
||||
# end
|
||||
# end
|
||||
|
||||
# # Removal and re-adding is the current way of handling updates.
|
||||
# service.storage.lists.delete list.id
|
||||
# service.storage.lists[list.id] = list
|
||||
|
||||
end
|
||||
|
||||
# new_storage = TodoD::Storage.new "../new-storage/"
|
||||
|
||||
# service.storage.lists.delete list.id
|
||||
# service.storage.lists.get_nn_partition(
|
||||
# service.storage.lists[list.id] = list
|
||||
# service.storage.lists[@list.to_s]
|
||||
# service.storage.lists[@list.to_s]?
|
||||
# service.storage.lists[task.list.to_s]?
|
||||
# service.storage.tasks.delete task.id
|
||||
# service.storage.tasks[task.id] = task
|
||||
# service.storage.tasks[@task.to_s]?
|
||||
# service.storage.tasks[uuid]
|
@ -51,4 +51,3 @@ class Project
|
||||
[] of Project
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user