Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
[DLAB-1990]: Fixed total quota shouldn't be reset if only project quo…
Browse files Browse the repository at this point in the history
…ta is updated (#857)
  • Loading branch information
DG1202 committed Aug 12, 2020
1 parent 8209389 commit 0b754e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ export class ManageEnvironmentComponent implements OnInit {
this.setProjectsControl();
this.manageUsersForm.controls['total'].setValue(this.data.total.conf_max_budget || '');
this.onFormChange();
this.manageUsersForm.value.total = +this.manageUsersForm.value.total;
if (this.manageUsersForm.value.total === 0) this.manageUsersForm.value.total = null;
this.initialFormState = this.manageUsersForm.value;
}

public onFormChange() {
this.manageUsersForm.valueChanges.subscribe(value => {
this.isFormChanged = JSON.stringify(this.initialFormState) === JSON.stringify(this.manageUsersForm.value);
console.log(JSON.stringify(this.initialFormState));
console.log(JSON.stringify(this.manageUsersForm.value));
if ((this.getCurrentTotalValue() && this.getCurrentTotalValue() >= this.getCurrentUsersTotal())) {
this.manageUsersForm.controls['projects']['controls'].forEach(v => {
v.controls['budget'].errors &&
Expand All @@ -79,10 +83,8 @@ export class ManageEnvironmentComponent implements OnInit {
value.projects = value.projects.filter((v, i) =>
this.initialFormState.projects[i].budget !== v.budget ||
this.initialFormState.projects[i].monthlyBudget !== v.monthlyBudget);
if (this.initialFormState.total === value.total) {
delete value.total;
}
this.dialogRef.close(value);
value.isTotalChanged = this.initialFormState.total !== value.total;
this.dialogRef.close(value);
} else {
this.manageUsersForm.controls['total'].setErrors({ overrun: true });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,30 @@ export class ManagementComponent implements OnInit {
// }

setBudgetLimits($event) {
this.projectService.updateProjectsBudget($event.projects).subscribe((result: any) => {
if ($event.projects.length) {
this.projectService.updateProjectsBudget($event.projects).subscribe((result: any) => {
if ($event.isTotalChanged) {
this.healthStatusService.updateTotalBudgetData($event.total).subscribe((res: any) => {
result.status === HTTP_STATUS_CODES.OK
&& res.status === HTTP_STATUS_CODES.NO_CONTENT
&& this.toastr.success('Budget limits updated!', 'Success!');
this.buildGrid();
});
} else {
result.status === HTTP_STATUS_CODES.OK && this.toastr.success('Budget limits updated!', 'Success!');
this.buildGrid();
}

}, error => this.toastr.error(error.message, 'Oops!'));
} else {
this.healthStatusService.updateTotalBudgetData($event.total).subscribe((res: any) => {
result.status === HTTP_STATUS_CODES.OK
&& res.status === HTTP_STATUS_CODES.NO_CONTENT
&& this.toastr.success('Budget limits updated!', 'Success!');
res.status === HTTP_STATUS_CODES.NO_CONTENT
&& this.toastr.success('Budget limits updated!', 'Success!');
this.buildGrid();
});
}, error => this.toastr.error(error.message, 'Oops!'));
}
}
}


// manageEnvironment(event: { action: string, project: any }) {
// if (event.action === 'stop')
Expand Down

0 comments on commit 0b754e8

Please sign in to comment.