conversion seems to be ok

This commit is contained in:
Philippe PITTOLI 2019-12-13 05:47:45 +01:00
parent 5e2295ae9a
commit a8dbeb006b
4 changed files with 111 additions and 106 deletions

View File

@ -38,6 +38,47 @@ class TodoD::List
}
@tasks = [] of String
end
def users_with_read_permissions : Array(Int32)
@permissions.map do |level, uids|
# Would raise on invalid level.
level = PermissionLevel.parse level
uids
end.flatten
end
def is_admin?(uid)
@permissions["admin"].any? &.==(uid)
end
def is_editor?(uid)
@permissions.any? do |level, uids|
level = PermissionLevel.parse level
uids.any? do |id|
id == uid && level >= PermissionLevel::Edit
end
end
end
def is_reader?(uid)
@permissions.any? do |level, uids|
level = PermissionLevel.parse level
uids.any? do |id|
id == uid && level >= PermissionLevel::Read
end
end
end
def set_permission(uid : Int32, level : PermissionLevel)
@permissions.each &.[1].select!(&.!=(uid))
return if level.none?
@permissions[level.to_s].push uid
end
end
class TodoD::Task

View File

@ -2,21 +2,24 @@ require "option_parser"
require "uuid"
require "uuid/json"
require "fs"
require "dodb"
class TodoD::Storage
getter root : String
getter lists : FS::Hash(String, List)
getter tasks : FS::Hash(String, Task)
getter lists : DODB::DataBase(String, List)
getter tasks : DODB::DataBase(String, Task)
getter lists_per_user : DODB::Tags(List)
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
@lists = DODB::DataBase(String, List).new("#{@root}/lists")
@lists_per_user = @lists.new_tags "user", &.users_with_read_permissions.map(&.to_s)
@tasks = FS::Hash(String, Task).new("#{@root}/tasks").tap do |tasks|
end
@tasks = DODB::DataBase(String, Task).new("#{@root}/tasks")
end
def new_list(list)

View File

@ -2,131 +2,92 @@
require "json"
require "./src/project.cr"
# require "./altsrc/common.cr"
# require "./altsrc/main.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),
# })
# 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
# 2. for each project
# pp! old_storage
old_storage.each do |old_project|
puts ""
puts ""
puts ""
puts "projet #{old_project.name}"
# 3.1. get list properties
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
# 3.2. get tasks, create new tasks and store them
tasks = Array(TodoD::Task).new
old_project.tasks.each do |t|
pp! t
# pp! t
# 1. get informations about the task
# 2. create a task in the new format
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)
task_extra_properties["column"] = JSON.parse(t.column.to_json)
task_extra_properties["backgroundColor"] = JSON.parse(t.color.to_json)
task_extra_properties["assigneeId"] = JSON.parse(t.assigned_to.to_json)
newtask = ::TodoD::Task.new old_project.id, old_project.name, t.author,
newtask = ::TodoD::Task.new old_project.id, t.title, 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
# pp! newtask
# 3. store the new task
# list.tasks << task.id
# service.storage.tasks[task.id] = task
tasks << newtask
new_storage.tasks[newtask.id] = newtask
end
# finally, create the list with all the parameters
# list = List.new old_project.name, user, extra_properties
# list.tasks = tasks.map &.id
u = User.new
list = TodoD::List.new old_project.name, u, extra_properties
list.tasks = tasks.map &.id
# puts ""
pp! list
####### 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
# finally, store the new list
new_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]

View File

@ -12,8 +12,8 @@ dependencies:
github: kemalcr/kemal
authd:
github: Lukc/authd
fs:
git: https://git.karchnu.fr/WeirdOS/fs.cr
dodb:
git: https://git.karchnu.fr/WeirdOS/dodb.cr
# pg:
# github: will/crystal-pg