user preferences via API

This commit is contained in:
STEINNI
2025-10-07 19:57:58 +00:00
parent d5940e2f08
commit db3d10539a
7 changed files with 79 additions and 65 deletions
+18 -58
View File
@@ -35,55 +35,6 @@ class myUser extends app.LoadedClasses.User {
*/
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.identity = jsonresp.payload.userInfos.identity
this.roles = jsonresp.payload.userInfos.roles
this.loadUserModel()
callBack()
}
@@ -136,12 +88,24 @@ class myUser extends app.LoadedClasses.User {
if(await this.login()) {
document.querySelector('div.loginerr').classList.remove('show')
console.log('Successful login !!!')
this.loadUserModel()
callBack()
} else {
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}
@@ -226,23 +190,19 @@ class myUser extends app.LoadedClasses.User {
}
loadPreferences() {
if(app.MessageBus) {
app.MessageBus.requestWssGwAction('GET', { key: `${this.identity.uuid}:userPrefs`})
.then(settings => {
console.log('Loading prefs...')
this.model.getPreferences().then(settings => {
console.log("Prefs received from bus:", settings)
this.preferences = settings.value || {}
})
}
})
}
savePreferences() {
if(app.MessageBus) {
app.MessageBus.requestWssGwAction('SET', {
console.log('Saving prefs...')
this.model.setPreferences({
key: `${this.identity.uuid}:userPrefs`,
value: this.preferences
})
}
}
getPreference(path) {