cards.js 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748
  1. import {
  2. ALLOWED_COLORS,
  3. TYPE_CARD,
  4. TYPE_LINKED_BOARD,
  5. TYPE_LINKED_CARD,
  6. } from '../config/const';
  7. Cards = new Mongo.Collection('cards');
  8. // XXX To improve pub/sub performances a card document should include a
  9. // de-normalized number of comments so we don't have to publish the whole list
  10. // of comments just to display the number of them in the board view.
  11. Cards.attachSchema(
  12. new SimpleSchema({
  13. title: {
  14. /**
  15. * the title of the card
  16. */
  17. type: String,
  18. optional: true,
  19. defaultValue: '',
  20. },
  21. archived: {
  22. /**
  23. * is the card archived
  24. */
  25. type: Boolean,
  26. // eslint-disable-next-line consistent-return
  27. autoValue() {
  28. // eslint-disable-line consistent-return
  29. if (this.isInsert && !this.isSet) {
  30. return false;
  31. }
  32. },
  33. },
  34. archivedAt: {
  35. /**
  36. * latest archiving date
  37. */
  38. type: Date,
  39. optional: true,
  40. },
  41. parentId: {
  42. /**
  43. * ID of the parent card
  44. */
  45. type: String,
  46. optional: true,
  47. defaultValue: '',
  48. },
  49. listId: {
  50. /**
  51. * List ID where the card is
  52. */
  53. type: String,
  54. optional: true,
  55. defaultValue: '',
  56. },
  57. swimlaneId: {
  58. /**
  59. * Swimlane ID where the card is
  60. */
  61. type: String,
  62. },
  63. // The system could work without this `boardId` information (we could deduce
  64. // the board identifier from the card), but it would make the system more
  65. // difficult to manage and less efficient.
  66. boardId: {
  67. /**
  68. * Board ID of the card
  69. */
  70. type: String,
  71. optional: true,
  72. defaultValue: '',
  73. },
  74. coverId: {
  75. /**
  76. * Cover ID of the card
  77. */
  78. type: String,
  79. optional: true,
  80. defaultValue: '',
  81. },
  82. color: {
  83. type: String,
  84. optional: true,
  85. allowedValues: ALLOWED_COLORS,
  86. },
  87. createdAt: {
  88. /**
  89. * creation date
  90. */
  91. type: Date,
  92. // eslint-disable-next-line consistent-return
  93. autoValue() {
  94. if (this.isInsert) {
  95. return new Date();
  96. } else if (this.isUpsert) {
  97. return { $setOnInsert: new Date() };
  98. } else {
  99. this.unset();
  100. }
  101. },
  102. },
  103. modifiedAt: {
  104. type: Date,
  105. denyUpdate: false,
  106. // eslint-disable-next-line consistent-return
  107. autoValue() {
  108. if (this.isInsert || this.isUpsert || this.isUpdate) {
  109. return new Date();
  110. } else {
  111. this.unset();
  112. }
  113. },
  114. },
  115. customFields: {
  116. /**
  117. * list of custom fields
  118. */
  119. type: [Object],
  120. optional: true,
  121. defaultValue: [],
  122. },
  123. 'customFields.$': {
  124. type: new SimpleSchema({
  125. _id: {
  126. /**
  127. * the ID of the related custom field
  128. */
  129. type: String,
  130. optional: true,
  131. defaultValue: '',
  132. },
  133. value: {
  134. /**
  135. * value attached to the custom field
  136. */
  137. type: Match.OneOf(String, Number, Boolean, Date, [String]),
  138. optional: true,
  139. defaultValue: '',
  140. },
  141. 'value.$': {
  142. type: String,
  143. optional: true,
  144. },
  145. }),
  146. },
  147. dateLastActivity: {
  148. /**
  149. * Date of last activity
  150. */
  151. type: Date,
  152. autoValue() {
  153. return new Date();
  154. },
  155. },
  156. description: {
  157. /**
  158. * description of the card
  159. */
  160. type: String,
  161. optional: true,
  162. defaultValue: '',
  163. },
  164. requestedBy: {
  165. /**
  166. * who requested the card (ID of the user)
  167. */
  168. type: String,
  169. optional: true,
  170. defaultValue: '',
  171. },
  172. assignedBy: {
  173. /**
  174. * who assigned the card (ID of the user)
  175. */
  176. type: String,
  177. optional: true,
  178. defaultValue: '',
  179. },
  180. labelIds: {
  181. /**
  182. * list of labels ID the card has
  183. */
  184. type: [String],
  185. optional: true,
  186. defaultValue: [],
  187. },
  188. members: {
  189. /**
  190. * list of members (user IDs)
  191. */
  192. type: [String],
  193. optional: true,
  194. defaultValue: [],
  195. },
  196. assignees: {
  197. /**
  198. * who is assignee of the card (user ID),
  199. * maximum one ID of assignee in array.
  200. */
  201. type: [String],
  202. optional: true,
  203. defaultValue: [],
  204. },
  205. receivedAt: {
  206. /**
  207. * Date the card was received
  208. */
  209. type: Date,
  210. optional: true,
  211. },
  212. startAt: {
  213. /**
  214. * Date the card was started to be worked on
  215. */
  216. type: Date,
  217. optional: true,
  218. },
  219. dueAt: {
  220. /**
  221. * Date the card is due
  222. */
  223. type: Date,
  224. optional: true,
  225. },
  226. endAt: {
  227. /**
  228. * Date the card ended
  229. */
  230. type: Date,
  231. optional: true,
  232. },
  233. spentTime: {
  234. /**
  235. * How much time has been spent on this
  236. */
  237. type: Number,
  238. decimal: true,
  239. optional: true,
  240. defaultValue: 0,
  241. },
  242. isOvertime: {
  243. /**
  244. * is the card over time?
  245. */
  246. type: Boolean,
  247. defaultValue: false,
  248. optional: true,
  249. },
  250. // XXX Should probably be called `authorId`. Is it even needed since we have
  251. // the `members` field?
  252. userId: {
  253. /**
  254. * user ID of the author of the card
  255. */
  256. type: String,
  257. // eslint-disable-next-line consistent-return
  258. autoValue() {
  259. // eslint-disable-line consistent-return
  260. if (this.isInsert && !this.isSet) {
  261. return this.userId;
  262. }
  263. },
  264. },
  265. sort: {
  266. /**
  267. * Sort value
  268. */
  269. type: Number,
  270. decimal: true,
  271. defaultValue: 0,
  272. optional: true,
  273. },
  274. subtaskSort: {
  275. /**
  276. * subtask sort value
  277. */
  278. type: Number,
  279. decimal: true,
  280. defaultValue: -1,
  281. optional: true,
  282. },
  283. type: {
  284. /**
  285. * type of the card
  286. */
  287. type: String,
  288. defaultValue: TYPE_CARD,
  289. // allowedValues: [TYPE_CARD, TYPE_LINKED_CARD, TYPE_LINKED_BOARD, TYPE_TEMPLATE_CARD],
  290. },
  291. linkedId: {
  292. /**
  293. * ID of the linked card
  294. */
  295. type: String,
  296. optional: true,
  297. defaultValue: '',
  298. },
  299. vote: {
  300. /**
  301. * vote object, see below
  302. */
  303. type: Object,
  304. optional: true,
  305. },
  306. 'vote.question': {
  307. type: String,
  308. defaultValue: '',
  309. },
  310. 'vote.positive': {
  311. /**
  312. * list of members (user IDs)
  313. */
  314. type: [String],
  315. optional: true,
  316. defaultValue: [],
  317. },
  318. 'vote.negative': {
  319. /**
  320. * list of members (user IDs)
  321. */
  322. type: [String],
  323. optional: true,
  324. defaultValue: [],
  325. },
  326. 'vote.end': {
  327. type: Date,
  328. optional: true,
  329. defaultValue: null,
  330. },
  331. 'vote.public': {
  332. type: Boolean,
  333. defaultValue: false,
  334. },
  335. 'vote.allowNonBoardMembers': {
  336. type: Boolean,
  337. defaultValue: false,
  338. },
  339. poker: {
  340. /**
  341. * poker object, see below
  342. */
  343. type: Object,
  344. optional: true,
  345. },
  346. 'poker.question': {
  347. type: Boolean,
  348. defaultValue: false,
  349. },
  350. 'poker.one': {
  351. /**
  352. * poker card one
  353. */
  354. type: [String],
  355. optional: true,
  356. defaultValue: [],
  357. },
  358. 'poker.two': {
  359. /**
  360. * poker card two
  361. */
  362. type: [String],
  363. optional: true,
  364. defaultValue: [],
  365. },
  366. 'poker.three': {
  367. /**
  368. * poker card three
  369. */
  370. type: [String],
  371. optional: true,
  372. defaultValue: [],
  373. },
  374. 'poker.five': {
  375. /**
  376. * poker card five
  377. */
  378. type: [String],
  379. optional: true,
  380. defaultValue: [],
  381. },
  382. 'poker.eight': {
  383. /**
  384. * poker card eight
  385. */
  386. type: [String],
  387. optional: true,
  388. defaultValue: [],
  389. },
  390. 'poker.thirteen': {
  391. /**
  392. * poker card thirteen
  393. */
  394. type: [String],
  395. optional: true,
  396. defaultValue: [],
  397. },
  398. 'poker.twenty': {
  399. /**
  400. * poker card twenty
  401. */
  402. type: [String],
  403. optional: true,
  404. defaultValue: [],
  405. },
  406. 'poker.forty': {
  407. /**
  408. * poker card forty
  409. */
  410. type: [String],
  411. optional: true,
  412. defaultValue: [],
  413. },
  414. 'poker.oneHundred': {
  415. /**
  416. * poker card oneHundred
  417. */
  418. type: [String],
  419. optional: true,
  420. defaultValue: [],
  421. },
  422. 'poker.unsure': {
  423. /**
  424. * poker card unsure
  425. */
  426. type: [String],
  427. optional: true,
  428. defaultValue: [],
  429. },
  430. 'poker.end': {
  431. type: Date,
  432. optional: true,
  433. defaultValue: null,
  434. },
  435. 'poker.allowNonBoardMembers': {
  436. type: Boolean,
  437. defaultValue: false,
  438. },
  439. 'poker.estimation': {
  440. /**
  441. * poker estimation value
  442. */
  443. type: Number,
  444. optional: true,
  445. },
  446. targetId_gantt: {
  447. /**
  448. * ID of card which is the child link in gantt view
  449. */
  450. type: [String],
  451. optional: true,
  452. defaultValue: [],
  453. },
  454. linkType_gantt: {
  455. /**
  456. * ID of card which is the parent link in gantt view
  457. */
  458. type: [Number],
  459. decimal: false,
  460. optional: true,
  461. defaultValue: [],
  462. },
  463. linkId_gantt: {
  464. /**
  465. * ID of card which is the parent link in gantt view
  466. */
  467. type: [String],
  468. optional: true,
  469. defaultValue: [],
  470. },
  471. cardNumber: {
  472. /**
  473. * A boardwise sequentially increasing number that is assigned
  474. * to every newly created card
  475. */
  476. type: Number,
  477. decimal: true,
  478. optional: true,
  479. defaultValue: 0,
  480. },
  481. }),
  482. );
  483. Cards.allow({
  484. insert(userId, doc) {
  485. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  486. },
  487. update(userId, doc, fields) {
  488. // Allow board members or logged in users if only vote get's changed
  489. return (
  490. allowIsBoardMember(userId, Boards.findOne(doc.boardId)) ||
  491. (_.isEqual(fields, ['vote', 'modifiedAt', 'dateLastActivity']) &&
  492. !!userId)
  493. );
  494. },
  495. remove(userId, doc) {
  496. return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
  497. },
  498. fetch: ['boardId'],
  499. });
  500. Cards.helpers({
  501. // Gantt https://github.com/wekan/wekan/issues/2870#issuecomment-857171127
  502. setGanttTargetId(sourceId, targetId, linkType, linkId){
  503. return Cards.update({ _id: sourceId}, {
  504. $push: {
  505. targetId_gantt: targetId,
  506. linkType_gantt : linkType,
  507. linkId_gantt: linkId
  508. }
  509. });
  510. },
  511. removeGanttTargetId(sourceId, targetId, linkType, linkId){
  512. return Cards.update({ _id: sourceId}, {
  513. $pull: {
  514. targetId_gantt: targetId,
  515. linkType_gantt : linkType,
  516. linkId_gantt: linkId
  517. }
  518. });
  519. },
  520. mapCustomFieldsToBoard(boardId) {
  521. // Map custom fields to new board
  522. return this.customFields.map(cf => {
  523. const oldCf = CustomFields.findOne(cf._id);
  524. const newCf = CustomFields.findOne({
  525. boardIds: boardId,
  526. name: oldCf.name,
  527. type: oldCf.type,
  528. });
  529. if (newCf) {
  530. cf._id = newCf._id;
  531. } else if (!_.contains(oldCf.boardIds, boardId)) {
  532. oldCf.addBoard(boardId);
  533. }
  534. return cf;
  535. });
  536. },
  537. copy(boardId, swimlaneId, listId) {
  538. const oldId = this._id;
  539. const oldCard = Cards.findOne(oldId);
  540. // we must only copy the labels and custom fields if the target board
  541. // differs from the source board
  542. if (this.boardId !== boardId) {
  543. const oldBoard = Boards.findOne(this.boardId);
  544. const oldBoardLabels = oldBoard.labels;
  545. // Get old label names
  546. const oldCardLabels = _.pluck(
  547. _.filter(oldBoardLabels, label => {
  548. return _.contains(this.labelIds, label._id);
  549. }),
  550. 'name',
  551. );
  552. const newBoard = Boards.findOne(boardId);
  553. const newBoardLabels = newBoard.labels;
  554. const newCardLabels = _.pluck(
  555. _.filter(newBoardLabels, label => {
  556. return _.contains(oldCardLabels, label.name);
  557. }),
  558. '_id',
  559. );
  560. // now set the new label ids
  561. delete this.labelIds;
  562. this.labelIds = newCardLabels;
  563. this.customFields = this.mapCustomFieldsToBoard(newBoard._id);
  564. }
  565. delete this._id;
  566. this.boardId = boardId;
  567. this.swimlaneId = swimlaneId;
  568. this.listId = listId;
  569. const _id = Cards.insert(this);
  570. // Copy attachments
  571. oldCard.attachments().forEach(att => {
  572. att.cardId = _id;
  573. delete att._id;
  574. return Attachments.insert(att);
  575. });
  576. // copy checklists
  577. Checklists.find({ cardId: oldId }).forEach(ch => {
  578. ch.copy(_id);
  579. });
  580. // copy subtasks
  581. Cards.find({ parentId: oldId }).forEach(subtask => {
  582. subtask.parentId = _id;
  583. subtask._id = null;
  584. Cards.insert(subtask);
  585. });
  586. // copy card comments
  587. CardComments.find({ cardId: oldId }).forEach(cmt => {
  588. cmt.copy(_id);
  589. });
  590. return _id;
  591. },
  592. link(boardId, swimlaneId, listId) {
  593. // TODO is there a better method to create a deepcopy?
  594. linkCard = JSON.parse(JSON.stringify(this));
  595. // TODO is this how it is meant to be?
  596. linkCard.linkedId = linkCard.linkedId || linkCard._id;
  597. linkCard.boardId = boardId;
  598. linkCard.swimlaneId = swimlaneId;
  599. linkCard.listId = listId;
  600. linkCard.type = 'cardType-linkedCard';
  601. delete linkCard._id;
  602. // TODO shall we copy the labels for a linked card?!
  603. delete linkCard.labelIds;
  604. return Cards.insert(linkCard);
  605. },
  606. list() {
  607. return Lists.findOne(this.listId);
  608. },
  609. swimlane() {
  610. return Swimlanes.findOne(this.swimlaneId);
  611. },
  612. board() {
  613. return Boards.findOne(this.boardId);
  614. },
  615. getList() {
  616. const list = this.list();
  617. if (!list) {
  618. return {
  619. _id: this.listId,
  620. title: 'Undefined List',
  621. archived: false,
  622. colorClass: '',
  623. };
  624. }
  625. return list;
  626. },
  627. getSwimlane() {
  628. const swimlane = this.swimlane();
  629. if (!swimlane) {
  630. return {
  631. _id: this.swimlaneId,
  632. title: 'Undefined Swimlane',
  633. archived: false,
  634. colorClass: '',
  635. };
  636. }
  637. return swimlane;
  638. },
  639. getBoard() {
  640. const board = this.board();
  641. if (!board) {
  642. return {
  643. _id: this.boardId,
  644. title: 'Undefined Board',
  645. archived: false,
  646. colorClass: '',
  647. };
  648. }
  649. return board;
  650. },
  651. labels() {
  652. const boardLabels = this.board().labels;
  653. const cardLabels = _.filter(boardLabels, label => {
  654. return _.contains(this.labelIds, label._id);
  655. });
  656. return cardLabels;
  657. },
  658. hasLabel(labelId) {
  659. return _.contains(this.labelIds, labelId);
  660. },
  661. user() {
  662. return Users.findOne(this.userId);
  663. },
  664. isAssigned(memberId) {
  665. return _.contains(this.getMembers(), memberId);
  666. },
  667. isAssignee(assigneeId) {
  668. return _.contains(this.getAssignees(), assigneeId);
  669. },
  670. activities() {
  671. if (this.isLinkedCard()) {
  672. return Activities.find(
  673. { cardId: this.linkedId },
  674. { sort: { createdAt: -1 } },
  675. );
  676. } else if (this.isLinkedBoard()) {
  677. return Activities.find(
  678. { boardId: this.linkedId },
  679. { sort: { createdAt: -1 } },
  680. );
  681. } else {
  682. return Activities.find({ cardId: this._id }, { sort: { createdAt: -1 } });
  683. }
  684. },
  685. comments() {
  686. if (this.isLinkedCard()) {
  687. return CardComments.find(
  688. { cardId: this.linkedId },
  689. { sort: { createdAt: -1 } },
  690. );
  691. } else {
  692. return CardComments.find(
  693. { cardId: this._id },
  694. { sort: { createdAt: -1 } },
  695. );
  696. }
  697. },
  698. attachments() {
  699. if (this.isLinkedCard()) {
  700. return Attachments.find(
  701. { cardId: this.linkedId },
  702. { sort: { uploadedAt: -1 } },
  703. );
  704. } else {
  705. return Attachments.find(
  706. { cardId: this._id },
  707. { sort: { uploadedAt: -1 } },
  708. );
  709. }
  710. },
  711. cover() {
  712. if (!this.coverId) return false;
  713. const cover = Attachments.findOne(this.coverId);
  714. // if we return a cover before it is fully stored, we will get errors when we try to display it
  715. // todo XXX we could return a default "upload pending" image in the meantime?
  716. return cover && cover.url() && cover;
  717. },
  718. checklists() {
  719. if (this.isLinkedCard()) {
  720. return Checklists.find({ cardId: this.linkedId }, { sort: { sort: 1 } });
  721. } else {
  722. return Checklists.find({ cardId: this._id }, { sort: { sort: 1 } });
  723. }
  724. },
  725. checklistItemCount() {
  726. const checklists = this.checklists().fetch();
  727. return checklists
  728. .map(checklist => {
  729. return checklist.itemCount();
  730. })
  731. .reduce((prev, next) => {
  732. return prev + next;
  733. }, 0);
  734. },
  735. checklistFinishedCount() {
  736. const checklists = this.checklists().fetch();
  737. return checklists
  738. .map(checklist => {
  739. return checklist.finishedCount();
  740. })
  741. .reduce((prev, next) => {
  742. return prev + next;
  743. }, 0);
  744. },
  745. checklistFinished() {
  746. return (
  747. this.hasChecklist() &&
  748. this.checklistItemCount() === this.checklistFinishedCount()
  749. );
  750. },
  751. hasChecklist() {
  752. return this.checklistItemCount() !== 0;
  753. },
  754. subtasks() {
  755. return Cards.find(
  756. {
  757. parentId: this._id,
  758. archived: false,
  759. },
  760. {
  761. sort: {
  762. sort: 1,
  763. },
  764. },
  765. );
  766. },
  767. subtasksFinished() {
  768. return Cards.find({
  769. parentId: this._id,
  770. archived: true,
  771. });
  772. },
  773. allSubtasks() {
  774. return Cards.find({
  775. parentId: this._id,
  776. });
  777. },
  778. subtasksCount() {
  779. const subtasks = this.subtasks();
  780. return subtasks.count();
  781. },
  782. subtasksFinishedCount() {
  783. const subtasksArchived = this.subtasksFinished();
  784. return subtasksArchived.count();
  785. },
  786. allSubtasksCount() {
  787. const allSubtasks = this.allSubtasks();
  788. return allSubtasks.count();
  789. },
  790. allowsSubtasks() {
  791. return this.subtasksCount() !== 0;
  792. },
  793. customFieldIndex(customFieldId) {
  794. return _.pluck(this.customFields, '_id').indexOf(customFieldId);
  795. },
  796. // customFields with definitions
  797. customFieldsWD() {
  798. // get all definitions
  799. const definitions = CustomFields.find({
  800. boardIds: { $in: [this.boardId] },
  801. }).fetch();
  802. if (!definitions) {
  803. return {};
  804. }
  805. // match right definition to each field
  806. if (!this.customFields) return [];
  807. const ret = this.customFields.map(customField => {
  808. const definition = definitions.find(definition => {
  809. return definition._id === customField._id;
  810. });
  811. if (!definition) {
  812. return {};
  813. }
  814. //search for "True Value" which is for DropDowns other then the Value (which is the id)
  815. let trueValue = customField.value;
  816. if (
  817. definition.settings.dropdownItems &&
  818. definition.settings.dropdownItems.length > 0
  819. ) {
  820. for (let i = 0; i < definition.settings.dropdownItems.length; i++) {
  821. if (definition.settings.dropdownItems[i]._id === customField.value) {
  822. trueValue = definition.settings.dropdownItems[i].name;
  823. }
  824. }
  825. }
  826. return {
  827. _id: customField._id,
  828. value: customField.value,
  829. trueValue,
  830. definition,
  831. };
  832. });
  833. // at linked cards custom fields definition is not found
  834. ret.sort(
  835. (a, b) =>
  836. a.definition !== undefined &&
  837. b.definition !== undefined &&
  838. a.definition.name !== undefined &&
  839. b.definition.name !== undefined &&
  840. a.definition.name.localeCompare(b.definition.name),
  841. );
  842. return ret;
  843. },
  844. colorClass() {
  845. if (this.color) return this.color;
  846. return '';
  847. },
  848. absoluteUrl() {
  849. const board = this.board();
  850. return FlowRouter.url('card', {
  851. boardId: board._id,
  852. slug: board.slug,
  853. cardId: this._id,
  854. });
  855. },
  856. originRelativeUrl() {
  857. const board = this.board();
  858. return FlowRouter.path('card', {
  859. boardId: board._id,
  860. slug: board.slug,
  861. cardId: this._id,
  862. });
  863. },
  864. canBeRestored() {
  865. const list = Lists.findOne({
  866. _id: this.listId,
  867. });
  868. if (
  869. !list.getWipLimit('soft') &&
  870. list.getWipLimit('enabled') &&
  871. list.getWipLimit('value') === list.cards().count()
  872. ) {
  873. return false;
  874. }
  875. return true;
  876. },
  877. parentCard() {
  878. if (this.parentId === '') {
  879. return null;
  880. }
  881. return Cards.findOne(this.parentId);
  882. },
  883. parentCardName() {
  884. let result = '';
  885. if (this.parentId !== '') {
  886. const card = Cards.findOne(this.parentId);
  887. if (card) {
  888. result = card.title;
  889. }
  890. }
  891. return result;
  892. },
  893. parentListId() {
  894. const result = [];
  895. let crtParentId = this.parentId;
  896. while (crtParentId !== '') {
  897. const crt = Cards.findOne(crtParentId);
  898. if (crt === null || crt === undefined) {
  899. // maybe it has been deleted
  900. break;
  901. }
  902. if (crtParentId in result) {
  903. // circular reference
  904. break;
  905. }
  906. result.unshift(crtParentId);
  907. crtParentId = crt.parentId;
  908. }
  909. return result;
  910. },
  911. parentList() {
  912. const resultId = [];
  913. const result = [];
  914. let crtParentId = this.parentId;
  915. while (crtParentId !== '') {
  916. const crt = Cards.findOne(crtParentId);
  917. if (crt === null || crt === undefined) {
  918. // maybe it has been deleted
  919. break;
  920. }
  921. if (crtParentId in resultId) {
  922. // circular reference
  923. break;
  924. }
  925. resultId.unshift(crtParentId);
  926. result.unshift(crt);
  927. crtParentId = crt.parentId;
  928. }
  929. return result;
  930. },
  931. parentString(sep) {
  932. return this.parentList()
  933. .map(function(elem) {
  934. return elem.title;
  935. })
  936. .join(sep);
  937. },
  938. isTopLevel() {
  939. return this.parentId === '';
  940. },
  941. isLinkedCard() {
  942. return this.type === 'cardType-linkedCard';
  943. },
  944. isLinkedBoard() {
  945. return this.type === 'cardType-linkedBoard';
  946. },
  947. isLinked() {
  948. return this.isLinkedCard() || this.isLinkedBoard();
  949. },
  950. setDescription(description) {
  951. if (this.isLinkedCard()) {
  952. return Cards.update({ _id: this.linkedId }, { $set: { description } });
  953. } else if (this.isLinkedBoard()) {
  954. return Boards.update({ _id: this.linkedId }, { $set: { description } });
  955. } else {
  956. return Cards.update({ _id: this._id }, { $set: { description } });
  957. }
  958. },
  959. getDescription() {
  960. if (this.isLinkedCard()) {
  961. const card = Cards.findOne({ _id: this.linkedId });
  962. if (card && card.description) return card.description;
  963. else return null;
  964. } else if (this.isLinkedBoard()) {
  965. const board = Boards.findOne({ _id: this.linkedId });
  966. if (board && board.description) return board.description;
  967. else return null;
  968. } else if (this.description) {
  969. return this.description;
  970. } else {
  971. return null;
  972. }
  973. },
  974. getMembers() {
  975. if (this.isLinkedCard()) {
  976. const card = Cards.findOne({ _id: this.linkedId });
  977. if (card === undefined) {
  978. return null;
  979. } else {
  980. return card.members;
  981. }
  982. } else if (this.isLinkedBoard()) {
  983. const board = Boards.findOne({ _id: this.linkedId });
  984. if (board === undefined) {
  985. return null;
  986. } else {
  987. return board.activeMembers().map(member => {
  988. return member.userId;
  989. });
  990. }
  991. } else {
  992. return this.members;
  993. }
  994. },
  995. getAssignees() {
  996. if (this.isLinkedCard()) {
  997. const card = Cards.findOne({ _id: this.linkedId });
  998. if (card === undefined) {
  999. return null;
  1000. } else {
  1001. return card.assignees;
  1002. }
  1003. } else if (this.isLinkedBoard()) {
  1004. const board = Boards.findOne({ _id: this.linkedId });
  1005. if (board === undefined) {
  1006. return null;
  1007. } else {
  1008. return board.activeMembers().map(assignee => {
  1009. return assignee.userId;
  1010. });
  1011. }
  1012. } else {
  1013. return this.assignees;
  1014. }
  1015. },
  1016. assignMember(memberId) {
  1017. if (this.isLinkedCard()) {
  1018. return Cards.update(
  1019. { _id: this.linkedId },
  1020. { $addToSet: { members: memberId } },
  1021. );
  1022. } else if (this.isLinkedBoard()) {
  1023. const board = Boards.findOne({ _id: this.linkedId });
  1024. return board.addMember(memberId);
  1025. } else {
  1026. return Cards.update(
  1027. { _id: this._id },
  1028. { $addToSet: { members: memberId } },
  1029. );
  1030. }
  1031. },
  1032. assignAssignee(assigneeId) {
  1033. if (this.isLinkedCard()) {
  1034. return Cards.update(
  1035. { _id: this.linkedId },
  1036. { $addToSet: { assignees: assigneeId } },
  1037. );
  1038. } else if (this.isLinkedBoard()) {
  1039. const board = Boards.findOne({ _id: this.linkedId });
  1040. return board.addAssignee(assigneeId);
  1041. } else {
  1042. return Cards.update(
  1043. { _id: this._id },
  1044. { $addToSet: { assignees: assigneeId } },
  1045. );
  1046. }
  1047. },
  1048. unassignMember(memberId) {
  1049. if (this.isLinkedCard()) {
  1050. return Cards.update(
  1051. { _id: this.linkedId },
  1052. { $pull: { members: memberId } },
  1053. );
  1054. } else if (this.isLinkedBoard()) {
  1055. const board = Boards.findOne({ _id: this.linkedId });
  1056. return board.removeMember(memberId);
  1057. } else {
  1058. return Cards.update({ _id: this._id }, { $pull: { members: memberId } });
  1059. }
  1060. },
  1061. unassignAssignee(assigneeId) {
  1062. if (this.isLinkedCard()) {
  1063. return Cards.update(
  1064. { _id: this.linkedId },
  1065. { $pull: { assignees: assigneeId } },
  1066. );
  1067. } else if (this.isLinkedBoard()) {
  1068. const board = Boards.findOne({ _id: this.linkedId });
  1069. return board.removeAssignee(assigneeId);
  1070. } else {
  1071. return Cards.update(
  1072. { _id: this._id },
  1073. { $pull: { assignees: assigneeId } },
  1074. );
  1075. }
  1076. },
  1077. toggleMember(memberId) {
  1078. if (this.getMembers() && this.getMembers().indexOf(memberId) > -1) {
  1079. return this.unassignMember(memberId);
  1080. } else {
  1081. return this.assignMember(memberId);
  1082. }
  1083. },
  1084. toggleAssignee(assigneeId) {
  1085. if (this.getAssignees() && this.getAssignees().indexOf(assigneeId) > -1) {
  1086. return this.unassignAssignee(assigneeId);
  1087. } else {
  1088. return this.assignAssignee(assigneeId);
  1089. }
  1090. },
  1091. getReceived() {
  1092. if (this.isLinkedCard()) {
  1093. const card = Cards.findOne({ _id: this.linkedId });
  1094. if (card === undefined) {
  1095. return null;
  1096. } else {
  1097. return card.receivedAt;
  1098. }
  1099. } else {
  1100. return this.receivedAt;
  1101. }
  1102. },
  1103. setReceived(receivedAt) {
  1104. if (this.isLinkedCard()) {
  1105. return Cards.update({ _id: this.linkedId }, { $set: { receivedAt } });
  1106. } else {
  1107. return Cards.update({ _id: this._id }, { $set: { receivedAt } });
  1108. }
  1109. },
  1110. getStart() {
  1111. if (this.isLinkedCard()) {
  1112. const card = Cards.findOne({ _id: this.linkedId });
  1113. if (card === undefined) {
  1114. return null;
  1115. } else {
  1116. return card.startAt;
  1117. }
  1118. } else if (this.isLinkedBoard()) {
  1119. const board = Boards.findOne({ _id: this.linkedId });
  1120. if (board === undefined) {
  1121. return null;
  1122. } else {
  1123. return board.startAt;
  1124. }
  1125. } else {
  1126. return this.startAt;
  1127. }
  1128. },
  1129. setStart(startAt) {
  1130. if (this.isLinkedCard()) {
  1131. return Cards.update({ _id: this.linkedId }, { $set: { startAt } });
  1132. } else if (this.isLinkedBoard()) {
  1133. return Boards.update({ _id: this.linkedId }, { $set: { startAt } });
  1134. } else {
  1135. return Cards.update({ _id: this._id }, { $set: { startAt } });
  1136. }
  1137. },
  1138. getDue() {
  1139. if (this.isLinkedCard()) {
  1140. const card = Cards.findOne({ _id: this.linkedId });
  1141. if (card === undefined) {
  1142. return null;
  1143. } else {
  1144. return card.dueAt;
  1145. }
  1146. } else if (this.isLinkedBoard()) {
  1147. const board = Boards.findOne({ _id: this.linkedId });
  1148. if (board === undefined) {
  1149. return null;
  1150. } else {
  1151. return board.dueAt;
  1152. }
  1153. } else {
  1154. return this.dueAt;
  1155. }
  1156. },
  1157. setDue(dueAt) {
  1158. if (this.isLinkedCard()) {
  1159. return Cards.update({ _id: this.linkedId }, { $set: { dueAt } });
  1160. } else if (this.isLinkedBoard()) {
  1161. return Boards.update({ _id: this.linkedId }, { $set: { dueAt } });
  1162. } else {
  1163. return Cards.update({ _id: this._id }, { $set: { dueAt } });
  1164. }
  1165. },
  1166. getEnd() {
  1167. if (this.isLinkedCard()) {
  1168. const card = Cards.findOne({ _id: this.linkedId });
  1169. if (card === undefined) {
  1170. return null;
  1171. } else {
  1172. return card.endAt;
  1173. }
  1174. } else if (this.isLinkedBoard()) {
  1175. const board = Boards.findOne({ _id: this.linkedId });
  1176. if (board === undefined) {
  1177. return null;
  1178. } else {
  1179. return board.endAt;
  1180. }
  1181. } else {
  1182. return this.endAt;
  1183. }
  1184. },
  1185. setEnd(endAt) {
  1186. if (this.isLinkedCard()) {
  1187. return Cards.update({ _id: this.linkedId }, { $set: { endAt } });
  1188. } else if (this.isLinkedBoard()) {
  1189. return Boards.update({ _id: this.linkedId }, { $set: { endAt } });
  1190. } else {
  1191. return Cards.update({ _id: this._id }, { $set: { endAt } });
  1192. }
  1193. },
  1194. getIsOvertime() {
  1195. if (this.isLinkedCard()) {
  1196. const card = Cards.findOne({ _id: this.linkedId });
  1197. if (card === undefined) {
  1198. return null;
  1199. } else {
  1200. return card.isOvertime;
  1201. }
  1202. } else if (this.isLinkedBoard()) {
  1203. const board = Boards.findOne({ _id: this.linkedId });
  1204. if (board === undefined) {
  1205. return null;
  1206. } else {
  1207. return board.isOvertime;
  1208. }
  1209. } else {
  1210. return this.isOvertime;
  1211. }
  1212. },
  1213. setIsOvertime(isOvertime) {
  1214. if (this.isLinkedCard()) {
  1215. return Cards.update({ _id: this.linkedId }, { $set: { isOvertime } });
  1216. } else if (this.isLinkedBoard()) {
  1217. return Boards.update({ _id: this.linkedId }, { $set: { isOvertime } });
  1218. } else {
  1219. return Cards.update({ _id: this._id }, { $set: { isOvertime } });
  1220. }
  1221. },
  1222. getSpentTime() {
  1223. if (this.isLinkedCard()) {
  1224. const card = Cards.findOne({ _id: this.linkedId });
  1225. if (card === undefined) {
  1226. return null;
  1227. } else {
  1228. return card.spentTime;
  1229. }
  1230. } else if (this.isLinkedBoard()) {
  1231. const board = Boards.findOne({ _id: this.linkedId });
  1232. if (board === undefined) {
  1233. return null;
  1234. } else {
  1235. return board.spentTime;
  1236. }
  1237. } else {
  1238. return this.spentTime;
  1239. }
  1240. },
  1241. setSpentTime(spentTime) {
  1242. if (this.isLinkedCard()) {
  1243. return Cards.update({ _id: this.linkedId }, { $set: { spentTime } });
  1244. } else if (this.isLinkedBoard()) {
  1245. return Boards.update({ _id: this.linkedId }, { $set: { spentTime } });
  1246. } else {
  1247. return Cards.update({ _id: this._id }, { $set: { spentTime } });
  1248. }
  1249. },
  1250. getVoteQuestion() {
  1251. if (this.isLinkedCard()) {
  1252. const card = Cards.findOne({ _id: this.linkedId });
  1253. if (card === undefined) {
  1254. return null;
  1255. } else if (card && card.vote) {
  1256. return card.vote.question;
  1257. } else {
  1258. return null;
  1259. }
  1260. } else if (this.isLinkedBoard()) {
  1261. const board = Boards.findOne({ _id: this.linkedId });
  1262. if (board === undefined) {
  1263. return null;
  1264. } else if (board && board.vote) {
  1265. return board.vote.question;
  1266. } else {
  1267. return null;
  1268. }
  1269. } else if (this.vote) {
  1270. return this.vote.question;
  1271. } else {
  1272. return null;
  1273. }
  1274. },
  1275. getVotePublic() {
  1276. if (this.isLinkedCard()) {
  1277. const card = Cards.findOne({ _id: this.linkedId });
  1278. if (card === undefined) {
  1279. return null;
  1280. } else if (card && card.vote) {
  1281. return card.vote.public;
  1282. } else {
  1283. return null;
  1284. }
  1285. } else if (this.isLinkedBoard()) {
  1286. const board = Boards.findOne({ _id: this.linkedId });
  1287. if (board === undefined) {
  1288. return null;
  1289. } else if (board && board.vote) {
  1290. return board.vote.public;
  1291. } else {
  1292. return null;
  1293. }
  1294. } else if (this.vote) {
  1295. return this.vote.public;
  1296. } else {
  1297. return null;
  1298. }
  1299. },
  1300. getVoteEnd() {
  1301. if (this.isLinkedCard()) {
  1302. const card = Cards.findOne({ _id: this.linkedId });
  1303. if (card === undefined) {
  1304. return null;
  1305. } else if (card && card.vote) {
  1306. return card.vote.end;
  1307. } else {
  1308. return null;
  1309. }
  1310. } else if (this.isLinkedBoard()) {
  1311. const board = Boards.findOne({ _id: this.linkedId });
  1312. if (board === undefined) {
  1313. return null;
  1314. } else if (board && board.vote) {
  1315. return board.vote.end;
  1316. } else {
  1317. return null;
  1318. }
  1319. } else if (this.vote) {
  1320. return this.vote.end;
  1321. } else {
  1322. return null;
  1323. }
  1324. },
  1325. expiredVote() {
  1326. let end = this.getVoteEnd();
  1327. if (end) {
  1328. end = moment(end);
  1329. return end.isBefore(new Date());
  1330. }
  1331. return false;
  1332. },
  1333. voteMemberPositive() {
  1334. if (this.vote && this.vote.positive)
  1335. return Users.find({ _id: { $in: this.vote.positive } });
  1336. return [];
  1337. },
  1338. voteMemberNegative() {
  1339. if (this.vote && this.vote.negative)
  1340. return Users.find({ _id: { $in: this.vote.negative } });
  1341. return [];
  1342. },
  1343. voteState() {
  1344. const userId = Meteor.userId();
  1345. let state;
  1346. if (this.vote) {
  1347. if (this.vote.positive) {
  1348. state = _.contains(this.vote.positive, userId);
  1349. if (state === true) return true;
  1350. }
  1351. if (this.vote.negative) {
  1352. state = _.contains(this.vote.negative, userId);
  1353. if (state === true) return false;
  1354. }
  1355. }
  1356. return null;
  1357. },
  1358. getPokerQuestion() {
  1359. if (this.isLinkedCard()) {
  1360. const card = Cards.findOne({ _id: this.linkedId });
  1361. if (card === undefined) {
  1362. return null;
  1363. } else if (card && card.poker) {
  1364. return card.poker.question;
  1365. } else {
  1366. return null;
  1367. }
  1368. } else if (this.isLinkedBoard()) {
  1369. const board = Boards.findOne({ _id: this.linkedId });
  1370. if (board === undefined) {
  1371. return null;
  1372. } else if (board && board.poker) {
  1373. return board.poker.question;
  1374. } else {
  1375. return null;
  1376. }
  1377. } else if (this.poker) {
  1378. return this.poker.question;
  1379. } else {
  1380. return null;
  1381. }
  1382. },
  1383. getPokerEstimation() {
  1384. if (this.poker) {
  1385. return this.poker.estimation;
  1386. } else {
  1387. return null;
  1388. }
  1389. },
  1390. getPokerEnd() {
  1391. if (this.isLinkedCard()) {
  1392. const card = Cards.findOne({ _id: this.linkedId });
  1393. if (card === undefined) {
  1394. return null;
  1395. } else if (card && card.poker) {
  1396. return card.poker.end;
  1397. } else {
  1398. return null;
  1399. }
  1400. } else if (this.isLinkedBoard()) {
  1401. const board = Boards.findOne({ _id: this.linkedId });
  1402. if (board === undefined) {
  1403. return null;
  1404. } else if (board && board.poker) {
  1405. return board.poker.end;
  1406. } else {
  1407. return null;
  1408. }
  1409. } else if (this.poker) {
  1410. return this.poker.end;
  1411. } else {
  1412. return null;
  1413. }
  1414. },
  1415. expiredPoker() {
  1416. let end = this.getPokerEnd();
  1417. if (end) {
  1418. end = moment(end);
  1419. return end.isBefore(new Date());
  1420. }
  1421. return false;
  1422. },
  1423. pokerMemberOne() {
  1424. if (this.poker && this.poker.one)
  1425. return Users.find({ _id: { $in: this.poker.one } });
  1426. return [];
  1427. },
  1428. pokerMemberTwo() {
  1429. if (this.poker && this.poker.two)
  1430. return Users.find({ _id: { $in: this.poker.two } });
  1431. return [];
  1432. },
  1433. pokerMemberThree() {
  1434. if (this.poker && this.poker.three)
  1435. return Users.find({ _id: { $in: this.poker.three } });
  1436. return [];
  1437. },
  1438. pokerMemberFive() {
  1439. if (this.poker && this.poker.five)
  1440. return Users.find({ _id: { $in: this.poker.five } });
  1441. return [];
  1442. },
  1443. pokerMemberEight() {
  1444. if (this.poker && this.poker.eight)
  1445. return Users.find({ _id: { $in: this.poker.eight } });
  1446. return [];
  1447. },
  1448. pokerMemberThirteen() {
  1449. if (this.poker && this.poker.thirteen)
  1450. return Users.find({ _id: { $in: this.poker.thirteen } });
  1451. return [];
  1452. },
  1453. pokerMemberTwenty() {
  1454. if (this.poker && this.poker.twenty)
  1455. return Users.find({ _id: { $in: this.poker.twenty } });
  1456. return [];
  1457. },
  1458. pokerMemberForty() {
  1459. if (this.poker && this.poker.forty)
  1460. return Users.find({ _id: { $in: this.poker.forty } });
  1461. return [];
  1462. },
  1463. pokerMemberOneHundred() {
  1464. if (this.poker && this.poker.oneHundred)
  1465. return Users.find({ _id: { $in: this.poker.oneHundred } });
  1466. return [];
  1467. },
  1468. pokerMemberUnsure() {
  1469. if (this.poker && this.poker.unsure)
  1470. return Users.find({ _id: { $in: this.poker.unsure } });
  1471. return [];
  1472. },
  1473. pokerState() {
  1474. const userId = Meteor.userId();
  1475. let state;
  1476. if (this.poker) {
  1477. if (this.poker.one) {
  1478. state = _.contains(this.poker.one, userId);
  1479. if (state === true) {
  1480. return 'one';
  1481. }
  1482. }
  1483. if (this.poker.two) {
  1484. state = _.contains(this.poker.two, userId);
  1485. if (state === true) {
  1486. return 'two';
  1487. }
  1488. }
  1489. if (this.poker.three) {
  1490. state = _.contains(this.poker.three, userId);
  1491. if (state === true) {
  1492. return 'three';
  1493. }
  1494. }
  1495. if (this.poker.five) {
  1496. state = _.contains(this.poker.five, userId);
  1497. if (state === true) {
  1498. return 'five';
  1499. }
  1500. }
  1501. if (this.poker.eight) {
  1502. state = _.contains(this.poker.eight, userId);
  1503. if (state === true) {
  1504. return 'eight';
  1505. }
  1506. }
  1507. if (this.poker.thirteen) {
  1508. state = _.contains(this.poker.thirteen, userId);
  1509. if (state === true) {
  1510. return 'thirteen';
  1511. }
  1512. }
  1513. if (this.poker.twenty) {
  1514. state = _.contains(this.poker.twenty, userId);
  1515. if (state === true) {
  1516. return 'twenty';
  1517. }
  1518. }
  1519. if (this.poker.forty) {
  1520. state = _.contains(this.poker.forty, userId);
  1521. if (state === true) {
  1522. return 'forty';
  1523. }
  1524. }
  1525. if (this.poker.oneHundred) {
  1526. state = _.contains(this.poker.oneHundred, userId);
  1527. if (state === true) {
  1528. return 'oneHundred';
  1529. }
  1530. }
  1531. if (this.poker.unsure) {
  1532. state = _.contains(this.poker.unsure, userId);
  1533. if (state === true) {
  1534. return 'unsure';
  1535. }
  1536. }
  1537. }
  1538. return null;
  1539. },
  1540. getId() {
  1541. if (this.isLinked()) {
  1542. return this.linkedId;
  1543. } else {
  1544. return this._id;
  1545. }
  1546. },
  1547. getTitle() {
  1548. if (this.isLinkedCard()) {
  1549. const card = Cards.findOne({ _id: this.linkedId });
  1550. if (card === undefined) {
  1551. return null;
  1552. } else {
  1553. return card.title;
  1554. }
  1555. } else if (this.isLinkedBoard()) {
  1556. const board = Boards.findOne({ _id: this.linkedId });
  1557. if (board === undefined) {
  1558. return null;
  1559. } else {
  1560. return board.title;
  1561. }
  1562. } else if (this.title === undefined) {
  1563. return null;
  1564. } else {
  1565. return this.title;
  1566. }
  1567. },
  1568. getCardNumber() {
  1569. return this.cardNumber;
  1570. },
  1571. getBoardTitle() {
  1572. if (this.isLinkedCard()) {
  1573. const card = Cards.findOne({ _id: this.linkedId });
  1574. if (card === undefined) {
  1575. return null;
  1576. }
  1577. const board = Boards.findOne({ _id: card.boardId });
  1578. if (board === undefined) {
  1579. return null;
  1580. } else {
  1581. return board.title;
  1582. }
  1583. } else if (this.isLinkedBoard()) {
  1584. const board = Boards.findOne({ _id: this.linkedId });
  1585. if (board === undefined) {
  1586. return null;
  1587. } else {
  1588. return board.title;
  1589. }
  1590. } else {
  1591. const board = Boards.findOne({ _id: this.boardId });
  1592. if (board === undefined) {
  1593. return null;
  1594. } else {
  1595. return board.title;
  1596. }
  1597. }
  1598. },
  1599. setTitle(title) {
  1600. if (this.isLinkedCard()) {
  1601. return Cards.update({ _id: this.linkedId }, { $set: { title } });
  1602. } else if (this.isLinkedBoard()) {
  1603. return Boards.update({ _id: this.linkedId }, { $set: { title } });
  1604. } else {
  1605. return Cards.update({ _id: this._id }, { $set: { title } });
  1606. }
  1607. },
  1608. getArchived() {
  1609. if (this.isLinkedCard()) {
  1610. const card = Cards.findOne({ _id: this.linkedId });
  1611. if (card === undefined) {
  1612. return null;
  1613. } else {
  1614. return card.archived;
  1615. }
  1616. } else if (this.isLinkedBoard()) {
  1617. const board = Boards.findOne({ _id: this.linkedId });
  1618. if (board === undefined) {
  1619. return null;
  1620. } else {
  1621. return board.archived;
  1622. }
  1623. } else {
  1624. return this.archived;
  1625. }
  1626. },
  1627. setRequestedBy(requestedBy) {
  1628. if (this.isLinkedCard()) {
  1629. return Cards.update({ _id: this.linkedId }, { $set: { requestedBy } });
  1630. } else {
  1631. return Cards.update({ _id: this._id }, { $set: { requestedBy } });
  1632. }
  1633. },
  1634. getRequestedBy() {
  1635. if (this.isLinkedCard()) {
  1636. const card = Cards.findOne({ _id: this.linkedId });
  1637. if (card === undefined) {
  1638. return null;
  1639. } else {
  1640. return card.requestedBy;
  1641. }
  1642. } else {
  1643. return this.requestedBy;
  1644. }
  1645. },
  1646. setAssignedBy(assignedBy) {
  1647. if (this.isLinkedCard()) {
  1648. return Cards.update({ _id: this.linkedId }, { $set: { assignedBy } });
  1649. } else {
  1650. return Cards.update({ _id: this._id }, { $set: { assignedBy } });
  1651. }
  1652. },
  1653. getAssignedBy() {
  1654. if (this.isLinkedCard()) {
  1655. const card = Cards.findOne({ _id: this.linkedId });
  1656. if (card === undefined) {
  1657. return null;
  1658. } else {
  1659. return card.assignedBy;
  1660. }
  1661. } else {
  1662. return this.assignedBy;
  1663. }
  1664. },
  1665. isTemplateCard() {
  1666. return this.type === 'template-card';
  1667. },
  1668. votePublic() {
  1669. if (this.vote) return this.vote.public;
  1670. return null;
  1671. },
  1672. voteAllowNonBoardMembers() {
  1673. if (this.vote) return this.vote.allowNonBoardMembers;
  1674. return null;
  1675. },
  1676. voteCountNegative() {
  1677. if (this.vote && this.vote.negative) return this.vote.negative.length;
  1678. return null;
  1679. },
  1680. voteCountPositive() {
  1681. if (this.vote && this.vote.positive) return this.vote.positive.length;
  1682. return null;
  1683. },
  1684. voteCount() {
  1685. return this.voteCountPositive() + this.voteCountNegative();
  1686. },
  1687. pokerAllowNonBoardMembers() {
  1688. if (this.poker) return this.poker.allowNonBoardMembers;
  1689. return null;
  1690. },
  1691. pokerCountOne() {
  1692. if (this.poker && this.poker.one) return this.poker.one.length;
  1693. return null;
  1694. },
  1695. pokerCountTwo() {
  1696. if (this.poker && this.poker.two) return this.poker.two.length;
  1697. return null;
  1698. },
  1699. pokerCountThree() {
  1700. if (this.poker && this.poker.three) return this.poker.three.length;
  1701. return null;
  1702. },
  1703. pokerCountFive() {
  1704. if (this.poker && this.poker.five) return this.poker.five.length;
  1705. return null;
  1706. },
  1707. pokerCountEight() {
  1708. if (this.poker && this.poker.eight) return this.poker.eight.length;
  1709. return null;
  1710. },
  1711. pokerCountThirteen() {
  1712. if (this.poker && this.poker.thirteen) return this.poker.thirteen.length;
  1713. return null;
  1714. },
  1715. pokerCountTwenty() {
  1716. if (this.poker && this.poker.twenty) return this.poker.twenty.length;
  1717. return null;
  1718. },
  1719. pokerCountForty() {
  1720. if (this.poker && this.poker.forty) return this.poker.forty.length;
  1721. return null;
  1722. },
  1723. pokerCountOneHundred() {
  1724. if (this.poker && this.poker.oneHundred) return this.poker.oneHundred.length;
  1725. return null;
  1726. },
  1727. pokerCountUnsure() {
  1728. if (this.poker && this.poker.unsure) return this.poker.unsure.length;
  1729. return null;
  1730. },
  1731. pokerCount() {
  1732. return (
  1733. this.pokerCountOne() +
  1734. this.pokerCountTwo() +
  1735. this.pokerCountThree() +
  1736. this.pokerCountFive() +
  1737. this.pokerCountEight() +
  1738. this.pokerCountThirteen() +
  1739. this.pokerCountTwenty() +
  1740. this.pokerCountForty() +
  1741. this.pokerCountOneHundred() +
  1742. this.pokerCountUnsure()
  1743. );
  1744. },
  1745. pokerWinner() {
  1746. const pokerListMaps = [];
  1747. let pokerWinnersListMap = [];
  1748. if (this.expiredPoker()) {
  1749. const one = { count: this.pokerCountOne(), pokerCard: 1 };
  1750. const two = { count: this.pokerCountTwo(), pokerCard: 2 };
  1751. const three = { count: this.pokerCountThree(), pokerCard: 3 };
  1752. const five = { count: this.pokerCountFive(), pokerCard: 5 };
  1753. const eight = { count: this.pokerCountEight(), pokerCard: 8 };
  1754. const thirteen = { count: this.pokerCountThirteen(), pokerCard: 13 };
  1755. const twenty = { count: this.pokerCountTwenty(), pokerCard: 20 };
  1756. const forty = { count: this.pokerCountForty(), pokerCard: 40 };
  1757. const oneHundred = { count: this.pokerCountOneHundred(), pokerCard: 100 };
  1758. const unsure = { count: this.pokerCountUnsure(), pokerCard: 'Unsure' };
  1759. pokerListMaps.push(one);
  1760. pokerListMaps.push(two);
  1761. pokerListMaps.push(three);
  1762. pokerListMaps.push(five);
  1763. pokerListMaps.push(eight);
  1764. pokerListMaps.push(thirteen);
  1765. pokerListMaps.push(twenty);
  1766. pokerListMaps.push(forty);
  1767. pokerListMaps.push(oneHundred);
  1768. pokerListMaps.push(unsure);
  1769. pokerListMaps.sort(function(a, b) {
  1770. return b.count - a.count;
  1771. });
  1772. const max = pokerListMaps[0].count;
  1773. pokerWinnersListMap = pokerListMaps.filter(task => task.count >= max);
  1774. pokerWinnersListMap.sort(function(a, b) {
  1775. return b.pokerCard - a.pokerCard;
  1776. });
  1777. }
  1778. return pokerWinnersListMap[0].pokerCard;
  1779. },
  1780. });
  1781. Cards.mutations({
  1782. applyToChildren(funct) {
  1783. Cards.find({
  1784. parentId: this._id,
  1785. }).forEach(card => {
  1786. funct(card);
  1787. });
  1788. },
  1789. archive() {
  1790. this.applyToChildren(card => {
  1791. return card.archive();
  1792. });
  1793. return {
  1794. $set: {
  1795. archived: true,
  1796. archivedAt: new Date(),
  1797. },
  1798. };
  1799. },
  1800. restore() {
  1801. this.applyToChildren(card => {
  1802. return card.restore();
  1803. });
  1804. return {
  1805. $set: {
  1806. archived: false,
  1807. },
  1808. };
  1809. },
  1810. moveToEndOfList({ listId } = {}) {
  1811. let swimlaneId = this.swimlaneId;
  1812. const boardId = this.boardId;
  1813. let sortIndex = 0;
  1814. // This should never happen, but there was a bug that was fixed in commit
  1815. // ea0239538a68e225c867411a4f3e0d27c158383.
  1816. if (!swimlaneId) {
  1817. const board = Boards.findOne(boardId);
  1818. swimlaneId = board.getDefaultSwimline()._id;
  1819. }
  1820. // Move the minicard to the end of the target list
  1821. let parentElementDom = $(`#swimlane-${this.swimlaneId}`).get(0);
  1822. if (!parentElementDom) parentElementDom = $(':root');
  1823. const lastCardDom = $(parentElementDom)
  1824. .find(`#js-list-${listId} .js-minicard:last`)
  1825. .get(0);
  1826. if (lastCardDom) sortIndex = Utils.calculateIndex(lastCardDom, null).base;
  1827. return this.moveOptionalArgs({
  1828. boardId,
  1829. swimlaneId,
  1830. listId,
  1831. sort: sortIndex,
  1832. });
  1833. },
  1834. moveOptionalArgs({ boardId, swimlaneId, listId, sort } = {}) {
  1835. boardId = boardId || this.boardId;
  1836. swimlaneId = swimlaneId || this.swimlaneId;
  1837. // This should never happen, but there was a bug that was fixed in commit
  1838. // ea0239538a68e225c867411a4f3e0d27c158383.
  1839. if (!swimlaneId) {
  1840. const board = Boards.findOne(boardId);
  1841. swimlaneId = board.getDefaultSwimline()._id;
  1842. }
  1843. listId = listId || this.listId;
  1844. if (sort === undefined || sort === null) sort = this.sort;
  1845. return this.move(boardId, swimlaneId, listId, sort);
  1846. },
  1847. move(boardId, swimlaneId, listId, sort = null) {
  1848. const mutatedFields = {
  1849. boardId,
  1850. swimlaneId,
  1851. listId,
  1852. };
  1853. if (sort !== null) {
  1854. mutatedFields.sort = sort;
  1855. }
  1856. // we must only copy the labels and custom fields if the target board
  1857. // differs from the source board
  1858. if (this.boardId !== boardId) {
  1859. // Get label names
  1860. const oldBoard = Boards.findOne(this.boardId);
  1861. const oldBoardLabels = oldBoard.labels;
  1862. const oldCardLabels = _.pluck(
  1863. _.filter(oldBoardLabels, label => {
  1864. return _.contains(this.labelIds, label._id);
  1865. }),
  1866. 'name',
  1867. );
  1868. const newBoard = Boards.findOne(boardId);
  1869. const newBoardLabels = newBoard.labels;
  1870. const newCardLabelIds = _.pluck(
  1871. _.filter(newBoardLabels, label => {
  1872. return label.name && _.contains(oldCardLabels, label.name);
  1873. }),
  1874. '_id',
  1875. );
  1876. Object.assign(mutatedFields, {
  1877. labelIds: newCardLabelIds,
  1878. });
  1879. mutatedFields.customFields = this.mapCustomFieldsToBoard(newBoard._id);
  1880. }
  1881. Cards.update(this._id, {
  1882. $set: mutatedFields,
  1883. });
  1884. },
  1885. addLabel(labelId) {
  1886. return {
  1887. $addToSet: {
  1888. labelIds: labelId,
  1889. },
  1890. };
  1891. },
  1892. removeLabel(labelId) {
  1893. return {
  1894. $pull: {
  1895. labelIds: labelId,
  1896. },
  1897. };
  1898. },
  1899. toggleLabel(labelId) {
  1900. if (this.labelIds && this.labelIds.indexOf(labelId) > -1) {
  1901. return this.removeLabel(labelId);
  1902. } else {
  1903. return this.addLabel(labelId);
  1904. }
  1905. },
  1906. setColor(newColor) {
  1907. if (newColor === 'white') {
  1908. newColor = null;
  1909. }
  1910. return {
  1911. $set: {
  1912. color: newColor,
  1913. },
  1914. };
  1915. },
  1916. assignMember(memberId) {
  1917. return {
  1918. $addToSet: {
  1919. members: memberId,
  1920. },
  1921. };
  1922. },
  1923. assignAssignee(assigneeId) {
  1924. // If there is not any assignee, allow one assignee, not more.
  1925. /*
  1926. if (this.getAssignees().length === 0) {
  1927. return {
  1928. $addToSet: {
  1929. assignees: assigneeId,
  1930. },
  1931. };
  1932. */
  1933. // Allow more that one assignee:
  1934. // https://github.com/wekan/wekan/issues/3302
  1935. return {
  1936. $addToSet: {
  1937. assignees: assigneeId,
  1938. },
  1939. };
  1940. //} else {
  1941. // return false,
  1942. //}
  1943. },
  1944. unassignMember(memberId) {
  1945. return {
  1946. $pull: {
  1947. members: memberId,
  1948. },
  1949. };
  1950. },
  1951. unassignAssignee(assigneeId) {
  1952. return {
  1953. $pull: {
  1954. assignees: assigneeId,
  1955. },
  1956. };
  1957. },
  1958. toggleMember(memberId) {
  1959. if (this.members && this.members.indexOf(memberId) > -1) {
  1960. return this.unassignMember(memberId);
  1961. } else {
  1962. return this.assignMember(memberId);
  1963. }
  1964. },
  1965. toggleAssignee(assigneeId) {
  1966. if (this.assignees && this.assignees.indexOf(assigneeId) > -1) {
  1967. return this.unassignAssignee(assigneeId);
  1968. } else {
  1969. return this.assignAssignee(assigneeId);
  1970. }
  1971. },
  1972. assignCustomField(customFieldId) {
  1973. return {
  1974. $addToSet: {
  1975. customFields: {
  1976. _id: customFieldId,
  1977. value: null,
  1978. },
  1979. },
  1980. };
  1981. },
  1982. unassignCustomField(customFieldId) {
  1983. return {
  1984. $pull: {
  1985. customFields: {
  1986. _id: customFieldId,
  1987. },
  1988. },
  1989. };
  1990. },
  1991. toggleCustomField(customFieldId) {
  1992. if (this.customFields && this.customFieldIndex(customFieldId) > -1) {
  1993. return this.unassignCustomField(customFieldId);
  1994. } else {
  1995. return this.assignCustomField(customFieldId);
  1996. }
  1997. },
  1998. setCustomField(customFieldId, value) {
  1999. // todo
  2000. const index = this.customFieldIndex(customFieldId);
  2001. if (index > -1) {
  2002. const update = {
  2003. $set: {},
  2004. };
  2005. update.$set[`customFields.${index}.value`] = value;
  2006. return update;
  2007. }
  2008. // TODO
  2009. // Ignatz 18.05.2018: Return null to silence ESLint. No Idea if that is correct
  2010. return null;
  2011. },
  2012. setCover(coverId) {
  2013. return {
  2014. $set: {
  2015. coverId,
  2016. },
  2017. };
  2018. },
  2019. unsetCover() {
  2020. return {
  2021. $unset: {
  2022. coverId: '',
  2023. },
  2024. };
  2025. },
  2026. setReceived(receivedAt) {
  2027. return {
  2028. $set: {
  2029. receivedAt,
  2030. },
  2031. };
  2032. },
  2033. unsetReceived() {
  2034. return {
  2035. $unset: {
  2036. receivedAt: '',
  2037. },
  2038. };
  2039. },
  2040. setStart(startAt) {
  2041. return {
  2042. $set: {
  2043. startAt,
  2044. },
  2045. };
  2046. },
  2047. unsetStart() {
  2048. return {
  2049. $unset: {
  2050. startAt: '',
  2051. },
  2052. };
  2053. },
  2054. setDue(dueAt) {
  2055. return {
  2056. $set: {
  2057. dueAt,
  2058. },
  2059. };
  2060. },
  2061. unsetDue() {
  2062. return {
  2063. $unset: {
  2064. dueAt: '',
  2065. },
  2066. };
  2067. },
  2068. setEnd(endAt) {
  2069. return {
  2070. $set: {
  2071. endAt,
  2072. },
  2073. };
  2074. },
  2075. unsetEnd() {
  2076. return {
  2077. $unset: {
  2078. endAt: '',
  2079. },
  2080. };
  2081. },
  2082. setOvertime(isOvertime) {
  2083. return {
  2084. $set: {
  2085. isOvertime,
  2086. },
  2087. };
  2088. },
  2089. setSpentTime(spentTime) {
  2090. return {
  2091. $set: {
  2092. spentTime,
  2093. },
  2094. };
  2095. },
  2096. unsetSpentTime() {
  2097. return {
  2098. $unset: {
  2099. spentTime: '',
  2100. isOvertime: false,
  2101. },
  2102. };
  2103. },
  2104. setParentId(parentId) {
  2105. return {
  2106. $set: {
  2107. parentId,
  2108. },
  2109. };
  2110. },
  2111. setVoteQuestion(question, publicVote, allowNonBoardMembers) {
  2112. return {
  2113. $set: {
  2114. vote: {
  2115. question,
  2116. public: publicVote,
  2117. allowNonBoardMembers,
  2118. positive: [],
  2119. negative: [],
  2120. },
  2121. },
  2122. };
  2123. },
  2124. unsetVote() {
  2125. return {
  2126. $unset: {
  2127. vote: '',
  2128. },
  2129. };
  2130. },
  2131. setVoteEnd(end) {
  2132. return {
  2133. $set: { 'vote.end': end },
  2134. };
  2135. },
  2136. unsetVoteEnd() {
  2137. return {
  2138. $unset: { 'vote.end': '' },
  2139. };
  2140. },
  2141. setVote(userId, forIt) {
  2142. switch (forIt) {
  2143. case true:
  2144. // vote for it
  2145. return {
  2146. $pull: {
  2147. 'vote.negative': userId,
  2148. },
  2149. $addToSet: {
  2150. 'vote.positive': userId,
  2151. },
  2152. };
  2153. case false:
  2154. // vote against
  2155. return {
  2156. $pull: {
  2157. 'vote.positive': userId,
  2158. },
  2159. $addToSet: {
  2160. 'vote.negative': userId,
  2161. },
  2162. };
  2163. default:
  2164. // Remove votes
  2165. return {
  2166. $pull: {
  2167. 'vote.positive': userId,
  2168. 'vote.negative': userId,
  2169. },
  2170. };
  2171. }
  2172. },
  2173. setPokerQuestion(question, allowNonBoardMembers) {
  2174. return {
  2175. $set: {
  2176. poker: {
  2177. question,
  2178. allowNonBoardMembers,
  2179. one: [],
  2180. two: [],
  2181. three: [],
  2182. five: [],
  2183. eight: [],
  2184. thirteen: [],
  2185. twenty: [],
  2186. forty: [],
  2187. oneHundred: [],
  2188. unsure: [],
  2189. },
  2190. },
  2191. };
  2192. },
  2193. setPokerEstimation(estimation) {
  2194. return {
  2195. $set: { 'poker.estimation': estimation },
  2196. };
  2197. },
  2198. unsetPokerEstimation() {
  2199. return {
  2200. $unset: { 'poker.estimation': '' },
  2201. };
  2202. },
  2203. unsetPoker() {
  2204. return {
  2205. $unset: {
  2206. poker: '',
  2207. },
  2208. };
  2209. },
  2210. setPokerEnd(end) {
  2211. return {
  2212. $set: { 'poker.end': end },
  2213. };
  2214. },
  2215. unsetPokerEnd() {
  2216. return {
  2217. $unset: { 'poker.end': '' },
  2218. };
  2219. },
  2220. setPoker(userId, state) {
  2221. switch (state) {
  2222. case 'one':
  2223. // poker one
  2224. return {
  2225. $pull: {
  2226. 'poker.two': userId,
  2227. 'poker.three': userId,
  2228. 'poker.five': userId,
  2229. 'poker.eight': userId,
  2230. 'poker.thirteen': userId,
  2231. 'poker.twenty': userId,
  2232. 'poker.forty': userId,
  2233. 'poker.oneHundred': userId,
  2234. 'poker.unsure': userId,
  2235. },
  2236. $addToSet: {
  2237. 'poker.one': userId,
  2238. },
  2239. };
  2240. case 'two':
  2241. // poker two
  2242. return {
  2243. $pull: {
  2244. 'poker.one': userId,
  2245. 'poker.three': userId,
  2246. 'poker.five': userId,
  2247. 'poker.eight': userId,
  2248. 'poker.thirteen': userId,
  2249. 'poker.twenty': userId,
  2250. 'poker.forty': userId,
  2251. 'poker.oneHundred': userId,
  2252. 'poker.unsure': userId,
  2253. },
  2254. $addToSet: {
  2255. 'poker.two': userId,
  2256. },
  2257. };
  2258. case 'three':
  2259. // poker three
  2260. return {
  2261. $pull: {
  2262. 'poker.one': userId,
  2263. 'poker.two': userId,
  2264. 'poker.five': userId,
  2265. 'poker.eight': userId,
  2266. 'poker.thirteen': userId,
  2267. 'poker.twenty': userId,
  2268. 'poker.forty': userId,
  2269. 'poker.oneHundred': userId,
  2270. 'poker.unsure': userId,
  2271. },
  2272. $addToSet: {
  2273. 'poker.three': userId,
  2274. },
  2275. };
  2276. case 'five':
  2277. // poker five
  2278. return {
  2279. $pull: {
  2280. 'poker.one': userId,
  2281. 'poker.two': userId,
  2282. 'poker.three': userId,
  2283. 'poker.eight': userId,
  2284. 'poker.thirteen': userId,
  2285. 'poker.twenty': userId,
  2286. 'poker.forty': userId,
  2287. 'poker.oneHundred': userId,
  2288. 'poker.unsure': userId,
  2289. },
  2290. $addToSet: {
  2291. 'poker.five': userId,
  2292. },
  2293. };
  2294. case 'eight':
  2295. // poker eight
  2296. return {
  2297. $pull: {
  2298. 'poker.one': userId,
  2299. 'poker.two': userId,
  2300. 'poker.three': userId,
  2301. 'poker.five': userId,
  2302. 'poker.thirteen': userId,
  2303. 'poker.twenty': userId,
  2304. 'poker.forty': userId,
  2305. 'poker.oneHundred': userId,
  2306. 'poker.unsure': userId,
  2307. },
  2308. $addToSet: {
  2309. 'poker.eight': userId,
  2310. },
  2311. };
  2312. case 'thirteen':
  2313. // poker thirteen
  2314. return {
  2315. $pull: {
  2316. 'poker.one': userId,
  2317. 'poker.two': userId,
  2318. 'poker.three': userId,
  2319. 'poker.five': userId,
  2320. 'poker.eight': userId,
  2321. 'poker.twenty': userId,
  2322. 'poker.forty': userId,
  2323. 'poker.oneHundred': userId,
  2324. 'poker.unsure': userId,
  2325. },
  2326. $addToSet: {
  2327. 'poker.thirteen': userId,
  2328. },
  2329. };
  2330. case 'twenty':
  2331. // poker twenty
  2332. return {
  2333. $pull: {
  2334. 'poker.one': userId,
  2335. 'poker.two': userId,
  2336. 'poker.three': userId,
  2337. 'poker.five': userId,
  2338. 'poker.eight': userId,
  2339. 'poker.thirteen': userId,
  2340. 'poker.forty': userId,
  2341. 'poker.oneHundred': userId,
  2342. 'poker.unsure': userId,
  2343. },
  2344. $addToSet: {
  2345. 'poker.twenty': userId,
  2346. },
  2347. };
  2348. case 'forty':
  2349. // poker forty
  2350. return {
  2351. $pull: {
  2352. 'poker.one': userId,
  2353. 'poker.two': userId,
  2354. 'poker.three': userId,
  2355. 'poker.five': userId,
  2356. 'poker.eight': userId,
  2357. 'poker.thirteen': userId,
  2358. 'poker.twenty': userId,
  2359. 'poker.oneHundred': userId,
  2360. 'poker.unsure': userId,
  2361. },
  2362. $addToSet: {
  2363. 'poker.forty': userId,
  2364. },
  2365. };
  2366. case 'oneHundred':
  2367. // poker one hundred
  2368. return {
  2369. $pull: {
  2370. 'poker.one': userId,
  2371. 'poker.two': userId,
  2372. 'poker.three': userId,
  2373. 'poker.five': userId,
  2374. 'poker.eight': userId,
  2375. 'poker.thirteen': userId,
  2376. 'poker.twenty': userId,
  2377. 'poker.forty': userId,
  2378. 'poker.unsure': userId,
  2379. },
  2380. $addToSet: {
  2381. 'poker.oneHundred': userId,
  2382. },
  2383. };
  2384. case 'unsure':
  2385. // poker unsure
  2386. return {
  2387. $pull: {
  2388. 'poker.one': userId,
  2389. 'poker.two': userId,
  2390. 'poker.three': userId,
  2391. 'poker.five': userId,
  2392. 'poker.eight': userId,
  2393. 'poker.thirteen': userId,
  2394. 'poker.twenty': userId,
  2395. 'poker.forty': userId,
  2396. 'poker.oneHundred': userId,
  2397. },
  2398. $addToSet: {
  2399. 'poker.unsure': userId,
  2400. },
  2401. };
  2402. default:
  2403. // Remove pokers
  2404. return {
  2405. $pull: {
  2406. 'poker.one': userId,
  2407. 'poker.two': userId,
  2408. 'poker.three': userId,
  2409. 'poker.five': userId,
  2410. 'poker.eight': userId,
  2411. 'poker.thirteen': userId,
  2412. 'poker.twenty': userId,
  2413. 'poker.forty': userId,
  2414. 'poker.oneHundred': userId,
  2415. 'poker.unsure': userId,
  2416. },
  2417. };
  2418. }
  2419. },
  2420. replayPoker() {
  2421. return {
  2422. $set: {
  2423. 'poker.one': [],
  2424. 'poker.two': [],
  2425. 'poker.three': [],
  2426. 'poker.five': [],
  2427. 'poker.eight': [],
  2428. 'poker.thirteen': [],
  2429. 'poker.twelve': [],
  2430. 'poker.forty': [],
  2431. 'poker.oneHundred': [],
  2432. 'poker.unsure': [],
  2433. },
  2434. };
  2435. },
  2436. });
  2437. //FUNCTIONS FOR creation of Activities
  2438. function updateActivities(doc, fieldNames, modifier) {
  2439. if (_.contains(fieldNames, 'labelIds') && _.contains(fieldNames, 'boardId')) {
  2440. Activities.find({
  2441. activityType: 'addedLabel',
  2442. cardId: doc._id,
  2443. }).forEach(a => {
  2444. const lidx = doc.labelIds.indexOf(a.labelId);
  2445. if (lidx !== -1 && modifier.$set.labelIds.length > lidx) {
  2446. Activities.update(a._id, {
  2447. $set: {
  2448. labelId: modifier.$set.labelIds[doc.labelIds.indexOf(a.labelId)],
  2449. boardId: modifier.$set.boardId,
  2450. },
  2451. });
  2452. } else {
  2453. Activities.remove(a._id);
  2454. }
  2455. });
  2456. } else if (_.contains(fieldNames, 'boardId')) {
  2457. Activities.remove({
  2458. activityType: 'addedLabel',
  2459. cardId: doc._id,
  2460. });
  2461. }
  2462. }
  2463. function cardMove(
  2464. userId,
  2465. doc,
  2466. fieldNames,
  2467. oldListId,
  2468. oldSwimlaneId,
  2469. oldBoardId,
  2470. ) {
  2471. if (_.contains(fieldNames, 'boardId') && doc.boardId !== oldBoardId) {
  2472. Activities.insert({
  2473. userId,
  2474. activityType: 'moveCardBoard',
  2475. boardName: Boards.findOne(doc.boardId).title,
  2476. boardId: doc.boardId,
  2477. oldBoardId,
  2478. oldBoardName: Boards.findOne(oldBoardId).title,
  2479. cardId: doc._id,
  2480. swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,
  2481. swimlaneId: doc.swimlaneId,
  2482. oldSwimlaneId,
  2483. });
  2484. } else if (
  2485. (_.contains(fieldNames, 'listId') && doc.listId !== oldListId) ||
  2486. (_.contains(fieldNames, 'swimlaneId') && doc.swimlaneId !== oldSwimlaneId)
  2487. ) {
  2488. Activities.insert({
  2489. userId,
  2490. oldListId,
  2491. activityType: 'moveCard',
  2492. listName: Lists.findOne(doc.listId).title,
  2493. listId: doc.listId,
  2494. boardId: doc.boardId,
  2495. cardId: doc._id,
  2496. cardTitle: doc.title,
  2497. swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,
  2498. swimlaneId: doc.swimlaneId,
  2499. oldSwimlaneId,
  2500. });
  2501. }
  2502. }
  2503. function cardState(userId, doc, fieldNames) {
  2504. if (_.contains(fieldNames, 'archived')) {
  2505. if (doc.archived) {
  2506. Activities.insert({
  2507. userId,
  2508. activityType: 'archivedCard',
  2509. listName: Lists.findOne(doc.listId).title,
  2510. boardId: doc.boardId,
  2511. listId: doc.listId,
  2512. cardId: doc._id,
  2513. swimlaneId: doc.swimlaneId,
  2514. });
  2515. } else {
  2516. Activities.insert({
  2517. userId,
  2518. activityType: 'restoredCard',
  2519. boardId: doc.boardId,
  2520. listName: Lists.findOne(doc.listId).title,
  2521. listId: doc.listId,
  2522. cardId: doc._id,
  2523. swimlaneId: doc.swimlaneId,
  2524. });
  2525. }
  2526. }
  2527. }
  2528. function cardMembers(userId, doc, fieldNames, modifier) {
  2529. if (!_.contains(fieldNames, 'members')) return;
  2530. let memberId;
  2531. // Say hello to the new member
  2532. if (modifier.$addToSet && modifier.$addToSet.members) {
  2533. memberId = modifier.$addToSet.members;
  2534. const username = Users.findOne(memberId).username;
  2535. if (!_.contains(doc.members, memberId)) {
  2536. Activities.insert({
  2537. userId,
  2538. username,
  2539. activityType: 'joinMember',
  2540. boardId: doc.boardId,
  2541. cardId: doc._id,
  2542. memberId,
  2543. listId: doc.listId,
  2544. swimlaneId: doc.swimlaneId,
  2545. });
  2546. }
  2547. }
  2548. // Say goodbye to the former member
  2549. if (modifier.$pull && modifier.$pull.members) {
  2550. memberId = modifier.$pull.members;
  2551. const username = Users.findOne(memberId).username;
  2552. // Check that the former member is member of the card
  2553. if (_.contains(doc.members, memberId)) {
  2554. Activities.insert({
  2555. userId,
  2556. username,
  2557. activityType: 'unjoinMember',
  2558. boardId: doc.boardId,
  2559. cardId: doc._id,
  2560. memberId,
  2561. listId: doc.listId,
  2562. swimlaneId: doc.swimlaneId,
  2563. });
  2564. }
  2565. }
  2566. }
  2567. function cardAssignees(userId, doc, fieldNames, modifier) {
  2568. if (!_.contains(fieldNames, 'assignees')) return;
  2569. let assigneeId;
  2570. // Say hello to the new assignee
  2571. if (modifier.$addToSet && modifier.$addToSet.assignees) {
  2572. assigneeId = modifier.$addToSet.assignees;
  2573. const username = Users.findOne(assigneeId).username;
  2574. if (!_.contains(doc.assignees, assigneeId)) {
  2575. Activities.insert({
  2576. userId,
  2577. username,
  2578. activityType: 'joinAssignee',
  2579. boardId: doc.boardId,
  2580. cardId: doc._id,
  2581. assigneeId,
  2582. listId: doc.listId,
  2583. swimlaneId: doc.swimlaneId,
  2584. });
  2585. }
  2586. }
  2587. // Say goodbye to the former assignee
  2588. if (modifier.$pull && modifier.$pull.assignees) {
  2589. assigneeId = modifier.$pull.assignees;
  2590. const username = Users.findOne(assigneeId).username;
  2591. // Check that the former assignee is assignee of the card
  2592. if (_.contains(doc.assignees, assigneeId)) {
  2593. Activities.insert({
  2594. userId,
  2595. username,
  2596. activityType: 'unjoinAssignee',
  2597. boardId: doc.boardId,
  2598. cardId: doc._id,
  2599. assigneeId,
  2600. listId: doc.listId,
  2601. swimlaneId: doc.swimlaneId,
  2602. });
  2603. }
  2604. }
  2605. }
  2606. function cardLabels(userId, doc, fieldNames, modifier) {
  2607. if (!_.contains(fieldNames, 'labelIds')) return;
  2608. let labelId;
  2609. // Say hello to the new label
  2610. if (modifier.$addToSet && modifier.$addToSet.labelIds) {
  2611. labelId = modifier.$addToSet.labelIds;
  2612. if (!_.contains(doc.labelIds, labelId)) {
  2613. const act = {
  2614. userId,
  2615. labelId,
  2616. activityType: 'addedLabel',
  2617. boardId: doc.boardId,
  2618. cardId: doc._id,
  2619. listId: doc.listId,
  2620. swimlaneId: doc.swimlaneId,
  2621. };
  2622. Activities.insert(act);
  2623. }
  2624. }
  2625. // Say goodbye to the label
  2626. if (modifier.$pull && modifier.$pull.labelIds) {
  2627. labelId = modifier.$pull.labelIds;
  2628. // Check that the former member is member of the card
  2629. if (_.contains(doc.labelIds, labelId)) {
  2630. Activities.insert({
  2631. userId,
  2632. labelId,
  2633. activityType: 'removedLabel',
  2634. boardId: doc.boardId,
  2635. cardId: doc._id,
  2636. listId: doc.listId,
  2637. swimlaneId: doc.swimlaneId,
  2638. });
  2639. }
  2640. }
  2641. }
  2642. function cardCustomFields(userId, doc, fieldNames, modifier) {
  2643. if (!_.contains(fieldNames, 'customFields')) return;
  2644. // Say hello to the new customField value
  2645. if (modifier.$set) {
  2646. _.each(modifier.$set, (value, key) => {
  2647. if (key.startsWith('customFields')) {
  2648. const dotNotation = key.split('.');
  2649. // only individual changes are registered
  2650. if (dotNotation.length > 1) {
  2651. const customFieldId = doc.customFields[dotNotation[1]]._id;
  2652. const act = {
  2653. userId,
  2654. customFieldId,
  2655. value,
  2656. activityType: 'setCustomField',
  2657. boardId: doc.boardId,
  2658. cardId: doc._id,
  2659. listId: doc.listId,
  2660. swimlaneId: doc.swimlaneId,
  2661. };
  2662. Activities.insert(act);
  2663. }
  2664. }
  2665. });
  2666. }
  2667. // Say goodbye to the former customField value
  2668. if (modifier.$unset) {
  2669. _.each(modifier.$unset, (value, key) => {
  2670. if (key.startsWith('customFields')) {
  2671. const dotNotation = key.split('.');
  2672. // only individual changes are registered
  2673. if (dotNotation.length > 1) {
  2674. const customFieldId = doc.customFields[dotNotation[1]]._id;
  2675. const act = {
  2676. userId,
  2677. customFieldId,
  2678. activityType: 'unsetCustomField',
  2679. boardId: doc.boardId,
  2680. cardId: doc._id,
  2681. };
  2682. Activities.insert(act);
  2683. }
  2684. }
  2685. });
  2686. }
  2687. }
  2688. function cardCreation(userId, doc) {
  2689. Activities.insert({
  2690. userId,
  2691. activityType: 'createCard',
  2692. boardId: doc.boardId,
  2693. listName: Lists.findOne(doc.listId).title,
  2694. listId: doc.listId,
  2695. cardId: doc._id,
  2696. cardTitle: doc.title,
  2697. swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,
  2698. swimlaneId: doc.swimlaneId,
  2699. });
  2700. }
  2701. function cardRemover(userId, doc) {
  2702. ChecklistItems.remove({
  2703. cardId: doc._id,
  2704. });
  2705. Checklists.remove({
  2706. cardId: doc._id,
  2707. });
  2708. Cards.remove({
  2709. parentId: doc._id,
  2710. });
  2711. CardComments.remove({
  2712. cardId: doc._id,
  2713. });
  2714. Attachments.remove({
  2715. cardId: doc._id,
  2716. });
  2717. }
  2718. const findDueCards = days => {
  2719. const seekDue = ($from, $to, activityType) => {
  2720. Cards.find({
  2721. archived: false,
  2722. dueAt: { $gte: $from, $lt: $to },
  2723. }).forEach(card => {
  2724. const username = Users.findOne(card.userId).username;
  2725. const activity = {
  2726. userId: card.userId,
  2727. username,
  2728. activityType,
  2729. boardId: card.boardId,
  2730. cardId: card._id,
  2731. cardTitle: card.title,
  2732. listId: card.listId,
  2733. timeValue: card.dueAt,
  2734. swimlaneId: card.swimlaneId,
  2735. };
  2736. Activities.insert(activity);
  2737. });
  2738. };
  2739. const now = new Date(),
  2740. aday = 3600 * 24 * 1e3,
  2741. then = day => new Date(now.setHours(0, 0, 0, 0) + day * aday);
  2742. if (!days) return;
  2743. if (!days.map) days = [days];
  2744. days.map(day => {
  2745. let args = [];
  2746. if (day === 0) {
  2747. args = [then(0), then(1), 'duenow'];
  2748. } else if (day > 0) {
  2749. args = [then(1), then(day), 'almostdue'];
  2750. } else {
  2751. args = [then(day), now, 'pastdue'];
  2752. }
  2753. seekDue(...args);
  2754. });
  2755. };
  2756. const addCronJob = _.debounce(
  2757. Meteor.bindEnvironment(function findDueCardsDebounced() {
  2758. const envValue = process.env.NOTIFY_DUE_DAYS_BEFORE_AND_AFTER;
  2759. if (!envValue) {
  2760. return;
  2761. }
  2762. const notifydays = envValue
  2763. .split(',')
  2764. .map(value => {
  2765. const iValue = parseInt(value, 10);
  2766. if (!(iValue > 0 && iValue < 15)) {
  2767. // notifying due is disabled
  2768. return false;
  2769. } else {
  2770. return iValue;
  2771. }
  2772. })
  2773. .filter(Boolean);
  2774. 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
  2775. const defaultitvl = 8; // default every morning at 8am, if the passed env variable has parsing error use default
  2776. const itvl = parseInt(notifyitvl, 10) || defaultitvl;
  2777. const scheduler = (job => () => {
  2778. const now = new Date();
  2779. const hour = 3600 * 1e3;
  2780. if (now.getHours() === itvl) {
  2781. if (typeof job === 'function') {
  2782. job();
  2783. }
  2784. }
  2785. Meteor.setTimeout(scheduler, hour);
  2786. })(() => {
  2787. findDueCards(notifydays);
  2788. });
  2789. scheduler();
  2790. }),
  2791. 500,
  2792. );
  2793. if (Meteor.isServer) {
  2794. // Cards are often fetched within a board, so we create an index to make these
  2795. // queries more efficient.
  2796. Meteor.startup(() => {
  2797. Cards._collection._ensureIndex({ modifiedAt: -1 });
  2798. Cards._collection._ensureIndex({ boardId: 1, createdAt: -1 });
  2799. // https://github.com/wekan/wekan/issues/1863
  2800. // Swimlane added a new field in the cards collection of mongodb named parentId.
  2801. // When loading a board, mongodb is searching for every cards, the id of the parent (in the swinglanes collection).
  2802. // With a huge database, this result in a very slow app and high CPU on the mongodb side.
  2803. // To correct it, add Index to parentId:
  2804. Cards._collection._ensureIndex({ parentId: 1 });
  2805. // let notifydays = parseInt(process.env.NOTIFY_DUE_DAYS_BEFORE_AND_AFTER) || 2; // default as 2 days b4 and after
  2806. // let notifyitvl = parseInt(process.env.NOTIFY_DUE_AT_HOUR_OF_DAY) || 3600 * 24 * 1e3; // default interval as one day
  2807. // Meteor.call("findDueCards",notifydays,notifyitvl);
  2808. Meteor.defer(() => {
  2809. addCronJob();
  2810. });
  2811. });
  2812. Cards.after.insert((userId, doc) => {
  2813. cardCreation(userId, doc);
  2814. });
  2815. // New activity for card (un)archivage
  2816. Cards.after.update((userId, doc, fieldNames) => {
  2817. cardState(userId, doc, fieldNames);
  2818. });
  2819. //New activity for card moves
  2820. Cards.after.update(function(userId, doc, fieldNames) {
  2821. const oldListId = this.previous.listId;
  2822. const oldSwimlaneId = this.previous.swimlaneId;
  2823. const oldBoardId = this.previous.boardId;
  2824. cardMove(userId, doc, fieldNames, oldListId, oldSwimlaneId, oldBoardId);
  2825. });
  2826. // Add a new activity if we add or remove a member to the card
  2827. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2828. cardMembers(userId, doc, fieldNames, modifier);
  2829. updateActivities(doc, fieldNames, modifier);
  2830. });
  2831. // Add a new activity if we add or remove a assignee to the card
  2832. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2833. cardAssignees(userId, doc, fieldNames, modifier);
  2834. updateActivities(doc, fieldNames, modifier);
  2835. });
  2836. // Add a new activity if we add or remove a label to the card
  2837. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2838. cardLabels(userId, doc, fieldNames, modifier);
  2839. });
  2840. // Add a new activity if we edit a custom field
  2841. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2842. cardCustomFields(userId, doc, fieldNames, modifier);
  2843. });
  2844. // Add a new activity if modify time related field like dueAt startAt etc
  2845. Cards.before.update((userId, doc, fieldNames, modifier) => {
  2846. const dla = 'dateLastActivity';
  2847. const fields = fieldNames.filter(name => name !== dla);
  2848. const timingaction = ['receivedAt', 'dueAt', 'startAt', 'endAt'];
  2849. const action = fields[0];
  2850. if (fields.length > 0 && _.contains(timingaction, action)) {
  2851. // add activities for user change these attributes
  2852. const value = modifier.$set[action];
  2853. const oldvalue = doc[action] || '';
  2854. const activityType = `a-${action}`;
  2855. const card = Cards.findOne(doc._id);
  2856. const list = card.list();
  2857. if (list) {
  2858. // change list modifiedAt, when user modified the key values in
  2859. // timingaction array, if it's endAt, put the modifiedAt of list
  2860. // back to one year ago for sorting purpose
  2861. const modifiedAt = moment()
  2862. .subtract(1, 'year')
  2863. .toISOString();
  2864. const boardId = list.boardId;
  2865. Lists.direct.update(
  2866. {
  2867. _id: list._id,
  2868. },
  2869. {
  2870. $set: {
  2871. modifiedAt,
  2872. boardId,
  2873. },
  2874. },
  2875. );
  2876. }
  2877. const username = Users.findOne(userId).username;
  2878. const activity = {
  2879. userId,
  2880. username,
  2881. activityType,
  2882. boardId: doc.boardId,
  2883. cardId: doc._id,
  2884. cardTitle: doc.title,
  2885. timeKey: action,
  2886. timeValue: value,
  2887. timeOldValue: oldvalue,
  2888. listId: card.listId,
  2889. swimlaneId: card.swimlaneId,
  2890. };
  2891. Activities.insert(activity);
  2892. }
  2893. });
  2894. // Remove all activities associated with a card if we remove the card
  2895. // Remove also card_comments / checklists / attachments
  2896. Cards.before.remove((userId, doc) => {
  2897. cardRemover(userId, doc);
  2898. });
  2899. }
  2900. //SWIMLANES REST API
  2901. if (Meteor.isServer) {
  2902. /**
  2903. * @operation get_swimlane_cards
  2904. * @summary get all cards attached to a swimlane
  2905. *
  2906. * @param {string} boardId the board ID
  2907. * @param {string} swimlaneId the swimlane ID
  2908. * @return_type [{_id: string,
  2909. * title: string,
  2910. * description: string,
  2911. * listId: string}]
  2912. */
  2913. JsonRoutes.add(
  2914. 'GET',
  2915. '/api/boards/:boardId/swimlanes/:swimlaneId/cards',
  2916. function(req, res) {
  2917. const paramBoardId = req.params.boardId;
  2918. const paramSwimlaneId = req.params.swimlaneId;
  2919. Authentication.checkBoardAccess(req.userId, paramBoardId);
  2920. JsonRoutes.sendResult(res, {
  2921. code: 200,
  2922. data: Cards.find({
  2923. boardId: paramBoardId,
  2924. swimlaneId: paramSwimlaneId,
  2925. archived: false,
  2926. }).map(function(doc) {
  2927. return {
  2928. _id: doc._id,
  2929. title: doc.title,
  2930. description: doc.description,
  2931. listId: doc.listId,
  2932. receivedAt: doc.receivedAt,
  2933. startAt: doc.startAt,
  2934. dueAt: doc.dueAt,
  2935. endAt: doc.endAt,
  2936. assignees: doc.assignees,
  2937. };
  2938. }),
  2939. });
  2940. },
  2941. );
  2942. }
  2943. //LISTS REST API
  2944. if (Meteor.isServer) {
  2945. /**
  2946. * @operation get_all_cards
  2947. * @summary Get all Cards attached to a List
  2948. *
  2949. * @param {string} boardId the board ID
  2950. * @param {string} listId the list ID
  2951. * @return_type [{_id: string,
  2952. * title: string,
  2953. * description: string}]
  2954. */
  2955. JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId/cards', function(
  2956. req,
  2957. res,
  2958. ) {
  2959. const paramBoardId = req.params.boardId;
  2960. const paramListId = req.params.listId;
  2961. Authentication.checkBoardAccess(req.userId, paramBoardId);
  2962. JsonRoutes.sendResult(res, {
  2963. code: 200,
  2964. data: Cards.find({
  2965. boardId: paramBoardId,
  2966. listId: paramListId,
  2967. archived: false,
  2968. }).map(function(doc) {
  2969. return {
  2970. _id: doc._id,
  2971. title: doc.title,
  2972. description: doc.description,
  2973. receivedAt: doc.receivedAt,
  2974. startAt: doc.startAt,
  2975. dueAt: doc.dueAt,
  2976. endAt: doc.endAt,
  2977. assignees: doc.assignees,
  2978. };
  2979. }),
  2980. });
  2981. });
  2982. /**
  2983. * @operation get_card
  2984. * @summary Get a Card
  2985. *
  2986. * @param {string} boardId the board ID
  2987. * @param {string} listId the list ID of the card
  2988. * @param {string} cardId the card ID
  2989. * @return_type Cards
  2990. */
  2991. JsonRoutes.add(
  2992. 'GET',
  2993. '/api/boards/:boardId/lists/:listId/cards/:cardId',
  2994. function(req, res) {
  2995. const paramBoardId = req.params.boardId;
  2996. const paramListId = req.params.listId;
  2997. const paramCardId = req.params.cardId;
  2998. Authentication.checkBoardAccess(req.userId, paramBoardId);
  2999. JsonRoutes.sendResult(res, {
  3000. code: 200,
  3001. data: Cards.findOne({
  3002. _id: paramCardId,
  3003. listId: paramListId,
  3004. boardId: paramBoardId,
  3005. archived: false,
  3006. }),
  3007. });
  3008. },
  3009. );
  3010. /**
  3011. * @operation new_card
  3012. * @summary Create a new Card
  3013. *
  3014. * @param {string} boardId the board ID of the new card
  3015. * @param {string} listId the list ID of the new card
  3016. * @param {string} authorID the user ID of the person owning the card
  3017. * @param {string} parentId the parent ID of the new card
  3018. * @param {string} title the title of the new card
  3019. * @param {string} description the description of the new card
  3020. * @param {string} swimlaneId the swimlane ID of the new card
  3021. * @param {string} [members] the member IDs list of the new card
  3022. * @param {string} [assignees] the array of maximum one ID of assignee of the new card
  3023. * @return_type {_id: string}
  3024. */
  3025. JsonRoutes.add('POST', '/api/boards/:boardId/lists/:listId/cards', function(
  3026. req,
  3027. res,
  3028. ) {
  3029. // Check user is logged in
  3030. Authentication.checkLoggedIn(req.userId);
  3031. const paramBoardId = req.params.boardId;
  3032. // Check user has permission to add card to the board
  3033. const board = Boards.findOne({
  3034. _id: paramBoardId,
  3035. });
  3036. const addPermission = allowIsBoardMemberCommentOnly(req.userId, board);
  3037. Authentication.checkAdminOrCondition(req.userId, addPermission);
  3038. const paramListId = req.params.listId;
  3039. const paramParentId = req.params.parentId;
  3040. const nextCardNumber = board.getNextCardNumber();
  3041. const currentCards = Cards.find(
  3042. {
  3043. listId: paramListId,
  3044. archived: false,
  3045. },
  3046. { sort: ['sort'] },
  3047. );
  3048. const check = Users.findOne({
  3049. _id: req.body.authorId,
  3050. });
  3051. const members = req.body.members;
  3052. const assignees = req.body.assignees;
  3053. if (typeof check !== 'undefined') {
  3054. const id = Cards.direct.insert({
  3055. title: req.body.title,
  3056. boardId: paramBoardId,
  3057. listId: paramListId,
  3058. parentId: paramParentId,
  3059. description: req.body.description,
  3060. userId: req.body.authorId,
  3061. swimlaneId: req.body.swimlaneId,
  3062. sort: currentCards.count(),
  3063. cardNumber: nextCardNumber,
  3064. members,
  3065. assignees,
  3066. });
  3067. JsonRoutes.sendResult(res, {
  3068. code: 200,
  3069. data: {
  3070. _id: id,
  3071. },
  3072. });
  3073. const card = Cards.findOne({
  3074. _id: id,
  3075. });
  3076. cardCreation(req.body.authorId, card);
  3077. } else {
  3078. JsonRoutes.sendResult(res, {
  3079. code: 401,
  3080. });
  3081. }
  3082. });
  3083. /*
  3084. * Note for the JSDoc:
  3085. * 'list' will be interpreted as the path parameter
  3086. * 'listID' will be interpreted as the body parameter
  3087. */
  3088. /**
  3089. * @operation edit_card
  3090. * @summary Edit Fields in a Card
  3091. *
  3092. * @description Edit a card
  3093. *
  3094. * The color has to be chosen between `white`, `green`, `yellow`, `orange`,
  3095. * `red`, `purple`, `blue`, `sky`, `lime`, `pink`, `black`, `silver`,
  3096. * `peachpuff`, `crimson`, `plum`, `darkgreen`, `slateblue`, `magenta`,
  3097. * `gold`, `navy`, `gray`, `saddlebrown`, `paleturquoise`, `mistyrose`,
  3098. * `indigo`:
  3099. *
  3100. * <img src="/card-colors.png" width="40%" alt="Wekan card colors" />
  3101. *
  3102. * Note: setting the color to white has the same effect than removing it.
  3103. *
  3104. * @param {string} boardId the board ID of the card
  3105. * @param {string} list the list ID of the card
  3106. * @param {string} cardId the ID of the card
  3107. * @param {string} [title] the new title of the card
  3108. * @param {string} [sort] the new sort value of the card
  3109. * @param {string} [listId] the new list ID of the card (move operation)
  3110. * @param {string} [description] the new description of the card
  3111. * @param {string} [authorId] change the owner of the card
  3112. * @param {string} [parentId] change the parent of the card
  3113. * @param {string} [labelIds] the new list of label IDs attached to the card
  3114. * @param {string} [swimlaneId] the new swimlane ID of the card
  3115. * @param {string} [members] the new list of member IDs attached to the card
  3116. * @param {string} [assignees] the array of maximum one ID of assignee attached to the card
  3117. * @param {string} [requestedBy] the new requestedBy field of the card
  3118. * @param {string} [assignedBy] the new assignedBy field of the card
  3119. * @param {string} [receivedAt] the new receivedAt field of the card
  3120. * @param {string} [assignBy] the new assignBy field of the card
  3121. * @param {string} [startAt] the new startAt field of the card
  3122. * @param {string} [dueAt] the new dueAt field of the card
  3123. * @param {string} [endAt] the new endAt field of the card
  3124. * @param {string} [spentTime] the new spentTime field of the card
  3125. * @param {boolean} [isOverTime] the new isOverTime field of the card
  3126. * @param {string} [customFields] the new customFields value of the card
  3127. * @param {string} [color] the new color of the card
  3128. * @param {Object} [vote] the vote object
  3129. * @param {string} vote.question the vote question
  3130. * @param {boolean} vote.public show who voted what
  3131. * @param {boolean} vote.allowNonBoardMembers allow all logged in users to vote?
  3132. * @param {Object} [poker] the poker object
  3133. * @param {string} poker.question the vote question
  3134. * @param {boolean} poker.allowNonBoardMembers allow all logged in users to vote?
  3135. * @return_type {_id: string}
  3136. */
  3137. JsonRoutes.add(
  3138. 'PUT',
  3139. '/api/boards/:boardId/lists/:listId/cards/:cardId',
  3140. function(req, res) {
  3141. const paramBoardId = req.params.boardId;
  3142. Authentication.checkBoardAccess(req.userId, paramBoardId);
  3143. const paramCardId = req.params.cardId;
  3144. const paramListId = req.params.listId;
  3145. if (req.body.hasOwnProperty('title')) {
  3146. const newTitle = req.body.title;
  3147. Cards.direct.update(
  3148. {
  3149. _id: paramCardId,
  3150. listId: paramListId,
  3151. boardId: paramBoardId,
  3152. archived: false,
  3153. },
  3154. {
  3155. $set: {
  3156. title: newTitle,
  3157. },
  3158. },
  3159. );
  3160. }
  3161. if (req.body.hasOwnProperty('sort')) {
  3162. const newSort = req.body.sort;
  3163. Cards.direct.update(
  3164. {
  3165. _id: paramCardId,
  3166. listId: paramListId,
  3167. boardId: paramBoardId,
  3168. archived: false,
  3169. },
  3170. {
  3171. $set: {
  3172. sort: newSort,
  3173. },
  3174. },
  3175. );
  3176. }
  3177. if (req.body.hasOwnProperty('parentId')) {
  3178. const newParentId = req.body.parentId;
  3179. Cards.direct.update(
  3180. {
  3181. _id: paramCardId,
  3182. listId: paramListId,
  3183. boardId: paramBoardId,
  3184. archived: false,
  3185. },
  3186. {
  3187. $set: {
  3188. parentId: newParentId,
  3189. },
  3190. },
  3191. );
  3192. }
  3193. if (req.body.hasOwnProperty('description')) {
  3194. const newDescription = req.body.description;
  3195. Cards.direct.update(
  3196. {
  3197. _id: paramCardId,
  3198. listId: paramListId,
  3199. boardId: paramBoardId,
  3200. archived: false,
  3201. },
  3202. {
  3203. $set: {
  3204. description: newDescription,
  3205. },
  3206. },
  3207. );
  3208. }
  3209. if (req.body.hasOwnProperty('color')) {
  3210. const newColor = req.body.color;
  3211. Cards.direct.update(
  3212. {
  3213. _id: paramCardId,
  3214. listId: paramListId,
  3215. boardId: paramBoardId,
  3216. archived: false,
  3217. },
  3218. { $set: { color: newColor } },
  3219. );
  3220. }
  3221. if (req.body.hasOwnProperty('vote')) {
  3222. const newVote = req.body.vote;
  3223. newVote.positive = [];
  3224. newVote.negative = [];
  3225. if (!newVote.hasOwnProperty('public')) newVote.public = false;
  3226. if (!newVote.hasOwnProperty('allowNonBoardMembers'))
  3227. newVote.allowNonBoardMembers = false;
  3228. Cards.direct.update(
  3229. {
  3230. _id: paramCardId,
  3231. listId: paramListId,
  3232. boardId: paramBoardId,
  3233. archived: false,
  3234. },
  3235. { $set: { vote: newVote } },
  3236. );
  3237. }
  3238. if (req.body.hasOwnProperty('poker')) {
  3239. const newPoker = req.body.poker;
  3240. newPoker.one = [];
  3241. newPoker.two = [];
  3242. newPoker.three = [];
  3243. newPoker.five = [];
  3244. newPoker.eight = [];
  3245. newPoker.thirteen = [];
  3246. newPoker.twenty = [];
  3247. newPoker.forty = [];
  3248. newPoker.oneHundred = [];
  3249. newPoker.unsure = [];
  3250. if (!newPoker.hasOwnProperty('allowNonBoardMembers'))
  3251. newPoker.allowNonBoardMembers = false;
  3252. Cards.direct.update(
  3253. {
  3254. _id: paramCardId,
  3255. listId: paramListId,
  3256. boardId: paramBoardId,
  3257. archived: false,
  3258. },
  3259. { $set: { poker: newPoker } },
  3260. );
  3261. }
  3262. if (req.body.hasOwnProperty('labelIds')) {
  3263. let newlabelIds = req.body.labelIds;
  3264. if (_.isString(newlabelIds)) {
  3265. if (newlabelIds === '') {
  3266. newlabelIds = null;
  3267. } else {
  3268. newlabelIds = [newlabelIds];
  3269. }
  3270. }
  3271. Cards.direct.update(
  3272. {
  3273. _id: paramCardId,
  3274. listId: paramListId,
  3275. boardId: paramBoardId,
  3276. archived: false,
  3277. },
  3278. {
  3279. $set: {
  3280. labelIds: newlabelIds,
  3281. },
  3282. },
  3283. );
  3284. }
  3285. if (req.body.hasOwnProperty('requestedBy')) {
  3286. const newrequestedBy = req.body.requestedBy;
  3287. Cards.direct.update(
  3288. {
  3289. _id: paramCardId,
  3290. listId: paramListId,
  3291. boardId: paramBoardId,
  3292. archived: false,
  3293. },
  3294. { $set: { requestedBy: newrequestedBy } },
  3295. );
  3296. }
  3297. if (req.body.hasOwnProperty('assignedBy')) {
  3298. const newassignedBy = req.body.assignedBy;
  3299. Cards.direct.update(
  3300. {
  3301. _id: paramCardId,
  3302. listId: paramListId,
  3303. boardId: paramBoardId,
  3304. archived: false,
  3305. },
  3306. { $set: { assignedBy: newassignedBy } },
  3307. );
  3308. }
  3309. if (req.body.hasOwnProperty('receivedAt')) {
  3310. const newreceivedAt = req.body.receivedAt;
  3311. Cards.direct.update(
  3312. {
  3313. _id: paramCardId,
  3314. listId: paramListId,
  3315. boardId: paramBoardId,
  3316. archived: false,
  3317. },
  3318. { $set: { receivedAt: newreceivedAt } },
  3319. );
  3320. }
  3321. if (req.body.hasOwnProperty('startAt')) {
  3322. const newstartAt = req.body.startAt;
  3323. Cards.direct.update(
  3324. {
  3325. _id: paramCardId,
  3326. listId: paramListId,
  3327. boardId: paramBoardId,
  3328. archived: false,
  3329. },
  3330. { $set: { startAt: newstartAt } },
  3331. );
  3332. }
  3333. if (req.body.hasOwnProperty('dueAt')) {
  3334. const newdueAt = req.body.dueAt;
  3335. Cards.direct.update(
  3336. {
  3337. _id: paramCardId,
  3338. listId: paramListId,
  3339. boardId: paramBoardId,
  3340. archived: false,
  3341. },
  3342. { $set: { dueAt: newdueAt } },
  3343. );
  3344. }
  3345. if (req.body.hasOwnProperty('endAt')) {
  3346. const newendAt = req.body.endAt;
  3347. Cards.direct.update(
  3348. {
  3349. _id: paramCardId,
  3350. listId: paramListId,
  3351. boardId: paramBoardId,
  3352. archived: false,
  3353. },
  3354. { $set: { endAt: newendAt } },
  3355. );
  3356. }
  3357. if (req.body.hasOwnProperty('spentTime')) {
  3358. const newspentTime = req.body.spentTime;
  3359. Cards.direct.update(
  3360. {
  3361. _id: paramCardId,
  3362. listId: paramListId,
  3363. boardId: paramBoardId,
  3364. archived: false,
  3365. },
  3366. { $set: { spentTime: newspentTime } },
  3367. );
  3368. }
  3369. if (req.body.hasOwnProperty('isOverTime')) {
  3370. const newisOverTime = req.body.isOverTime;
  3371. Cards.direct.update(
  3372. {
  3373. _id: paramCardId,
  3374. listId: paramListId,
  3375. boardId: paramBoardId,
  3376. archived: false,
  3377. },
  3378. { $set: { isOverTime: newisOverTime } },
  3379. );
  3380. }
  3381. if (req.body.hasOwnProperty('customFields')) {
  3382. const newcustomFields = req.body.customFields;
  3383. Cards.direct.update(
  3384. {
  3385. _id: paramCardId,
  3386. listId: paramListId,
  3387. boardId: paramBoardId,
  3388. archived: false,
  3389. },
  3390. { $set: { customFields: newcustomFields } },
  3391. );
  3392. }
  3393. if (req.body.hasOwnProperty('members')) {
  3394. let newmembers = req.body.members;
  3395. if (_.isString(newmembers)) {
  3396. if (newmembers === '') {
  3397. newmembers = null;
  3398. } else {
  3399. newmembers = [newmembers];
  3400. }
  3401. }
  3402. Cards.direct.update(
  3403. {
  3404. _id: paramCardId,
  3405. listId: paramListId,
  3406. boardId: paramBoardId,
  3407. archived: false,
  3408. },
  3409. { $set: { members: newmembers } },
  3410. );
  3411. }
  3412. if (req.body.hasOwnProperty('assignees')) {
  3413. let newassignees = req.body.assignees;
  3414. if (_.isString(newassignees)) {
  3415. if (newassignees === '') {
  3416. newassignees = null;
  3417. } else {
  3418. newassignees = [newassignees];
  3419. }
  3420. }
  3421. Cards.direct.update(
  3422. {
  3423. _id: paramCardId,
  3424. listId: paramListId,
  3425. boardId: paramBoardId,
  3426. archived: false,
  3427. },
  3428. { $set: { assignees: newassignees } },
  3429. );
  3430. }
  3431. if (req.body.hasOwnProperty('swimlaneId')) {
  3432. const newParamSwimlaneId = req.body.swimlaneId;
  3433. Cards.direct.update(
  3434. {
  3435. _id: paramCardId,
  3436. listId: paramListId,
  3437. boardId: paramBoardId,
  3438. archived: false,
  3439. },
  3440. { $set: { swimlaneId: newParamSwimlaneId } },
  3441. );
  3442. }
  3443. if (req.body.hasOwnProperty('listId')) {
  3444. const newParamListId = req.body.listId;
  3445. Cards.direct.update(
  3446. {
  3447. _id: paramCardId,
  3448. listId: paramListId,
  3449. boardId: paramBoardId,
  3450. archived: false,
  3451. },
  3452. {
  3453. $set: {
  3454. listId: newParamListId,
  3455. },
  3456. },
  3457. );
  3458. const card = Cards.findOne({
  3459. _id: paramCardId,
  3460. });
  3461. cardMove(
  3462. req.body.authorId,
  3463. card,
  3464. {
  3465. fieldName: 'listId',
  3466. },
  3467. paramListId,
  3468. );
  3469. }
  3470. JsonRoutes.sendResult(res, {
  3471. code: 200,
  3472. data: {
  3473. _id: paramCardId,
  3474. },
  3475. });
  3476. },
  3477. );
  3478. /**
  3479. * @operation delete_card
  3480. * @summary Delete a card from a board
  3481. *
  3482. * @description This operation **deletes** a card, and therefore the card
  3483. * is not put in the recycle bin.
  3484. *
  3485. * @param {string} boardId the board ID of the card
  3486. * @param {string} list the list ID of the card
  3487. * @param {string} cardId the ID of the card
  3488. * @return_type {_id: string}
  3489. */
  3490. JsonRoutes.add(
  3491. 'DELETE',
  3492. '/api/boards/:boardId/lists/:listId/cards/:cardId',
  3493. function(req, res) {
  3494. const paramBoardId = req.params.boardId;
  3495. Authentication.checkBoardAccess(req.userId, paramBoardId);
  3496. const paramListId = req.params.listId;
  3497. const paramCardId = req.params.cardId;
  3498. const card = Cards.findOne({
  3499. _id: paramCardId,
  3500. });
  3501. Cards.direct.remove({
  3502. _id: paramCardId,
  3503. listId: paramListId,
  3504. boardId: paramBoardId,
  3505. });
  3506. cardRemover(req.body.authorId, card);
  3507. JsonRoutes.sendResult(res, {
  3508. code: 200,
  3509. data: {
  3510. _id: paramCardId,
  3511. },
  3512. });
  3513. },
  3514. );
  3515. /**
  3516. * @operation get_cards_by_custom_field
  3517. * @summary Get all Cards that matchs a value of a specific custom field
  3518. *
  3519. * @param {string} boardId the board ID
  3520. * @param {string} customFieldId the list ID
  3521. * @param {string} customFieldValue the value to look for
  3522. * @return_type [{_id: string,
  3523. * title: string,
  3524. * description: string,
  3525. * listId: string,
  3526. * swinlaneId: string}]
  3527. */
  3528. JsonRoutes.add(
  3529. 'GET',
  3530. '/api/boards/:boardId/cardsByCustomField/:customFieldId/:customFieldValue',
  3531. function(req, res) {
  3532. const paramBoardId = req.params.boardId;
  3533. const paramCustomFieldId = req.params.customFieldId;
  3534. const paramCustomFieldValue = req.params.customFieldValue;
  3535. Authentication.checkBoardAccess(req.userId, paramBoardId);
  3536. JsonRoutes.sendResult(res, {
  3537. code: 200,
  3538. data: Cards.find({
  3539. boardId: paramBoardId,
  3540. customFields: {
  3541. $elemMatch: {
  3542. _id: paramCustomFieldId,
  3543. value: paramCustomFieldValue,
  3544. },
  3545. },
  3546. archived: false,
  3547. }).fetch(),
  3548. });
  3549. },
  3550. );
  3551. }
  3552. export default Cards;