LT-275: Creating measure flow component common section
This commit is contained in:
1 parent
9a8eaff560
commit
bbb7dad905
60 files changed
+391
-156
No files matched your search
@@ -0,0 +1,2 @@
|
||||
import './mongo.js';
|
||||
import './user.js';
|
||||
@@ -0,0 +1,26 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
// Mongo data manipulation utilities
|
||||
class MongoUtils {
|
||||
|
||||
// Check if there is an user logged in
|
||||
static validateUser() {
|
||||
// Throw error if there is no user logged in
|
||||
if (!Meteor.userId()) {
|
||||
throw new Meteor.Error('not-authorized');
|
||||
}
|
||||
}
|
||||
|
||||
// Generic callback to MongoDB write operations
|
||||
static writeCallback(error, affected) {
|
||||
// Throw error if it was not possible to complete the write operation
|
||||
if (error) {
|
||||
throw new Meteor.Error('data-write', error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Expose the class in the OHIF object
|
||||
OHIF.MongoUtils = MongoUtils;
|
||||
@@ -0,0 +1,54 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
// Manipulate user's persistent data
|
||||
class UserData {
|
||||
|
||||
// Get the persistent data by key
|
||||
static get(key) {
|
||||
// Check if there is an user logged in
|
||||
OHIF.MongoUtils.validateUser();
|
||||
|
||||
// Get the user's profile data
|
||||
const profileData = Meteor.user().profile;
|
||||
|
||||
// Return the data if it is set
|
||||
if (profileData.persistent) {
|
||||
return profileData.persistent[key];
|
||||
}
|
||||
}
|
||||
|
||||
// Store the persistent data by giving a key and a value to store
|
||||
static set(key, value) {
|
||||
// Check if there is an user logged in
|
||||
OHIF.MongoUtils.validateUser();
|
||||
|
||||
// Build the query to update only the current user's data
|
||||
var 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
|
||||
}
|
||||
};
|
||||
|
||||
// Update the user's profile data with the persistent information
|
||||
Accounts.users.update(query, data, OHIF.MongoUtils.writeCallback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Register the methods
|
||||
Meteor.methods({
|
||||
userDataGet: key => UserData.get(key),
|
||||
userDataSet: (key, value) => UserData.set(key, value)
|
||||
});
|
||||
|
||||
// Expose the class in the OHIF object
|
||||
OHIF.UserData = UserData;
|
||||
Reference in new issue
Block a user