-
-
Notifications
You must be signed in to change notification settings - Fork 748
/
evaluation-sheet.component.ts
137 lines (114 loc) · 4.02 KB
/
evaluation-sheet.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnDestroy,
OnInit,
Output
} from '@angular/core';
import {DEFAULT_METRIC_FOR_DAY} from '../metric.const';
import {MetricCopy} from '../metric.model';
import {MetricService} from '../metric.service';
import {ObstructionService} from '../obstruction/obstruction.service';
import {ImprovementService} from '../improvement/improvement.service';
import {BehaviorSubject, combineLatest, Subscription} from 'rxjs';
import {NoteService} from '../../note/note.service';
import {getWorklogStr} from '../../../util/get-work-log-str';
import {filter, map, switchMap, withLatestFrom} from 'rxjs/operators';
import {ProjectService} from '../../project/project.service';
import {T} from '../../../t.const';
@Component({
selector: 'evaluation-sheet',
templateUrl: './evaluation-sheet.component.html',
styleUrls: ['./evaluation-sheet.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class EvaluationSheetComponent implements OnDestroy, OnInit {
@Input() set day(val: string) {
this.day$.next(val);
}
@Output() save = new EventEmitter<any>();
T = T;
tomorrowsNote: string;
metricForDay: MetricCopy;
day$ = new BehaviorSubject<string>(getWorklogStr());
// isForToday$: Observable<boolean> = this.day$.pipe(map(day => day === getWorklogStr()));
private _metricForDay$ = combineLatest(
this.day$,
this._projectService.isRelatedDataLoadedForCurrentProject$,
).pipe(
filter(([day, isLoaded]) => isLoaded),
switchMap(([day]) => this._metricService.getMetricForDay$(day)),
withLatestFrom(this.day$),
map(([metric, day]) => {
return metric || {
id: day,
...DEFAULT_METRIC_FOR_DAY,
};
})
);
private _subs = new Subscription();
constructor(
public obstructionService: ObstructionService,
public improvementService: ImprovementService,
private _metricService: MetricService,
private _projectService: ProjectService,
private _noteService: NoteService,
private _cd: ChangeDetectorRef,
) {
}
ngOnInit(): void {
this._subs.add(this._metricForDay$.subscribe(metric => {
this.metricForDay = metric;
this._cd.detectChanges();
}));
}
ngOnDestroy(): void {
this._subs.unsubscribe();
}
addObstruction(v: string) {
this.metricForDay.obstructions = [...this.metricForDay.obstructions, v];
}
addNewObstruction(v: string) {
const id = this.obstructionService.addObstruction(v);
this.metricForDay.obstructions = [...this.metricForDay.obstructions, id];
}
removeObstruction(idToRemove: string) {
this.metricForDay.obstructions = this.metricForDay.obstructions.filter(id => id !== idToRemove);
}
addImprovement(v: string) {
this.metricForDay.improvements = [...this.metricForDay.improvements, v];
}
addNewImprovement(v: string) {
const id = this.improvementService.addImprovement(v);
this.metricForDay.improvements = [...this.metricForDay.improvements, id];
}
removeImprovement(idToRemove: string) {
this.metricForDay.improvements = this.metricForDay.improvements.filter(id => id !== idToRemove);
}
addImprovementTomorrow(v: string) {
this.metricForDay.improvementsTomorrow = [...this.metricForDay.improvementsTomorrow, v];
}
addNewImprovementTomorrow(v: string) {
const id = this.improvementService.addImprovement(v);
this.metricForDay.improvementsTomorrow = [...this.metricForDay.improvementsTomorrow, id];
}
removeImprovementTomorrow(idToRemove: string) {
this.metricForDay.improvementsTomorrow = this.metricForDay.improvementsTomorrow.filter(id => id !== idToRemove);
}
submit() {
if (this.tomorrowsNote && this.tomorrowsNote.trim().length > 0) {
const date = new Date();
// tomorrow at 10 o'clock
date.setHours(10, 0, 0, 0);
date.setDate(date.getDate() + 1);
this._noteService.add({
content: this.tomorrowsNote,
}, date.getTime());
}
this._metricService.upsertMetric(this.metricForDay);
this.save.emit();
}
}