1
1
import { getOwner } from "@ember/application" ;
2
+ import { action } from "@ember/object" ;
2
3
import { htmlSafe } from "@ember/template" ;
3
4
import { isEmpty } from "@ember/utils" ;
4
5
import { hbs } from "ember-cli-htmlbars" ;
@@ -24,8 +25,6 @@ import EditTopicAssignments from "../components/modal/edit-topic-assignments";
24
25
import TopicLevelAssignMenu from "../components/topic-level-assign-menu" ;
25
26
import { extendTopicModel } from "../models/topic" ;
26
27
27
- const PLUGIN_ID = "discourse-assign" ;
28
-
29
28
const DEPENDENT_KEYS = [
30
29
"topic.assigned_to_user" ,
31
30
"topic.assigned_to_group" ,
@@ -361,18 +360,21 @@ function initialize(api) {
361
360
return getURL ( `/g/${ assignedToGroup . name } /assigned/everyone` ) ;
362
361
}
363
362
364
- api . modifyClass ( "model:bookmark" , {
365
- pluginId : PLUGIN_ID ,
363
+ api . modifyClass (
364
+ "model:bookmark" ,
365
+ ( Superclass ) =>
366
+ class extends Superclass {
367
+ @discourseComputed ( "assigned_to_user" )
368
+ assignedToUserPath ( assignedToUser ) {
369
+ return assignedToUserPath ( assignedToUser ) ;
370
+ }
366
371
367
- @discourseComputed ( "assigned_to_user" )
368
- assignedToUserPath ( assignedToUser ) {
369
- return assignedToUserPath ( assignedToUser ) ;
370
- } ,
371
- @discourseComputed ( "assigned_to_group" )
372
- assignedToGroupPath ( assignedToGroup ) {
373
- return assignedToGroupPath ( assignedToGroup ) ;
374
- } ,
375
- } ) ;
372
+ @discourseComputed ( "assigned_to_group" )
373
+ assignedToGroupPath ( assignedToGroup ) {
374
+ return assignedToGroupPath ( assignedToGroup ) ;
375
+ }
376
+ }
377
+ ) ;
376
378
377
379
api . modifyClass (
378
380
"component:topic-notifications-button" ,
@@ -590,83 +592,91 @@ function initialize(api) {
590
592
} ,
591
593
} ) ;
592
594
593
- api . modifyClass ( "model:group" , {
594
- pluginId : PLUGIN_ID ,
595
-
596
- asJSON ( ) {
597
- return Object . assign ( { } , this . _super ( ...arguments ) , {
598
- assignable_level : this . assignable_level ,
599
- } ) ;
600
- } ,
601
- } ) ;
602
-
603
- api . modifyClass ( "controller:topic" , {
604
- pluginId : PLUGIN_ID ,
605
-
606
- subscribe ( ) {
607
- this . _super ( ...arguments ) ;
608
-
609
- this . messageBus . subscribe ( "/staff/topic-assignment" , ( data ) => {
610
- const topic = this . model ;
611
- const topicId = topic . id ;
612
-
613
- if ( data . topic_id === topicId ) {
614
- let post ;
615
- if ( data . post_id ) {
616
- post = topic . postStream . posts . find ( ( p ) => p . id === data . post_id ) ;
617
- }
618
- const target = post || topic ;
619
-
620
- target . set ( "assignment_note" , data . assignment_note ) ;
621
- target . set ( "assignment_status" , data . assignment_status ) ;
622
- if ( data . assigned_type === "User" ) {
623
- target . set (
624
- "assigned_to_user_id" ,
625
- data . type === "assigned" ? data . assigned_to . id : null
626
- ) ;
627
- target . set ( "assigned_to_user" , data . assigned_to ) ;
628
- }
629
- if ( data . assigned_type === "Group" ) {
630
- target . set (
631
- "assigned_to_group_id" ,
632
- data . type === "assigned" ? data . assigned_to . id : null
633
- ) ;
634
- target . set ( "assigned_to_group" , data . assigned_to ) ;
635
- }
595
+ api . modifyClass (
596
+ "model:group" ,
597
+ ( Superclass ) =>
598
+ class extends Superclass {
599
+ asJSON ( ) {
600
+ return Object . assign ( { } , super . asJSON ( ...arguments ) , {
601
+ assignable_level : this . assignable_level ,
602
+ } ) ;
603
+ }
604
+ }
605
+ ) ;
636
606
637
- if ( data . post_id ) {
638
- if ( data . type === "unassigned" ) {
639
- delete topic . indirectly_assigned_to [ data . post_number ] ;
607
+ api . modifyClass (
608
+ "controller:topic" ,
609
+ ( Superclass ) =>
610
+ class extends Superclass {
611
+ subscribe ( ) {
612
+ super . subscribe ( ...arguments ) ;
613
+
614
+ this . messageBus . subscribe ( "/staff/topic-assignment" , ( data ) => {
615
+ const topic = this . model ;
616
+ const topicId = topic . id ;
617
+
618
+ if ( data . topic_id === topicId ) {
619
+ let post ;
620
+ if ( data . post_id ) {
621
+ post = topic . postStream . posts . find (
622
+ ( p ) => p . id === data . post_id
623
+ ) ;
624
+ }
625
+ const target = post || topic ;
626
+
627
+ target . set ( "assignment_note" , data . assignment_note ) ;
628
+ target . set ( "assignment_status" , data . assignment_status ) ;
629
+ if ( data . assigned_type === "User" ) {
630
+ target . set (
631
+ "assigned_to_user_id" ,
632
+ data . type === "assigned" ? data . assigned_to . id : null
633
+ ) ;
634
+ target . set ( "assigned_to_user" , data . assigned_to ) ;
635
+ }
636
+ if ( data . assigned_type === "Group" ) {
637
+ target . set (
638
+ "assigned_to_group_id" ,
639
+ data . type === "assigned" ? data . assigned_to . id : null
640
+ ) ;
641
+ target . set ( "assigned_to_group" , data . assigned_to ) ;
642
+ }
643
+
644
+ if ( data . post_id ) {
645
+ if ( data . type === "unassigned" ) {
646
+ delete topic . indirectly_assigned_to [ data . post_number ] ;
647
+ }
648
+
649
+ this . appEvents . trigger ( "post-stream:refresh" , {
650
+ id : topic . postStream . posts [ 0 ] . id ,
651
+ } ) ;
652
+ this . appEvents . trigger ( "post-stream:refresh" , {
653
+ id : data . post_id ,
654
+ } ) ;
655
+ }
656
+ if ( topic . closed ) {
657
+ this . appEvents . trigger ( "post-stream:refresh" , {
658
+ id : topic . postStream . posts [ 0 ] . id ,
659
+ } ) ;
660
+ }
640
661
}
641
-
642
- this . appEvents . trigger ( "post-stream:refresh" , {
643
- id : topic . postStream . posts [ 0 ] . id ,
644
- } ) ;
645
- this . appEvents . trigger ( "post-stream:refresh" , { id : data . post_id } ) ;
646
- }
647
- if ( topic . closed ) {
662
+ this . appEvents . trigger ( "header:update-topic" , topic ) ;
648
663
this . appEvents . trigger ( "post-stream:refresh" , {
649
664
id : topic . postStream . posts [ 0 ] . id ,
650
665
} ) ;
651
- }
666
+ } ) ;
652
667
}
653
- this . appEvents . trigger ( "header:update-topic" , topic ) ;
654
- this . appEvents . trigger ( "post-stream:refresh" , {
655
- id : topic . postStream . posts [ 0 ] . id ,
656
- } ) ;
657
- } ) ;
658
- } ,
659
668
660
- unsubscribe ( ) {
661
- this . _super ( ...arguments ) ;
669
+ unsubscribe ( ) {
670
+ super . unsubscribe ( ...arguments ) ;
662
671
663
- if ( ! this . model ?. id ) {
664
- return ;
665
- }
672
+ if ( ! this . model ?. id ) {
673
+ return ;
674
+ }
666
675
667
- this . messageBus . unsubscribe ( "/staff/topic-assignment" ) ;
668
- } ,
669
- } ) ;
676
+ this . messageBus . unsubscribe ( "/staff/topic-assignment" ) ;
677
+ }
678
+ }
679
+ ) ;
670
680
671
681
api . decorateWidget ( "post-contents:after-cooked" , ( dec ) => {
672
682
const postModel = dec . getModel ( ) ;
@@ -710,16 +720,17 @@ function initialize(api) {
710
720
"group-plus"
711
721
) ;
712
722
713
- api . modifyClass ( "controller:preferences/notifications" , {
714
- pluginId : PLUGIN_ID ,
715
-
716
- actions : {
717
- save ( ) {
718
- this . saveAttrNames . push ( "custom_fields" ) ;
719
- this . _super ( ...arguments ) ;
720
- } ,
721
- } ,
722
- } ) ;
723
+ api . modifyClass (
724
+ "controller:preferences/notifications" ,
725
+ ( Superclass ) =>
726
+ class extends Superclass {
727
+ @action
728
+ save ( ) {
729
+ this . saveAttrNames . push ( "custom_fields" ) ;
730
+ super . save ( ...arguments ) ;
731
+ }
732
+ }
733
+ ) ;
723
734
724
735
api . addKeyboardShortcut ( "g a" , "" , { path : "/my/activity/assigned" } ) ;
725
736
}
@@ -834,7 +845,7 @@ export default {
834
845
}
835
846
836
847
withPluginApi ( "1.34.0" , ( api ) => {
837
- extendTopicModel ( api , PLUGIN_ID ) ;
848
+ extendTopicModel ( api ) ;
838
849
initialize ( api ) ;
839
850
registerTopicFooterButtons ( api ) ;
840
851
0 commit comments