-
Notifications
You must be signed in to change notification settings - Fork 2
/
add-task-bar.component.ts
89 lines (80 loc) · 2.63 KB
/
add-task-bar.component.ts
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
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { TaskService } from '../task.service';
import { JiraApiService } from '../../issue/jira/jira-api.service';
import { debounceTime, switchMap, takeUntil, tap, throttle, withLatestFrom } from 'rxjs/operators';
import { ProjectService } from '../../project/project.service';
import { JiraIssue } from '../../issue/jira/jira-issue/jira-issue.model';
import { Subject } from 'rxjs';
import { JiraIssueService } from '../../issue/jira/jira-issue/jira-issue.service';
@Component({
selector: 'add-task-bar',
templateUrl: './add-task-bar.component.html',
styleUrls: ['./add-task-bar.component.scss']
})
export class AddTaskBarComponent implements OnInit, OnDestroy {
destroy$: Subject<boolean> = new Subject<boolean>();
taskSuggestionsCtrl: FormControl = new FormControl();
filteredIssueSuggestions: any[];
isLoading = false;
constructor(
private _taskService: TaskService,
private _projectService: ProjectService,
private _jiraApiService: JiraApiService,
private _jiraIssueService: JiraIssueService,
) {
}
ngOnInit() {
this.taskSuggestionsCtrl.setValue('');
this.taskSuggestionsCtrl.valueChanges.pipe(
withLatestFrom(this._projectService.currentJiraCfg$),
debounceTime(400),
tap(([searchTerm, jiraCfg]) => {
if (jiraCfg && jiraCfg.isEnabled) {
this.isLoading = true;
}
}),
switchMap(([searchTerm, jiraCfg]) => {
if (searchTerm && searchTerm.length > 1 && jiraCfg && jiraCfg.isEnabled) {
return this._jiraApiService.search(searchTerm);
} else {
// Note: the outer array signifies the observable stream the other is the value
return [[]];
}
}),
takeUntil(this.destroy$)
)
.subscribe((val) => {
this.isLoading = false;
this.filteredIssueSuggestions = val;
});
}
ngOnDestroy() {
this.destroy$.next(true);
this.destroy$.unsubscribe();
}
onBlur() {
}
displayWith(issue: JiraIssue) {
return issue && issue.summary;
}
addTask() {
const issueOrTitle = this.taskSuggestionsCtrl.value;
console.log(issueOrTitle);
if (typeof issueOrTitle === 'string') {
this._taskService.add(issueOrTitle);
} else {
this._taskService.addWithIssue(
issueOrTitle.summary,
'JIRA',
issueOrTitle,
);
// get full data
this._jiraApiService.getIssueById(issueOrTitle.id)
.then((issue) => {
this._jiraIssueService.add(issue);
});
}
this.taskSuggestionsCtrl.setValue('');
}
}