mirror of https://github.com/wekan/wekan
The Open Source kanban (built with Meteor). Keep variable/table/field names camelCase. For translations, only add Pull Request changes to wekan/i18n/en.i18n.json , other translations are done at https://transifex.com/wekan/wekan only.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.0 KiB
89 lines
2.0 KiB
// simple version, only toggle watch / unwatch
|
|
const simpleWatchable = collection => {
|
|
collection.attachSchema({
|
|
watchers: {
|
|
type: [String],
|
|
optional: true,
|
|
},
|
|
});
|
|
|
|
collection.helpers({
|
|
getWatchLevels() {
|
|
return [true, false];
|
|
},
|
|
|
|
watcherIndex(userId) {
|
|
return this.watchers.indexOf(userId);
|
|
},
|
|
|
|
findWatcher(userId) {
|
|
return _.contains(this.watchers, userId);
|
|
},
|
|
});
|
|
|
|
collection.mutations({
|
|
setWatcher(userId, level) {
|
|
// if level undefined or null or false, then remove
|
|
if (!level) return { $pull: { watchers: userId } };
|
|
return { $addToSet: { watchers: userId } };
|
|
},
|
|
});
|
|
};
|
|
|
|
// more complex version of same interface, with 3 watching levels
|
|
const complexWatchOptions = ['watching', 'tracking', 'muted'];
|
|
const complexWatchDefault = 'muted';
|
|
|
|
const complexWatchable = collection => {
|
|
collection.attachSchema({
|
|
'watchers.$.userId': {
|
|
type: String,
|
|
},
|
|
'watchers.$.level': {
|
|
type: String,
|
|
allowedValues: complexWatchOptions,
|
|
},
|
|
});
|
|
|
|
collection.helpers({
|
|
getWatchOptions() {
|
|
return complexWatchOptions;
|
|
},
|
|
|
|
getWatchDefault() {
|
|
return complexWatchDefault;
|
|
},
|
|
|
|
watcherIndex(userId) {
|
|
return _.pluck(this.watchers, 'userId').indexOf(userId);
|
|
},
|
|
|
|
findWatcher(userId) {
|
|
return _.findWhere(this.watchers, { userId });
|
|
},
|
|
|
|
getWatchLevel(userId) {
|
|
const watcher = this.findWatcher(userId);
|
|
return watcher ? watcher.level : complexWatchDefault;
|
|
},
|
|
});
|
|
|
|
collection.mutations({
|
|
setWatcher(userId, level) {
|
|
// if level undefined or null or false, then remove
|
|
if (level === complexWatchDefault) level = null;
|
|
if (!level) return { $pull: { watchers: { userId } } };
|
|
const index = this.watcherIndex(userId);
|
|
if (index < 0) return { $push: { watchers: { userId, level } } };
|
|
return {
|
|
$set: {
|
|
[`watchers.${index}.level`]: level,
|
|
},
|
|
};
|
|
},
|
|
});
|
|
};
|
|
|
|
complexWatchable(Boards);
|
|
simpleWatchable(Lists);
|
|
simpleWatchable(Cards);
|
|
|