notion_ruby_mapping 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -6
- data/exe/notionErDiagram.rb +30 -24
- data/lib/notion_ruby_mapping/blocks/base.rb +32 -4
- data/lib/notion_ruby_mapping/blocks/block.rb +0 -1
- data/lib/notion_ruby_mapping/blocks/column_block.rb +7 -2
- data/lib/notion_ruby_mapping/blocks/data_source.rb +167 -0
- data/lib/notion_ruby_mapping/blocks/database.rb +41 -21
- data/lib/notion_ruby_mapping/blocks/file_base_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/list.rb +5 -5
- data/lib/notion_ruby_mapping/controllers/mermaid.rb +13 -13
- data/lib/notion_ruby_mapping/controllers/{mermaid_database.rb → mermaid_data_source.rb} +39 -39
- data/lib/notion_ruby_mapping/controllers/notion_cache.rb +53 -10
- data/lib/notion_ruby_mapping/controllers/property_cache.rb +26 -4
- data/lib/notion_ruby_mapping/objects/file_upload_object.rb +11 -3
- data/lib/notion_ruby_mapping/properties/checkbox_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/created_by_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/created_time_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/date_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/files_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/formula_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/multi_select_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/number_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/people_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/phone_number_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/property.rb +23 -5
- data/lib/notion_ruby_mapping/properties/relation_property.rb +26 -14
- data/lib/notion_ruby_mapping/properties/rich_text_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/rollup_property.rb +7 -7
- data/lib/notion_ruby_mapping/properties/select_property.rb +5 -5
- data/lib/notion_ruby_mapping/properties/text_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/title_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/unique_id_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/url_property.rb +1 -1
- data/lib/notion_ruby_mapping/version.rb +2 -2
- data/lib/notion_ruby_mapping.rb +3 -3
- data/tools/an +4 -4
- metadata +5 -14
- data/exe/erdToNotionDb.rb +0 -56
- data/exe/notionSitemap.rb +0 -131
- data/exe/notionTimeRecorder.rb +0 -284
- data/lib/notion_ruby_mapping/blocks/template_block.rb +0 -34
data/exe/notionTimeRecorder.rb
DELETED
@@ -1,284 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
|
3
|
-
require "tk"
|
4
|
-
require "notion_ruby_mapping"
|
5
|
-
require "yaml"
|
6
|
-
require "time"
|
7
|
-
include Tk
|
8
|
-
include NotionRubyMapping
|
9
|
-
|
10
|
-
CONF_FILE_NAME = "#{ENV["HOME"]}/.notionTimeRecorder.yml"
|
11
|
-
|
12
|
-
class TaskConf
|
13
|
-
KEY_TO_METHOD = {
|
14
|
-
api_key: "NOTION_API_KEY",
|
15
|
-
db_id: "TASK_DB_ID",
|
16
|
-
tpn: "TITLE_PROPERTY_NAME",
|
17
|
-
dpn: "DATE_PROPERTY_NAME",
|
18
|
-
fpn: "FINISH_PROPERTY_NAME",
|
19
|
-
fpt: "FINISH_PROPERTY_TYPE",
|
20
|
-
ipv: "IN_PROGRESS_PROPERTY_VALUE",
|
21
|
-
fpv: "FINISH_PROPERTY_VALUE",
|
22
|
-
bln: "BLOCKING_PROPERTY_NAME",
|
23
|
-
bbn: "BLOCKED_BY_PROPERTY_NAME",
|
24
|
-
ppd: "PERCENT_PREVIOUS_DONE_FUNC_NAME",
|
25
|
-
}
|
26
|
-
|
27
|
-
# @param [Boolean] force_setup
|
28
|
-
def initialize(yaml_name, force_setup = false)
|
29
|
-
@yaml_name = yaml_name
|
30
|
-
@config = {}
|
31
|
-
setup(force_setup) if force_setup || !File.exist?(@yaml_name)
|
32
|
-
load_conf
|
33
|
-
end
|
34
|
-
|
35
|
-
# @param [Boolean] force_setup
|
36
|
-
def setup(force_setup)
|
37
|
-
load_conf if force_setup
|
38
|
-
@variables = {}
|
39
|
-
@conf_frame = TkLabelFrame.new(nil, text: "Configuration").pack(padx: 10, pady: 10)
|
40
|
-
KEY_TO_METHOD.each do |method, key|
|
41
|
-
@variables[method] = TkVariable.new @config[key]&.to_s
|
42
|
-
label_frame = TkLabelFrame.new(@conf_frame, text: key).pack(padx: 10, pady: 5)
|
43
|
-
if method == :fpt
|
44
|
-
TkRadioButton.new(label_frame, text: "status", variable: @variables[method], value: "status").pack
|
45
|
-
TkRadioButton.new(label_frame, text: "checkbox", variable: @variables[method], value: "checkbox").pack
|
46
|
-
else
|
47
|
-
TkEntry.new(label_frame, textvariable: @variables[method]).pack
|
48
|
-
end
|
49
|
-
end
|
50
|
-
cmd_frame = TkFrame.new(@conf_frame).pack
|
51
|
-
TkButton.new(cmd_frame, text: "Quit", command: ->{ exit }).pack(side: :left)
|
52
|
-
TkButton.new(cmd_frame, text: "Save", command: ->{ save }).pack(side: :right)
|
53
|
-
Tk.mainloop
|
54
|
-
end
|
55
|
-
|
56
|
-
def load_conf
|
57
|
-
@config = YAML.load_file @yaml_name
|
58
|
-
KEY_TO_METHOD.each do |method, key|
|
59
|
-
self.class.define_method(method) { @config[key] }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def save
|
64
|
-
KEY_TO_METHOD.each do |method, key|
|
65
|
-
@config[key] = @variables[method].value.chomp
|
66
|
-
end
|
67
|
-
@config["FINISH_PROPERTY_VALUE"] = true if @config["FINISH_PROPERTY_VALUE"] == "true"
|
68
|
-
File.open(@yaml_name, "w") do |f|
|
69
|
-
YAML.dump @config, f
|
70
|
-
end
|
71
|
-
load_conf
|
72
|
-
@conf_frame.destroy
|
73
|
-
@task_cache = TaskCache.new self
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class Task
|
78
|
-
# @param [NotionRubyMapping::Page] page
|
79
|
-
# @param [TaskCache] tc
|
80
|
-
def initialize(page, tc)
|
81
|
-
@page = page
|
82
|
-
@tc = tc
|
83
|
-
@conf = tc.conf
|
84
|
-
@date_property = @page.properties[@conf.dpn]
|
85
|
-
@finish_property = @page.properties[@conf.fpn]
|
86
|
-
@finish = (@conf.fpt == "status" ? @finish_property.status_name : @finish_property.checkbox) == @conf.fpv
|
87
|
-
@start_date = @date_property.start_date_obj
|
88
|
-
@end_date = @date_property.end_date_obj
|
89
|
-
end
|
90
|
-
|
91
|
-
def save
|
92
|
-
@page.save
|
93
|
-
@start_date = @date_property.start_date_obj
|
94
|
-
@end_date = @date_property.end_date_obj
|
95
|
-
@finish = (@conf.fpt == "status" ? @finish_property.status_name : @finish_property.checkbox) == @conf.fpv
|
96
|
-
end
|
97
|
-
|
98
|
-
def start_time_str
|
99
|
-
@start_date.nil? || @start_date.is_a?(Date) ? "-" : @start_date.strftime("%H:%M")
|
100
|
-
end
|
101
|
-
|
102
|
-
def end_time_str
|
103
|
-
@end_date.nil? || @end_date.is_a?(Date) ? "-" : @end_date.strftime("%H:%M")
|
104
|
-
end
|
105
|
-
|
106
|
-
def state
|
107
|
-
@finish ? "disabled" : "normal"
|
108
|
-
end
|
109
|
-
|
110
|
-
def time_recording(force_set_date = false)
|
111
|
-
if @start_date.nil? || force_set_date
|
112
|
-
@date_property.start_date = Date.today
|
113
|
-
@date_property.end_date = nil
|
114
|
-
save
|
115
|
-
@tc.move_to_today self
|
116
|
-
elsif @start_date.is_a?(Date)
|
117
|
-
@date_property.start_date = Time.now
|
118
|
-
@finish_property.send("#{@conf.fpt}=", @conf.ipv) unless @conf.ipv.empty?
|
119
|
-
@date_property.end_date = nil
|
120
|
-
save
|
121
|
-
@tc.update_today_tasks
|
122
|
-
else
|
123
|
-
@date_property.start_date = @date_property.start_date_obj
|
124
|
-
@date_property.end_date = Time.now
|
125
|
-
@finish_property.send("#{@conf.fpt}=", @conf.fpv)
|
126
|
-
save
|
127
|
-
if blocking_count&.positive?
|
128
|
-
@tc.reload_someday
|
129
|
-
@tc.update_today_tasks
|
130
|
-
else
|
131
|
-
@tc.update_today_tasks
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def blocking_count
|
137
|
-
@conf.bln.empty? ? nil : @page.properties[@conf.bln].relation.count
|
138
|
-
end
|
139
|
-
|
140
|
-
def view_task(frame, index, today_task = true)
|
141
|
-
TkButton.new(frame, text: @page.title, state: state, command: -> { time_recording }).grid(row: index, column: 0)
|
142
|
-
if today_task
|
143
|
-
TkLabel.new(frame, text: start_time_str).grid(row: index, column: 1)
|
144
|
-
TkLabel.new(frame, text: end_time_str).grid(row: index, column: 2)
|
145
|
-
elsif (bcnt = blocking_count)
|
146
|
-
TkLabel.new(frame, text: "+#{bcnt}").grid(row: index, column: 1)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
class TaskCache
|
152
|
-
# @param [TaskConf] conf
|
153
|
-
def initialize(conf)
|
154
|
-
@conf = conf
|
155
|
-
NotionRubyMapping.configure do |c|
|
156
|
-
c.notion_token = @conf.api_key
|
157
|
-
end
|
158
|
-
|
159
|
-
@db = Database.find conf.db_id
|
160
|
-
@db_date_property, @db_finish_property = @db.properties.values_at @conf.dpn, @conf.fpn
|
161
|
-
@today_tasks = []
|
162
|
-
@someday_tasks = []
|
163
|
-
@unfinished_tasks = []
|
164
|
-
@new_today_task_val = TkVariable.new
|
165
|
-
create_view
|
166
|
-
end
|
167
|
-
attr_reader :conf
|
168
|
-
|
169
|
-
def create_view
|
170
|
-
@today_outer_frame = TkLabelFrame.new(nil, text: "Today's tasks").pack(padx: 10, pady: 5)
|
171
|
-
@today_inner_frame = nil
|
172
|
-
@someday_outer_frame = TkLabelFrame.new(nil, text: "Someday").pack(padx: 10, pady: 5)
|
173
|
-
@someday_inner_frame = nil
|
174
|
-
@new_frame = TkLabelFrame.new(nil, text: "New task").pack(padx: 10, pady: 5)
|
175
|
-
entry = TkEntry.new(@new_frame, textvariable: @new_today_task_val).pack(side: :left)
|
176
|
-
entry.focus
|
177
|
-
entry.bind("Return", -> { add_someday_task })
|
178
|
-
TkButton.new(@new_frame, text: "Add", command: -> { add_someday_task }).pack(side: :right)
|
179
|
-
|
180
|
-
cmd_frame = TkFrame.new(nil).pack(pady: 5)
|
181
|
-
TkButton.new(cmd_frame, text: "Reload", command: ->{ reload }).pack(side: :left)
|
182
|
-
TkButton.new(cmd_frame, text: "Quit", command: ->{ exit }).pack(side: :right)
|
183
|
-
reload
|
184
|
-
end
|
185
|
-
|
186
|
-
def reload
|
187
|
-
NotionCache.instance.clear_object_hash
|
188
|
-
load_today_tasks
|
189
|
-
load_unfinished_tasks
|
190
|
-
update_today_tasks
|
191
|
-
load_someday_tasks
|
192
|
-
update_someday_tasks
|
193
|
-
end
|
194
|
-
|
195
|
-
def reload_someday
|
196
|
-
NotionCache.instance.clear_object_hash
|
197
|
-
load_someday_tasks
|
198
|
-
update_someday_tasks
|
199
|
-
end
|
200
|
-
|
201
|
-
def load_unfinished_tasks
|
202
|
-
now = Time.now
|
203
|
-
end_of_day = Time.local(now.year, now.month, now.mday, 23, 59, 59) - 86400
|
204
|
-
query = @db_date_property.filter_before(end_of_day)
|
205
|
-
.and(@db_finish_property.filter_does_not_equal(@conf.fpv))
|
206
|
-
@unfinished_tasks = @db.query_database(query).map { |tp| Task.new tp, self }
|
207
|
-
end
|
208
|
-
|
209
|
-
def load_today_tasks
|
210
|
-
query = @db_date_property.filter_equals(Date.today)
|
211
|
-
.ascending(@db_date_property)
|
212
|
-
@today_tasks = @db.query_database(query).map { |tp| Task.new tp, self }
|
213
|
-
end
|
214
|
-
|
215
|
-
def update_today_tasks
|
216
|
-
@today_inner_frame&.destroy
|
217
|
-
@today_inner_frame = TkFrame.new(@today_outer_frame).pack
|
218
|
-
@today_tasks.sort! { |a, b| a.start_time_str <=> b.start_time_str }
|
219
|
-
@today_tasks.each_with_index { |task, i| task.view_task @today_inner_frame, i }
|
220
|
-
uc = @unfinished_tasks.count
|
221
|
-
TkButton.new(@today_inner_frame, text: "Add unfinished #{uc} tasks", command: -> { add_unfinished_tasks })
|
222
|
-
.grid(row: @today_tasks.count, column: 0) if uc.positive?
|
223
|
-
end
|
224
|
-
|
225
|
-
def load_someday_tasks
|
226
|
-
query = @db_date_property.filter_is_empty
|
227
|
-
.and(@db_finish_property.filter_does_not_equal(@conf.fpv))
|
228
|
-
unless @conf.ppd.empty?
|
229
|
-
ppd_p = @db.properties[@conf.ppd]
|
230
|
-
query_is_empty = ppd_p.filter_is_empty another_type: "number"
|
231
|
-
query_equals_1 = ppd_p.filter_equals 1, another_type: "number"
|
232
|
-
query.and(query_is_empty.or(query_equals_1))
|
233
|
-
end
|
234
|
-
@someday_tasks = @db.query_database(query).map { |tp| Task.new tp, self }
|
235
|
-
end
|
236
|
-
|
237
|
-
def update_someday_tasks
|
238
|
-
@someday_inner_frame&.destroy
|
239
|
-
@someday_inner_frame = TkFrame.new(@someday_outer_frame).pack
|
240
|
-
@someday_tasks.each_with_index { |task, i| task.view_task @someday_inner_frame, i, false }
|
241
|
-
end
|
242
|
-
|
243
|
-
def add_someday_task
|
244
|
-
task_name = @new_today_task_val.value
|
245
|
-
if !@conf.bbn.empty? && task_name.include?("|")
|
246
|
-
previous_id = nil
|
247
|
-
task_name.split("|").each do |title|
|
248
|
-
page = @db.create_child_page do |_, pp|
|
249
|
-
pp[@conf.tpn] << title
|
250
|
-
pp[@conf.bbn].relation = previous_id if previous_id
|
251
|
-
end
|
252
|
-
previous_id = page.id
|
253
|
-
end
|
254
|
-
@new_today_task_val.value = ""
|
255
|
-
reload
|
256
|
-
else
|
257
|
-
tp = @db.create_child_page do |_, pp|
|
258
|
-
pp[@conf.tpn] << task_name
|
259
|
-
end
|
260
|
-
@new_today_task_val.value = ""
|
261
|
-
@someday_tasks << Task.new(tp, self)
|
262
|
-
update_someday_tasks
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
def add_unfinished_tasks
|
267
|
-
@unfinished_tasks.each do |task|
|
268
|
-
task.time_recording true
|
269
|
-
end
|
270
|
-
@unfinished_tasks = []
|
271
|
-
update_today_tasks
|
272
|
-
end
|
273
|
-
|
274
|
-
def move_to_today(task)
|
275
|
-
@someday_tasks.delete task
|
276
|
-
@today_tasks << task
|
277
|
-
update_today_tasks
|
278
|
-
update_someday_tasks
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
@task_conf = TaskConf.new CONF_FILE_NAME, ARGV.first == "-c"
|
283
|
-
@task_cache = TaskCache.new @task_conf
|
284
|
-
Tk.mainloop
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module NotionRubyMapping
|
4
|
-
# Notion block
|
5
|
-
class TemplateBlock < Block
|
6
|
-
# @param [RichTextArray, String, Array<String>, RichTextObject, Array<RichTextObject>] text_info
|
7
|
-
# @param [NotionRubyMapping::Block, Array<NotionRubyMapping::Block>, nil] sub_blocks
|
8
|
-
def initialize(text_info = nil, sub_blocks: nil, json: nil, id: nil, parent: nil)
|
9
|
-
super(json: json, id: id, parent: parent)
|
10
|
-
if @json
|
11
|
-
decode_block_rich_text_array
|
12
|
-
else
|
13
|
-
rich_text_array_and_color "rich_text", text_info, nil
|
14
|
-
add_sub_blocks sub_blocks
|
15
|
-
end
|
16
|
-
@can_have_children = true
|
17
|
-
end
|
18
|
-
|
19
|
-
attr_reader :rich_text_array
|
20
|
-
|
21
|
-
# @param [Boolean] not_update false when update
|
22
|
-
# @return [Hash{String (frozen)->Hash}]
|
23
|
-
def block_json(not_update: true)
|
24
|
-
ans = super
|
25
|
-
ans[type] = @rich_text_array.update_property_schema_json not_update
|
26
|
-
ans[type]["children"] = @sub_blocks.map(&:block_json) if @sub_blocks
|
27
|
-
ans
|
28
|
-
end
|
29
|
-
|
30
|
-
def type
|
31
|
-
"template"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|