collavre_notion 0.1.2 → 0.1.4
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 911a0816f31071621d67860607d4c8351cf3713fd53fde43719e822b8fa06cfb
|
|
4
|
+
data.tar.gz: 69c180ccdd9b7de6aa0096d34a1570167a092151dcdffccf8d903f6ac682f877
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 586a45e62d1009bb7feee452d1699bc73148982ff3bc19a6bc44bfed11e481ecc69ac0645e86e9c7e46d8f89c9c4e62a9b72514e4479869ebd80115390940eac
|
|
7
|
+
data.tar.gz: 58b078595daad1d91f27863ae8f57fbc9c31ce1ca8118ae14379d83a67ec5157f3fe260d2b88dbb0db4e5beb35aea44ef816a30bfa05cb460c8429bcf8492e7e
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module CollavreNotion
|
|
2
2
|
module Creatives
|
|
3
3
|
class NotionIntegrationsController < ApplicationController
|
|
4
|
+
include Collavre::IntegrationSetup
|
|
4
5
|
include Collavre::IntegrationPermission
|
|
5
6
|
|
|
6
7
|
before_action :set_creative
|
|
@@ -122,10 +123,6 @@ module CollavreNotion
|
|
|
122
123
|
|
|
123
124
|
private
|
|
124
125
|
|
|
125
|
-
def set_creative
|
|
126
|
-
@creative = Collavre::Creative.find(params[:creative_id])
|
|
127
|
-
end
|
|
128
|
-
|
|
129
126
|
def linked_page_links(account)
|
|
130
127
|
return CollavreNotion::NotionPageLink.none unless account
|
|
131
128
|
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { csrfToken, showError, clearError, updateStepVisibility, openOAuthPopup, fetchWithCsrf, setupModalClose } from 'collavre/modules/integration_wizard';
|
|
2
|
+
import { alertDialog, confirmDialog } from 'collavre/lib/utils/dialog';
|
|
3
|
+
|
|
1
4
|
let notionIntegrationInitialized = false;
|
|
2
5
|
|
|
3
6
|
if (!notionIntegrationInitialized) {
|
|
@@ -43,10 +46,6 @@ if (!notionIntegrationInitialized) {
|
|
|
43
46
|
let exportType = 'new-page';
|
|
44
47
|
let selectedParentPage = null;
|
|
45
48
|
|
|
46
|
-
function csrfToken() {
|
|
47
|
-
return document.querySelector('meta[name="csrf-token"]')?.content;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
49
|
function resetWizard() {
|
|
51
50
|
currentStep = 'connect';
|
|
52
51
|
hasExistingIntegration = false;
|
|
@@ -55,8 +54,7 @@ if (!notionIntegrationInitialized) {
|
|
|
55
54
|
exportType = 'new-page';
|
|
56
55
|
selectedParentPage = null;
|
|
57
56
|
statusEl.textContent = '';
|
|
58
|
-
errorEl
|
|
59
|
-
errorEl.textContent = '';
|
|
57
|
+
clearError(errorEl);
|
|
60
58
|
if (existingContainer) {
|
|
61
59
|
existingContainer.style.display = 'none';
|
|
62
60
|
}
|
|
@@ -74,12 +72,7 @@ if (!notionIntegrationInitialized) {
|
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
function updateStep() {
|
|
77
|
-
['connect', 'workspace', 'summary']
|
|
78
|
-
.forEach(function (step) {
|
|
79
|
-
const el = document.getElementById(`notion-step-${step}`);
|
|
80
|
-
if (!el) return;
|
|
81
|
-
el.style.display = (step === currentStep) ? 'block' : 'none';
|
|
82
|
-
});
|
|
75
|
+
updateStepVisibility(currentStep, ['connect', 'workspace', 'summary'], 'notion-step');
|
|
83
76
|
|
|
84
77
|
if (currentStep === 'connect') {
|
|
85
78
|
prevBtn.style.display = 'none';
|
|
@@ -105,29 +98,13 @@ if (!notionIntegrationInitialized) {
|
|
|
105
98
|
}
|
|
106
99
|
}
|
|
107
100
|
|
|
108
|
-
function showError(message) {
|
|
109
|
-
errorEl.textContent = message;
|
|
110
|
-
errorEl.style.display = 'block';
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function clearError() {
|
|
114
|
-
errorEl.style.display = 'none';
|
|
115
|
-
errorEl.textContent = '';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
101
|
function loadIntegrationStatus() {
|
|
119
102
|
if (!creativeId) return;
|
|
120
103
|
|
|
121
104
|
statusEl.textContent = modal.dataset.loading;
|
|
122
|
-
clearError();
|
|
105
|
+
clearError(errorEl);
|
|
123
106
|
|
|
124
|
-
|
|
125
|
-
method: 'GET',
|
|
126
|
-
headers: {
|
|
127
|
-
'X-CSRF-Token': csrfToken(),
|
|
128
|
-
'Content-Type': 'application/json'
|
|
129
|
-
}
|
|
130
|
-
})
|
|
107
|
+
fetchWithCsrf(`/notion/creatives/${creativeId}/notion_integration`)
|
|
131
108
|
.then(response => response.json())
|
|
132
109
|
.then(data => {
|
|
133
110
|
console.log('Notion integration status:', data);
|
|
@@ -168,7 +145,7 @@ if (!notionIntegrationInitialized) {
|
|
|
168
145
|
.catch(error => {
|
|
169
146
|
console.error('Error loading integration status:', error);
|
|
170
147
|
statusEl.textContent = '';
|
|
171
|
-
showError(modal.dataset.loadFailed);
|
|
148
|
+
showError(errorEl, modal.dataset.loadFailed);
|
|
172
149
|
});
|
|
173
150
|
}
|
|
174
151
|
|
|
@@ -285,13 +262,13 @@ if (!notionIntegrationInitialized) {
|
|
|
285
262
|
|
|
286
263
|
function performExport() {
|
|
287
264
|
if (!creativeId) {
|
|
288
|
-
showError(modal.dataset.noCreative);
|
|
265
|
+
showError(errorEl, modal.dataset.noCreative);
|
|
289
266
|
return;
|
|
290
267
|
}
|
|
291
268
|
|
|
292
269
|
exportBtn.disabled = true;
|
|
293
270
|
exportBtn.textContent = modal.dataset.exporting;
|
|
294
|
-
clearError();
|
|
271
|
+
clearError(errorEl);
|
|
295
272
|
|
|
296
273
|
const requestData = {
|
|
297
274
|
action: 'export'
|
|
@@ -304,13 +281,9 @@ if (!notionIntegrationInitialized) {
|
|
|
304
281
|
console.log('Sending export request:', requestData);
|
|
305
282
|
console.log('Export type:', exportType, 'Selected parent page:', selectedParentPage);
|
|
306
283
|
|
|
307
|
-
|
|
284
|
+
fetchWithCsrf(`/notion/creatives/${creativeId}/notion_integration`, {
|
|
308
285
|
method: 'PATCH',
|
|
309
|
-
|
|
310
|
-
'X-CSRF-Token': csrfToken(),
|
|
311
|
-
'Content-Type': 'application/json'
|
|
312
|
-
},
|
|
313
|
-
body: JSON.stringify(requestData)
|
|
286
|
+
body: requestData
|
|
314
287
|
})
|
|
315
288
|
.then(response => response.json())
|
|
316
289
|
.then(data => {
|
|
@@ -322,12 +295,12 @@ if (!notionIntegrationInitialized) {
|
|
|
322
295
|
resetWizard();
|
|
323
296
|
}, 2000);
|
|
324
297
|
} else {
|
|
325
|
-
showError(data.message || modal.dataset.exportFailed);
|
|
298
|
+
showError(errorEl, data.message || modal.dataset.exportFailed);
|
|
326
299
|
}
|
|
327
300
|
})
|
|
328
301
|
.catch(error => {
|
|
329
302
|
console.error('Export error:', error);
|
|
330
|
-
showError(modal.dataset.exportFailed);
|
|
303
|
+
showError(errorEl, modal.dataset.exportFailed);
|
|
331
304
|
})
|
|
332
305
|
.finally(() => {
|
|
333
306
|
exportBtn.disabled = false;
|
|
@@ -340,15 +313,11 @@ if (!notionIntegrationInitialized) {
|
|
|
340
313
|
|
|
341
314
|
syncBtn.disabled = true;
|
|
342
315
|
syncBtn.textContent = modal.dataset.syncing;
|
|
343
|
-
clearError();
|
|
316
|
+
clearError(errorEl);
|
|
344
317
|
|
|
345
|
-
|
|
318
|
+
fetchWithCsrf(`/notion/creatives/${creativeId}/notion_integration`, {
|
|
346
319
|
method: 'PATCH',
|
|
347
|
-
|
|
348
|
-
'X-CSRF-Token': csrfToken(),
|
|
349
|
-
'Content-Type': 'application/json'
|
|
350
|
-
},
|
|
351
|
-
body: JSON.stringify({ action: 'sync' })
|
|
320
|
+
body: { action: 'sync' }
|
|
352
321
|
})
|
|
353
322
|
.then(response => response.json())
|
|
354
323
|
.then(data => {
|
|
@@ -356,12 +325,12 @@ if (!notionIntegrationInitialized) {
|
|
|
356
325
|
statusEl.textContent = modal.dataset.syncSuccess || 'Sync completed successfully';
|
|
357
326
|
statusEl.style.color = 'green';
|
|
358
327
|
} else {
|
|
359
|
-
showError(data.message || modal.dataset.syncFailed);
|
|
328
|
+
showError(errorEl, data.message || modal.dataset.syncFailed);
|
|
360
329
|
}
|
|
361
330
|
})
|
|
362
331
|
.catch(error => {
|
|
363
332
|
console.error('Sync error:', error);
|
|
364
|
-
showError(modal.dataset.syncFailed);
|
|
333
|
+
showError(errorEl, modal.dataset.syncFailed);
|
|
365
334
|
})
|
|
366
335
|
.finally(() => {
|
|
367
336
|
syncBtn.disabled = false;
|
|
@@ -369,20 +338,14 @@ if (!notionIntegrationInitialized) {
|
|
|
369
338
|
});
|
|
370
339
|
}
|
|
371
340
|
|
|
372
|
-
function performDelete() {
|
|
373
|
-
if (!
|
|
341
|
+
async function performDelete() {
|
|
342
|
+
if (!(await confirmDialog(modal.dataset.deleteConfirm))) return;
|
|
374
343
|
|
|
375
344
|
deleteBtn.disabled = true;
|
|
376
345
|
deleteBtn.textContent = modal.dataset.removing;
|
|
377
|
-
clearError();
|
|
346
|
+
clearError(errorEl);
|
|
378
347
|
|
|
379
|
-
|
|
380
|
-
method: 'DELETE',
|
|
381
|
-
headers: {
|
|
382
|
-
'X-CSRF-Token': csrfToken(),
|
|
383
|
-
'Content-Type': 'application/json'
|
|
384
|
-
}
|
|
385
|
-
})
|
|
348
|
+
fetchWithCsrf(`/notion/creatives/${creativeId}/notion_integration`, { method: 'DELETE' })
|
|
386
349
|
.then(response => response.json())
|
|
387
350
|
.then(data => {
|
|
388
351
|
if (data.success) {
|
|
@@ -393,12 +356,12 @@ if (!notionIntegrationInitialized) {
|
|
|
393
356
|
resetWizard();
|
|
394
357
|
}, 2000);
|
|
395
358
|
} else {
|
|
396
|
-
showError(data.message || modal.dataset.deleteFailed);
|
|
359
|
+
showError(errorEl, data.message || modal.dataset.deleteFailed);
|
|
397
360
|
}
|
|
398
361
|
})
|
|
399
362
|
.catch(error => {
|
|
400
363
|
console.error('Delete error:', error);
|
|
401
|
-
showError(modal.dataset.deleteFailed);
|
|
364
|
+
showError(errorEl, modal.dataset.deleteFailed);
|
|
402
365
|
})
|
|
403
366
|
.finally(() => {
|
|
404
367
|
deleteBtn.disabled = false;
|
|
@@ -410,7 +373,7 @@ if (!notionIntegrationInitialized) {
|
|
|
410
373
|
openBtn.addEventListener('click', function () {
|
|
411
374
|
creativeId = this.dataset.creativeId;
|
|
412
375
|
if (!creativeId) {
|
|
413
|
-
|
|
376
|
+
alertDialog(modal.dataset.noCreative);
|
|
414
377
|
return;
|
|
415
378
|
}
|
|
416
379
|
modal.style.display = 'flex';
|
|
@@ -418,10 +381,7 @@ if (!notionIntegrationInitialized) {
|
|
|
418
381
|
loadIntegrationStatus();
|
|
419
382
|
});
|
|
420
383
|
|
|
421
|
-
|
|
422
|
-
modal.style.display = 'none';
|
|
423
|
-
resetWizard();
|
|
424
|
-
});
|
|
384
|
+
setupModalClose(modal, closeBtn, resetWizard);
|
|
425
385
|
|
|
426
386
|
// Listen for OAuth success message from popup window
|
|
427
387
|
window.addEventListener('message', function(event) {
|
|
@@ -436,26 +396,19 @@ if (!notionIntegrationInitialized) {
|
|
|
436
396
|
|
|
437
397
|
loginBtn.addEventListener('click', function () {
|
|
438
398
|
console.log('Notion login button clicked');
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
399
|
+
const authWindow = openOAuthPopup('notion-auth-window', {
|
|
400
|
+
width: parseInt(this.dataset.windowWidth) || 600,
|
|
401
|
+
height: parseInt(this.dataset.windowHeight) || 700,
|
|
402
|
+
onClose: function () {
|
|
403
|
+
console.log('Auth window closed, reloading integration status');
|
|
404
|
+
loadIntegrationStatus();
|
|
405
|
+
}
|
|
406
|
+
});
|
|
443
407
|
|
|
444
|
-
const authWindow = window.open('', 'notion-auth-window',
|
|
445
|
-
`width=${width},height=${height},left=${left},top=${top},scrollbars=yes,resizable=yes`);
|
|
446
|
-
|
|
447
408
|
if (authWindow) {
|
|
448
409
|
loginForm.target = 'notion-auth-window';
|
|
449
410
|
loginForm.submit();
|
|
450
411
|
console.log('Auth form submitted to popup window');
|
|
451
|
-
|
|
452
|
-
const checkClosed = setInterval(() => {
|
|
453
|
-
if (authWindow.closed) {
|
|
454
|
-
clearInterval(checkClosed);
|
|
455
|
-
console.log('Auth window closed, reloading integration status');
|
|
456
|
-
setTimeout(() => loadIntegrationStatus(), 1000);
|
|
457
|
-
}
|
|
458
|
-
}, 1000);
|
|
459
412
|
} else {
|
|
460
413
|
loginForm.target = '_blank';
|
|
461
414
|
loginForm.submit();
|
|
@@ -472,7 +425,7 @@ if (!notionIntegrationInitialized) {
|
|
|
472
425
|
});
|
|
473
426
|
|
|
474
427
|
nextBtn.addEventListener('click', function () {
|
|
475
|
-
clearError();
|
|
428
|
+
clearError(errorEl);
|
|
476
429
|
if (currentStep === 'connect') {
|
|
477
430
|
currentStep = 'workspace';
|
|
478
431
|
updateParentPageOptions();
|
|
@@ -501,11 +454,5 @@ if (!notionIntegrationInitialized) {
|
|
|
501
454
|
});
|
|
502
455
|
}
|
|
503
456
|
|
|
504
|
-
modal.addEventListener('click', function (e) {
|
|
505
|
-
if (e.target === modal) {
|
|
506
|
-
modal.style.display = 'none';
|
|
507
|
-
resetWizard();
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
457
|
});
|
|
511
458
|
}
|