@live-change/locale-settings-service 0.9.175 → 0.9.177
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/index.js +60 -0
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -63,4 +63,64 @@ const LocaleSettings = definition.model({
|
|
|
63
63
|
|
|
64
64
|
export { LocaleSettings }
|
|
65
65
|
|
|
66
|
+
const User = definition.foreignModel('user', 'User')
|
|
67
|
+
const Session = definition.foreignModel('session', 'Session')
|
|
68
|
+
|
|
69
|
+
definition.view({
|
|
70
|
+
name: 'userOrSessionLocaleSettings',
|
|
71
|
+
access: ['admin'],
|
|
72
|
+
properties: {
|
|
73
|
+
user: {
|
|
74
|
+
type: User
|
|
75
|
+
},
|
|
76
|
+
session: {
|
|
77
|
+
type: Session
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
daoPath({ user, session }, { client, context }) {
|
|
81
|
+
if(!user && !session) return null
|
|
82
|
+
if(user && !session) return LocaleSettings.path(
|
|
83
|
+
['user_User', user].map(p => JSON.stringify(p)).join(':')
|
|
84
|
+
)
|
|
85
|
+
if(!user && session) return LocaleSettings.path(
|
|
86
|
+
['session_Session', session].map(p => JSON.stringify(p)).join(':')
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
return ['database', 'queryObject', app.databaseName, `(${
|
|
90
|
+
async (input, output, { user, session, localeSettingsTableName }) => {
|
|
91
|
+
const localeSettingsTable = input.table(localeSettingsTableName)
|
|
92
|
+
const userObject = localeSettingsTable.object(
|
|
93
|
+
['user_User', user].map(p => JSON.stringify(p)).join(':')
|
|
94
|
+
)
|
|
95
|
+
const sessionObject = localeSettingsTable.object(
|
|
96
|
+
['session_Session', session].map(p => JSON.stringify(p)).join(':')
|
|
97
|
+
)
|
|
98
|
+
let userLocaleSettings = {}
|
|
99
|
+
let sessionLocaleSettings = {}
|
|
100
|
+
let oldResult = null
|
|
101
|
+
let loaded = false
|
|
102
|
+
async function updateResult() {
|
|
103
|
+
// mix values from user and session locale settings
|
|
104
|
+
const result = { ...sessionLocaleSettings, ...userLocaleSettings }
|
|
105
|
+
output.debug("USER LOCALE SETTINGS", userLocaleSettings)
|
|
106
|
+
output.debug("SESSION LOCALE SETTINGS", sessionLocaleSettings)
|
|
107
|
+
output.debug("RESULT LOCALE SETTINGS", result)
|
|
108
|
+
await output.change(result, oldResult)
|
|
109
|
+
oldResult = result
|
|
110
|
+
}
|
|
111
|
+
await sessionObject.onChange(async (obj, oldObj) => {
|
|
112
|
+
sessionLocaleSettings = obj
|
|
113
|
+
if(loaded) await updateResult()
|
|
114
|
+
})
|
|
115
|
+
await userObject.onChange(async (obj, oldObj) => {
|
|
116
|
+
userLocaleSettings = obj
|
|
117
|
+
if(loaded) await updateResult()
|
|
118
|
+
})
|
|
119
|
+
loaded = true
|
|
120
|
+
await updateResult()
|
|
121
|
+
}
|
|
122
|
+
})`, { user, session, localeSettingsTableName: LocaleSettings.tableName }]
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
|
|
66
126
|
export default definition
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/locale-settings-service",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.177",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.9.
|
|
26
|
-
"@live-change/relations-plugin": "^0.9.
|
|
25
|
+
"@live-change/framework": "^0.9.177",
|
|
26
|
+
"@live-change/relations-plugin": "^0.9.177"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "d75c8c63935b7b78623248d255820b1da2676929"
|
|
29
29
|
}
|