-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNotification.js
2250 lines (1996 loc) · 77 KB
/
Notification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* These are the classes that form the basis
* of the Trellinator, concerning the execution
* of functions in response to Notifications
* or as part of Time Triggers or in the
* Execution Queue
* @module TrellinatorCore
*/
/**
* @class Notification
* @memberof module:TrellinatorCore
* @constructor
* @param notification {Object} an object that has been posted
* to a webhook from the Trello API
* @classdesc The Notification object takes a
* notification from the Trello API sent to a
* webhook and makes it easy to determine what
* type of event took place and to get access to
* the entities that were part of
* the notification. The notifications passed into
* this constructor are always sent to webhooks registered
* at the board level. There are 4 types of method:
*
* - methods that return an object that was the source
* or origination of this notification, throwing an
* exception if that object is not present which
* indicates in turn that type of notification did
* not occur. The first part of the function name
* is the verb, with the object coming after,
* eg. archivedCard or completedChecklistItem.
*
* - methods that return an entity that was part of
* the notification, such as board(), card() and
* member(). Given these notifications are always
* at the board level, there is always a board()
* and given every notification originates with an
* action by a member there is always a member()
* however there is not always a card(), so if
* for example this notification is a list name
* being updated the card() method will throw an
* InvalidActionException
*
* - Finally there are a couple of convenience
* functions that are just shorthand for a
* few different common scenarios such as
* actionOnDueDate and replyToMember
*
* - Static methods that are used globally and
* are simply grouped within this class for
* logical reasons
*
* There are some methods that are deprecated or
* used internally by other class methods so you can
* ignore those, they are marked as such in the
* code comments, but aren't included in the API
* documentation.
*
* Even though all methods are marked as "static"
* by jsdoc, the ones that start with "this."
* aren't static. I don't know how to make jsdoc
* display them as non-static, so if you do then
* please send a pull request :)
*
* Methods that deal with detecting whether an
* action took place will throw an InvalidActionException
* if that action did not take place.
*
* Unless you want to explicitly take action in the case
* that some action didn't occur, you don't need to
* catch these exceptions; Trellinator will catch them
* for you. An InvalidActionException is not considered
* "fatal", neither is an InvalidDataException (typically
* thrown by entity classes or the IterableCollection).
*
* If you do want to catch exceptions, you should look
* at the Exceptions.js documentation and the two static methods
* on this class Notification.logException and Notification.expectException
* to see how to do this according to Trellinator best practices
*/
var Notification = function(notification)
{
this.notification = notification;
this.board_object = null;
this.member_object = null;
this.card_object = null;
this.list_object = null;
/**
* If this notification was the result of
* a member being added to a card, return
* an object of type Member, otherwise
* throw an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* var notif = new Notification(posted);
* var comment = "@"+notif.addedMemberToCard().name()+" welcome!";
* notif.card().postComment(comment);
*/
this.addedMemberToCard = function(name)
{
return this.memberAddedToCard(name);
}
/**
* If this notification was the result of
* a member being removed from a card, return
* an object of type Member, otherwise
* throw an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* var notif = new Notification(posted);
* var comment = "@"+notif.removedMemberFromCard().name()+" welcome!";
* notif.card().postComment(comment);
*/
this.removedMemberFromCard = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException('WeKan API does not support removedMemberFromCard');
if(
(this.notification.action.display.translationKey != "action_member_left_card") &&
(this.notification.action.display.translationKey != "action_removed_member_from_card")
)
throw new InvalidActionException("No member removed from card");
var ret = new Member(this.notification.action.member);
if(name && !TrelloApi.nameTest(name,ret.name()))
throw new InvalidActionException("Member was removed, but was not named: "+name);
return ret;
}
/**
* If this notification was the result of
* a member being added to a board, return
* an object of type Member, otherwise
* throw an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optional name (string or regex) to match against username
* @throws InvalidActionException
* @example
* var member = new Notification(posted).addedMemberToBoard();
*/
this.addedMemberToBoard = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
if(["act-addBoardMember"].indexOf(this.notification.description) > -1)
var ret = this.member();
else
throw new InvalidActionException("Member was not added to a board");
}
else
{
if(["action_added_member_to_board","action_added_member_to_board_as_admin"].indexOf(this.notification.action.display.translationKey) == -1)
{
throw new InvalidActionException("No member added to a board");
}
var ret = new Member(this.notification.action.member);
}
if(name && !TrelloApi.nameTest(name,ret.name()))
throw new InvalidActionException("The added member was not named "+name);
return ret;
}
/**
* If this notification was the result of
* a member being removed from a board, return
* an object of type Member, otherwise
* throw an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optional name (string or regex) to match against username
* @throws InvalidActionException
* @example
* var member = new Notification(posted).removedMemberFromBoard();
*/
this.removedMemberFromBoard = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("removedMemberFromBoard not yet implemented in WeKan API");
if(this.notification.action.display.translationKey != "action_removed_from_board")
throw new InvalidActionException("No member removed from a board");
var ret = new Member(this.notification.action.member);
if(name && !TrelloApi.nameTest(name,ret.name()))
throw new InvalidActionException("The removed member was not named "+name);
return ret;
}
/**
* A board was created, returns an object of type Board
* This is true if the board was created or copied from another board
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optional name (string or regex) to match against username
* @throws InvalidActionException
* @example
* var board = new Notification(posted).createdBoard();
*/
this.createdBoard = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("createdBoard not yet implemented in WeKan API");
if(["action_create_board","action_copy_board"].indexOf(this.notification.action.display.translationKey) == -1)
throw new InvalidActionException("No member added to a board");
return new Board(this.notification.action.data.board);
}
/**
* A board was copied, returns an object of type Board
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optional name (string or regex) to match against username
* @throws InvalidActionException
* @example
* var board = new Notification(posted).copiedBoard();
*/
this.copiedBoard = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("copiedBoard not yet implemented in WeKan API");
if(["action_copy_board"].indexOf(this.notification.action.display.translationKey) == -1)
throw new InvalidActionException("No member added to a board");
return new Board(this.notification.action.data.board);
}
/**
* If a checklist item was converted to a card
* return a Card object, otherwise throw an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionally pass in a string or RegExp object
* to match against the name of the converted checklist item
* @throws InvalidActionException
* @example
* new Notification(posted)
* .convertedChecklistItemToCard(new RegExp(".*Carmen San Diego.*"))
* .checklist().card().postComment("Great work gumshoe!");
*/
this.convertedChecklistItemToCard = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("convertedChecklistItemToCard not yet implemented in WeKan API");
if(this.notification.action.display.translationKey != "action_convert_to_card_from_checkitem")
throw new InvalidActionException("No checklist item was converted to a card");
var ret = new Card(this.notification.action.data.card);
ret.source = new Checklist(this.notification.action.data.checklist)
.setContainingCard(new Card(this.notification.action.data.cardSource));
if(name && !TrelloApi.nameTest(name,ret.name()))
throw new InvalidActionException("A checklist item was converted to a card but it was not named: "+name);
return ret;
}
/**
* If a checklist was completed as part of this notification
* return a Checklist object, otherwise throw an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionally pass in a string or RegExp object
* to match against the name of the completed checklist
* @throws InvalidActionException
* @example
* new Notification(posted)
* .completedChecklist(new RegExp(".*Carmen San Diego.*"))
* .card().postComment("Great work gumshoe!");
*/
this.completedChecklist = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
var item = this.completedChecklistItem();
var ret = item.checklist();
}
else
{
if(this.notification.action.display.translationKey != "action_completed_checkitem")
throw new InvalidActionException("No checklist item was completed, therefore no checklist was completed as part of this action");
var ret = this.checklist();
}
if(name && !TrelloApi.nameTest(name,ret.name()))
throw new InvalidActionException("The completed checklist was not named "+name);
else
{
if(!ret.isComplete())
throw new InvalidActionException("The checklist in which the item was checked is not complete");
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
//NO WAY TO DETERMINE IF THE CHECKLIST COMPLETION EVENT WAS THE MOST RECENT ONE
}
else
{
var completed_actions = new Array();
new IterableCollection(TrelloApi.get("cards/"+this.card().data.id+"/actions?filter=updateCheckItemStateOnCard")).each(function(elem)
{
if((elem.data.checkItem.state == "complete") && elem.data.checklist.id == ret.id())
completed_actions.push(elem);
});
if(this.notification.action.id != completed_actions[0].id)
throw new InvalidActionException("This was not the most recent completed notification for the checklist in question so couldn't be the one that caused the checklist to be completed");
}
}
ret.setContainingCard(this.card());
return ret;
}
/**
* Return a Custom Field object
* that was changed, optionally pass
* in a string or regex to match against
* the name of the field
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionaly pass in a string
* or RegExp to match against the name of the CARD
* on which the field was changed
* @throws InvalidActionException
* @example
* var card = new Notification(posted).changedCustomField("Priority").card();
*/
this.changedCustomField = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
//act-setCustomField
throw new InvalidRequestException("No custom field support in WeKan API yet");
if(this.notification.action.display.translationKey != "action_update_custom_field_item")
throw new InvalidActionException("No custom field was changed");
var ret = new CustomField(this.notification.action.data.customField)
.setContainingCard(this.card())
.setItemForCurrentCard(this.notification.action.data.customFieldItem)
.setOldValue(this.notification.action.data.old);
if(name && !TrelloApi.nameTest(name,ret.name()))
throw new InvalidActionException("The updated custom field was not named "+name);
return ret;
}
/**
* Return a Custom Field object
* that was created
* IMPLEMENT ME!
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionaly pass in a string
* or RegExp to match against the name of the CARD
* on which the field was changed
* @throws InvalidActionException
* @example
* IMPLMENT ME!!
*/
this.createdCustomField = function(name)
{
//act-createCustomField
throw new InvalidRequestException("No custom field support in WeKan API yet");
}
/**
* Return a Card object if a card was moved
* from one list to another (either on the same
* board or to a different board) as
* part of this notification, otherwise throw
* an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionaly pass in a string
* or RegExp to match against the name of the LIST
* into which the card was moved
* @throws InvalidActionException
* @example
* var notif = new Notification(posted);
* var card = notif.movedCard(new RegExp("Done.*"));
* var from = notif.listBefore().name();
* var to = notif.listAfter().name();
* card.postComment(from+" to "+to);
*/
this.movedCard = function(name)
{
this.listCardWasMovedTo(name);
return this.card();
}
/**
* Return a Card object if a card was added
* to a list as part of this notification.
* The "added" event can be any way that a card
* can arrive in a list, either by being
* created, copied, moved (within the same board
* or from a different board) or emailed to
* the board. If none of these things happened
* throws an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionaly pass in a string
* or RegExp to match against the name of the LIST
* into which the card was added
* @throws InvalidActionException
* @example
* new Notification(posted)
* .addedCard(new RegExp("ToDo.*"))
* .postComment("Hi there!");
*/
this.addedCard = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
try
{
this.createdCard();
}
catch(e)
{
Notification.expectException(InvalidActionException,e);
this.movedCard();
}
}
else
this.listCardWasAddedTo(name);
return this.card();
}
/**
* Return a Card object if a card was created
* on this board as part of this notification.
* The "created" event can be any way that a card
* can be added to a board for the first time,
* ie. created by a user, copied from another card
* including from a different board or emailed to
* the board. If none of these things happened
* throws an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionaly pass in a string
* or RegExp to match against the name of the LIST
* in which the card was created
* @throws InvalidActionException
* @example
* new Notification(posted)
* .createdCard(new RegExp("Incoming.*"))
* .postComment("Hi there!");
*/
this.createdCard = function(name)
{
this.listCardWasCreatedIn(name);
return this.card();
}
/**
* Return a Checklist object if a
* checklist was added to a card as part
* of this notification or throw an
* InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param name {string|RegExp} optionally pass in a string or RegExp
* to match against the name of the checklist that was added to the
* card
* @throws InvalidActionException
* @example
* new Notification(posted)
* .addedChecklist(new RegExp(".*Ghosts.*"))
* .addItem("Who you gonna call?");
*/
this.addedChecklist = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
if(["act-addChecklist"].indexOf(this.notification.description) > -1)
{
if(parts = /.*added checklist "(.+?)" to card "(.+?)".*/.exec(this.notification.text))
{
//Our attachments hack uses a checklist right now
if(parts[1] != "Attachments")
{
var ret = this.card().checklist(parts[1]);
}
else
throw new InvalidActionException("Ignore attachments");
}
}
else
throw new InvalidActionException("Card was not moved to a list");
}
else
{
if(!this.notification.action.display.translationKey == "action_add_checklist_to_card")
throw new InvalidActionException("No checklist was added to a card");
var ret = new Checklist(this.notification.action.display.entities.checklist);
ret.setContainingCard(this.card());
}
if(name && !TrelloApi.nameTest(name,ret.name()))
throw new InvalidDataException("A checklist was added but it was not named: "+name+" it was named: "+ret.name());
return ret;
}
/**
* Return a Checklist object if a
* checklist was removed from a card as part
* of this notification or throw an
* IMPLEMENT ME!!
* InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param name {string|RegExp} optionally pass in a string or RegExp
* to match against the name of the checklist that was added to the
* card
* @throws InvalidActionException
* @example
* new Notification(posted)
* .addedChecklist(new RegExp(".*Ghosts.*"))
* .addItem("Who you gonna call?");
*/
this.removedChecklist = function(name)
{
//act-removeChecklist
throw new InvalidRequestException("removedChecklist not implemented yet");
}
/**
* Return a CheckItem object if a
* checklist item was removed from a card as part
* of this notification or throw an InvalidActionException
* IMPLEMENT ME!!
* InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @param name {string|RegExp} optionally pass in a string or RegExp
* to match against the name of the checklist that was added to the
* card
* @throws InvalidActionException
* @example
* new Notification(posted)
* .addedChecklist(new RegExp(".*Ghosts.*"))
* .addItem("Who you gonna call?");
*/
this.removedChecklist = function(name)
{
//act-removedChecklistItem
throw new InvalidRequestException("act-removedChecklistItem not implemented yet");
}
/**
* Return a Board object that a card was moved
* from or throw InvalidActionException.
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* new Notification(posted)
* .boardBefore().name();
*/
this.boardBefore = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("boardBefore not supported in WeKan API because you can't move cards between boards");
if(this.notification.action.display.translationKey != "action_move_card_to_board")
{
throw new InvalidActionException("Card not moved from a board");
}
try
{
var ret = this.listBefore().board();
}
catch(e)
{
Notification.expectException(InvalidActionException,e);
if(!this.notification.action.data.boardSource)
throw new InvalidActionException("No boardSource, no listBefore");
var ret = new Board(this.notification.action.data.boardSource);
}
return ret;
}
/**
* Return a List object that a card
* was moved out of if a card was
* moved as part of this notification,
* or return an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* new Notification(posted)
* .listBefore().cards()
* .first()
* .postComment("We'll miss you!");
*/
this.listBefore = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
this.movedCard();
var ret = new List(
{
id: this.notification.oldList
}
).setBoard(this.board());
}
else
{
if(this.notification.action.data.listBefore)
ret = new List(this.notification.action.data.listBefore);
else
throw new InvalidActionException("No list before");
}
return ret;
}
/**
* Return a List object that a card
* was moved into if a card was
* moved as part of this notification,
* or return an InvalidActionException
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* new Notification(posted)
* .listAfter().cards()
* .first()
* .postComment("Welcome friend!");
*/
this.listAfter = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
this.movedCard();
var ret = this.list();
}
else
{
if(this.notification.action.data.listAfter)
var ret = new List(this.notification.action.data.listAfter);
else
throw new InvalidActionException("No list after");
}
return ret;
}
/**
* Return a List object that was created
* or moved from another board
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* Card.create(new Notification(posted)
* .addedList(),"Welcome to the list!");
*/
this.addedList = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
var ret = this.createdList();
}
else
{
if(["action_added_list_to_board","action_move_list_to_board"].indexOf(this.notification.action.display.translationKey) > -1)
var ret = new List(this.notification.action.data.list);
else
throw new InvalidActionException("No list added");
}
return ret;
}
/**
* Return a List object that was created
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* Card.create(new Notification(posted)
* .createdList(),"Welcome to the list!");
*/
this.createdList = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
if(["act-createList"].indexOf(this.notification.description) > -1)
var ret = this.list();
else
throw new InvalidActionException("Card was not moved to a list");
}
else
{
if(["action_added_list_to_board"].indexOf(this.notification.action.display.translationKey) > -1)
ret = new List(this.notification.action.data.list);
else
throw new InvalidActionException("No list created");
}
return ret;
}
/**
* Return a List object that was archived
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* new Notification(posted)
* .archivedList().unArchive();
*/
this.archivedList = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
{
if(["act-archivedList"].indexOf(this.notification.description) > -1)
var ret = this.list();
else
throw new InvalidActionException("List was not archived");
}
else
{
if(["action_archived_list"].indexOf(this.notification.action.display.translationKey) > -1)
var ret = new List(this.notification.action.data.list);
else
throw new InvalidActionException("No list archived");
}
return ret;
}
/**
* Return a List object that was deleted
* IMPLEMENT ME!!
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* IMPLEMENT ME!
*/
this.deletedList = function()
{
//act-removeList
throw new InvalidRequestException("deletedList not implemented yet");
}
/**
* Return the previous value after a change
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* new Notification(posted)
* .changedCardName().setName(new Notification(posted).oldValue());
*
*/
this.oldValue = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("Can't get the value from which we changed yet implemented in WeKan API");
if(this.notification.action.data.old)
{
for(var key in this.notification.action.data.old)
return this.notification.action.data.old[key];
}
else
{
throw new InvalidActionException("No old value present");
}
}
/**
* Return the name of the attribute that changed
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* var notif = new Notification(posted);
* notif
* .changedCardName().setName(notif.oldValue());
* notif.replyToMember("You changed: "+notif.whatChanged());
*/
this.whatChanged = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("Can't see what you changed in WeKan API");
if(this.notification.action.data.old)
{
for(var key in this.notification.action.data.old)
return key;
}
else
{
throw new InvalidActionException("No old value present");
}
}
/**
* Return a List object that had
* it's name changed or throws
* an InvalidActionException if no
* list name was changed
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* new Notification(posted)
* .changedListName()
* .cards().first()
* .postComment("My name changed");
*/
this.changedListName = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("changedListName not yet implemented in WeKan API");
return this.updatedList();
}
/**
* Return a Card object if the
* name/title of the card was
* changed or throw an InvalidActionException
* if no card name was changed
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* new Notification(posted)
* .changedCardName()
* .postComment("how dare you!");
*/
this.changedCardName = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("changedCardName not yet implemented in WeKan API");
return this.cardWithNameChanged();
}
/**
* Return a Card object if the
* description of the card was
* changed or throw an InvalidActionException
* if no card description was changed
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionally pass in a name of card to match
* @throws InvalidActionException
* @example
* new Notification(posted)
* .changedCardDescription()
* .postComment("how dare you!");
*/
this.changedCardDescription = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("changedCardDescription not yet implemented in WeKan API");
if(this.notification.action.display.translationKey != "action_changed_description_of_card")
throw new InvalidActionException("Card description was not changed");
var ret = this.card();
if(name && !TrelloApi.nameTest(name,ret.name()))
throw new InvalidActionException("Card item named: "+ret.name()+" description updated which doesn't match: "+name);
return ret;
}
/**
* Return previous desc if it was changed
* as part of this notification
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionally pass in a name of card to match
* @throws InvalidActionException
* @example
* new Notification(posted)
* .oldCardDescription();
*/
this.oldCardDescription = function(name)
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("oldCardDescription not yet implemented in WeKan API");
var ret = null;
if(this.notification && this.notification.action && this.notification.action.data && this.notification.action.data.old && this.notification.action.data.old.desc)
ret = this.notification.action.data.old.desc;
else
throw new InvalidDataException("No old description, probably it wasn't just changed");
return ret;
}
/**
* Return a Card object if the
* due date was marked complete
* or throw an InvalidActionException
* if no due date was completed
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* new Notification(posted)
* .completedDueDate()
* .postComment("Feels gooood :)");
*/
this.completedDueDate = function()
{
if((prov = Trellinator.provider()) && (prov.name == "WeKan"))
throw new InvalidRequestException("completedDueDate not yet implemented in WeKan API");
return this.cardDueDateWasCompletedOn();
}
/**
* Return a Member object if the
* member's username was mentioned
* in a comment or throw an InvalidActionException
* if no due date was completed.
* This will apply only to members who were mentioned
* who are part of this board, rather than arbitrary
* strings preceded by an @ sign
* @memberof module:TrellinatorCore.Notification
* @param {string|RegExp} optionally pass in a string
* or RegExp to match against the mentioned member's
* username
* @throws InvalidActionException
* @example
* new Notification(posted)
* .mentionedMember("johnnydepp")
* .postComment("Yarrrrr");
*/
this.mentionedMember = function(name)
{
return this.memberMentionedInComment(name);
}
/**
* Return an IterableCollection of Member objects
* that were mentioned in a comment, or throw
* an InvalidActionException if no members were
* mentioned. This applies only to members who
* are actually on the board, so won't consider
* any string preceded by an @ sign as a member
* name
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* var notif = new Notification(posted);
* notif.mentionedMembers()
* .each(function(member)
* {
* notif.card().addMember(member);
* });
*/
this.mentionedMembers = function()
{
return this.membersMentionedInComment();
}
/**
* Return a Comment object if a comment
* was added to a card as part of this
* Notification, or throw an InvalidActionException.
* BEWARE!! It's very easy to create "infinite loops"
* if you don't filter out comments added by
* Trellinator itself.
* @memberof module:TrellinatorCore.Notification
* @throws InvalidActionException
* @example
* var notif = new Notification(posted);
* var comment = notif.addedComment();
*
* if(notif.member().notTrellinator())
* notif.card().postComment("Okay!");