forked from trungvose/jira-clone-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-issue-modal.component.ts
89 lines (79 loc) · 2.49 KB
/
add-issue-modal.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 {ChangeDetectionStrategy, Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import {IssuePriority, IssueStatus, IssueType, JIssue} from '@trungk18/interface/issue';
import {quillConfiguration} from '@trungk18/project/config/editor';
import {NzModalRef} from 'ng-zorro-antd/modal';
import {ProjectService} from '@trungk18/project/state/project/project.service';
import {IssueUtil} from '@trungk18/project/utils/issue';
import {ProjectQuery} from '@trungk18/project/state/project/project.query';
import {UntilDestroy, untilDestroyed} from '@ngneat/until-destroy';
import {Observable} from 'rxjs';
import {JUser} from '@trungk18/interface/user';
import {tap} from 'rxjs/operators';
import {NoWhitespaceValidator} from '@trungk18/core/validators/no-whitespace.validator';
import {DateUtil} from '@trungk18/project/utils/date';
@Component({
selector: 'add-issue-modal',
templateUrl: './add-issue-modal.component.html',
styleUrls: ['./add-issue-modal.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
@UntilDestroy()
export class AddIssueModalComponent implements OnInit {
reporterUsers$: Observable<JUser[]>;
assignees$: Observable<JUser[]>;
issueForm: FormGroup;
editorOptions = quillConfiguration;
get f() {
return this.issueForm?.controls;
}
constructor(
private _fb: FormBuilder,
private _modalRef: NzModalRef,
private _projectService: ProjectService,
private _projectQuery: ProjectQuery) {}
ngOnInit(): void {
this.initForm();
this.reporterUsers$ = this._projectQuery.users$.pipe(
untilDestroyed(this),
tap((users) => {
const [user] = users;
if (user) {
this.f.reporterId.patchValue(user.id);
}
})
);
this.assignees$ = this._projectQuery.users$;
}
initForm() {
this.issueForm = this._fb.group({
type: [IssueType.TASK],
priority: [IssuePriority.MEDIUM],
title: ['', NoWhitespaceValidator()],
description: [''],
reporterId: [''],
userIds: [[]]
});
}
submitForm() {
if (this.issueForm.invalid) {
return;
}
const now = DateUtil.getNow();
const issue: JIssue = {
...this.issueForm.getRawValue(),
id: IssueUtil.getRandomId(),
status: IssueStatus.BACKLOG,
createdAt: now,
updatedAt: now
};
this._projectService.updateIssue(issue);
this.closeModal();
}
cancel() {
this.closeModal();
}
closeModal() {
this._modalRef.close();
}
}