Moving user functions to ohif:user package

This commit is contained in:
Bruno Alves de Faria 2017-04-13 17:46:12 -03:00
parent b7d1e91848
commit d2289f5eb0
7 changed files with 13 additions and 19 deletions

View File

@ -3,6 +3,5 @@ import './cornerstone.js';
import './object.js';
import './string.js';
import './ui.js';
import './user.js';
import './utils.js';
import './viewer.js';

View File

@ -1,2 +1 @@
import './mongo.js';
import './user.js';

View File

@ -1,7 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { OHIF } from 'meteor/ohif:core';
OHIF.user = {};
// Throw error if there is no user logged in
OHIF.user.validate = () => {
if (!Meteor.userId()) {
@ -31,5 +30,5 @@ OHIF.user.setData = (key, value) => {
OHIF.user.validate();
// Call the update method on server-side
Meteor.call('userDataSet', key, value);
Meteor.call('ohif.user.data.set', key, value);
};

View File

@ -1,3 +1,4 @@
import './data';
import './getName';
import './login';
import './logout';

View File

@ -28,6 +28,9 @@ Package.onUse(function(api) {
// Main module
api.mainModule('main.js', ['client', 'server']);
// Server imports
api.addFiles('server/index.js', 'server');
// Client imports
api.addFiles('client/index.js', 'client');
});

View File

@ -0,0 +1 @@
import './user.js';

View File

@ -1,5 +1,6 @@
import { OHIF } from 'meteor/ohif:core';
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { OHIF } from 'meteor/ohif:core';
// Manipulate user's persistent data
class UserData {
@ -24,19 +25,13 @@ class UserData {
OHIF.MongoUtils.validateUser();
// Build the query to update only the current user's data
var query = {
_id: Meteor.userId()
};
const query = { _id: Meteor.userId() };
// Build the path to the persistent data with the given key
const persistentPath = `profile.persistent.${key}`;
// Build the data to be updated
var data = {
$set: {
[persistentPath]: value
}
};
const data = { $set: { [persistentPath]: value } };
// Update the user's profile data with the persistent information
Accounts.users.update(query, data, OHIF.MongoUtils.writeCallback);
@ -46,9 +41,6 @@ class UserData {
// Register the methods
Meteor.methods({
userDataGet: key => UserData.get(key),
userDataSet: (key, value) => UserData.set(key, value)
'ohif.user.data.get': key => UserData.get(key),
'ohif.user.data.set': (key, value) => UserData.set(key, value)
});
// Expose the class in the OHIF object
OHIF.UserData = UserData;