user preferences via API
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
"molecule1": {
|
"molecule1": {
|
||||||
"type": "Mesh",
|
"type": "Mesh",
|
||||||
"geometry": { "type": "BoxGeometry", "args": [1, 1, 1] },
|
"geometry": { "type": "BoxGeometry", "args": [1, 1, 1] },
|
||||||
|
"position": [0, 0.5, 0],
|
||||||
"material": { "type": "MeshStandardMaterial", "color": "orange" },
|
"material": { "type": "MeshStandardMaterial", "color": "orange" },
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
@@ -10,6 +11,20 @@
|
|||||||
"geometry": { "type": "SphereGeometry", "args": [0.3, 16, 16] },
|
"geometry": { "type": "SphereGeometry", "args": [0.3, 16, 16] },
|
||||||
"material": { "type": "MeshStandardMaterial", "color": "blue" },
|
"material": { "type": "MeshStandardMaterial", "color": "blue" },
|
||||||
"position": [0, 0.5, 0]
|
"position": [0, 0.5, 0]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Mesh",
|
||||||
|
"childSuffix": "head",
|
||||||
|
"geometry": { "type": "CylinderGeometry", "args": [1, 1, 0.5] },
|
||||||
|
"material": { "type": "MeshBasicMaterial",
|
||||||
|
"color": "0x9090F0",
|
||||||
|
"transparent": true,
|
||||||
|
"opacity": 0.3,
|
||||||
|
"blending": "AdditiveBlending",
|
||||||
|
"side": "BackSide"
|
||||||
|
},
|
||||||
|
"scale": [1.5, 2, 1],
|
||||||
|
"position": [0, 0, 0]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
},
|
},
|
||||||
"userLib": {
|
"userLib": {
|
||||||
"className": "myUser",
|
"className": "myUser",
|
||||||
|
"modelPath": "/app/models/myUserModel",
|
||||||
"checkauthEndpoint": "/api/checkauth",
|
"checkauthEndpoint": "/api/checkauth",
|
||||||
"loginEndpoint": "/api/login",
|
"loginEndpoint": "/api/login",
|
||||||
"logoutEndpoint": "/api/logout",
|
"logoutEndpoint": "/api/logout",
|
||||||
|
|||||||
@@ -28,9 +28,6 @@ class EICAppController extends MasterController {
|
|||||||
app.User.logout()
|
app.User.logout()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
app.User.loadPreferences();
|
|
||||||
|
|
||||||
//if('ChatModule' in app.LoadedClasses) this.chat = new ChatModule(this.content);
|
//if('ChatModule' in app.LoadedClasses) this.chat = new ChatModule(this.content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-57
@@ -35,55 +35,6 @@ class myUser extends app.LoadedClasses.User {
|
|||||||
*/
|
*/
|
||||||
getRoles() { return(app.User.roles); }
|
getRoles() { return(app.User.roles); }
|
||||||
|
|
||||||
/**
|
|
||||||
* @async
|
|
||||||
* @returns {string}
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
fetchServices() {
|
|
||||||
let host = new URL(app.config.userLib.apiDiscoveryEndpoint).host
|
|
||||||
let stage = (host.split('.')[1] != 'eismea') ? '.'+host.split('.')[1] : ''
|
|
||||||
|
|
||||||
return(fetch('/app/assets/json/global/services.json?'+crypto.randomUUID(), {
|
|
||||||
method: 'GET'
|
|
||||||
})
|
|
||||||
.then(response=>response.text())
|
|
||||||
.then(response=>JSON.parse(response.replace(/__host__/g, host).replace(/__stage__/g, stage)))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Candidate for deprecation
|
|
||||||
* @returns {Promise}
|
|
||||||
*/
|
|
||||||
getApiServices() {
|
|
||||||
return(
|
|
||||||
this.fetchServices()
|
|
||||||
.then(response => {
|
|
||||||
if(response.success) {
|
|
||||||
// Was to much to ask to respect existing code & existing contract, so do the cleanup here
|
|
||||||
let api = {};
|
|
||||||
for(let entry of response.payload){
|
|
||||||
api[entry.resource] = entry.actions.reduce( (acc, v)=>{
|
|
||||||
acc[v.action]=v.availableMethod;
|
|
||||||
return(acc); }, {}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now override with exceptions from config. (also creates from exceptions)
|
|
||||||
for(let resource in app.config.userLib.apiStageExceptions){
|
|
||||||
if(!api.hasOwnProperty(resource)) api[resource] = [];
|
|
||||||
for(let action in app.config.userLib.apiStageExceptions[resource]) {
|
|
||||||
api[resource][action] = app.config.userLib.apiStageExceptions[resource][action];
|
|
||||||
console.warn(`Replacing / adding existing API with exception for resource: ${resource} action: ${action}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
app.config.api = api;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -123,6 +74,7 @@ class myUser extends app.LoadedClasses.User {
|
|||||||
this.isAuthenticated = true
|
this.isAuthenticated = true
|
||||||
this.identity = jsonresp.payload.userInfos.identity
|
this.identity = jsonresp.payload.userInfos.identity
|
||||||
this.roles = jsonresp.payload.userInfos.roles
|
this.roles = jsonresp.payload.userInfos.roles
|
||||||
|
this.loadUserModel()
|
||||||
callBack()
|
callBack()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,12 +88,24 @@ class myUser extends app.LoadedClasses.User {
|
|||||||
if(await this.login()) {
|
if(await this.login()) {
|
||||||
document.querySelector('div.loginerr').classList.remove('show')
|
document.querySelector('div.loginerr').classList.remove('show')
|
||||||
console.log('Successful login !!!')
|
console.log('Successful login !!!')
|
||||||
|
this.loadUserModel()
|
||||||
callBack()
|
callBack()
|
||||||
} else {
|
} else {
|
||||||
gobtn.disabled = false
|
gobtn.disabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadUserModel(){
|
||||||
|
app.events.addEvent('core.mvcReady', async () => {
|
||||||
|
await Loader.loadScripts({
|
||||||
|
'scripts':[app.config.userLib.modelPath],
|
||||||
|
'dependencies':[],
|
||||||
|
})
|
||||||
|
this.model = new MyUserModleModel()
|
||||||
|
this.loadPreferences()
|
||||||
|
}, 'myUser')
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@@ -226,23 +190,19 @@ class myUser extends app.LoadedClasses.User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadPreferences() {
|
loadPreferences() {
|
||||||
if(app.MessageBus) {
|
console.log('Loading prefs...')
|
||||||
app.MessageBus.requestWssGwAction('GET', { key: `${this.identity.uuid}:userPrefs`})
|
this.model.getPreferences().then(settings => {
|
||||||
.then(settings => {
|
|
||||||
console.log("Prefs received from bus:", settings)
|
console.log("Prefs received from bus:", settings)
|
||||||
this.preferences = settings.value || {}
|
this.preferences = settings.value || {}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
savePreferences() {
|
savePreferences() {
|
||||||
if(app.MessageBus) {
|
console.log('Saving prefs...')
|
||||||
app.MessageBus.requestWssGwAction('SET', {
|
this.model.setPreferences({
|
||||||
key: `${this.identity.uuid}:userPrefs`,
|
key: `${this.identity.uuid}:userPrefs`,
|
||||||
value: this.preferences
|
value: this.preferences
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPreference(path) {
|
getPreference(path) {
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
class MyUserModleModel extends Model {
|
||||||
|
|
||||||
|
constructor(privileges) {
|
||||||
|
super('', privileges)
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPreferences(){
|
||||||
|
// let endpoint = this.getApiEndpoint('read')
|
||||||
|
// endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||||
|
return (
|
||||||
|
this.request('/api/preferences', 'get')
|
||||||
|
.then( async serverData => serverData.payload)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async setPreferences(prefs){
|
||||||
|
// let endpoint = this.getApiEndpoint('read')
|
||||||
|
// endpoint.uri = endpoint.uri.replace('{mid}', mid)
|
||||||
|
return (
|
||||||
|
this.request('/api/preferences', 'put', prefs)
|
||||||
|
.then( async serverData => serverData.payload)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
app.registerClass('MyUserModleModel', MyUserModleModel)
|
||||||
+15
-2
@@ -213,12 +213,25 @@ export class Threetobus{
|
|||||||
return(renderEngine)
|
return(renderEngine)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
agentFromJSON(id, desc){
|
agentFromJSON(id, desc){
|
||||||
let obj
|
let obj
|
||||||
if(desc.type === 'Mesh') {
|
if(desc.type === 'Mesh') {
|
||||||
const geom = new THREE[desc.geometry.type](...(desc.geometry.args || []))
|
const geom = new THREE[desc.geometry.type](...(desc.geometry.args || []))
|
||||||
const mat = new THREE[desc.material.type]( desc.material.color ? { color: desc.material.color } : {} )
|
|
||||||
|
const matType = desc.material.type
|
||||||
|
const matProps = { ...desc.material }
|
||||||
|
for (const key in matProps) {
|
||||||
|
if (key === 'type') continue
|
||||||
|
if (typeof matProps[key] === 'string' && THREE[matProps[key]] !== undefined) {
|
||||||
|
matProps[key] = THREE[matProps[key]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// convert color strings like "0xffffaa" to numbers
|
||||||
|
if (typeof matProps.color === 'string' && matProps.color.startsWith('0x')) {
|
||||||
|
matProps.color = parseInt(matProps.color)
|
||||||
|
}
|
||||||
|
const mat = new THREE[matType](matProps)
|
||||||
|
|
||||||
obj = new THREE.Mesh(geom, mat)
|
obj = new THREE.Mesh(geom, mat)
|
||||||
} else if(desc.type === 'Group') {
|
} else if(desc.type === 'Group') {
|
||||||
obj = new THREE.Group()
|
obj = new THREE.Group()
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class Sparc {
|
|||||||
onMVCReady() {
|
onMVCReady() {
|
||||||
// Now that we are authenticated, we have the config and the MVC
|
// Now that we are authenticated, we have the config and the MVC
|
||||||
// load the top routes and then route !
|
// load the top routes and then route !
|
||||||
|
app.events.trigger('core.mvcReady')
|
||||||
this.Assets.loadJson({ 'name': 'baseRoutes.json', 'path': '/app/config/' })
|
this.Assets.loadJson({ 'name': 'baseRoutes.json', 'path': '/app/config/' })
|
||||||
.then(
|
.then(
|
||||||
(topRoutes) =>{
|
(topRoutes) =>{
|
||||||
|
|||||||
Reference in New Issue
Block a user