File tree Expand file tree Collapse file tree 12 files changed +146
-0
lines changed Expand file tree Collapse file tree 12 files changed +146
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { apiInitializer } from " discourse/lib/api" ;
2
+ import ButtonLink from " ../components/button-link" ;
3
+ import CustomStatusPicker from " ../components/custom-status-picker" ;
4
+ import concatClass from " discourse/helpers/concat-class" ;
5
+ import { htmlSafe } from " @ember/template" ;
6
+
7
+ export default apiInitializer (" 1.8.0" , (api ) => {
8
+ // loop through settings.buttons and render a button for each one
9
+ settings .buttons .forEach ((button ) => {
10
+ api .renderInOutlet (button .outlet , <template >
11
+ <ButtonLink @ button ={{button }} />
12
+ </template >);
13
+ });
14
+ settings .custom_text_block .forEach ((component ) => {
15
+ console .log (" component" , component);
16
+ api .renderInOutlet (component .outlet , <template >
17
+ <div class ={{concatClass " custom-component" component.class }} >
18
+ {{htmlSafe component.text }}
19
+ </div >
20
+ </template >);
21
+ });
22
+ });
Original file line number Diff line number Diff line change
1
+ import Component from " @glimmer/component" ;
2
+ import { service } from " @ember/service" ;
3
+ import DButton from " discourse/components/d-button" ;
4
+ import concatClass from " discourse/helpers/concat-class" ;
5
+
6
+ export default class ButtonLink extends Component {
7
+ @service currentUser;
8
+ get showButtonLink () {
9
+ // assign isGroupMember to true if user is a member of any of the groups in the button object
10
+ // user is in group if any this.currentUser.groups have an id that is in the button.groups array
11
+ let isGroupMember = this .args .button .groups .some ((group ) => {
12
+ return this .currentUser .groups .some ((userGroup ) => {
13
+ return userGroup .id === group;
14
+ });
15
+ });
16
+ if (this .args .button .group_action === " show" ) {
17
+ return isGroupMember;
18
+ } else {
19
+ return ! isGroupMember;
20
+ }
21
+ }
22
+ get button () {
23
+ return this .args .button ;
24
+ }
25
+
26
+ <template >
27
+ {{#if this . showButtonLink }}
28
+ <DButton
29
+ @ icon ={{this .button.icon }}
30
+ @ translatedLabel ={{this .button.text }}
31
+ class ={{concatClass " btn-custom" this . button.class}}
32
+ @ translatedTitle ={{this .button.title }}
33
+ @ href ={{this .button.url }}
34
+ />
35
+ {{/if }}
36
+ </template >
37
+ }
Original file line number Diff line number Diff line change
1
+ import Component from " @glimmer/component" ;
2
+ import { service } from " @ember/service" ;
3
+ import concatClass from " discourse/helpers/concat-class" ;
4
+ import UserStatusPicker from " discourse/components/user-status-picker" ;
5
+ import { TrackedObject } from " @ember-compat/tracked-built-ins" ;
6
+
7
+ // this is a proof of concept.
8
+ // It will show the status picker, but it doesn't work.
9
+
10
+ export default class CustomStatusPicker extends Component {
11
+ @service currentUser;
12
+ get showStatusPicker () {
13
+ console .log (" show the picker" , this .args .statusPicker );
14
+ console .log (" this.currentUser" , this .currentUser );
15
+ // status = new TrackedObject({ ...this.args.model.status });
16
+
17
+ // assign isGroupMember to true if user is a member of any of the groups in the button object
18
+ // user is in group if any this.currentUser.groups have an id that is in the button.groups array
19
+ let isGroupMember = this .args .statusPicker .groups .some ((group ) => {
20
+ return this .currentUser .groups .some ((userGroup ) => {
21
+ return userGroup .id === group;
22
+ });
23
+ });
24
+ if (this .args .statusPicker .group_action === " show" ) {
25
+ return isGroupMember;
26
+ } else {
27
+ return ! isGroupMember;
28
+ }
29
+ return true ;
30
+ }
31
+ get picker () {
32
+ return this .args .statusPicker ;
33
+ }
34
+
35
+ <template >
36
+ {{#if this . showStatusPicker }}
37
+ <UserStatusPicker status ={{this .picker.status }} />
38
+ {{/if }}
39
+ </template >
40
+ }
Original file line number Diff line number Diff line change 3
3
description : Add custom components (e.g., buttons) at any plugin outlet
4
4
settings :
5
5
example_setting : A description of a setting.
6
+ buttons :
7
+ description : A list of buttons to display at the specified outlet
8
+ schema :
9
+ properties :
10
+ text :
11
+ label : Button Text
12
+ description : The text to display on the button
13
+ title :
14
+ label : Button Title
15
+ description : The title attribute for the button
16
+ url :
17
+ label : Button URL
18
+ description : The URL to link to when the button is clicked
19
+ class :
20
+ label : Button Class
21
+ description : The class to apply to the button
22
+ icon :
23
+ label : Button Icon
24
+ description : The name of the icon to display on the button
25
+ outlet :
26
+ label : Button Outlet
27
+ description : The name of the outlet where the button should be displayed
28
+ group_action :
29
+ label : Group Action
30
+ description : Whether to show or hide the button for the specified groups
31
+ groups :
32
+ label : Button Groups
33
+ description : The button will be displayed/hidden if the user is in one of these groups
34
+ custom_text_block :
35
+ description : A list of text blocks to display at the specified outlet
36
+ schema :
37
+ properties :
38
+ text :
39
+ label : Text Block
40
+ description : The text to display (html is allowed)
41
+ outlet :
42
+ label : Text Block Outlet
43
+ description : The name of the plugin outlet where the text block should be displayed
44
+ class :
45
+ label : Text Block Class
46
+ description : The class to apply to the text block
47
+ group_action :
48
+ label : Group Action
49
+ description : Whether to show or hide the text block for the specified groups
50
+ groups :
51
+ label : Text Block Groups
52
+ description : The text block will be displayed/hidden if the user is in one of these groups
You can’t perform that action at this time.
0 commit comments