1
- import { ChangeDetectionStrategy , Component , Inject , OnInit } from '@angular/core' ;
1
+ import { ChangeDetectionStrategy , Component , ElementRef , Inject , OnInit , ViewChild } from '@angular/core' ;
2
2
import { FormControl , FormGroup , Validators } from '@angular/forms' ;
3
3
import { Quarter } from '../../types/model/Quarter' ;
4
4
import { TeamService } from '../../services/team.service' ;
@@ -24,12 +24,15 @@ import { AlignmentPossibility } from '../../types/model/AlignmentPossibility';
24
24
changeDetection : ChangeDetectionStrategy . OnPush ,
25
25
} )
26
26
export class ObjectiveFormComponent implements OnInit {
27
+ @ViewChild ( 'input' ) input ! : ElementRef < HTMLInputElement > ;
28
+ filteredOptions : AlignmentPossibility [ ] = [ ] ;
29
+
27
30
objectiveForm = new FormGroup ( {
28
31
title : new FormControl < string > ( '' , [ Validators . required , Validators . minLength ( 2 ) , Validators . maxLength ( 250 ) ] ) ,
29
32
description : new FormControl < string > ( '' , [ Validators . maxLength ( 4096 ) ] ) ,
30
33
quarter : new FormControl < number > ( 0 , [ Validators . required ] ) ,
31
34
team : new FormControl < number > ( { value : 0 , disabled : true } , [ Validators . required ] ) ,
32
- alignment : new FormControl < string > ( '' ) ,
35
+ alignment : new FormControl < AlignmentPossibility | null > ( null ) ,
33
36
createKeyResults : new FormControl < boolean > ( false ) ,
34
37
} ) ;
35
38
quarters$ : Observable < Quarter [ ] > = of ( [ ] ) ;
@@ -65,6 +68,19 @@ export class ObjectiveFormComponent implements OnInit {
65
68
onSubmit ( submitType : any ) : void {
66
69
const value = this . objectiveForm . getRawValue ( ) ;
67
70
const state = this . data . objective . objectiveId == null ? submitType : this . state ;
71
+
72
+ let alignmentEntity : string | null = '' ;
73
+ let alignment : any = value . alignment ;
74
+ if ( alignment ) {
75
+ if ( alignment ?. objectiveId ) {
76
+ alignmentEntity = 'O' + alignment . objectiveId ;
77
+ } else {
78
+ alignmentEntity = 'K' + alignment . keyResultId ;
79
+ }
80
+ } else {
81
+ alignmentEntity = null ;
82
+ }
83
+
68
84
let objectiveDTO : Objective = {
69
85
id : this . data . objective . objectiveId ,
70
86
version : this . version ,
@@ -73,7 +89,7 @@ export class ObjectiveFormComponent implements OnInit {
73
89
title : value . title ,
74
90
teamId : value . team ,
75
91
state : state ,
76
- alignedEntityId : value . alignment == 'Onull' ? null : value . alignment ,
92
+ alignedEntityId : alignmentEntity ,
77
93
} as unknown as Objective ;
78
94
79
95
const submitFunction = this . getSubmitFunction ( objectiveDTO . id , objectiveDTO ) ;
@@ -106,14 +122,15 @@ export class ObjectiveFormComponent implements OnInit {
106
122
this . teams$ . subscribe ( ( value ) => {
107
123
this . currentTeam . next ( value . filter ( ( team ) => team . id == teamId ) [ 0 ] ) ;
108
124
} ) ;
109
- this . generateAlignmentPossibilities ( quarterId ) ;
125
+ this . generateAlignmentPossibilities ( quarterId , objective , teamId ! ) ;
110
126
111
127
this . objectiveForm . patchValue ( {
112
128
title : objective . title ,
113
129
description : objective . description ,
114
130
team : teamId ,
115
131
quarter : quarterId ,
116
- alignment : objective . alignedEntityId ? objective . alignedEntityId : 'Onull' ,
132
+ // alignment: null,
133
+ // alignment: objective.alignedEntityId ? objective.alignedEntityId : 'Onull',
117
134
} ) ;
118
135
} ) ;
119
136
}
@@ -238,47 +255,120 @@ export class ObjectiveFormComponent implements OnInit {
238
255
return GJ_REGEX_PATTERN . test ( label ) ;
239
256
}
240
257
241
- generateAlignmentPossibilities ( quarterId : number ) {
258
+ generateAlignmentPossibilities ( quarterId : number , objective : Objective | null , teamId : number | null ) {
242
259
this . alignmentPossibilities$ = this . objectiveService . getAlignmentPossibilities ( quarterId ) ;
243
260
this . alignmentPossibilities$ . subscribe ( ( value : AlignmentPossibility [ ] ) => {
244
- if ( this . objective ?. id ) {
245
- value = value . filter ( ( item : AlignmentPossibility ) => ! ( item . objectiveId == this . objective ! . id ) ) ;
261
+ if ( teamId ) {
262
+ value = value . filter ( ( item : AlignmentPossibility ) => ! ( item . teamId == teamId ) ) ;
246
263
}
247
- let firstSelectOption = {
248
- objectiveId : null ,
249
- objectiveTitle : 'Kein Alignment' ,
250
- keyResultAlignmentsDtos : [ ] ,
251
- } ;
252
- if ( value . length != 0 ) {
253
- if ( this . objective ?. alignedEntityId ) {
254
- if ( value [ 0 ] . objectiveTitle == 'Bitte wählen' ) {
255
- value . splice ( 0 , 1 ) ;
264
+ // let firstSelectOption = {
265
+ // objectiveId: null,
266
+ // objectiveTitle: 'Kein Alignment',
267
+ // keyResultAlignmentsDtos: [],
268
+ // };
269
+ // if (value.length != 0) {
270
+ // if (this.objective?.alignedEntityId) {
271
+ // if (value[0].objectiveTitle == 'Bitte wählen') {
272
+ // value.splice(0, 1);
273
+ // }
274
+ // } else {
275
+ // firstSelectOption.objectiveTitle = 'Bitte wählen';
276
+ // }
277
+ // }
278
+ // value.unshift(firstSelectOption);
279
+
280
+ if ( objective ) {
281
+ let alignment = objective . alignedEntityId ;
282
+ if ( alignment ) {
283
+ let alignmentType = alignment . charAt ( 0 ) ;
284
+ let alignmentId = parseInt ( alignment . substring ( 1 ) ) ;
285
+ if ( alignmentType == 'O' ) {
286
+ let element =
287
+ value . find ( ( ap ) => ap . alignmentObjects . find ( ( apObjective ) => apObjective . objectId == alignmentId ) ) ||
288
+ null ;
289
+ this . objectiveForm . patchValue ( {
290
+ alignment : element ,
291
+ } ) ;
256
292
}
257
- } else {
258
- firstSelectOption . objectiveTitle = 'Bitte wählen' ;
293
+ // else {
294
+ // for (let objectiveAlignment of value) {
295
+ // let keyResult = objectiveAlignment.keyResultAlignmentsDtos.find((kr) => kr.keyResultId == alignmentId);
296
+ // if (keyResult) {
297
+ // // TODO change this to keyresult
298
+ // this.objectiveForm.patchValue({
299
+ // alignment: objectiveAlignment,
300
+ // });
301
+ // }
302
+ // }
303
+ // }
259
304
}
305
+ } else {
306
+ this . objectiveForm . patchValue ( {
307
+ alignment : null ,
308
+ } ) ;
260
309
}
261
- value . unshift ( firstSelectOption ) ;
310
+
311
+ this . filteredOptions = value . slice ( ) ;
262
312
this . alignmentPossibilities$ = of ( value ) ;
263
313
} ) ;
264
314
}
265
315
266
316
updateAlignments ( ) {
267
- this . generateAlignmentPossibilities ( this . objectiveForm . value . quarter ! ) ;
268
- this . objectiveForm . patchValue ( {
269
- alignment : 'Onull' ,
317
+ this . currentTeam . subscribe ( ( team ) => {
318
+ this . generateAlignmentPossibilities ( this . objectiveForm . value . quarter ! , null , team . id ) ;
270
319
} ) ;
320
+ // this.objectiveForm.patchValue({
321
+ // alignment: 'Onull',
322
+ // });
271
323
}
272
324
273
- changeFirstAlignmentPossibility ( ) {
274
- this . alignmentPossibilities$ . subscribe ( ( value : AlignmentPossibility [ ] ) => {
275
- let element : AlignmentPossibility = value [ 0 ] ;
276
- element . objectiveTitle = 'Kein Alignment' ;
277
- value . splice ( 0 , 1 ) ;
278
- value . unshift ( element ) ;
279
- this . alignmentPossibilities$ = of ( value ) ;
325
+ // changeFirstAlignmentPossibility() {
326
+ // this.alignmentPossibilities$.subscribe((value: AlignmentPossibility[]) => {
327
+ // let element: AlignmentPossibility = value[0];
328
+ // element.objectiveTitle = 'Kein Alignment';
329
+ // value.splice(0, 1);
330
+ // value.unshift(element);
331
+ // this.alignmentPossibilities$ = of(value);
332
+ // });
333
+ // }
334
+
335
+ filter ( ) {
336
+ let filterValue = this . input . nativeElement . value . toLowerCase ( ) ;
337
+ this . alignmentPossibilities$ . subscribe ( ( value ) => {
338
+ // this.filteredOptions = value.filter((o) => o.objectiveTitle.toLowerCase().includes(filterValue));
339
+ this . filteredOptions = value . filter (
340
+ ( o ) => o . teamName . toLowerCase ( ) . includes ( filterValue ) ,
341
+ // ||
342
+ // o.alignmentObjects.some((object) => object.objectTitle.toLowerCase().includes(filterValue))
343
+
344
+ // o.objectiveTitle.toLowerCase().includes(filterValue) || // Check if objectiveTitle includes the filterValue
345
+ // o.keyResultAlignmentsDtos.some((kr) => kr.keyResultTitle.toLowerCase().includes(filterValue)), // Check if any keyResultTitle includes the filterValue
346
+ ) ;
347
+ console . log ( this . filteredOptions ) ;
280
348
} ) ;
281
349
}
282
350
351
+ displayWith ( value : any ) : string {
352
+ return value ;
353
+ // if (value) {
354
+ // if (value.objectiveId) {
355
+ // return value.objectiveTitle;
356
+ // } else {
357
+ // return value.keyResultTitle;
358
+ // }
359
+ // } else {
360
+ // return 'Bitte wählen';
361
+ // }
362
+ }
363
+
364
+ get displayedValue ( ) : string {
365
+ if ( this . input ) {
366
+ const inputValue = this . input . nativeElement . value ;
367
+ return inputValue . length > 40 ? inputValue . slice ( 0 , 40 ) + '...' : inputValue ;
368
+ } else {
369
+ return '' ;
370
+ }
371
+ }
372
+
283
373
protected readonly getQuarterLabel = getQuarterLabel ;
284
374
}
0 commit comments