collavre_notion 0.1.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 +7 -0
- data/README.md +58 -0
- data/Rakefile +3 -0
- data/app/controllers/collavre_notion/application_controller.rb +12 -0
- data/app/controllers/collavre_notion/creatives/notion_integrations_controller.rb +196 -0
- data/app/controllers/collavre_notion/notion_auth_controller.rb +48 -0
- data/app/javascript/collavre_notion.js +506 -0
- data/app/jobs/collavre_notion/notion_export_job.rb +29 -0
- data/app/jobs/collavre_notion/notion_sync_job.rb +47 -0
- data/app/models/collavre_notion/notion_account.rb +17 -0
- data/app/models/collavre_notion/notion_block_link.rb +10 -0
- data/app/models/collavre_notion/notion_page_link.rb +19 -0
- data/app/services/collavre_notion/notion_client.rb +231 -0
- data/app/services/collavre_notion/notion_creative_exporter.rb +296 -0
- data/app/services/collavre_notion/notion_service.rb +249 -0
- data/app/views/collavre_notion/integrations/_modal.html.erb +91 -0
- data/config/locales/en.yml +36 -0
- data/config/locales/ko.yml +36 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20241201000000_create_notion_integrations.rb +29 -0
- data/db/migrate/20250312000000_create_notion_block_links.rb +16 -0
- data/db/migrate/20250312010000_allow_multiple_notion_blocks_per_creative.rb +5 -0
- data/lib/collavre_notion/engine.rb +89 -0
- data/lib/collavre_notion/version.rb +3 -0
- data/lib/collavre_notion.rb +5 -0
- metadata +109 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
module CollavreNotion
|
|
2
|
+
require "digest"
|
|
3
|
+
|
|
4
|
+
class NotionService
|
|
5
|
+
def initialize(user:)
|
|
6
|
+
@user = user
|
|
7
|
+
@account = user.notion_account
|
|
8
|
+
raise NotionAuthError, "No Notion account found" unless @account
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def client
|
|
12
|
+
@client ||= NotionClient.new(@account)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def search_pages(query: nil, start_cursor: nil, page_size: 10)
|
|
16
|
+
with_token_refresh { client.search_pages(query: query, start_cursor: start_cursor, page_size: page_size) }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_page(page_id)
|
|
20
|
+
with_token_refresh { client.get_page(page_id) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def create_page(parent_id:, title:, blocks: [])
|
|
24
|
+
with_token_refresh { client.create_page(parent_id: parent_id, title: title, blocks: blocks) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def update_page(page_id, properties: {}, blocks: nil)
|
|
28
|
+
with_token_refresh { client.update_page(page_id, properties: properties, blocks: blocks) }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get_page_blocks(page_id, start_cursor: nil, page_size: 100)
|
|
32
|
+
with_token_refresh { client.get_page_blocks(page_id, start_cursor: start_cursor, page_size: page_size) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def replace_page_blocks(page_id, blocks)
|
|
36
|
+
with_token_refresh { client.replace_page_blocks(page_id, blocks) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def append_blocks(parent_id, blocks)
|
|
40
|
+
with_token_refresh { client.append_blocks(parent_id, blocks) }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def delete_block(block_id)
|
|
44
|
+
with_token_refresh { client.delete_block(block_id) }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def get_workspace
|
|
48
|
+
with_token_refresh { client.get_workspace }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Create or update a page for a creative
|
|
52
|
+
def sync_creative(creative, parent_page_id: nil)
|
|
53
|
+
notion_link = find_or_create_page_link(creative, parent_page_id)
|
|
54
|
+
|
|
55
|
+
if notion_link.page_id.present?
|
|
56
|
+
# Update existing page
|
|
57
|
+
update_creative_page(creative, notion_link)
|
|
58
|
+
else
|
|
59
|
+
# Create new page
|
|
60
|
+
create_creative_page(creative, notion_link, parent_page_id)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
notion_link.mark_synced!
|
|
64
|
+
notion_link
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def with_token_refresh(&block)
|
|
70
|
+
yield
|
|
71
|
+
rescue NotionAuthError => e
|
|
72
|
+
if refresh_token!
|
|
73
|
+
@client = nil # Reset client with new token
|
|
74
|
+
yield
|
|
75
|
+
else
|
|
76
|
+
raise e
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def refresh_token!
|
|
81
|
+
# Notion uses OAuth 2.0 but doesn't issue refresh tokens in the same way as Google
|
|
82
|
+
# For now, we'll just log the error and return false
|
|
83
|
+
# In a production app, you'd implement proper token refresh logic here
|
|
84
|
+
Rails.logger.error("Notion token refresh needed but not implemented")
|
|
85
|
+
false
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def find_or_create_page_link(creative, parent_page_id)
|
|
89
|
+
@account.notion_page_links.find_or_initialize_by(creative: creative) do |link|
|
|
90
|
+
link.parent_page_id = parent_page_id
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def create_creative_page(creative, notion_link, parent_page_id)
|
|
95
|
+
title = ActionController::Base.helpers.strip_tags(creative.description).strip.presence || "Untitled Creative"
|
|
96
|
+
|
|
97
|
+
# Export only the children - the page title serves as the root creative
|
|
98
|
+
children = creative.children.to_a
|
|
99
|
+
Rails.logger.info("NotionService: Exporting creative #{creative.id} as page title with #{children.count} children as blocks")
|
|
100
|
+
|
|
101
|
+
exporter = NotionCreativeExporter.new(creative)
|
|
102
|
+
blocks = []
|
|
103
|
+
|
|
104
|
+
# If no parent specified, search for a suitable workspace page
|
|
105
|
+
parent_page_id ||= find_default_parent_page
|
|
106
|
+
|
|
107
|
+
response = create_page(
|
|
108
|
+
parent_id: parent_page_id,
|
|
109
|
+
title: title,
|
|
110
|
+
blocks: blocks
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
notion_link.update!(
|
|
114
|
+
page_id: response["id"],
|
|
115
|
+
page_title: title,
|
|
116
|
+
page_url: response["url"],
|
|
117
|
+
parent_page_id: parent_page_id
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
sync_child_blocks(notion_link, creative, children, exporter)
|
|
121
|
+
|
|
122
|
+
response
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def update_creative_page(creative, notion_link)
|
|
126
|
+
title = ActionController::Base.helpers.strip_tags(creative.description).strip.presence || "Untitled Creative"
|
|
127
|
+
|
|
128
|
+
# Update with only the children - page title serves as the root creative
|
|
129
|
+
children = creative.children.to_a
|
|
130
|
+
Rails.logger.info("NotionService: Updating creative #{creative.id} as page title with #{children.count} children as blocks")
|
|
131
|
+
|
|
132
|
+
exporter = NotionCreativeExporter.new(creative)
|
|
133
|
+
|
|
134
|
+
properties = {
|
|
135
|
+
title: {
|
|
136
|
+
title: [ { text: { content: title } } ]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
update_page(notion_link.page_id, properties: properties)
|
|
141
|
+
notion_link.update!(page_title: title)
|
|
142
|
+
|
|
143
|
+
sync_child_blocks(notion_link, creative, children, exporter)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def find_default_parent_page
|
|
147
|
+
# Search for pages in the workspace to find a suitable parent
|
|
148
|
+
pages = search_pages(page_size: 1)
|
|
149
|
+
pages.dig("results")&.first&.dig("id") || raise(NotionError, "No accessible pages found in workspace")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def sync_child_blocks(notion_link, creative, children, exporter)
|
|
153
|
+
child_ids = children.map(&:id)
|
|
154
|
+
existing_links = notion_link.notion_block_links.includes(:creative).order(:created_at).to_a
|
|
155
|
+
existing_links_by_creative = existing_links.group_by(&:creative_id)
|
|
156
|
+
|
|
157
|
+
page_blocks = existing_links.any? ? fetch_all_page_blocks(notion_link.page_id) : []
|
|
158
|
+
page_block_ids = page_blocks.map { |block| block["id"] }
|
|
159
|
+
|
|
160
|
+
block_to_creative = {}
|
|
161
|
+
existing_links.each do |link|
|
|
162
|
+
block_to_creative[link.block_id] = link.creative_id if page_block_ids.include?(link.block_id)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
existing_order = page_block_ids.map { |block_id| block_to_creative[block_id] }.compact.uniq
|
|
166
|
+
expected_order = child_ids.select { |id| existing_links_by_creative.key?(id) }
|
|
167
|
+
reorder_detected = existing_order != expected_order
|
|
168
|
+
|
|
169
|
+
removed_ids = existing_links_by_creative.keys - child_ids
|
|
170
|
+
changes_detected = removed_ids.any?
|
|
171
|
+
|
|
172
|
+
child_exports = children.map do |child|
|
|
173
|
+
exported_blocks = exporter.export_tree_blocks([ child ], 1, 0)
|
|
174
|
+
content_hash = Digest::SHA256.hexdigest(exported_blocks.to_json)
|
|
175
|
+
links = existing_links_by_creative[child.id] || []
|
|
176
|
+
missing_blocks = links.any? { |link| !page_block_ids.include?(link.block_id) }
|
|
177
|
+
|
|
178
|
+
if exported_blocks.empty?
|
|
179
|
+
changes_detected ||= links.present?
|
|
180
|
+
else
|
|
181
|
+
changes_detected ||= links.blank?
|
|
182
|
+
changes_detected ||= links.size != exported_blocks.size
|
|
183
|
+
changes_detected ||= links.first.content_hash != content_hash
|
|
184
|
+
changes_detected ||= missing_blocks
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
{
|
|
188
|
+
child: child,
|
|
189
|
+
exported_blocks: exported_blocks,
|
|
190
|
+
content_hash: content_hash
|
|
191
|
+
}
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
unless changes_detected || reorder_detected
|
|
195
|
+
return
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
blocks_to_clear = page_blocks.presence || fetch_all_page_blocks(notion_link.page_id)
|
|
199
|
+
blocks_to_clear.each do |block|
|
|
200
|
+
begin
|
|
201
|
+
delete_block(block["id"])
|
|
202
|
+
rescue NotionError => e
|
|
203
|
+
Rails.logger.warn("NotionService: Failed to delete Notion block #{block['id']} during resync: #{e.message}")
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
NotionBlockLink.transaction do
|
|
208
|
+
notion_link.notion_block_links.delete_all
|
|
209
|
+
|
|
210
|
+
child_exports.each do |data|
|
|
211
|
+
exported_blocks = data[:exported_blocks]
|
|
212
|
+
next if exported_blocks.empty?
|
|
213
|
+
|
|
214
|
+
response = append_blocks(notion_link.page_id, exported_blocks)
|
|
215
|
+
response_results = response.is_a?(Hash) ? response.fetch("results", []) : []
|
|
216
|
+
new_block_ids = response_results.filter_map { |result| result["id"] }
|
|
217
|
+
|
|
218
|
+
if new_block_ids.empty?
|
|
219
|
+
Rails.logger.warn("NotionService: Unable to determine new block ids for creative #{data[:child].id}")
|
|
220
|
+
next
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
new_block_ids.each do |block_id|
|
|
224
|
+
notion_link.notion_block_links.create!(
|
|
225
|
+
creative: data[:child],
|
|
226
|
+
block_id: block_id,
|
|
227
|
+
content_hash: data[:content_hash]
|
|
228
|
+
)
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def fetch_all_page_blocks(page_id)
|
|
235
|
+
blocks = []
|
|
236
|
+
cursor = nil
|
|
237
|
+
|
|
238
|
+
loop do
|
|
239
|
+
response = get_page_blocks(page_id, start_cursor: cursor)
|
|
240
|
+
blocks.concat(response.fetch("results", []))
|
|
241
|
+
break unless response["has_more"]
|
|
242
|
+
|
|
243
|
+
cursor = response["next_cursor"]
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
blocks
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<div id="notion-integration-modal"
|
|
2
|
+
data-success-message="<%= t('collavre_notion.modal.success_message', default: 'Notion integration saved successfully.') %>"
|
|
3
|
+
data-login-required="<%= t('collavre_notion.modal.login_required', default: 'Sign in with your Notion account to start the integration.') %>"
|
|
4
|
+
data-no-creative="<%= t('collavre_notion.modal.missing_creative', default: 'No Creative selected for integration.') %>"
|
|
5
|
+
data-existing-message="<%= t('collavre_notion.modal.existing_message', default: 'You\'re already connected to Notion pages below.') %>"
|
|
6
|
+
data-delete-confirm="<%= t('collavre_notion.modal.delete_confirm', default: 'Do you want to remove the Notion integration?') %>"
|
|
7
|
+
data-delete-success="<%= t('collavre_notion.modal.delete_success', default: 'Notion integration removed successfully.') %>"
|
|
8
|
+
data-delete-error="<%= t('collavre_notion.modal.delete_error', default: 'Failed to remove the Notion integration.') %>"
|
|
9
|
+
data-delete-button-label="<%= t('collavre_notion.modal.delete_button', default: 'Remove integration') %>"
|
|
10
|
+
data-export-success="<%= t('collavre_notion.modal.export_success', default: 'Creative exported to Notion successfully.') %>"
|
|
11
|
+
data-sync-success="<%= t('collavre_notion.modal.sync_success', default: 'Creative synced to Notion successfully.') %>"
|
|
12
|
+
style="display:none;position:fixed;top:0;left:0;width:100vw;height:100vh;z-index:1000;align-items:center;justify-content:center;">
|
|
13
|
+
<div class="popup-box" style="min-width:360px;max-width:90vw;">
|
|
14
|
+
<button type="button" id="close-notion-modal" class="popup-close-btn">×</button>
|
|
15
|
+
<h2><%= t('collavre_notion.modal.title', default: 'Configure Notion integration') %></h2>
|
|
16
|
+
<p id="notion-integration-status" class="notion-modal-status"></p>
|
|
17
|
+
|
|
18
|
+
<div class="notion-wizard-step" id="notion-step-connect">
|
|
19
|
+
<p id="notion-connect-message" class="notion-modal-subtext"><%= t('collavre_notion.modal.connect', default: 'Sign in with your Notion account to start exporting.') %></p>
|
|
20
|
+
<form id="notion-login-form" action="/auth/notion" method="get" target="notion-auth-window" style="display:none;">
|
|
21
|
+
<input type="hidden" name="popup" value="true">
|
|
22
|
+
</form>
|
|
23
|
+
<button type="button" id="notion-login-btn" class="btn btn-primary" data-window-width="620" data-window-height="720">
|
|
24
|
+
<%= t('collavre_notion.modal.login_button', default: 'Sign in with Notion') %>
|
|
25
|
+
</button>
|
|
26
|
+
<div id="notion-existing-connections" style="display:none;margin-top:1.25em;">
|
|
27
|
+
<p style="margin-bottom:0.5em;"><%= t('collavre_notion.modal.existing_intro', default: 'Linked Notion pages:') %></p>
|
|
28
|
+
<ul id="notion-existing-page-list" style="padding-left:1.2em;margin-bottom:0.75em;color:var(--color-text);"></ul>
|
|
29
|
+
<div style="display:flex;gap:0.5em;">
|
|
30
|
+
<button type="button" id="notion-sync-btn" class="btn btn-secondary" style="display:none;">
|
|
31
|
+
<%= t('collavre_notion.modal.sync_button', default: 'Sync to Notion') %>
|
|
32
|
+
</button>
|
|
33
|
+
<button type="button" id="notion-delete-btn" class="btn btn-danger" style="display:none;">
|
|
34
|
+
<%= t('collavre_notion.modal.delete_button', default: 'Remove link') %>
|
|
35
|
+
</button>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<div class="notion-wizard-step" id="notion-step-workspace" style="display:none;">
|
|
41
|
+
<p class="notion-modal-subtext"><%= t('collavre_notion.modal.workspace', default: 'Your Notion workspace is connected. Choose how to export your creative.') %></p>
|
|
42
|
+
<div id="notion-workspace-info" style="margin-bottom:1em;padding:1em;background:var(--color-bg-alt);border-radius:4px;">
|
|
43
|
+
<strong id="notion-workspace-name"></strong>
|
|
44
|
+
</div>
|
|
45
|
+
<div style="margin-bottom:1em;">
|
|
46
|
+
<label style="display:block;margin-bottom:0.5em;">
|
|
47
|
+
<%= t('collavre_notion.modal.export_option', default: 'Export option:') %>
|
|
48
|
+
</label>
|
|
49
|
+
<div style="display:flex;flex-direction:column;gap:0.5em;">
|
|
50
|
+
<label style="display:flex;align-items:center;gap:0.5em;">
|
|
51
|
+
<input type="radio" name="notion-export-type" value="new-page" checked>
|
|
52
|
+
<%= t('collavre_notion.modal.export_new_page', default: 'Create new page') %>
|
|
53
|
+
</label>
|
|
54
|
+
<label style="display:flex;align-items:center;gap:0.5em;">
|
|
55
|
+
<input type="radio" name="notion-export-type" value="select-parent">
|
|
56
|
+
<%= t('collavre_notion.modal.export_under_page', default: 'Create as subpage under existing page') %>
|
|
57
|
+
</label>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
<div id="notion-parent-page-section" style="display:none;margin-bottom:1em;">
|
|
61
|
+
<label for="notion-parent-page-select" style="display:block;margin-bottom:0.5em;">
|
|
62
|
+
<%= t('collavre_notion.modal.parent_page', default: 'Parent page:') %>
|
|
63
|
+
</label>
|
|
64
|
+
<select id="notion-parent-page-select" style="width:100%;padding:0.5em;border:1px solid var(--color-border);border-radius:4px;">
|
|
65
|
+
<option value=""><%= t('collavre_notion.modal.loading_pages', default: 'Loading pages...') %></option>
|
|
66
|
+
</select>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<div class="notion-wizard-step" id="notion-step-summary" style="display:none;">
|
|
71
|
+
<p class="notion-modal-subtext"><%= t('collavre_notion.modal.summary', default: 'Ready to export your creative tree to Notion:') %></p>
|
|
72
|
+
<div id="notion-export-summary" style="margin:1em 0;padding:1em;background:var(--color-bg-alt);border-radius:4px;">
|
|
73
|
+
<div><strong><%= t('collavre_notion.modal.creative_title', default: 'Root Creative:') %></strong> <span id="notion-creative-title"></span></div>
|
|
74
|
+
<div><strong><%= t('collavre_notion.modal.workspace_label', default: 'Workspace:') %></strong> <span id="notion-workspace-summary"></span></div>
|
|
75
|
+
<div><strong><%= t('collavre_notion.modal.export_as', default: 'Export as:') %></strong> <span id="notion-export-type-summary"></span></div>
|
|
76
|
+
<div id="notion-parent-summary" style="display:none;"><strong><%= t('collavre_notion.modal.parent_page', default: 'Parent page:') %></strong> <span id="notion-parent-page-summary"></span></div>
|
|
77
|
+
<div style="margin-top:0.5em;color:var(--color-text-secondary);font-size:0.9em;"><%= t('collavre_notion.modal.tree_note', default: 'This will export the selected creative and all its descendants as a structured document.') %></div>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<div id="notion-wizard-error" style="display:none;margin:0.5em 0;color:#c0392b;font-weight:bold;"></div>
|
|
82
|
+
|
|
83
|
+
<div class="notion-wizard-footer" style="display:flex;justify-content:space-between;gap:0.5em;margin-top:1.5em;">
|
|
84
|
+
<button type="button" id="notion-prev-btn" class="btn btn-secondary" style="display:none;"><%= t('app.previous', default: 'Previous') %></button>
|
|
85
|
+
<div style="margin-left:auto;display:flex;gap:0.5em;">
|
|
86
|
+
<button type="button" id="notion-next-btn" class="btn btn-primary" style="display:none;"><%= t('app.next', default: 'Next') %></button>
|
|
87
|
+
<button type="button" id="notion-export-btn" class="btn btn-primary" style="display:none;"><%= t('collavre_notion.modal.export_button', default: 'Export to Notion') %></button>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
en:
|
|
2
|
+
collavre_notion:
|
|
3
|
+
integration:
|
|
4
|
+
label: "Notion"
|
|
5
|
+
description: "Export creative trees to Notion pages"
|
|
6
|
+
notion_auth:
|
|
7
|
+
login_first: "Please sign in first."
|
|
8
|
+
connected: "Notion account connected successfully."
|
|
9
|
+
modal:
|
|
10
|
+
title: "Configure Notion integration"
|
|
11
|
+
success_message: "Notion integration saved successfully."
|
|
12
|
+
login_required: "Sign in with your Notion account to start the integration."
|
|
13
|
+
missing_creative: "No Creative selected for integration."
|
|
14
|
+
existing_message: "You're already connected to Notion pages below."
|
|
15
|
+
delete_confirm: "Do you want to remove the Notion integration?"
|
|
16
|
+
delete_success: "Notion integration removed successfully."
|
|
17
|
+
delete_error: "Failed to remove the Notion integration."
|
|
18
|
+
delete_button: "Remove integration"
|
|
19
|
+
export_success: "Creative exported to Notion successfully."
|
|
20
|
+
sync_success: "Creative synced to Notion successfully."
|
|
21
|
+
connect: "Sign in with your Notion account to start exporting."
|
|
22
|
+
login_button: "Sign in with Notion"
|
|
23
|
+
existing_intro: "Linked Notion pages:"
|
|
24
|
+
sync_button: "Sync to Notion"
|
|
25
|
+
workspace: "Your Notion workspace is connected. Choose how to export your creative."
|
|
26
|
+
export_option: "Export option:"
|
|
27
|
+
export_new_page: "Create new page"
|
|
28
|
+
export_under_page: "Create as subpage under existing page"
|
|
29
|
+
parent_page: "Parent page:"
|
|
30
|
+
loading_pages: "Loading pages..."
|
|
31
|
+
summary: "Ready to export your creative tree to Notion:"
|
|
32
|
+
creative_title: "Root Creative:"
|
|
33
|
+
workspace_label: "Workspace:"
|
|
34
|
+
export_as: "Export as:"
|
|
35
|
+
tree_note: "This will export the selected creative and all its descendants as a structured document."
|
|
36
|
+
export_button: "Export to Notion"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
ko:
|
|
2
|
+
collavre_notion:
|
|
3
|
+
integration:
|
|
4
|
+
label: "Notion"
|
|
5
|
+
description: "Creative 트리를 Notion 페이지로 내보내기"
|
|
6
|
+
notion_auth:
|
|
7
|
+
login_first: "먼저 로그인해 주세요."
|
|
8
|
+
connected: "Notion 계정이 연동되었습니다."
|
|
9
|
+
modal:
|
|
10
|
+
title: "Notion 연동 설정"
|
|
11
|
+
success_message: "Notion 연동이 저장되었습니다."
|
|
12
|
+
login_required: "Notion 계정으로 로그인하여 연동을 시작하세요."
|
|
13
|
+
missing_creative: "연동할 Creative가 선택되지 않았습니다."
|
|
14
|
+
existing_message: "이미 아래 Notion 페이지와 연동 중입니다."
|
|
15
|
+
delete_confirm: "Notion 연동을 삭제하시겠습니까?"
|
|
16
|
+
delete_success: "Notion 연동이 삭제되었습니다."
|
|
17
|
+
delete_error: "Notion 연동 삭제에 실패했습니다."
|
|
18
|
+
delete_button: "연동 삭제"
|
|
19
|
+
export_success: "Creative가 Notion으로 내보내기 되었습니다."
|
|
20
|
+
sync_success: "Creative가 Notion과 동기화되었습니다."
|
|
21
|
+
connect: "Notion 계정으로 로그인하여 내보내기를 시작하세요."
|
|
22
|
+
login_button: "Notion 계정으로 로그인"
|
|
23
|
+
existing_intro: "연동된 Notion 페이지:"
|
|
24
|
+
sync_button: "Notion으로 동기화"
|
|
25
|
+
workspace: "Notion 워크스페이스가 연결되었습니다. 내보내기 방법을 선택하세요."
|
|
26
|
+
export_option: "내보내기 옵션:"
|
|
27
|
+
export_new_page: "새 페이지 생성"
|
|
28
|
+
export_under_page: "기존 페이지 하위에 생성"
|
|
29
|
+
parent_page: "상위 페이지:"
|
|
30
|
+
loading_pages: "페이지 로딩 중..."
|
|
31
|
+
summary: "Creative 트리를 Notion으로 내보낼 준비가 되었습니다:"
|
|
32
|
+
creative_title: "루트 Creative:"
|
|
33
|
+
workspace_label: "워크스페이스:"
|
|
34
|
+
export_as: "내보내기 형태:"
|
|
35
|
+
tree_note: "선택한 크리에이티브와 모든 하위 항목이 구조화된 문서로 내보내집니다."
|
|
36
|
+
export_button: "Notion으로 내보내기"
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class CreateNotionIntegrations < ActiveRecord::Migration[8.0]
|
|
2
|
+
def change
|
|
3
|
+
create_table :notion_accounts do |t|
|
|
4
|
+
t.references :user, null: false, foreign_key: true, index: { unique: true }
|
|
5
|
+
t.string :notion_uid, null: false
|
|
6
|
+
t.string :workspace_name
|
|
7
|
+
t.string :workspace_id
|
|
8
|
+
t.string :bot_id
|
|
9
|
+
t.string :token, null: false
|
|
10
|
+
t.datetime :token_expires_at
|
|
11
|
+
t.timestamps
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
create_table :notion_page_links do |t|
|
|
15
|
+
t.references :creative, null: false, foreign_key: true
|
|
16
|
+
t.references :notion_account, null: false, foreign_key: true
|
|
17
|
+
t.string :page_id, null: false
|
|
18
|
+
t.string :page_title
|
|
19
|
+
t.string :page_url
|
|
20
|
+
t.string :parent_page_id
|
|
21
|
+
t.datetime :last_synced_at
|
|
22
|
+
t.timestamps
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
add_index :notion_accounts, :notion_uid, unique: true
|
|
26
|
+
add_index :notion_page_links, :page_id, unique: true
|
|
27
|
+
add_index :notion_page_links, [ :creative_id, :page_id ], unique: true, name: "index_notion_links_on_creative_and_page"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class CreateNotionBlockLinks < ActiveRecord::Migration[8.0]
|
|
2
|
+
def change
|
|
3
|
+
create_table :notion_block_links do |t|
|
|
4
|
+
t.references :notion_page_link, null: false, foreign_key: true, index: false
|
|
5
|
+
t.references :creative, null: false, foreign_key: true, index: false
|
|
6
|
+
t.string :block_id, null: false
|
|
7
|
+
t.string :content_hash
|
|
8
|
+
t.timestamps
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
add_index :notion_block_links, :notion_page_link_id, name: "index_notion_block_links_on_notion_page_link_id"
|
|
12
|
+
add_index :notion_block_links, :creative_id
|
|
13
|
+
add_index :notion_block_links, [ :notion_page_link_id, :creative_id ], unique: true, name: "index_notion_block_links_on_page_link_and_creative"
|
|
14
|
+
add_index :notion_block_links, [ :notion_page_link_id, :block_id ], unique: true, name: "index_notion_block_links_on_page_link_and_block"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module CollavreNotion
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace CollavreNotion
|
|
4
|
+
|
|
5
|
+
config.generators do |g|
|
|
6
|
+
g.test_framework :minitest
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.javascript_path
|
|
10
|
+
root.join("app/javascript")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.stylesheet_path
|
|
14
|
+
root.join("app/assets/stylesheets")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
config.i18n.load_path += Dir[root.join("config", "locales", "*.yml")]
|
|
18
|
+
|
|
19
|
+
initializer "collavre_notion.routes", before: :add_routing_paths do |app|
|
|
20
|
+
app.routes.append do
|
|
21
|
+
mount CollavreNotion::Engine => "/notion", as: :notion_engine
|
|
22
|
+
match "/auth/notion/callback", to: "collavre_notion/notion_auth#callback", via: [ :get, :post ]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
initializer "collavre_notion.assets" do |app|
|
|
27
|
+
if app.config.respond_to?(:assets) && app.config.assets.respond_to?(:paths)
|
|
28
|
+
app.config.assets.paths << root.join("app/assets/stylesheets")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
initializer "collavre_notion.migrations" do |app|
|
|
33
|
+
unless app.root.to_s.match?(root.to_s)
|
|
34
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
|
35
|
+
app.config.paths["db/migrate"] << expanded_path
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
initializer "collavre_notion.register_integration", after: :load_config_initializers do
|
|
41
|
+
Rails.application.config.to_prepare do
|
|
42
|
+
if defined?(Collavre::IntegrationRegistry)
|
|
43
|
+
Collavre::IntegrationRegistry.register(:notion, {
|
|
44
|
+
label: I18n.t("collavre_notion.integration.label", default: "Notion"),
|
|
45
|
+
icon: "notion",
|
|
46
|
+
description: I18n.t("collavre_notion.integration.description", default: "Export creative trees to Notion pages"),
|
|
47
|
+
routes: CollavreNotion::Engine.routes.url_helpers,
|
|
48
|
+
creative_menu_partial: "collavre_notion/integrations/modal"
|
|
49
|
+
})
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
initializer "collavre_notion.user_associations", after: :load_config_initializers do
|
|
55
|
+
Rails.application.config.to_prepare do
|
|
56
|
+
user_class = Collavre.user_class rescue nil
|
|
57
|
+
next unless user_class
|
|
58
|
+
|
|
59
|
+
unless user_class.reflect_on_association(:notion_account)
|
|
60
|
+
user_class.has_one :notion_account,
|
|
61
|
+
class_name: "CollavreNotion::NotionAccount",
|
|
62
|
+
dependent: :destroy
|
|
63
|
+
Rails.logger.info("[CollavreNotion] Added notion_account association to #{user_class.name}")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
initializer "collavre_notion.creative_associations", after: :load_config_initializers do
|
|
69
|
+
Rails.application.config.to_prepare do
|
|
70
|
+
creative_class = Collavre::Creative rescue nil
|
|
71
|
+
next unless creative_class
|
|
72
|
+
|
|
73
|
+
unless creative_class.reflect_on_association(:notion_page_links)
|
|
74
|
+
creative_class.has_many :notion_page_links,
|
|
75
|
+
class_name: "CollavreNotion::NotionPageLink",
|
|
76
|
+
dependent: :destroy
|
|
77
|
+
Rails.logger.info("[CollavreNotion] Added notion_page_links association to #{creative_class.name}")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
unless creative_class.reflect_on_association(:notion_block_links)
|
|
81
|
+
creative_class.has_many :notion_block_links,
|
|
82
|
+
class_name: "CollavreNotion::NotionBlockLink",
|
|
83
|
+
dependent: :destroy
|
|
84
|
+
Rails.logger.info("[CollavreNotion] Added notion_block_links association to #{creative_class.name}")
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|