| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761 | import {  ALLOWED_COLORS,  TYPE_CARD,  TYPE_LINKED_BOARD,  TYPE_LINKED_CARD,} from '../config/const';Cards = new Mongo.Collection('cards');// XXX To improve pub/sub performances a card document should include a// de-normalized number of comments so we don't have to publish the whole list// of comments just to display the number of them in the board view.Cards.attachSchema(  new SimpleSchema({    title: {      /**       * the title of the card       */      type: String,      optional: true,      defaultValue: '',    },    archived: {      /**       * is the card archived       */      type: Boolean,      // eslint-disable-next-line consistent-return      autoValue() {        // eslint-disable-line consistent-return        if (this.isInsert && !this.isSet) {          return false;        }      },    },    archivedAt: {      /**       * latest archiving date       */      type: Date,      optional: true,    },    parentId: {      /**       * ID of the parent card       */      type: String,      optional: true,      defaultValue: '',    },    listId: {      /**       * List ID where the card is       */      type: String,      optional: true,      defaultValue: '',    },    swimlaneId: {      /**       * Swimlane ID where the card is       */      type: String,    },    // The system could work without this `boardId` information (we could deduce    // the board identifier from the card), but it would make the system more    // difficult to manage and less efficient.    boardId: {      /**       * Board ID of the card       */      type: String,      optional: true,      defaultValue: '',    },    coverId: {      /**       * Cover ID of the card       */      type: String,      optional: true,      defaultValue: '',    },    color: {      type: String,      optional: true,      allowedValues: ALLOWED_COLORS,    },    createdAt: {      /**       * creation date       */      type: Date,      // eslint-disable-next-line consistent-return      autoValue() {        if (this.isInsert) {          return new Date();        } else if (this.isUpsert) {          return { $setOnInsert: new Date() };        } else {          this.unset();        }      },    },    modifiedAt: {      type: Date,      denyUpdate: false,      // eslint-disable-next-line consistent-return      autoValue() {        if (this.isInsert || this.isUpsert || this.isUpdate) {          return new Date();        } else {          this.unset();        }      },    },    customFields: {      /**       * list of custom fields       */      type: [Object],      optional: true,      defaultValue: [],    },    'customFields.$': {      type: new SimpleSchema({        _id: {          /**           * the ID of the related custom field           */          type: String,          optional: true,          defaultValue: '',        },        value: {          /**           * value attached to the custom field           */          type: Match.OneOf(String, Number, Boolean, Date, [String]),          optional: true,          defaultValue: '',        },        'value.$': {          type: String,          optional: true,        },      }),    },    dateLastActivity: {      /**       * Date of last activity       */      type: Date,      autoValue() {        return new Date();      },    },    description: {      /**       * description of the card       */      type: String,      optional: true,      defaultValue: '',    },    requestedBy: {      /**       * who requested the card (ID of the user)       */      type: String,      optional: true,      defaultValue: '',    },    assignedBy: {      /**       * who assigned the card (ID of the user)       */      type: String,      optional: true,      defaultValue: '',    },    labelIds: {      /**       * list of labels ID the card has       */      type: [String],      optional: true,      defaultValue: [],    },    members: {      /**       * list of members (user IDs)       */      type: [String],      optional: true,      defaultValue: [],    },    assignees: {      /**       * who is assignee of the card (user ID),       * maximum one ID of assignee in array.       */      type: [String],      optional: true,      defaultValue: [],    },    receivedAt: {      /**       * Date the card was received       */      type: Date,      optional: true,    },    startAt: {      /**       * Date the card was started to be worked on       */      type: Date,      optional: true,    },    dueAt: {      /**       * Date the card is due       */      type: Date,      optional: true,    },    endAt: {      /**       * Date the card ended       */      type: Date,      optional: true,    },    spentTime: {      /**       * How much time has been spent on this       */      type: Number,      decimal: true,      optional: true,      defaultValue: 0,    },    isOvertime: {      /**       * is the card over time?       */      type: Boolean,      defaultValue: false,      optional: true,    },    // XXX Should probably be called `authorId`. Is it even needed since we have    // the `members` field?    userId: {      /**       * user ID of the author of the card       */      type: String,      // eslint-disable-next-line consistent-return      autoValue() {        // eslint-disable-line consistent-return        if (this.isInsert && !this.isSet) {          return this.userId;        }      },    },    sort: {      /**       * Sort value       */      type: Number,      decimal: true,      defaultValue: 0,      optional: true,    },    subtaskSort: {      /**       * subtask sort value       */      type: Number,      decimal: true,      defaultValue: -1,      optional: true,    },    type: {      /**       * type of the card       */      type: String,      defaultValue: TYPE_CARD,      // allowedValues: [TYPE_CARD, TYPE_LINKED_CARD, TYPE_LINKED_BOARD, TYPE_TEMPLATE_CARD],    },    linkedId: {      /**       * ID of the linked card       */      type: String,      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,    },    'vote.public': {      type: Boolean,      defaultValue: false,    },    'vote.allowNonBoardMembers': {      type: Boolean,      defaultValue: false,    },    poker: {      /**       * poker object, see below       */      type: Object,      optional: true,    },    'poker.question': {      type: Boolean,      defaultValue: false,    },    'poker.one': {      /**       * poker card one       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.two': {      /**       * poker card two       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.three': {      /**       * poker card three       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.five': {      /**       * poker card five       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.eight': {      /**       * poker card eight       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.thirteen': {      /**       * poker card thirteen       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.twenty': {      /**       * poker card twenty       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.forty': {      /**       * poker card forty       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.oneHundred': {      /**       * poker card oneHundred       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.unsure': {      /**       * poker card unsure       */      type: [String],      optional: true,      defaultValue: [],    },    'poker.end': {      type: Date,      optional: true,      defaultValue: null,    },    'poker.allowNonBoardMembers': {      type: Boolean,      defaultValue: false,    },    'poker.estimation': {      /**       * poker estimation value       */      type: Number,      optional: true,    },    targetId_gantt: {      /**       * ID of card which is the child link in gantt view       */      type: [String],      optional: true,      defaultValue: [],    },    linkType_gantt: {      /**       * ID of card which is the parent link in gantt view       */      type: [Number],      decimal: false,      optional: true,      defaultValue: [],    },    linkId_gantt: {      /**       * ID of card which is the parent link in gantt view       */      type: [String],      optional: true,      defaultValue: [],    },    cardNumber: {      /**       * A boardwise sequentially increasing number that is assigned       * to every newly created card       */      type: Number,      decimal: true,      optional: true,      defaultValue: 0,    },  }),);Cards.allow({  insert(userId, doc) {    return allowIsBoardMember(userId, Boards.findOne(doc.boardId));  },  update(userId, doc, fields) {    // Allow board members or logged in users if only vote get's changed    return (      allowIsBoardMember(userId, Boards.findOne(doc.boardId)) ||      (_.isEqual(fields, ['vote', 'modifiedAt', 'dateLastActivity']) &&        !!userId)    );  },  remove(userId, doc) {    return allowIsBoardMember(userId, Boards.findOne(doc.boardId));  },  fetch: ['boardId'],});Cards.helpers({  // Gantt https://github.com/wekan/wekan/issues/2870#issuecomment-857171127  setGanttTargetId(sourceId, targetId, linkType, linkId){    return Cards.update({ _id: sourceId}, {      $push: {        targetId_gantt: targetId,        linkType_gantt : linkType,        linkId_gantt: linkId      }    });  },  removeGanttTargetId(sourceId, targetId, linkType, linkId){    return Cards.update({ _id: sourceId}, {      $pull: {        targetId_gantt: targetId,        linkType_gantt : linkType,        linkId_gantt: linkId      }    });  },  mapCustomFieldsToBoard(boardId) {    // Map custom fields to new board    return this.customFields.map(cf => {      const oldCf = CustomFields.findOne(cf._id);      const newCf = CustomFields.findOne({        boardIds: boardId,        name: oldCf.name,        type: oldCf.type,      });      if (newCf) {        cf._id = newCf._id;      } else if (!_.contains(oldCf.boardIds, boardId)) {        oldCf.addBoard(boardId);      }      return cf;    });  },  copy(boardId, swimlaneId, listId) {    const oldId = this._id;    const oldCard = Cards.findOne(oldId);    // we must only copy the labels and custom fields if the target board    // differs from the source board    if (this.boardId !== boardId) {      const oldBoard = Boards.findOne(this.boardId);      const oldBoardLabels = oldBoard.labels;      // Get old label names      const oldCardLabels = _.pluck(        _.filter(oldBoardLabels, label => {          return _.contains(this.labelIds, label._id);        }),        'name',      );      const newBoard = Boards.findOne(boardId);      const newBoardLabels = newBoard.labels;      const newCardLabels = _.pluck(        _.filter(newBoardLabels, label => {          return _.contains(oldCardLabels, label.name);        }),        '_id',      );      // now set the new label ids      delete this.labelIds;      this.labelIds = newCardLabels;      this.customFields = this.mapCustomFieldsToBoard(newBoard._id);    }    delete this._id;    this.boardId = boardId;    this.cardNumber = Boards.findOne(boardId).getNextCardNumber();    this.swimlaneId = swimlaneId;    this.listId = listId;    const _id = Cards.insert(this);    // Copy attachments    oldCard.attachments().forEach(att => {      att.cardId = _id;      delete att._id;      return Attachments.insert(att);    });    // copy checklists    Checklists.find({ cardId: oldId }).forEach(ch => {      ch.copy(_id);    });    // copy subtasks    Cards.find({ parentId: oldId }).forEach(subtask => {      subtask.parentId = _id;      subtask._id = null;      Cards.insert(subtask);    });    // copy card comments    CardComments.find({ cardId: oldId }).forEach(cmt => {      cmt.copy(_id);    });    return _id;  },  link(boardId, swimlaneId, listId) {    // TODO is there a better method to create a deepcopy?    linkCard = JSON.parse(JSON.stringify(this));    // TODO is this how it is meant to be?    linkCard.linkedId = linkCard.linkedId || linkCard._id;    linkCard.boardId = boardId;    linkCard.swimlaneId = swimlaneId;    linkCard.listId = listId;    linkCard.type = 'cardType-linkedCard';    delete linkCard._id;    // TODO shall we copy the labels for a linked card?!    delete linkCard.labelIds;    return Cards.insert(linkCard);  },  list() {    return Lists.findOne(this.listId);  },  swimlane() {    return Swimlanes.findOne(this.swimlaneId);  },  board() {    return Boards.findOne(this.boardId);  },  getList() {    const list = this.list();    if (!list) {      return {        _id: this.listId,        title: 'Undefined List',        archived: false,        colorClass: '',      };    }    return list;  },  getSwimlane() {    const swimlane = this.swimlane();    if (!swimlane) {      return {        _id: this.swimlaneId,        title: 'Undefined Swimlane',        archived: false,        colorClass: '',      };    }    return swimlane;  },  getBoard() {    const board = this.board();    if (!board) {      return {        _id: this.boardId,        title: 'Undefined Board',        archived: false,        colorClass: '',      };    }    return board;  },  labels() {    const boardLabels = this.board().labels;    const cardLabels = _.filter(boardLabels, label => {      return _.contains(this.labelIds, label._id);    });    return cardLabels;  },  hasLabel(labelId) {    return _.contains(this.labelIds, labelId);  },  user() {    return Users.findOne(this.userId);  },  isAssigned(memberId) {    return _.contains(this.getMembers(), memberId);  },  isAssignee(assigneeId) {    return _.contains(this.getAssignees(), assigneeId);  },  activities() {    if (this.isLinkedCard()) {      return Activities.find(        { cardId: this.linkedId },        { sort: { createdAt: -1 } },      );    } else if (this.isLinkedBoard()) {      return Activities.find(        { boardId: this.linkedId },        { sort: { createdAt: -1 } },      );    } else {      return Activities.find({ cardId: this._id }, { sort: { createdAt: -1 } });    }  },  comments() {    if (this.isLinkedCard()) {      return CardComments.find(        { cardId: this.linkedId },        { sort: { createdAt: -1 } },      );    } else {      return CardComments.find(        { cardId: this._id },        { sort: { createdAt: -1 } },      );    }  },  attachments() {    if (this.isLinkedCard()) {      return Attachments.find(        { cardId: this.linkedId },        { sort: { uploadedAt: -1 } },      );    } else {      return Attachments.find(        { cardId: this._id },        { sort: { uploadedAt: -1 } },      );    }  },  cover() {    if (!this.coverId) return false;    const cover = Attachments.findOne(this.coverId);    // if we return a cover before it is fully stored, we will get errors when we try to display it    // todo XXX we could return a default "upload pending" image in the meantime?    return cover && cover.url() && cover;  },  checklists() {    if (this.isLinkedCard()) {      return Checklists.find({ cardId: this.linkedId }, { sort: { sort: 1 } });    } else {      return Checklists.find({ cardId: this._id }, { sort: { sort: 1 } });    }  },  checklistItemCount() {    const checklists = this.checklists().fetch();    return checklists      .map(checklist => {        return checklist.itemCount();      })      .reduce((prev, next) => {        return prev + next;      }, 0);  },  checklistFinishedCount() {    const checklists = this.checklists().fetch();    return checklists      .map(checklist => {        return checklist.finishedCount();      })      .reduce((prev, next) => {        return prev + next;      }, 0);  },  checklistFinished() {    return (      this.hasChecklist() &&      this.checklistItemCount() === this.checklistFinishedCount()    );  },  hasChecklist() {    return this.checklistItemCount() !== 0;  },  subtasks() {    return Cards.find(      {        parentId: this._id,        archived: false,      },      {        sort: {          sort: 1,        },      },    );  },  subtasksFinished() {    return Cards.find({      parentId: this._id,      archived: true,    });  },  allSubtasks() {    return Cards.find({      parentId: this._id,    });  },  subtasksCount() {    const subtasks = this.subtasks();    return subtasks.count();  },  subtasksFinishedCount() {    const subtasksArchived = this.subtasksFinished();    return subtasksArchived.count();  },  allSubtasksCount() {    const allSubtasks = this.allSubtasks();    return allSubtasks.count();  },  allowsSubtasks() {    return this.subtasksCount() !== 0;  },  customFieldIndex(customFieldId) {    return _.pluck(this.customFields, '_id').indexOf(customFieldId);  },  // customFields with definitions  customFieldsWD() {    // get all definitions    const definitions = CustomFields.find({      boardIds: { $in: [this.boardId] },    }).fetch();    if (!definitions) {      return {};    }    // match right definition to each field    if (!this.customFields) return [];    const ret = this.customFields.map(customField => {      const definition = definitions.find(definition => {        return definition._id === customField._id;      });      if (!definition) {        return {};      }      //search for "True Value" which is for DropDowns other then the Value (which is the id)      let trueValue = customField.value;      if (        definition.settings.dropdownItems &&        definition.settings.dropdownItems.length > 0      ) {        for (let i = 0; i < definition.settings.dropdownItems.length; i++) {          if (definition.settings.dropdownItems[i]._id === customField.value) {            trueValue = definition.settings.dropdownItems[i].name;          }        }      }      return {        _id: customField._id,        value: customField.value,        trueValue,        definition,      };    });    // at linked cards custom fields definition is not found    ret.sort(      (a, b) =>        a.definition !== undefined &&        b.definition !== undefined &&        a.definition.name !== undefined &&        b.definition.name !== undefined &&        a.definition.name.localeCompare(b.definition.name),    );    return ret;  },  colorClass() {    if (this.color) return this.color;    return '';  },  absoluteUrl() {    const board = this.board();    return FlowRouter.url('card', {      boardId: board._id,      slug: board.slug,      cardId: this._id,    });  },  originRelativeUrl() {    const board = this.board();    return FlowRouter.path('card', {      boardId: board._id,      slug: board.slug,      cardId: this._id,    });  },  canBeRestored() {    const list = Lists.findOne({      _id: this.listId,    });    if (      !list.getWipLimit('soft') &&      list.getWipLimit('enabled') &&      list.getWipLimit('value') === list.cards().count()    ) {      return false;    }    return true;  },  parentCard() {    if (this.parentId === '') {      return null;    }    return Cards.findOne(this.parentId);  },  parentCardName() {    let result = '';    if (this.parentId !== '') {      const card = Cards.findOne(this.parentId);      if (card) {        result = card.title;      }    }    return result;  },  parentListId() {    const result = [];    let crtParentId = this.parentId;    while (crtParentId !== '') {      const crt = Cards.findOne(crtParentId);      if (crt === null || crt === undefined) {        // maybe it has been deleted        break;      }      if (crtParentId in result) {        // circular reference        break;      }      result.unshift(crtParentId);      crtParentId = crt.parentId;    }    return result;  },  parentList() {    const resultId = [];    const result = [];    let crtParentId = this.parentId;    while (crtParentId !== '') {      const crt = Cards.findOne(crtParentId);      if (crt === null || crt === undefined) {        // maybe it has been deleted        break;      }      if (crtParentId in resultId) {        // circular reference        break;      }      resultId.unshift(crtParentId);      result.unshift(crt);      crtParentId = crt.parentId;    }    return result;  },  parentString(sep) {    return this.parentList()      .map(function(elem) {        return elem.title;      })      .join(sep);  },  isTopLevel() {    return this.parentId === '';  },  isLinkedCard() {    return this.type === 'cardType-linkedCard';  },  isLinkedBoard() {    return this.type === 'cardType-linkedBoard';  },  isLinked() {    return this.isLinkedCard() || this.isLinkedBoard();  },  setDescription(description) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { description } });    } else if (this.isLinkedBoard()) {      return Boards.update({ _id: this.linkedId }, { $set: { description } });    } else {      return Cards.update({ _id: this._id }, { $set: { description } });    }  },  getDescription() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card && card.description) return card.description;      else return null;    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board && board.description) return board.description;      else return null;    } else if (this.description) {      return this.description;    } else {      return null;    }  },  getMembers() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.members;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.activeMembers().map(member => {          return member.userId;        });      }    } else {      return this.members;    }  },  getAssignees() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.assignees;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.activeMembers().map(assignee => {          return assignee.userId;        });      }    } else {      return this.assignees;    }  },  assignMember(memberId) {    if (this.isLinkedCard()) {      return Cards.update(        { _id: this.linkedId },        { $addToSet: { members: memberId } },      );    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      return board.addMember(memberId);    } else {      return Cards.update(        { _id: this._id },        { $addToSet: { members: memberId } },      );    }  },  assignAssignee(assigneeId) {    if (this.isLinkedCard()) {      return Cards.update(        { _id: this.linkedId },        { $addToSet: { assignees: assigneeId } },      );    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      return board.addAssignee(assigneeId);    } else {      return Cards.update(        { _id: this._id },        { $addToSet: { assignees: assigneeId } },      );    }  },  unassignMember(memberId) {    if (this.isLinkedCard()) {      return Cards.update(        { _id: this.linkedId },        { $pull: { members: memberId } },      );    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      return board.removeMember(memberId);    } else {      return Cards.update({ _id: this._id }, { $pull: { members: memberId } });    }  },  unassignAssignee(assigneeId) {    if (this.isLinkedCard()) {      return Cards.update(        { _id: this.linkedId },        { $pull: { assignees: assigneeId } },      );    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      return board.removeAssignee(assigneeId);    } else {      return Cards.update(        { _id: this._id },        { $pull: { assignees: assigneeId } },      );    }  },  toggleMember(memberId) {    if (this.getMembers() && this.getMembers().indexOf(memberId) > -1) {      return this.unassignMember(memberId);    } else {      return this.assignMember(memberId);    }  },  toggleAssignee(assigneeId) {    if (this.getAssignees() && this.getAssignees().indexOf(assigneeId) > -1) {      return this.unassignAssignee(assigneeId);    } else {      return this.assignAssignee(assigneeId);    }  },  getReceived() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.receivedAt;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.receivedAt;      }    } else {      return this.receivedAt;    }  },  setReceived(receivedAt) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { receivedAt } });    } else if (this.isLinkedBoard()) {      return Boards.update({ _id: this.linkedId }, { $set: { receivedAt } });    } else {      return Cards.update({ _id: this._id }, { $set: { receivedAt } });    }  },  getStart() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.startAt;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.startAt;      }    } else {      return this.startAt;    }  },  setStart(startAt) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { startAt } });    } else if (this.isLinkedBoard()) {      return Boards.update({ _id: this.linkedId }, { $set: { startAt } });    } else {      return Cards.update({ _id: this._id }, { $set: { startAt } });    }  },  getDue() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.dueAt;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.dueAt;      }    } else {      return this.dueAt;    }  },  setDue(dueAt) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { dueAt } });    } else if (this.isLinkedBoard()) {      return Boards.update({ _id: this.linkedId }, { $set: { dueAt } });    } else {      return Cards.update({ _id: this._id }, { $set: { dueAt } });    }  },  getEnd() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.endAt;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.endAt;      }    } else {      return this.endAt;    }  },  setEnd(endAt) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { endAt } });    } else if (this.isLinkedBoard()) {      return Boards.update({ _id: this.linkedId }, { $set: { endAt } });    } else {      return Cards.update({ _id: this._id }, { $set: { endAt } });    }  },  getIsOvertime() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.isOvertime;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.isOvertime;      }    } else {      return this.isOvertime;    }  },  setIsOvertime(isOvertime) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { isOvertime } });    } else if (this.isLinkedBoard()) {      return Boards.update({ _id: this.linkedId }, { $set: { isOvertime } });    } else {      return Cards.update({ _id: this._id }, { $set: { isOvertime } });    }  },  getSpentTime() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.spentTime;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.spentTime;      }    } else {      return this.spentTime;    }  },  setSpentTime(spentTime) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { spentTime } });    } else if (this.isLinkedBoard()) {      return Boards.update({ _id: this.linkedId }, { $set: { spentTime } });    } else {      return Cards.update({ _id: this._id }, { $set: { spentTime } });    }  },  getVoteQuestion() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else if (card && card.vote) {        return card.vote.question;      } else {        return null;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else if (board && board.vote) {        return board.vote.question;      } else {        return null;      }    } else if (this.vote) {      return this.vote.question;    } else {      return null;    }  },  getVotePublic() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else if (card && card.vote) {        return card.vote.public;      } else {        return null;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else if (board && board.vote) {        return board.vote.public;      } else {        return null;      }    } else if (this.vote) {      return this.vote.public;    } else {      return null;    }  },  getVoteEnd() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else if (card && card.vote) {        return card.vote.end;      } else {        return null;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else if (board && board.vote) {        return board.vote.end;      } else {        return null;      }    } else if (this.vote) {      return this.vote.end;    } else {      return null;    }  },  expiredVote() {    let end = this.getVoteEnd();    if (end) {      end = moment(end);      return end.isBefore(new Date());    }    return false;  },  voteMemberPositive() {    if (this.vote && this.vote.positive)      return Users.find({ _id: { $in: this.vote.positive } });    return [];  },  voteMemberNegative() {    if (this.vote && this.vote.negative)      return Users.find({ _id: { $in: this.vote.negative } });    return [];  },  voteState() {    const userId = Meteor.userId();    let state;    if (this.vote) {      if (this.vote.positive) {        state = _.contains(this.vote.positive, userId);        if (state === true) return true;      }      if (this.vote.negative) {        state = _.contains(this.vote.negative, userId);        if (state === true) return false;      }    }    return null;  },  getPokerQuestion() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else if (card && card.poker) {        return card.poker.question;      } else {        return null;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else if (board && board.poker) {        return board.poker.question;      } else {        return null;      }    } else if (this.poker) {      return this.poker.question;    } else {      return null;    }  },  getPokerEstimation() {    if (this.poker) {      return this.poker.estimation;    } else {      return null;    }  },  getPokerEnd() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else if (card && card.poker) {        return card.poker.end;      } else {        return null;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else if (board && board.poker) {        return board.poker.end;      } else {        return null;      }    } else if (this.poker) {      return this.poker.end;    } else {      return null;    }  },  expiredPoker() {    let end = this.getPokerEnd();    if (end) {      end = moment(end);      return end.isBefore(new Date());    }    return false;  },  pokerMemberOne() {    if (this.poker && this.poker.one)      return Users.find({ _id: { $in: this.poker.one } });    return [];  },  pokerMemberTwo() {    if (this.poker && this.poker.two)      return Users.find({ _id: { $in: this.poker.two } });    return [];  },  pokerMemberThree() {    if (this.poker && this.poker.three)      return Users.find({ _id: { $in: this.poker.three } });    return [];  },  pokerMemberFive() {    if (this.poker && this.poker.five)      return Users.find({ _id: { $in: this.poker.five } });    return [];  },  pokerMemberEight() {    if (this.poker && this.poker.eight)      return Users.find({ _id: { $in: this.poker.eight } });    return [];  },  pokerMemberThirteen() {    if (this.poker && this.poker.thirteen)      return Users.find({ _id: { $in: this.poker.thirteen } });    return [];  },  pokerMemberTwenty() {    if (this.poker && this.poker.twenty)      return Users.find({ _id: { $in: this.poker.twenty } });    return [];  },  pokerMemberForty() {    if (this.poker && this.poker.forty)      return Users.find({ _id: { $in: this.poker.forty } });    return [];  },  pokerMemberOneHundred() {    if (this.poker && this.poker.oneHundred)      return Users.find({ _id: { $in: this.poker.oneHundred } });    return [];  },  pokerMemberUnsure() {    if (this.poker && this.poker.unsure)      return Users.find({ _id: { $in: this.poker.unsure } });    return [];  },  pokerState() {    const userId = Meteor.userId();    let state;    if (this.poker) {      if (this.poker.one) {        state = _.contains(this.poker.one, userId);        if (state === true) {          return 'one';        }      }      if (this.poker.two) {        state = _.contains(this.poker.two, userId);        if (state === true) {          return 'two';        }      }      if (this.poker.three) {        state = _.contains(this.poker.three, userId);        if (state === true) {          return 'three';        }      }      if (this.poker.five) {        state = _.contains(this.poker.five, userId);        if (state === true) {          return 'five';        }      }      if (this.poker.eight) {        state = _.contains(this.poker.eight, userId);        if (state === true) {          return 'eight';        }      }      if (this.poker.thirteen) {        state = _.contains(this.poker.thirteen, userId);        if (state === true) {          return 'thirteen';        }      }      if (this.poker.twenty) {        state = _.contains(this.poker.twenty, userId);        if (state === true) {          return 'twenty';        }      }      if (this.poker.forty) {        state = _.contains(this.poker.forty, userId);        if (state === true) {          return 'forty';        }      }      if (this.poker.oneHundred) {        state = _.contains(this.poker.oneHundred, userId);        if (state === true) {          return 'oneHundred';        }      }      if (this.poker.unsure) {        state = _.contains(this.poker.unsure, userId);        if (state === true) {          return 'unsure';        }      }    }    return null;  },  getId() {    if (this.isLinked()) {      return this.linkedId;    } else {      return this._id;    }  },  getTitle() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.title;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.title;      }    } else if (this.title === undefined) {      return null;    } else {      return this.title;    }  },  getCardNumber() {    return this.cardNumber;  },  getBoardTitle() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      }      const board = Boards.findOne({ _id: card.boardId });      if (board === undefined) {        return null;      } else {        return board.title;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.title;      }    } else {      const board = Boards.findOne({ _id: this.boardId });      if (board === undefined) {        return null;      } else {        return board.title;      }    }  },  setTitle(title) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { title } });    } else if (this.isLinkedBoard()) {      return Boards.update({ _id: this.linkedId }, { $set: { title } });    } else {      return Cards.update({ _id: this._id }, { $set: { title } });    }  },  getArchived() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.archived;      }    } else if (this.isLinkedBoard()) {      const board = Boards.findOne({ _id: this.linkedId });      if (board === undefined) {        return null;      } else {        return board.archived;      }    } else {      return this.archived;    }  },  setRequestedBy(requestedBy) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { requestedBy } });    } else {      return Cards.update({ _id: this._id }, { $set: { requestedBy } });    }  },  getRequestedBy() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.requestedBy;      }    } else {      return this.requestedBy;    }  },  setAssignedBy(assignedBy) {    if (this.isLinkedCard()) {      return Cards.update({ _id: this.linkedId }, { $set: { assignedBy } });    } else {      return Cards.update({ _id: this._id }, { $set: { assignedBy } });    }  },  getAssignedBy() {    if (this.isLinkedCard()) {      const card = Cards.findOne({ _id: this.linkedId });      if (card === undefined) {        return null;      } else {        return card.assignedBy;      }    } else {      return this.assignedBy;    }  },  isTemplateCard() {    return this.type === 'template-card';  },  votePublic() {    if (this.vote) return this.vote.public;    return null;  },  voteAllowNonBoardMembers() {    if (this.vote) return this.vote.allowNonBoardMembers;    return null;  },  voteCountNegative() {    if (this.vote && this.vote.negative) return this.vote.negative.length;    return null;  },  voteCountPositive() {    if (this.vote && this.vote.positive) return this.vote.positive.length;    return null;  },  voteCount() {    return this.voteCountPositive() + this.voteCountNegative();  },  pokerAllowNonBoardMembers() {    if (this.poker) return this.poker.allowNonBoardMembers;    return null;  },  pokerCountOne() {    if (this.poker && this.poker.one) return this.poker.one.length;    return null;  },  pokerCountTwo() {    if (this.poker && this.poker.two) return this.poker.two.length;    return null;  },  pokerCountThree() {    if (this.poker && this.poker.three) return this.poker.three.length;    return null;  },  pokerCountFive() {    if (this.poker && this.poker.five) return this.poker.five.length;    return null;  },  pokerCountEight() {    if (this.poker && this.poker.eight) return this.poker.eight.length;    return null;  },  pokerCountThirteen() {    if (this.poker && this.poker.thirteen) return this.poker.thirteen.length;    return null;  },  pokerCountTwenty() {    if (this.poker && this.poker.twenty) return this.poker.twenty.length;    return null;  },  pokerCountForty() {    if (this.poker && this.poker.forty) return this.poker.forty.length;    return null;  },  pokerCountOneHundred() {    if (this.poker && this.poker.oneHundred) return this.poker.oneHundred.length;    return null;  },  pokerCountUnsure() {    if (this.poker && this.poker.unsure) return this.poker.unsure.length;    return null;  },  pokerCount() {    return (      this.pokerCountOne() +      this.pokerCountTwo() +      this.pokerCountThree() +      this.pokerCountFive() +      this.pokerCountEight() +      this.pokerCountThirteen() +      this.pokerCountTwenty() +      this.pokerCountForty() +      this.pokerCountOneHundred() +      this.pokerCountUnsure()    );  },  pokerWinner() {    const pokerListMaps = [];    let pokerWinnersListMap = [];    if (this.expiredPoker()) {      const one = { count: this.pokerCountOne(), pokerCard: 1 };      const two = { count: this.pokerCountTwo(), pokerCard: 2 };      const three = { count: this.pokerCountThree(), pokerCard: 3 };      const five = { count: this.pokerCountFive(), pokerCard: 5 };      const eight = { count: this.pokerCountEight(), pokerCard: 8 };      const thirteen = { count: this.pokerCountThirteen(), pokerCard: 13 };      const twenty = { count: this.pokerCountTwenty(), pokerCard: 20 };      const forty = { count: this.pokerCountForty(), pokerCard: 40 };      const oneHundred = { count: this.pokerCountOneHundred(), pokerCard: 100 };      const unsure = { count: this.pokerCountUnsure(), pokerCard: 'Unsure' };      pokerListMaps.push(one);      pokerListMaps.push(two);      pokerListMaps.push(three);      pokerListMaps.push(five);      pokerListMaps.push(eight);      pokerListMaps.push(thirteen);      pokerListMaps.push(twenty);      pokerListMaps.push(forty);      pokerListMaps.push(oneHundred);      pokerListMaps.push(unsure);      pokerListMaps.sort(function(a, b) {        return b.count - a.count;      });      const max = pokerListMaps[0].count;      pokerWinnersListMap = pokerListMaps.filter(task => task.count >= max);      pokerWinnersListMap.sort(function(a, b) {        return b.pokerCard - a.pokerCard;      });    }    return pokerWinnersListMap[0].pokerCard;  },});Cards.mutations({  applyToChildren(funct) {    Cards.find({      parentId: this._id,    }).forEach(card => {      funct(card);    });  },  archive() {    this.applyToChildren(card => {      return card.archive();    });    return {      $set: {        archived: true,        archivedAt: new Date(),      },    };  },  restore() {    this.applyToChildren(card => {      return card.restore();    });    return {      $set: {        archived: false,      },    };  },  moveToEndOfList({ listId } = {}) {    let swimlaneId = this.swimlaneId;    const boardId = this.boardId;    let sortIndex = 0;    // This should never happen, but there was a bug that was fixed in commit    // ea0239538a68e225c867411a4f3e0d27c158383.    if (!swimlaneId) {      const board = Boards.findOne(boardId);      swimlaneId = board.getDefaultSwimline()._id;    }    // Move the minicard to the end of the target list    let parentElementDom = $(`#swimlane-${this.swimlaneId}`).get(0);    if (!parentElementDom) parentElementDom = $(':root');    const lastCardDom = $(parentElementDom)      .find(`#js-list-${listId} .js-minicard:last`)      .get(0);    if (lastCardDom) sortIndex = Utils.calculateIndex(lastCardDom, null).base;    return this.moveOptionalArgs({      boardId,      swimlaneId,      listId,      sort: sortIndex,    });  },  moveOptionalArgs({ boardId, swimlaneId, listId, sort } = {}) {    boardId = boardId || this.boardId;    swimlaneId = swimlaneId || this.swimlaneId;    // This should never happen, but there was a bug that was fixed in commit    // ea0239538a68e225c867411a4f3e0d27c158383.    if (!swimlaneId) {      const board = Boards.findOne(boardId);      swimlaneId = board.getDefaultSwimline()._id;    }    listId = listId || this.listId;    if (sort === undefined || sort === null) sort = this.sort;    return this.move(boardId, swimlaneId, listId, sort);  },  move(boardId, swimlaneId, listId, sort = null) {    const mutatedFields = {      boardId,      swimlaneId,      listId,    };    if (sort !== null) {      mutatedFields.sort = sort;    }    // we must only copy the labels and custom fields if the target board    // differs from the source board    if (this.boardId !== boardId) {      // Get label names      const oldBoard = Boards.findOne(this.boardId);      const oldBoardLabels = oldBoard.labels;      const oldCardLabels = _.pluck(        _.filter(oldBoardLabels, label => {          return _.contains(this.labelIds, label._id);        }),        'name',      );      const newBoard = Boards.findOne(boardId);      const newBoardLabels = newBoard.labels;      const newCardLabelIds = _.pluck(        _.filter(newBoardLabels, label => {          return label.name && _.contains(oldCardLabels, label.name);        }),        '_id',      );      // assign the new card number from the target board      const newCardNumber = newBoard.getNextCardNumber();      Object.assign(mutatedFields, {        labelIds: newCardLabelIds,        cardNumber: newCardNumber      });      mutatedFields.customFields = this.mapCustomFieldsToBoard(newBoard._id);    }    Cards.update(this._id, {      $set: mutatedFields,    });  },  addLabel(labelId) {    return {      $addToSet: {        labelIds: labelId,      },    };  },  removeLabel(labelId) {    return {      $pull: {        labelIds: labelId,      },    };  },  toggleLabel(labelId) {    if (this.labelIds && this.labelIds.indexOf(labelId) > -1) {      return this.removeLabel(labelId);    } else {      return this.addLabel(labelId);    }  },  setColor(newColor) {    if (newColor === 'white') {      newColor = null;    }    return {      $set: {        color: newColor,      },    };  },  assignMember(memberId) {    return {      $addToSet: {        members: memberId,      },    };  },  assignAssignee(assigneeId) {    // If there is not any assignee, allow one assignee, not more.    /*    if (this.getAssignees().length === 0) {      return {        $addToSet: {          assignees: assigneeId,        },      };    */    // Allow more that one assignee:    // https://github.com/wekan/wekan/issues/3302    return {      $addToSet: {        assignees: assigneeId,      },    };    //} else {    //  return false,    //}  },  unassignMember(memberId) {    return {      $pull: {        members: memberId,      },    };  },  unassignAssignee(assigneeId) {    return {      $pull: {        assignees: assigneeId,      },    };  },  toggleMember(memberId) {    if (this.members && this.members.indexOf(memberId) > -1) {      return this.unassignMember(memberId);    } else {      return this.assignMember(memberId);    }  },  toggleAssignee(assigneeId) {    if (this.assignees && this.assignees.indexOf(assigneeId) > -1) {      return this.unassignAssignee(assigneeId);    } else {      return this.assignAssignee(assigneeId);    }  },  assignCustomField(customFieldId) {    return {      $addToSet: {        customFields: {          _id: customFieldId,          value: null,        },      },    };  },  unassignCustomField(customFieldId) {    return {      $pull: {        customFields: {          _id: customFieldId,        },      },    };  },  toggleCustomField(customFieldId) {    if (this.customFields && this.customFieldIndex(customFieldId) > -1) {      return this.unassignCustomField(customFieldId);    } else {      return this.assignCustomField(customFieldId);    }  },  setCustomField(customFieldId, value) {    // todo    const index = this.customFieldIndex(customFieldId);    if (index > -1) {      const update = {        $set: {},      };      update.$set[`customFields.${index}.value`] = value;      return update;    }    // TODO    // Ignatz 18.05.2018: Return null to silence ESLint. No Idea if that is correct    return null;  },  setCover(coverId) {    return {      $set: {        coverId,      },    };  },  unsetCover() {    return {      $unset: {        coverId: '',      },    };  },  //setReceived(receivedAt) {  //  return {  //    $set: {  //      receivedAt,  //    },  //  };  //},  unsetReceived() {    return {      $unset: {        receivedAt: '',      },    };  },  //setStart(startAt) {  //  return {  //    $set: {  //      startAt,  //    },  //  };  //},  unsetStart() {    return {      $unset: {        startAt: '',      },    };  },  //setDue(dueAt) {  //  return {  //    $set: {  //      dueAt,  //    },  //  };  //},  unsetDue() {    return {      $unset: {        dueAt: '',      },    };  },  //setEnd(endAt) {  //  return {  //    $set: {  //      endAt,  //    },  //  };  //},  unsetEnd() {    return {      $unset: {        endAt: '',      },    };  },  setOvertime(isOvertime) {    return {      $set: {        isOvertime,      },    };  },  setSpentTime(spentTime) {    return {      $set: {        spentTime,      },    };  },  unsetSpentTime() {    return {      $unset: {        spentTime: '',        isOvertime: false,      },    };  },  setParentId(parentId) {    return {      $set: {        parentId,      },    };  },  setVoteQuestion(question, publicVote, allowNonBoardMembers) {    return {      $set: {        vote: {          question,          public: publicVote,          allowNonBoardMembers,          positive: [],          negative: [],        },      },    };  },  unsetVote() {    return {      $unset: {        vote: '',      },    };  },  setVoteEnd(end) {    return {      $set: { 'vote.end': end },    };  },  unsetVoteEnd() {    return {      $unset: { 'vote.end': '' },    };  },  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,          },        };    }  },  setPokerQuestion(question, allowNonBoardMembers) {    return {      $set: {        poker: {          question,          allowNonBoardMembers,          one: [],          two: [],          three: [],          five: [],          eight: [],          thirteen: [],          twenty: [],          forty: [],          oneHundred: [],          unsure: [],        },      },    };  },  setPokerEstimation(estimation) {    return {      $set: { 'poker.estimation': estimation },    };  },  unsetPokerEstimation() {    return {      $unset: { 'poker.estimation': '' },    };  },  unsetPoker() {    return {      $unset: {        poker: '',      },    };  },  setPokerEnd(end) {    return {      $set: { 'poker.end': end },    };  },  unsetPokerEnd() {    return {      $unset: { 'poker.end': '' },    };  },  setPoker(userId, state) {    switch (state) {      case 'one':        // poker one        return {          $pull: {            'poker.two': userId,            'poker.three': userId,            'poker.five': userId,            'poker.eight': userId,            'poker.thirteen': userId,            'poker.twenty': userId,            'poker.forty': userId,            'poker.oneHundred': userId,            'poker.unsure': userId,          },          $addToSet: {            'poker.one': userId,          },        };      case 'two':        // poker two        return {          $pull: {            'poker.one': userId,            'poker.three': userId,            'poker.five': userId,            'poker.eight': userId,            'poker.thirteen': userId,            'poker.twenty': userId,            'poker.forty': userId,            'poker.oneHundred': userId,            'poker.unsure': userId,          },          $addToSet: {            'poker.two': userId,          },        };      case 'three':        // poker three        return {          $pull: {            'poker.one': userId,            'poker.two': userId,            'poker.five': userId,            'poker.eight': userId,            'poker.thirteen': userId,            'poker.twenty': userId,            'poker.forty': userId,            'poker.oneHundred': userId,            'poker.unsure': userId,          },          $addToSet: {            'poker.three': userId,          },        };      case 'five':        // poker five        return {          $pull: {            'poker.one': userId,            'poker.two': userId,            'poker.three': userId,            'poker.eight': userId,            'poker.thirteen': userId,            'poker.twenty': userId,            'poker.forty': userId,            'poker.oneHundred': userId,            'poker.unsure': userId,          },          $addToSet: {            'poker.five': userId,          },        };      case 'eight':        // poker eight        return {          $pull: {            'poker.one': userId,            'poker.two': userId,            'poker.three': userId,            'poker.five': userId,            'poker.thirteen': userId,            'poker.twenty': userId,            'poker.forty': userId,            'poker.oneHundred': userId,            'poker.unsure': userId,          },          $addToSet: {            'poker.eight': userId,          },        };      case 'thirteen':        // poker thirteen        return {          $pull: {            'poker.one': userId,            'poker.two': userId,            'poker.three': userId,            'poker.five': userId,            'poker.eight': userId,            'poker.twenty': userId,            'poker.forty': userId,            'poker.oneHundred': userId,            'poker.unsure': userId,          },          $addToSet: {            'poker.thirteen': userId,          },        };      case 'twenty':        // poker twenty        return {          $pull: {            'poker.one': userId,            'poker.two': userId,            'poker.three': userId,            'poker.five': userId,            'poker.eight': userId,            'poker.thirteen': userId,            'poker.forty': userId,            'poker.oneHundred': userId,            'poker.unsure': userId,          },          $addToSet: {            'poker.twenty': userId,          },        };      case 'forty':        // poker forty        return {          $pull: {            'poker.one': userId,            'poker.two': userId,            'poker.three': userId,            'poker.five': userId,            'poker.eight': userId,            'poker.thirteen': userId,            'poker.twenty': userId,            'poker.oneHundred': userId,            'poker.unsure': userId,          },          $addToSet: {            'poker.forty': userId,          },        };      case 'oneHundred':        // poker one hundred        return {          $pull: {            'poker.one': userId,            'poker.two': userId,            'poker.three': userId,            'poker.five': userId,            'poker.eight': userId,            'poker.thirteen': userId,            'poker.twenty': userId,            'poker.forty': userId,            'poker.unsure': userId,          },          $addToSet: {            'poker.oneHundred': userId,          },        };      case 'unsure':        // poker unsure        return {          $pull: {            'poker.one': userId,            'poker.two': userId,            'poker.three': userId,            'poker.five': userId,            'poker.eight': userId,            'poker.thirteen': userId,            'poker.twenty': userId,            'poker.forty': userId,            'poker.oneHundred': userId,          },          $addToSet: {            'poker.unsure': userId,          },        };      default:        // Remove pokers        return {          $pull: {            'poker.one': userId,            'poker.two': userId,            'poker.three': userId,            'poker.five': userId,            'poker.eight': userId,            'poker.thirteen': userId,            'poker.twenty': userId,            'poker.forty': userId,            'poker.oneHundred': userId,            'poker.unsure': userId,          },        };    }  },  replayPoker() {    return {      $set: {        'poker.one': [],        'poker.two': [],        'poker.three': [],        'poker.five': [],        'poker.eight': [],        'poker.thirteen': [],        'poker.twelve': [],        'poker.forty': [],        'poker.oneHundred': [],        'poker.unsure': [],      },    };  },});//FUNCTIONS FOR creation of Activitiesfunction updateActivities(doc, fieldNames, modifier) {  if (_.contains(fieldNames, 'labelIds') && _.contains(fieldNames, 'boardId')) {    Activities.find({      activityType: 'addedLabel',      cardId: doc._id,    }).forEach(a => {      const lidx = doc.labelIds.indexOf(a.labelId);      if (lidx !== -1 && modifier.$set.labelIds.length > lidx) {        Activities.update(a._id, {          $set: {            labelId: modifier.$set.labelIds[doc.labelIds.indexOf(a.labelId)],            boardId: modifier.$set.boardId,          },        });      } else {        Activities.remove(a._id);      }    });  } else if (_.contains(fieldNames, 'boardId')) {    Activities.remove({      activityType: 'addedLabel',      cardId: doc._id,    });  }}function cardMove(  userId,  doc,  fieldNames,  oldListId,  oldSwimlaneId,  oldBoardId,) {  if (_.contains(fieldNames, 'boardId') && doc.boardId !== oldBoardId) {    Activities.insert({      userId,      activityType: 'moveCardBoard',      boardName: Boards.findOne(doc.boardId).title,      boardId: doc.boardId,      oldBoardId,      oldBoardName: Boards.findOne(oldBoardId).title,      cardId: doc._id,      swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,      swimlaneId: doc.swimlaneId,      oldSwimlaneId,    });  } else if (    (_.contains(fieldNames, 'listId') && doc.listId !== oldListId) ||    (_.contains(fieldNames, 'swimlaneId') && doc.swimlaneId !== oldSwimlaneId)  ) {    Activities.insert({      userId,      oldListId,      activityType: 'moveCard',      listName: Lists.findOne(doc.listId).title,      listId: doc.listId,      boardId: doc.boardId,      cardId: doc._id,      cardTitle: doc.title,      swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,      swimlaneId: doc.swimlaneId,      oldSwimlaneId,    });  }}function cardState(userId, doc, fieldNames) {  if (_.contains(fieldNames, 'archived')) {    if (doc.archived) {      Activities.insert({        userId,        activityType: 'archivedCard',        listName: Lists.findOne(doc.listId).title,        boardId: doc.boardId,        listId: doc.listId,        cardId: doc._id,        swimlaneId: doc.swimlaneId,      });    } else {      Activities.insert({        userId,        activityType: 'restoredCard',        boardId: doc.boardId,        listName: Lists.findOne(doc.listId).title,        listId: doc.listId,        cardId: doc._id,        swimlaneId: doc.swimlaneId,      });    }  }}function cardMembers(userId, doc, fieldNames, modifier) {  if (!_.contains(fieldNames, 'members')) return;  let memberId;  // Say hello to the new member  if (modifier.$addToSet && modifier.$addToSet.members) {    memberId = modifier.$addToSet.members;    const username = Users.findOne(memberId).username;    if (!_.contains(doc.members, memberId)) {      Activities.insert({        userId,        username,        activityType: 'joinMember',        boardId: doc.boardId,        cardId: doc._id,        memberId,        listId: doc.listId,        swimlaneId: doc.swimlaneId,      });    }  }  // Say goodbye to the former member  if (modifier.$pull && modifier.$pull.members) {    memberId = modifier.$pull.members;    const username = Users.findOne(memberId).username;    // Check that the former member is member of the card    if (_.contains(doc.members, memberId)) {      Activities.insert({        userId,        username,        activityType: 'unjoinMember',        boardId: doc.boardId,        cardId: doc._id,        memberId,        listId: doc.listId,        swimlaneId: doc.swimlaneId,      });    }  }}function cardAssignees(userId, doc, fieldNames, modifier) {  if (!_.contains(fieldNames, 'assignees')) return;  let assigneeId;  // Say hello to the new assignee  if (modifier.$addToSet && modifier.$addToSet.assignees) {    assigneeId = modifier.$addToSet.assignees;    const username = Users.findOne(assigneeId).username;    if (!_.contains(doc.assignees, assigneeId)) {      Activities.insert({        userId,        username,        activityType: 'joinAssignee',        boardId: doc.boardId,        cardId: doc._id,        assigneeId,        listId: doc.listId,        swimlaneId: doc.swimlaneId,      });    }  }  // Say goodbye to the former assignee  if (modifier.$pull && modifier.$pull.assignees) {    assigneeId = modifier.$pull.assignees;    const username = Users.findOne(assigneeId).username;    // Check that the former assignee is assignee of the card    if (_.contains(doc.assignees, assigneeId)) {      Activities.insert({        userId,        username,        activityType: 'unjoinAssignee',        boardId: doc.boardId,        cardId: doc._id,        assigneeId,        listId: doc.listId,        swimlaneId: doc.swimlaneId,      });    }  }}function cardLabels(userId, doc, fieldNames, modifier) {  if (!_.contains(fieldNames, 'labelIds')) return;  let labelId;  // Say hello to the new label  if (modifier.$addToSet && modifier.$addToSet.labelIds) {    labelId = modifier.$addToSet.labelIds;    if (!_.contains(doc.labelIds, labelId)) {      const act = {        userId,        labelId,        activityType: 'addedLabel',        boardId: doc.boardId,        cardId: doc._id,        listId: doc.listId,        swimlaneId: doc.swimlaneId,      };      Activities.insert(act);    }  }  // Say goodbye to the label  if (modifier.$pull && modifier.$pull.labelIds) {    labelId = modifier.$pull.labelIds;    // Check that the former member is member of the card    if (_.contains(doc.labelIds, labelId)) {      Activities.insert({        userId,        labelId,        activityType: 'removedLabel',        boardId: doc.boardId,        cardId: doc._id,        listId: doc.listId,        swimlaneId: doc.swimlaneId,      });    }  }}function cardCustomFields(userId, doc, fieldNames, modifier) {  if (!_.contains(fieldNames, 'customFields')) return;  // Say hello to the new customField value  if (modifier.$set) {    _.each(modifier.$set, (value, key) => {      if (key.startsWith('customFields')) {        const dotNotation = key.split('.');        // only individual changes are registered        if (dotNotation.length > 1) {          const customFieldId = doc.customFields[dotNotation[1]]._id;          const act = {            userId,            customFieldId,            value,            activityType: 'setCustomField',            boardId: doc.boardId,            cardId: doc._id,            listId: doc.listId,            swimlaneId: doc.swimlaneId,          };          Activities.insert(act);        }      }    });  }  // Say goodbye to the former customField value  if (modifier.$unset) {    _.each(modifier.$unset, (value, key) => {      if (key.startsWith('customFields')) {        const dotNotation = key.split('.');        // only individual changes are registered        if (dotNotation.length > 1) {          const customFieldId = doc.customFields[dotNotation[1]]._id;          const act = {            userId,            customFieldId,            activityType: 'unsetCustomField',            boardId: doc.boardId,            cardId: doc._id,          };          Activities.insert(act);        }      }    });  }}function cardCreation(userId, doc) {  Activities.insert({    userId,    activityType: 'createCard',    boardId: doc.boardId,    listName: Lists.findOne(doc.listId).title,    listId: doc.listId,    cardId: doc._id,    cardTitle: doc.title,    swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,    swimlaneId: doc.swimlaneId,  });}function cardRemover(userId, doc) {  ChecklistItems.remove({    cardId: doc._id,  });  Checklists.remove({    cardId: doc._id,  });  Cards.remove({    parentId: doc._id,  });  CardComments.remove({    cardId: doc._id,  });  Attachments.remove({    cardId: doc._id,  });}const findDueCards = days => {  const seekDue = ($from, $to, activityType) => {    Cards.find({      archived: false,      dueAt: { $gte: $from, $lt: $to },    }).forEach(card => {      const username = Users.findOne(card.userId).username;      const activity = {        userId: card.userId,        username,        activityType,        boardId: card.boardId,        cardId: card._id,        cardTitle: card.title,        listId: card.listId,        timeValue: card.dueAt,        swimlaneId: card.swimlaneId,      };      Activities.insert(activity);    });  };  const now = new Date(),    aday = 3600 * 24 * 1e3,    then = day => new Date(now.setHours(0, 0, 0, 0) + day * aday);  if (!days) return;  if (!days.map) days = [days];  days.map(day => {    let args = [];    if (day === 0) {      args = [then(0), then(1), 'duenow'];    } else if (day > 0) {      args = [then(1), then(day), 'almostdue'];    } else {      args = [then(day), now, 'pastdue'];    }    seekDue(...args);  });};const addCronJob = _.debounce(  Meteor.bindEnvironment(function findDueCardsDebounced() {    const envValue = process.env.NOTIFY_DUE_DAYS_BEFORE_AND_AFTER;    if (!envValue) {      return;    }    const notifydays = envValue      .split(',')      .map(value => {        const iValue = parseInt(value, 10);        if (!(iValue > 0 && iValue < 15)) {          // notifying due is disabled          return false;        } else {          return iValue;        }      })      .filter(Boolean);    const notifyitvl = process.env.NOTIFY_DUE_AT_HOUR_OF_DAY; //passed in the itvl has to be a number standing for the hour of current time    const defaultitvl = 8; // default every morning at 8am, if the passed env variable has parsing error use default    const itvl = parseInt(notifyitvl, 10) || defaultitvl;    const scheduler = (job => () => {      const now = new Date();      const hour = 3600 * 1e3;      if (now.getHours() === itvl) {        if (typeof job === 'function') {          job();        }      }      Meteor.setTimeout(scheduler, hour);    })(() => {      findDueCards(notifydays);    });    scheduler();  }),  500,);if (Meteor.isServer) {  // Cards are often fetched within a board, so we create an index to make these  // queries more efficient.  Meteor.startup(() => {    Cards._collection._ensureIndex({ modifiedAt: -1 });    Cards._collection._ensureIndex({ boardId: 1, createdAt: -1 });    // https://github.com/wekan/wekan/issues/1863    // Swimlane added a new field in the cards collection of mongodb named parentId.    // When loading a board, mongodb is searching for every cards, the id of the parent (in the swinglanes collection).    // With a huge database, this result in a very slow app and high CPU on the mongodb side.    // To correct it, add Index to parentId:    Cards._collection._ensureIndex({ parentId: 1 });    // let notifydays = parseInt(process.env.NOTIFY_DUE_DAYS_BEFORE_AND_AFTER) || 2; // default as 2 days b4 and after    // let notifyitvl = parseInt(process.env.NOTIFY_DUE_AT_HOUR_OF_DAY) || 3600 * 24 * 1e3; // default interval as one day    // Meteor.call("findDueCards",notifydays,notifyitvl);    Meteor.defer(() => {      addCronJob();    });  });  Cards.after.insert((userId, doc) => {    cardCreation(userId, doc);  });  // New activity for card (un)archivage  Cards.after.update((userId, doc, fieldNames) => {    cardState(userId, doc, fieldNames);  });  //New activity for card moves  Cards.after.update(function(userId, doc, fieldNames) {    const oldListId = this.previous.listId;    const oldSwimlaneId = this.previous.swimlaneId;    const oldBoardId = this.previous.boardId;    cardMove(userId, doc, fieldNames, oldListId, oldSwimlaneId, oldBoardId);  });  // Add a new activity if we add or remove a member to the card  Cards.before.update((userId, doc, fieldNames, modifier) => {    cardMembers(userId, doc, fieldNames, modifier);    updateActivities(doc, fieldNames, modifier);  });  // Add a new activity if we add or remove a assignee to the card  Cards.before.update((userId, doc, fieldNames, modifier) => {    cardAssignees(userId, doc, fieldNames, modifier);    updateActivities(doc, fieldNames, modifier);  });  // Add a new activity if we add or remove a label to the card  Cards.before.update((userId, doc, fieldNames, modifier) => {    cardLabels(userId, doc, fieldNames, modifier);  });  // Add a new activity if we edit a custom field  Cards.before.update((userId, doc, fieldNames, modifier) => {    cardCustomFields(userId, doc, fieldNames, modifier);  });  // Add a new activity if modify time related field like dueAt startAt etc  Cards.before.update((userId, doc, fieldNames, modifier) => {    const dla = 'dateLastActivity';    const fields = fieldNames.filter(name => name !== dla);    const timingaction = ['receivedAt', 'dueAt', 'startAt', 'endAt'];    const action = fields[0];    if (fields.length > 0 && _.contains(timingaction, action)) {      // add activities for user change these attributes      const value = modifier.$set[action];      const oldvalue = doc[action] || '';      const activityType = `a-${action}`;      const card = Cards.findOne(doc._id);      const list = card.list();      if (list) {        // 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 = moment()          .subtract(1, 'year')          .toISOString();        const boardId = list.boardId;        Lists.direct.update(          {            _id: list._id,          },          {            $set: {              modifiedAt,              boardId,            },          },        );      }      const username = Users.findOne(userId).username;      const activity = {        userId,        username,        activityType,        boardId: doc.boardId,        cardId: doc._id,        cardTitle: doc.title,        timeKey: action,        timeValue: value,        timeOldValue: oldvalue,        listId: card.listId,        swimlaneId: card.swimlaneId,      };      Activities.insert(activity);    }  });  // Remove all activities associated with a card if we remove the card  // Remove also card_comments / checklists / attachments  Cards.before.remove((userId, doc) => {    cardRemover(userId, doc);  });}//SWIMLANES REST APIif (Meteor.isServer) {  /**   * @operation get_swimlane_cards   * @summary get all cards attached to a swimlane   *   * @param {string} boardId the board ID   * @param {string} swimlaneId the swimlane ID   * @return_type [{_id: string,   *                title: string,   *                description: string,   *                listId: string}]   */  JsonRoutes.add(    'GET',    '/api/boards/:boardId/swimlanes/:swimlaneId/cards',    function(req, res) {      Authentication.checkUserId(req.userId);      const paramBoardId = req.params.boardId;      const paramSwimlaneId = req.params.swimlaneId;      JsonRoutes.sendResult(res, {        code: 200,        data: Cards.find({          boardId: paramBoardId,          swimlaneId: paramSwimlaneId,          archived: false,        }).map(function(doc) {          return {            _id: doc._id,            title: doc.title,            description: doc.description,            listId: doc.listId,            receivedAt: doc.receivedAt,            startAt: doc.startAt,            dueAt: doc.dueAt,            endAt: doc.endAt,            assignees: doc.assignees,          };        }),      });    },  );}//LISTS REST APIif (Meteor.isServer) {  /**   * @operation get_all_cards   * @summary Get all Cards attached to a List   *   * @param {string} boardId the board ID   * @param {string} listId the list ID   * @return_type [{_id: string,   *                title: string,   *                description: string}]   */  JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards', function(    req,    res,  ) {    Authentication.checkUserId(req.userId);    const paramBoardId = req.params.boardId;    const paramListId = req.params.listId;    JsonRoutes.sendResult(res, {      code: 200,      data: Cards.find({        boardId: paramBoardId,        listId: paramListId,        archived: false,      }).map(function(doc) {        return {          _id: doc._id,          title: doc.title,          description: doc.description,          receivedAt: doc.receivedAt,          startAt: doc.startAt,          dueAt: doc.dueAt,          endAt: doc.endAt,          assignees: doc.assignees,        };      }),    });  });  /**   * @operation get_card   * @summary Get a Card   *   * @param {string} boardId the board ID   * @param {string} listId the list ID of the card   * @param {string} cardId the card ID   * @return_type Cards   */  JsonRoutes.add(    'GET',    '/api/boards/:boardId/lists/:listId/cards/:cardId',    function(req, res) {      Authentication.checkUserId(req.userId);      const paramBoardId = req.params.boardId;      const paramListId = req.params.listId;      const paramCardId = req.params.cardId;      JsonRoutes.sendResult(res, {        code: 200,        data: Cards.findOne({          _id: paramCardId,          listId: paramListId,          boardId: paramBoardId,          archived: false,        }),      });    },  );  /**   * @operation new_card   * @summary Create a new Card   *   * @param {string} boardId the board ID of the new card   * @param {string} listId the list ID of the new card   * @param {string} authorID the user ID of the person owning the card   * @param {string} parentId the parent ID of the new card   * @param {string} title the title of the new card   * @param {string} description the description of the new card   * @param {string} swimlaneId the swimlane ID of the new card   * @param {string} [members] the member IDs list of the new card   * @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(    req,    res,  ) {    // Check user is logged in    Authentication.checkLoggedIn(req.userId);    const paramBoardId = req.params.boardId;    // Check user has permission to add card to the board    const board = Boards.findOne({      _id: paramBoardId,    });    const addPermission = allowIsBoardMemberCommentOnly(req.userId, board);    Authentication.checkAdminOrCondition(req.userId, addPermission);    const paramListId = req.params.listId;    const paramParentId = req.params.parentId;    const nextCardNumber = board.getNextCardNumber();    const currentCards = Cards.find(      {        listId: paramListId,        archived: false,      },      { sort: ['sort'] },    );    const check = Users.findOne({      _id: req.body.authorId,    });    const members = req.body.members;    const assignees = req.body.assignees;    if (typeof check !== 'undefined') {      const id = Cards.direct.insert({        title: req.body.title,        boardId: paramBoardId,        listId: paramListId,        parentId: paramParentId,        description: req.body.description,        userId: req.body.authorId,        swimlaneId: req.body.swimlaneId,        sort: currentCards.count(),        cardNumber: nextCardNumber,        members,        assignees,      });      JsonRoutes.sendResult(res, {        code: 200,        data: {          _id: id,        },      });      const card = Cards.findOne({        _id: id,      });      cardCreation(req.body.authorId, card);    } else {      JsonRoutes.sendResult(res, {        code: 401,      });    }  });  /*   * Note for the JSDoc:   * 'list' will be interpreted as the path parameter   * 'listID' will be interpreted as the body parameter   */  /**   * @operation edit_card   * @summary Edit Fields in a Card   *   * @description Edit a card   *   * The color has to be chosen between `white`, `green`, `yellow`, `orange`,   * `red`, `purple`, `blue`, `sky`, `lime`, `pink`, `black`, `silver`,   * `peachpuff`, `crimson`, `plum`, `darkgreen`, `slateblue`, `magenta`,   * `gold`, `navy`, `gray`, `saddlebrown`, `paleturquoise`, `mistyrose`,   * `indigo`:   *   * <img src="/card-colors.png" width="40%" alt="Wekan card colors" />   *   * Note: setting the color to white has the same effect than removing it.   *   * @param {string} boardId the board ID of the card   * @param {string} list the list ID of the card   * @param {string} cardId the ID of the card   * @param {string} [title] the new title of the card   * @param {string} [sort] the new sort value of the card   * @param {string} [listId] the new list ID of the card (move operation)   * @param {string} [description] the new description of the card   * @param {string} [authorId] change the owner of the card   * @param {string} [parentId] change the parent of the card   * @param {string} [labelIds] the new list of label IDs attached to the card   * @param {string} [swimlaneId] the new swimlane ID of the card   * @param {string} [members] the new list of member IDs attached to the card   * @param {string} [assignees] the array of maximum one ID of assignee attached to the card   * @param {string} [requestedBy] the new requestedBy field of the card   * @param {string} [assignedBy] the new assignedBy field of the card   * @param {string} [receivedAt] the new receivedAt field of the card   * @param {string} [assignBy] the new assignBy field of the card   * @param {string} [startAt] the new startAt field of the card   * @param {string} [dueAt] the new dueAt field of the card   * @param {string} [endAt] the new endAt field of the card   * @param {string} [spentTime] the new spentTime field of the card   * @param {boolean} [isOverTime] the new isOverTime field of the card   * @param {string} [customFields] the new customFields value of the card   * @param {string} [color] the new color of the card   * @param {Object} [vote] the vote object   * @param {string} vote.question the vote question   * @param {boolean} vote.public show who voted what   * @param {boolean} vote.allowNonBoardMembers allow all logged in users to vote?   * @param {Object} [poker] the poker object   * @param {string} poker.question the vote question   * @param {boolean} poker.allowNonBoardMembers allow all logged in users to vote?   * @return_type {_id: string}   */  JsonRoutes.add(    'PUT',    '/api/boards/:boardId/lists/:listId/cards/:cardId',    function(req, res) {      Authentication.checkUserId(req.userId);      const paramBoardId = req.params.boardId;      const paramCardId = req.params.cardId;      const paramListId = req.params.listId;      if (req.body.hasOwnProperty('title')) {        const newTitle = req.body.title;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          {            $set: {              title: newTitle,            },          },        );      }      if (req.body.hasOwnProperty('sort')) {        const newSort = req.body.sort;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          {            $set: {              sort: newSort,            },          },        );      }      if (req.body.hasOwnProperty('parentId')) {        const newParentId = req.body.parentId;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          {            $set: {              parentId: newParentId,            },          },        );      }      if (req.body.hasOwnProperty('description')) {        const newDescription = req.body.description;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          {            $set: {              description: newDescription,            },          },        );      }      if (req.body.hasOwnProperty('color')) {        const newColor = req.body.color;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { color: newColor } },        );      }      if (req.body.hasOwnProperty('vote')) {        const newVote = req.body.vote;        newVote.positive = [];        newVote.negative = [];        if (!newVote.hasOwnProperty('public')) newVote.public = false;        if (!newVote.hasOwnProperty('allowNonBoardMembers'))          newVote.allowNonBoardMembers = false;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { vote: newVote } },        );      }      if (req.body.hasOwnProperty('poker')) {        const newPoker = req.body.poker;        newPoker.one = [];        newPoker.two = [];        newPoker.three = [];        newPoker.five = [];        newPoker.eight = [];        newPoker.thirteen = [];        newPoker.twenty = [];        newPoker.forty = [];        newPoker.oneHundred = [];        newPoker.unsure = [];        if (!newPoker.hasOwnProperty('allowNonBoardMembers'))          newPoker.allowNonBoardMembers = false;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { poker: newPoker } },        );      }      if (req.body.hasOwnProperty('labelIds')) {        let newlabelIds = req.body.labelIds;        if (_.isString(newlabelIds)) {          if (newlabelIds === '') {            newlabelIds = null;          } else {            newlabelIds = [newlabelIds];          }        }        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          {            $set: {              labelIds: newlabelIds,            },          },        );      }      if (req.body.hasOwnProperty('requestedBy')) {        const newrequestedBy = req.body.requestedBy;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { requestedBy: newrequestedBy } },        );      }      if (req.body.hasOwnProperty('assignedBy')) {        const newassignedBy = req.body.assignedBy;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { assignedBy: newassignedBy } },        );      }      if (req.body.hasOwnProperty('receivedAt')) {        const newreceivedAt = req.body.receivedAt;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { receivedAt: newreceivedAt } },        );      }      if (req.body.hasOwnProperty('startAt')) {        const newstartAt = req.body.startAt;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { startAt: newstartAt } },        );      }      if (req.body.hasOwnProperty('dueAt')) {        const newdueAt = req.body.dueAt;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { dueAt: newdueAt } },        );      }      if (req.body.hasOwnProperty('endAt')) {        const newendAt = req.body.endAt;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { endAt: newendAt } },        );      }      if (req.body.hasOwnProperty('spentTime')) {        const newspentTime = req.body.spentTime;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { spentTime: newspentTime } },        );      }      if (req.body.hasOwnProperty('isOverTime')) {        const newisOverTime = req.body.isOverTime;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { isOverTime: newisOverTime } },        );      }      if (req.body.hasOwnProperty('customFields')) {        const newcustomFields = req.body.customFields;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { customFields: newcustomFields } },        );      }      if (req.body.hasOwnProperty('members')) {        let newmembers = req.body.members;        if (_.isString(newmembers)) {          if (newmembers === '') {            newmembers = null;          } else {            newmembers = [newmembers];          }        }        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { members: newmembers } },        );      }      if (req.body.hasOwnProperty('assignees')) {        let newassignees = req.body.assignees;        if (_.isString(newassignees)) {          if (newassignees === '') {            newassignees = null;          } else {            newassignees = [newassignees];          }        }        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { assignees: newassignees } },        );      }      if (req.body.hasOwnProperty('swimlaneId')) {        const newParamSwimlaneId = req.body.swimlaneId;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          { $set: { swimlaneId: newParamSwimlaneId } },        );      }      if (req.body.hasOwnProperty('listId')) {        const newParamListId = req.body.listId;        Cards.direct.update(          {            _id: paramCardId,            listId: paramListId,            boardId: paramBoardId,            archived: false,          },          {            $set: {              listId: newParamListId,            },          },        );        const card = Cards.findOne({          _id: paramCardId,        });        cardMove(          req.body.authorId,          card,          {            fieldName: 'listId',          },          paramListId,        );      }      JsonRoutes.sendResult(res, {        code: 200,        data: {          _id: paramCardId,        },      });    },  );  /**   * @operation delete_card   * @summary Delete a card from a board   *   * @description This operation **deletes** a card, and therefore the card   * is not put in the recycle bin.   *   * @param {string} boardId the board ID of the card   * @param {string} list the list ID of the card   * @param {string} cardId the ID of the card   * @return_type {_id: string}   */  JsonRoutes.add(    'DELETE',    '/api/boards/:boardId/lists/:listId/cards/:cardId',    function(req, res) {      Authentication.checkUserId(req.userId);      const paramBoardId = req.params.boardId;      const paramListId = req.params.listId;      const paramCardId = req.params.cardId;      const card = Cards.findOne({        _id: paramCardId,      });      Cards.direct.remove({        _id: paramCardId,        listId: paramListId,        boardId: paramBoardId,      });      cardRemover(req.body.authorId, card);      JsonRoutes.sendResult(res, {        code: 200,        data: {          _id: paramCardId,        },      });    },  );  /**   * @operation get_cards_by_custom_field   * @summary Get all Cards that matchs a value of a specific custom field   *   * @param {string} boardId the board ID   * @param {string} customFieldId the list ID   * @param {string} customFieldValue the value to look for   * @return_type [{_id: string,   *                title: string,   *                description: string,   *                listId: string,   *                swinlaneId: string}]   */  JsonRoutes.add(    'GET',    '/api/boards/:boardId/cardsByCustomField/:customFieldId/:customFieldValue',    function(req, res) {      Authentication.checkUserId(req.userId);      const paramBoardId = req.params.boardId;      const paramCustomFieldId = req.params.customFieldId;      const paramCustomFieldValue = req.params.customFieldValue;      JsonRoutes.sendResult(res, {        code: 200,        data: Cards.find({          boardId: paramBoardId,          customFields: {            $elemMatch: {              _id: paramCustomFieldId,              value: paramCustomFieldValue,            },          },          archived: false,        }).fetch(),      });    },  );}export default Cards;
 |