Fixing user preferences saving issues
This commit is contained in:
parent
f19ef98f5f
commit
15f04a5790
@ -1,3 +1,4 @@
|
|||||||
|
import './lib';
|
||||||
import './utils';
|
import './utils';
|
||||||
|
|
||||||
import './schema.js';
|
import './schema.js';
|
||||||
|
|||||||
1
Packages/ohif-core/both/lib/index.js
Normal file
1
Packages/ohif-core/both/lib/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
import './object.js';
|
||||||
@ -4,13 +4,14 @@ OHIF.object = {};
|
|||||||
|
|
||||||
// Transforms a shallow object with keys separated by "." into a nested object
|
// Transforms a shallow object with keys separated by "." into a nested object
|
||||||
OHIF.object.getNestedObject = shallowObject => {
|
OHIF.object.getNestedObject = shallowObject => {
|
||||||
var nestedObject = {};
|
const nestedObject = {};
|
||||||
for (var key in shallowObject) {
|
for (let key in shallowObject) {
|
||||||
var value = shallowObject[key];
|
if (!shallowObject.hasOwnProperty(key)) continue;
|
||||||
var propertyArray = key.split('.');
|
const value = shallowObject[key];
|
||||||
var currentObject = nestedObject;
|
const propertyArray = key.split('.');
|
||||||
|
let currentObject = nestedObject;
|
||||||
while (propertyArray.length) {
|
while (propertyArray.length) {
|
||||||
var currentProperty = propertyArray.shift();
|
const currentProperty = propertyArray.shift();
|
||||||
if (!propertyArray.length) {
|
if (!propertyArray.length) {
|
||||||
currentObject[currentProperty] = value;
|
currentObject[currentProperty] = value;
|
||||||
} else {
|
} else {
|
||||||
@ -28,11 +29,12 @@ OHIF.object.getNestedObject = shallowObject => {
|
|||||||
|
|
||||||
// Transforms a nested object into a shallowObject merging its keys with "." character
|
// Transforms a nested object into a shallowObject merging its keys with "." character
|
||||||
OHIF.object.getShallowObject = nestedObject => {
|
OHIF.object.getShallowObject = nestedObject => {
|
||||||
var shallowObject = {};
|
const shallowObject = {};
|
||||||
var putValues = function(baseKey, nestedObject, resultObject) {
|
const putValues = (baseKey, nestedObject, resultObject) => {
|
||||||
for (var key in nestedObject) {
|
for (let key in nestedObject) {
|
||||||
var currentKey = baseKey ? baseKey + '.' + key : key;
|
if (!nestedObject.hasOwnProperty(key)) continue;
|
||||||
var currentValue = nestedObject[key];
|
let currentKey = baseKey ? `${baseKey}.${key}` : key;
|
||||||
|
const currentValue = nestedObject[key];
|
||||||
if (typeof currentValue === 'object') {
|
if (typeof currentValue === 'object') {
|
||||||
if (currentValue instanceof Array) {
|
if (currentValue instanceof Array) {
|
||||||
currentKey += '[]';
|
currentKey += '[]';
|
||||||
@ -1,6 +1,5 @@
|
|||||||
import './blaze.js';
|
import './blaze.js';
|
||||||
import './cornerstone.js';
|
import './cornerstone.js';
|
||||||
import './object.js';
|
|
||||||
import './string.js';
|
import './string.js';
|
||||||
import './ui.js';
|
import './ui.js';
|
||||||
import './utils.js';
|
import './utils.js';
|
||||||
|
|||||||
@ -24,17 +24,23 @@ class UserData {
|
|||||||
// Check if there is an user logged in
|
// Check if there is an user logged in
|
||||||
OHIF.MongoUtils.validateUser();
|
OHIF.MongoUtils.validateUser();
|
||||||
|
|
||||||
// Build the query to update only the current user's data
|
// Get the user data
|
||||||
const query = { _id: Meteor.userId() };
|
const user = Meteor.user();
|
||||||
|
|
||||||
// Build the path to the persistent data with the given key
|
// Build the path to the persistent data with the given key
|
||||||
const persistentPath = `profile.persistent.${key}`;
|
const persistentPath = `profile.persistent.${key}`;
|
||||||
|
|
||||||
// Build the data to be updated
|
// Build the query to update the user's data
|
||||||
const data = { $set: { [persistentPath]: value } };
|
let query;
|
||||||
|
if (!user.profile.persistent) {
|
||||||
|
const persistentData = OHIF.object.getNestedObject({ [key]: value });
|
||||||
|
query = { $set: { 'profile.persistent': persistentData } };
|
||||||
|
} else {
|
||||||
|
query = { $set: { [persistentPath]: value } };
|
||||||
|
}
|
||||||
|
|
||||||
// Update the user's profile data with the persistent information
|
// Update the user's profile data with the persistent information
|
||||||
Accounts.users.update(query, data, OHIF.MongoUtils.writeCallback);
|
Accounts.users.update(user._id, query, OHIF.MongoUtils.writeCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user