@kaspernj/api-maker 1.0.273 → 1.0.275
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.
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ export default class ApiMakerCableSubscriptionPool {
|
|
|
16
16
|
connect (subscriptionData) {
|
|
17
17
|
const globalData = CommandsPool.current().globalRequestData
|
|
18
18
|
|
|
19
|
-
logger.
|
|
19
|
+
logger.debug(() => ["Creating subscription", {subscriptionData}])
|
|
20
20
|
|
|
21
21
|
this.subscription = ChannelsConsumer.subscriptions.create(
|
|
22
22
|
{
|
|
@@ -128,16 +128,16 @@ export default class ApiMakerCableSubscriptionPool {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
onSubscribed = () => {
|
|
131
|
-
logger.
|
|
131
|
+
logger.debug("onSubscribed")
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
onUnsubscribe () {
|
|
135
|
-
logger.
|
|
135
|
+
logger.debug(() => `activeSubscriptions before unsub: ${this.activeSubscriptions}`)
|
|
136
136
|
this.activeSubscriptions -= 1
|
|
137
|
-
logger.
|
|
137
|
+
logger.debug(() => `activeSubscriptions after unsub: ${this.activeSubscriptions}`)
|
|
138
138
|
|
|
139
139
|
if (this.activeSubscriptions <= 0) {
|
|
140
|
-
logger.
|
|
140
|
+
logger.debug("Unsubscribe from ActionCable subscription")
|
|
141
141
|
this.subscription.unsubscribe()
|
|
142
142
|
this.connected = false
|
|
143
143
|
}
|
|
@@ -146,7 +146,7 @@ export default class ApiMakerCableSubscriptionPool {
|
|
|
146
146
|
registerSubscriptions (subscriptions) {
|
|
147
147
|
this.subscriptions = subscriptions
|
|
148
148
|
|
|
149
|
-
logger.
|
|
149
|
+
logger.debug(() => ["registerSubscriptions", {subscriptions}])
|
|
150
150
|
|
|
151
151
|
for (const modelName in subscriptions) {
|
|
152
152
|
if (subscriptions[modelName].creates) {
|
|
@@ -176,12 +176,12 @@ export default class ApiMakerCableSubscriptionPool {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
connectUnsubscriptionForSubscription (subscription) {
|
|
179
|
-
logger.
|
|
179
|
+
logger.debug(() => ["Connecting to unsubscribe on subscription", {subscription}])
|
|
180
180
|
|
|
181
181
|
this.activeSubscriptions += 1
|
|
182
182
|
|
|
183
183
|
subscription.events.addListener("unsubscribed", () => {
|
|
184
|
-
logger.
|
|
184
|
+
logger.debug("Call onUnsubscribe on self")
|
|
185
185
|
|
|
186
186
|
this.onUnsubscribe(subscription)
|
|
187
187
|
})
|
|
@@ -11,11 +11,11 @@ export default class ApiMakerCableSubscription {
|
|
|
11
11
|
|
|
12
12
|
unsubscribe () {
|
|
13
13
|
if (!this.subscribed) {
|
|
14
|
-
logger.
|
|
14
|
+
logger.debug("Unsubscribed already called")
|
|
15
15
|
return
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
logger.
|
|
18
|
+
logger.debug("Unsubscribe called for subscription")
|
|
19
19
|
|
|
20
20
|
this.subscribed = false
|
|
21
21
|
this.events.emit("unsubscribed")
|
|
@@ -29,8 +29,6 @@ export default class ApiMakerSessionStatusUpdater {
|
|
|
29
29
|
wakeEvent(() => this.updateSessionStatus())
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
debug = (message) => logger.log(() => message)
|
|
33
|
-
|
|
34
32
|
async sessionStatus () {
|
|
35
33
|
return new Promise((resolve) => {
|
|
36
34
|
const xhr = new XMLHttpRequest()
|
|
@@ -48,7 +46,7 @@ export default class ApiMakerSessionStatusUpdater {
|
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
startTimeout () {
|
|
51
|
-
|
|
49
|
+
logger.debug("startTimeout")
|
|
52
50
|
|
|
53
51
|
if (this.updateTimeout)
|
|
54
52
|
clearTimeout(this.updateTimeout)
|
|
@@ -68,24 +66,24 @@ export default class ApiMakerSessionStatusUpdater {
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
async updateSessionStatus () {
|
|
71
|
-
|
|
69
|
+
logger.debug("updateSessionStatus")
|
|
72
70
|
|
|
73
71
|
const result = await this.sessionStatus()
|
|
74
72
|
|
|
75
|
-
|
|
73
|
+
logger.debug(() => `Result: ${JSON.stringify(result, null, 2)}`)
|
|
76
74
|
this.updateMetaElementsFromResult(result)
|
|
77
75
|
this.updateUserSessionsFromResult(result)
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
updateMetaElementsFromResult (result) {
|
|
81
|
-
|
|
79
|
+
logger.debug("updateMetaElementsFromResult")
|
|
82
80
|
const csrfTokenElement = document.querySelector("meta[name='csrf-token']")
|
|
83
81
|
|
|
84
82
|
if (csrfTokenElement) {
|
|
85
|
-
|
|
83
|
+
logger.debug(() => `Changing token from "${csrfTokenElement.getAttribute("content")}" to "${result.csrf_token}"`)
|
|
86
84
|
csrfTokenElement.setAttribute("content", result.csrf_token)
|
|
87
85
|
} else {
|
|
88
|
-
|
|
86
|
+
logger.debug("csrf token element couldn't be found")
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
|
|
@@ -106,7 +104,7 @@ export default class ApiMakerSessionStatusUpdater {
|
|
|
106
104
|
const signedInOnBackend = scope.signed_in
|
|
107
105
|
|
|
108
106
|
if (currentlySignedIn && !signedInOnBackend) {
|
|
109
|
-
|
|
107
|
+
logger.debug(() => `${inflection.camelize(scopeName)} signed in on frontend but not in backend!`)
|
|
110
108
|
|
|
111
109
|
Devise.setSignedOut({scope: scopeName})
|
|
112
110
|
Devise.callSignOutEvent({scope: scopeName})
|
|
@@ -2,11 +2,14 @@ import columnIdentifier from "./column-identifier.mjs"
|
|
|
2
2
|
import columnVisible from "./column-visible.mjs"
|
|
3
3
|
import {digg} from "diggerize"
|
|
4
4
|
import * as inflection from "inflection"
|
|
5
|
+
import Logger from "../logger.mjs"
|
|
5
6
|
import {ReadersWriterLock} from "epic-locks"
|
|
6
7
|
import {serialize as objectToFormData} from "object-to-formdata"
|
|
7
8
|
import {TableSetting} from "../models.mjs.erb"
|
|
8
9
|
import {v4 as uuidv4} from "uuid"
|
|
9
10
|
|
|
11
|
+
const logger = new Logger({name: "ApiMaker / TableSettings"})
|
|
12
|
+
|
|
10
13
|
// Have a lock for each unique table identifier
|
|
11
14
|
const tableSettingsLocks = {}
|
|
12
15
|
|
|
@@ -162,6 +165,7 @@ export default class ApiMakerTableSettings {
|
|
|
162
165
|
}
|
|
163
166
|
|
|
164
167
|
updateTableSetting = async (tableSetting) => {
|
|
168
|
+
const changedAttributesList = ["attributeName", "sortKey"]
|
|
165
169
|
const columns = this.columns()
|
|
166
170
|
const columnsData = {}
|
|
167
171
|
const tableSettingData = {columns_attributes: columnsData}
|
|
@@ -184,6 +188,7 @@ export default class ApiMakerTableSettings {
|
|
|
184
188
|
}
|
|
185
189
|
)
|
|
186
190
|
|
|
191
|
+
logger.debug(() => `Changed because of new column: ${column.label}`)
|
|
187
192
|
changed = true
|
|
188
193
|
}
|
|
189
194
|
}
|
|
@@ -193,6 +198,45 @@ export default class ApiMakerTableSettings {
|
|
|
193
198
|
|
|
194
199
|
if (column) {
|
|
195
200
|
// TODO: Update column if changed
|
|
201
|
+
let columnChanged = false
|
|
202
|
+
|
|
203
|
+
for (const changedAttribute of changedAttributesList) {
|
|
204
|
+
let columnAttributeName
|
|
205
|
+
|
|
206
|
+
if (changedAttribute == "attributeName") {
|
|
207
|
+
columnAttributeName = "attribute"
|
|
208
|
+
} else {
|
|
209
|
+
columnAttributeName = changedAttribute
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const oldAttributeValue = tableSettingColumn[changedAttribute]()
|
|
213
|
+
const newAttributeValue = digg(column, columnAttributeName)
|
|
214
|
+
|
|
215
|
+
if (oldAttributeValue != newAttributeValue) {
|
|
216
|
+
logger.debug(() => `${changedAttribute} changed from ${oldAttributeValue} to ${newAttributeValue} on column: ${column.label}`)
|
|
217
|
+
columnChanged = true
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const columnPathAsString = JSON.stringify(column.path)
|
|
222
|
+
const tableSettingColumnPathAsString = tableSettingColumn.path()
|
|
223
|
+
|
|
224
|
+
if (columnPathAsString != tableSettingColumnPathAsString) {
|
|
225
|
+
logger.debug(() => `Path changed on ${column.label} from ${columnPathAsString} to ${tableSettingColumnPathAsString}`)
|
|
226
|
+
columnChanged = true
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (columnChanged) {
|
|
230
|
+
const columnKey = ++columnsKeyCount
|
|
231
|
+
|
|
232
|
+
changed = true
|
|
233
|
+
columnsData[columnKey] = {
|
|
234
|
+
attribute_name: column.attributeName,
|
|
235
|
+
id: tableSettingColumn.id(),
|
|
236
|
+
path: column.path,
|
|
237
|
+
sort_key: column.sortKey
|
|
238
|
+
}
|
|
239
|
+
}
|
|
196
240
|
} else {
|
|
197
241
|
// Removed saved columns no longer found
|
|
198
242
|
const columnKey = ++columnsKeyCount
|
|
@@ -202,6 +246,8 @@ export default class ApiMakerTableSettings {
|
|
|
202
246
|
_destroy: true
|
|
203
247
|
}
|
|
204
248
|
changed = true
|
|
249
|
+
|
|
250
|
+
logger.debug(() => `Column got removed: ${tableSettingColumn.identifier()}`)
|
|
205
251
|
}
|
|
206
252
|
}
|
|
207
253
|
|