Voteing feature

This commit is contained in:
Nico 2020-04-07 20:43:35 +02:00
parent e47ff25d45
commit 2bbc312ad0
6 changed files with 237 additions and 16 deletions

View file

@ -304,6 +304,38 @@ Cards.attachSchema(
optional: true,
defaultValue: '',
},
vote: {
/**
* vote object, see below
*/
type: Object,
optional: true,
},
'vote.question': {
type: String,
defaultValue: '',
},
'vote.positive': {
/**
* list of members (user IDs)
*/
type: [String],
optional: true,
defaultValue: [],
},
'vote.negative': {
/**
* list of members (user IDs)
*/
type: [String],
optional: true,
defaultValue: [],
},
'vote.end': {
type: Date,
optional: true,
defaultValue: null
}
}),
);
@ -696,7 +728,7 @@ Cards.helpers({
parentString(sep) {
return this.parentList()
.map(function(elem) {
.map(function (elem) {
return elem.title;
})
.join(sep);
@ -980,6 +1012,22 @@ Cards.helpers({
}
},
getVoteQuestion() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
if (card && card.vote) return card.vote.question;
else return null;
} else if (this.isLinkedBoard()) {
const board = Boards.findOne({ _id: this.linkedId });
if (board && board.vote) return board.vote.question;
else return null;
} else if (this.vote) {
return this.vote.question;
} else {
return null;
}
},
getId() {
if (this.isLinked()) {
return this.linkedId;
@ -1396,6 +1444,57 @@ Cards.mutations({
},
};
},
setVoteQuestion(question) {
return {
$set: {
vote: {
question,
positive:[],
negative:[]
},
}
}
},
unsetVote() {
return {
$unset: {
vote: '',
},
};
},
setVote(userId, forIt) {
switch (forIt) {
case true:
// vote for it
return {
$pull:{
"vote.negative": userId
},
$addToSet: {
"vote.positive": userId
}
}
case false:
// vote against
return {
$pull:{
"vote.positive": userId
},
$addToSet: {
"vote.negative" : userId
}
}
default:
// Remove votes
return {
$pull:{
"vote.positive": userId,
"vote.negative" : userId
},
}
}
},
});
//FUNCTIONS FOR creation of Activities
@ -1798,7 +1897,7 @@ if (Meteor.isServer) {
});
//New activity for card moves
Cards.after.update(function(userId, doc, fieldNames) {
Cards.after.update(function (userId, doc, fieldNames) {
const oldListId = this.previous.listId;
const oldSwimlaneId = this.previous.swimlaneId;
const oldBoardId = this.previous.boardId;
@ -1844,7 +1943,7 @@ if (Meteor.isServer) {
// change list modifiedAt, when user modified the key values in timingaction array, if it's endAt, put the modifiedAt of list back to one year ago for sorting purpose
const modifiedAt = new Date(
new Date(value).getTime() -
(action === 'endAt' ? 365 * 24 * 3600 * 1e3 : 0),
(action === 'endAt' ? 365 * 24 * 3600 * 1e3 : 0),
); // set it as 1 year before
const boardId = list.boardId;
Lists.direct.update(
@ -1898,7 +1997,7 @@ if (Meteor.isServer) {
JsonRoutes.add(
'GET',
'/api/boards/:boardId/swimlanes/:swimlaneId/cards',
function(req, res) {
function (req, res) {
const paramBoardId = req.params.boardId;
const paramSwimlaneId = req.params.swimlaneId;
Authentication.checkBoardAccess(req.userId, paramBoardId);
@ -1908,7 +2007,7 @@ if (Meteor.isServer) {
boardId: paramBoardId,
swimlaneId: paramSwimlaneId,
archived: false,
}).map(function(doc) {
}).map(function (doc) {
return {
_id: doc._id,
title: doc.title,
@ -1932,7 +2031,7 @@ if (Meteor.isServer) {
* title: string,
* description: string}]
*/
JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards', function(
JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards', function (
req,
res,
) {
@ -1945,7 +2044,7 @@ if (Meteor.isServer) {
boardId: paramBoardId,
listId: paramListId,
archived: false,
}).map(function(doc) {
}).map(function (doc) {
return {
_id: doc._id,
title: doc.title,
@ -1967,7 +2066,7 @@ if (Meteor.isServer) {
JsonRoutes.add(
'GET',
'/api/boards/:boardId/lists/:listId/cards/:cardId',
function(req, res) {
function (req, res) {
const paramBoardId = req.params.boardId;
const paramListId = req.params.listId;
const paramCardId = req.params.cardId;
@ -1999,7 +2098,7 @@ if (Meteor.isServer) {
* @param {string} [assignees] the array of maximum one ID of assignee of the new card
* @return_type {_id: string}
*/
JsonRoutes.add('POST', '/api/boards/:boardId/lists/:listId/cards', function(
JsonRoutes.add('POST', '/api/boards/:boardId/lists/:listId/cards', function (
req,
res,
) {
@ -2106,7 +2205,7 @@ if (Meteor.isServer) {
JsonRoutes.add(
'PUT',
'/api/boards/:boardId/lists/:listId/cards/:cardId',
function(req, res) {
function (req, res) {
Authentication.checkUserId(req.userId);
const paramBoardId = req.params.boardId;
const paramCardId = req.params.cardId;
@ -2405,7 +2504,7 @@ if (Meteor.isServer) {
JsonRoutes.add(
'DELETE',
'/api/boards/:boardId/lists/:listId/cards/:cardId',
function(req, res) {
function (req, res) {
Authentication.checkUserId(req.userId);
const paramBoardId = req.params.boardId;
const paramListId = req.params.listId;