-
Notifications
You must be signed in to change notification settings - Fork 2
/
sal-changer.component.ts
78 lines (69 loc) · 1.89 KB
/
sal-changer.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
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { SalService } from 'build/openapi';
import { filter } from 'rxjs/operators';
import { Emp } from 'build/openapi/model/emp';
@Component({
selector: 'app-sal-changer',
templateUrl: './sal-changer.component.html',
styleUrls: ['./sal-changer.component.sass'],
standalone: false
})
export class SalChangerComponent implements OnInit, OnChanges {
constructor(private salaryService: SalService,
private router: Router) {
router.events.pipe(
filter(event => event instanceof NavigationEnd)
).subscribe(() => {
this.empSal = 0;
this.collectEmpSalary();
});
}
@Input() emp: Emp;
empSal = 0;
message = "";
showSpinner = false;
ngOnInit() {
this.collectEmpSalary();
}
ngOnChanges() {
this.collectEmpSalary();
}
collectEmpSalary() {
this.message = "";
const eid = this.emp.empId ?? -1;
if (eid === -1) {
this.empSal = 0;
} else {
this.salaryService.getSalByEmpId(eid)
.subscribe(c => this.empSal = parseInt(c, 0));
}
}
updateEmpSalary() {
const salStr = String(this.empSal);
const eId = this.emp.empId ?? -1;
if (eId !== -1) {
this.salaryService.updateSalWithForm(eId, salStr)
.subscribe(
//c => this.empSal = parseInt(c!, 0)
{
next: (v) => {
console.log(v);
this.message = "Salary has been updated";
this.showSpinner = false;
},
error: (e) => {
console.error(e);
this.message = e.statusText;
this.showSpinner = false;
},
complete: () => {
this.showSpinner = false;
}
}
);
} else{
this.message = "Employee is not identified";
}
}
}