summaryrefslogtreecommitdiffstats
path: root/models/users.js
diff options
context:
space:
mode:
author蔡仲明 (Romulus Urakagi Tsai) <urakagi@gmail.com>2019-11-21 11:25:56 +0800
committerGitHub <noreply@github.com>2019-11-21 11:25:56 +0800
commit3e0bedd8c7a6dec97352212adb1cbde1ade44190 (patch)
tree651ff30d25ddb0416444370368d699e597c142d7 /models/users.js
parent9bbeb73db1cd0ce1caaaca8dfb14ea92131bbf9d (diff)
parent4f5de87cc4c2281bd576548693de7c94e6a988c6 (diff)
downloadwekan-3e0bedd8c7a6dec97352212adb1cbde1ade44190.tar.gz
wekan-3e0bedd8c7a6dec97352212adb1cbde1ade44190.tar.bz2
wekan-3e0bedd8c7a6dec97352212adb1cbde1ade44190.zip
Merge pull request #1 from wekan/master
Update master
Diffstat (limited to 'models/users.js')
-rw-r--r--models/users.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/models/users.js b/models/users.js
index 55d85e07..83a224ba 100644
--- a/models/users.js
+++ b/models/users.js
@@ -4,6 +4,16 @@ const isSandstorm =
Meteor.settings && Meteor.settings.public && Meteor.settings.public.sandstorm;
Users = Meteor.users;
+const allowedSortValues = [
+ '-modifiedAt',
+ 'modifiedAt',
+ '-title',
+ 'title',
+ '-sort',
+ 'sort',
+];
+const defaultSortBy = allowedSortValues[0];
+
/**
* A User in wekan
*/
@@ -54,6 +64,8 @@ Users.attachSchema(
autoValue() {
if (this.isInsert) {
return new Date();
+ } else if (this.isUpsert) {
+ return { $setOnInsert: new Date() };
} else {
this.unset();
}
@@ -107,6 +119,13 @@ Users.attachSchema(
type: String,
optional: true,
},
+ 'profile.showDesktopDragHandles': {
+ /**
+ * does the user want to hide system messages?
+ */
+ type: Boolean,
+ optional: true,
+ },
'profile.hiddenSystemMessages': {
/**
* does the user want to hide system messages?
@@ -182,6 +201,15 @@ Users.attachSchema(
'board-view-cal',
],
},
+ 'profile.listSortBy': {
+ /**
+ * default sort list for user
+ */
+ type: String,
+ optional: true,
+ defaultValue: defaultSortBy,
+ allowedValues: allowedSortValues,
+ },
'profile.templatesBoardId': {
/**
* Reference to the templates board
@@ -356,6 +384,31 @@ Users.helpers({
return _.contains(invitedBoards, boardId);
},
+ _getListSortBy() {
+ const profile = this.profile || {};
+ const sortBy = profile.listSortBy || defaultSortBy;
+ const keyPattern = /^(-{0,1})(.*$)/;
+ const ret = [];
+ if (keyPattern.exec(sortBy)) {
+ ret[0] = RegExp.$2;
+ ret[1] = RegExp.$1 ? -1 : 1;
+ }
+ return ret;
+ },
+ hasSortBy() {
+ // if use doesn't have dragHandle, then we can let user to choose sort list by different order
+ return !this.hasShowDesktopDragHandles();
+ },
+ getListSortBy() {
+ return this._getListSortBy()[0];
+ },
+ getListSortTypes() {
+ return allowedSortValues;
+ },
+ getListSortByDirection() {
+ return this._getListSortBy()[1];
+ },
+
hasTag(tag) {
const { tags = [] } = this.profile || {};
return _.contains(tags, tag);
@@ -366,6 +419,11 @@ Users.helpers({
return _.contains(notifications, activityId);
},
+ hasShowDesktopDragHandles() {
+ const profile = this.profile || {};
+ return profile.showDesktopDragHandles || false;
+ },
+
hasHiddenSystemMessages() {
const profile = this.profile || {};
return profile.hiddenSystemMessages || false;
@@ -471,6 +529,21 @@ Users.mutations({
else this.addTag(tag);
},
+ setListSortBy(value) {
+ return {
+ $set: {
+ 'profile.listSortBy': value,
+ },
+ };
+ },
+ toggleDesktopHandles(value = false) {
+ return {
+ $set: {
+ 'profile.showDesktopDragHandles': !value,
+ },
+ };
+ },
+
toggleSystem(value = false) {
return {
$set: {
@@ -539,6 +612,7 @@ Users.mutations({
Meteor.methods({
setUsername(username, userId) {
check(username, String);
+ check(userId, String);
const nUsersWithUsername = Users.find({ username }).count();
if (nUsersWithUsername > 0) {
throw new Meteor.Error('username-already-taken');
@@ -546,6 +620,14 @@ Meteor.methods({
Users.update(userId, { $set: { username } });
}
},
+ setListSortBy(value) {
+ check(value, String);
+ Meteor.user().setListSortBy(value);
+ },
+ toggleDesktopDragHandles() {
+ const user = Meteor.user();
+ user.toggleDesktopHandles(user.hasShowDesktopDragHandles());
+ },
toggleSystemMessages() {
const user = Meteor.user();
user.toggleSystem(user.hasHiddenSystemMessages());
@@ -773,6 +855,9 @@ if (Meteor.isServer) {
if (Meteor.isServer) {
// Let mongoDB ensure username unicity
Meteor.startup(() => {
+ allowedSortValues.forEach(value => {
+ Lists._collection._ensureIndex(value);
+ });
Users._collection._ensureIndex({ modifiedAt: -1 });
Users._collection._ensureIndex(
{