@@ -10,30 +10,16 @@ import { DropdownOptions } from './dropdown-it-helper';
10
10
export class DropdownItComponent implements OnChanges {
11
11
12
12
@Input ( ) dropdownOptions : DropdownOptions ;
13
- // @Input () condition;
14
- // @Input () valueIfConditionTrue;
15
- // @Input () valueIfConditionFalse;
16
- // @Input () buttonTooltip: string;
17
- // @Input () labelingTasks;
18
- // @Input () property: string;
19
- // @Input () optionProperty: string;
20
- // @Input () disabledCondition: boolean;
21
- // @Input () hasCheckboxes: boolean;
22
- // @Input () formArrayName: string;
23
-
24
- @Output ( ) optionClicked = new EventEmitter < string > ( ) ;
25
-
26
- private hasInputErrors : string ;
27
-
13
+ @Output ( ) optionClicked = new EventEmitter < string | any > ( ) ;
28
14
15
+ hasInputErrors : string ;
29
16
buttonClassList : string ;
30
17
dropdownClassList : string ;
31
18
dropdownOptionCaptions : string [ ] ;
32
19
useValueAsCaption : boolean = false ;
33
20
34
21
constructor ( ) { }
35
22
ngOnChanges ( changes : SimpleChanges ) : void {
36
- console . log ( "changed something" , changes , this . dropdownOptions ) ;
37
23
this . dropdownOptionCaptions = this . getTextArray ( this . dropdownOptions . optionArray ) ;
38
24
this . runInputChecks ( ) ;
39
25
this . buildHelperValues ( ) ;
@@ -42,28 +28,29 @@ export class DropdownItComponent implements OnChanges {
42
28
private getTextArray ( arr : string [ ] | any [ ] ) : string [ ] {
43
29
if ( ! arr ) return [ ] ;
44
30
if ( arr . length == 0 ) return [ ] ;
45
- console . log ( typeof arr [ 0 ] )
46
31
if ( typeof arr [ 0 ] == 'string' ) return arr as string [ ] ;
47
- if ( arr [ 0 ] . name ) return arr . map ( a => a . name ) ;
48
- if ( arr [ 0 ] . text ) return arr . map ( a => a . text ) ;
32
+ let valueArray = arr ;
33
+ if ( arr [ 0 ] . value && typeof arr [ 0 ] . value == 'object' ) valueArray = arr . map ( x => x . getRawValue ( ) ) ;
34
+ if ( valueArray [ 0 ] . name ) return valueArray . map ( a => a . name ) ;
35
+ if ( valueArray [ 0 ] . text ) return valueArray . map ( a => a . text ) ;
49
36
50
37
let firstStringKey = "" ;
51
38
52
- for ( const key of Object . keys ( arr [ 0 ] ) ) {
53
- if ( typeof arr [ 0 ] [ key ] == 'string' ) {
39
+ for ( const key of Object . keys ( valueArray [ 0 ] ) ) {
40
+ if ( typeof valueArray [ 0 ] [ key ] == 'string' ) {
54
41
firstStringKey = key ;
55
42
break ;
56
43
}
57
44
}
58
45
if ( ! firstStringKey ) throw new Error ( "Cant find text in given array - dropdown" ) ;
59
- return arr . map ( a => a [ firstStringKey ] ) ;
46
+ return valueArray . map ( a => a [ firstStringKey ] ) ;
60
47
}
61
48
62
49
private buildHelperValues ( ) {
63
50
this . buttonClassList = "" ;
64
51
this . buttonClassList += this . dropdownOptions . isDisabled ? 'opacity-50 cursor-not-allowed' : 'opacity-100 cursor-pointer' ;
65
- this . buttonClassList += this . dropdownOptions . buttonTooltip ? 'tooltip tooltip-right' : '' ;
66
- this . dropdownClassList = this . dropdownOptions . hasCheckboxes ? 'w-80' : 'w-auto' ;
52
+ this . buttonClassList += this . dropdownOptions . buttonTooltip ? ' tooltip tooltip-right' : '' ;
53
+ this . dropdownClassList = this . dropdownOptions . hasCheckboxes ? ' w-80' : ' w-auto' ;
67
54
this . buttonClassList += this . dropdownClassList ;
68
55
}
69
56
@@ -79,10 +66,6 @@ export class DropdownItComponent implements OnChanges {
79
66
if ( this . dropdownOptions . optionIcons && this . dropdownOptions . optionIcons . length != this . dropdownOptions . optionIcons . length ) this . hasInputErrors = "array options != optionIcons length\n" ;
80
67
81
68
82
- if ( this . dropdownOptions . hasCheckboxes ) {
83
-
84
- }
85
-
86
69
if ( this . hasInputErrors ) console . log ( this . hasInputErrors ) ;
87
70
88
71
}
@@ -100,7 +83,8 @@ export class DropdownItComponent implements OnChanges {
100
83
}
101
84
102
85
performActionOnOption ( event : MouseEvent , clickIndex : number ) {
103
- if ( this . dropdownOptions . stopClickPropagation ) event . stopPropagation ( ) ;
86
+ if ( this . dropdownOptions . isOptionDisabled ?. length && this . dropdownOptions . isOptionDisabled [ clickIndex ] ) return ;
87
+ if ( this . dropdownOptions . keepDropdownOpen ) event . stopPropagation ( ) ;
104
88
105
89
if ( clickIndex >= this . dropdownOptions . optionArray . length ) {
106
90
console . log ( "something is wrong in the click action of the dropdown component" ) ;
@@ -109,7 +93,8 @@ export class DropdownItComponent implements OnChanges {
109
93
110
94
if ( ! this . dropdownOptions . valuePropertyPath ) {
111
95
if ( this . useValueAsCaption ) this . dropdownOptions . buttonCaption = this . dropdownOptionCaptions [ clickIndex ] ;
112
- this . optionClicked . emit ( this . dropdownOptionCaptions [ clickIndex ] ) ;
96
+ if ( this . dropdownOptions . hasCheckboxes ) this . optionClicked . emit ( this . dropdownOptions . optionArray [ clickIndex ] ) ;
97
+ else this . optionClicked . emit ( this . dropdownOptionCaptions [ clickIndex ] ) ;
113
98
return ;
114
99
}
115
100
@@ -128,50 +113,50 @@ export class DropdownItComponent implements OnChanges {
128
113
129
114
}
130
115
131
- // getActiveNegateGroupColor(group: FormGroup) {
132
- // if (!group.get('active').value) return null;
133
- // if (group.contains('negate'))
134
- // return group.get('negate').value ? '#ef4444' : '#2563eb';
135
- // return '#2563eb';
136
- // }
137
-
138
-
139
- // getDropdownDisplayText(
140
- // formControls: AbstractControl[],
141
- // labelFor: string
142
- // ): string {
143
- // let text = '';
144
- // let atLeastOneNegated: boolean = false;
145
- // for (let c of formControls) {
146
- // const hasNegate = Boolean(c.get('negate'));
147
- // if (labelFor == 'EMPTY' && c.get('active').value) return '';
148
- // else if (
149
- // labelFor == 'NOT_NEGATED' &&
150
- // c.get('active').value &&
151
- // (!hasNegate || (hasNegate && !c.get('negate').value))
152
- // ) {
153
- // text += (text == '' ? '' : ', ') + c.get('name').value;
154
- // } else if (
155
- // labelFor == 'NEGATED' &&
156
- // c.get('active').value &&
157
- // hasNegate &&
158
- // c.get('negate').value
159
- // ) {
160
- // text += (text == '' ? '' : ', ') + c.get('name').value;
161
- // }
162
- // if (
163
- // !atLeastOneNegated &&
164
- // c.get('active').value &&
165
- // hasNegate &&
166
- // c.get('negate').value
167
- // )
168
- // atLeastOneNegated = true;
169
- // }
170
- // if (labelFor == 'EMPTY') return 'None Selected';
171
-
172
- // if (labelFor == 'NOT_NEGATED' && atLeastOneNegated && text != '')
173
- // return text + ', ';
174
-
175
- // return text;
176
- // }
116
+ getActiveNegateGroupColor ( group : FormGroup ) {
117
+ if ( ! group . get ( 'active' ) . value ) return null ;
118
+ if ( group . contains ( 'negate' ) )
119
+ return group . get ( 'negate' ) . value ? '#ef4444' : '#2563eb' ;
120
+ return '#2563eb' ;
121
+ }
122
+
123
+
124
+ getDropdownDisplayText (
125
+ formControls : AbstractControl [ ] ,
126
+ labelFor : string
127
+ ) : string {
128
+ let text = '' ;
129
+ let atLeastOneNegated : boolean = false ;
130
+ for ( let c of formControls ) {
131
+ const hasNegate = Boolean ( c . get ( 'negate' ) ) ;
132
+ if ( labelFor == 'EMPTY' && c . get ( 'active' ) . value ) return '' ;
133
+ else if (
134
+ labelFor == 'NOT_NEGATED' &&
135
+ c . get ( 'active' ) . value &&
136
+ ( ! hasNegate || ( hasNegate && ! c . get ( 'negate' ) . value ) )
137
+ ) {
138
+ text += ( text == '' ? '' : ', ' ) + c . get ( 'name' ) . value ;
139
+ } else if (
140
+ labelFor == 'NEGATED' &&
141
+ c . get ( 'active' ) . value &&
142
+ hasNegate &&
143
+ c . get ( 'negate' ) . value
144
+ ) {
145
+ text += ( text == '' ? '' : ', ' ) + c . get ( 'name' ) . value ;
146
+ }
147
+ if (
148
+ ! atLeastOneNegated &&
149
+ c . get ( 'active' ) . value &&
150
+ hasNegate &&
151
+ c . get ( 'negate' ) . value
152
+ )
153
+ atLeastOneNegated = true ;
154
+ }
155
+ if ( labelFor == 'EMPTY' ) return 'None Selected' ;
156
+
157
+ if ( labelFor == 'NOT_NEGATED' && atLeastOneNegated && text != '' )
158
+ return text + ', ' ;
159
+
160
+ return text ;
161
+ }
177
162
}
0 commit comments