Fix bug 1565 to reset the project quotas count
* Able to empty the value which is entered as 0 or any
Change-Id: I6585a3bf91a46501d3dd60cd407e135e148ba8eb
Signed-off-by: Barath Kumar R <barath.r@tataelxsi.co.in>
diff --git a/src/app/projects/project-create-update/ProjectCreateUpdateComponent.html b/src/app/projects/project-create-update/ProjectCreateUpdateComponent.html
index b621a53..4e613fe 100644
--- a/src/app/projects/project-create-update/ProjectCreateUpdateComponent.html
+++ b/src/app/projects/project-create-update/ProjectCreateUpdateComponent.html
@@ -34,14 +34,14 @@
<label class="col-sm-12 col-form-label mandatory-label"
[ngClass]="{'text-danger': projectForm.invalid === true && submitted === true}">{{'MANDATORYCHECK' | translate}}</label>
<label class="col-sm-4 col-form-label">{{'PROJECT' | translate}} {{'NAME' | translate}}*</label>
- <div class="col-sm-8">
+ <div class="col-sm-4">
<input placeholder="{{'PROJECT' | translate}} {{'NAME' | translate}}" type="text" class="form-control"
formControlName="project_name" [ngClass]="{ 'is-invalid': submitted && f.project_name.errors }" required>
</div>
</div>
<div class="form-group row" *ngIf="getProjectType === 'Add'">
<label class="col-sm-4 col-form-label">{{'DOMAIN' | translate}} {{'NAME' | translate}}</label>
- <div class="col-sm-8">
+ <div class="col-sm-4">
<ng-select [clearable]="false" placeholder="{{'SELECT' | translate}}" [items]="domains" bindLabel="title"
bindValue="value" formControlName="domain_name" id="domain_name"
[ngClass]="{ 'is-invalid': submitted && f.domain_name.errors }"></ng-select>
@@ -50,15 +50,15 @@
<div class="form-check form-check-inline ml-2">
<input class="form-check-input" type="checkbox" formControlName="enable_quota" (change)="checkQuota()"
id="quotaCheck" *ngIf="getProjectType === 'Add' || quotaRefs === null">
- <label class="form-check-label" for="quotaCheck">{{'PAGE.PROJECT.QUOTA' | translate}}</label>
+ <label class="form-check-label" for="quotaCheck"><b>{{'PAGE.PROJECT.QUOTA' | translate}}</b></label>
</div>
<div class="row mt-1" [ngbCollapse]="!f.enable_quota.value">
<div class="form-group col-sm-6" *ngFor="let quota of quotaItems;">
<div class="row">
<label class="col-sm-7 col-form-label">{{quota.title | translate}}*</label>
<div class="col-sm-5">
- <input placeholder="{{'COUNT' | translate}}" type="number" min="{{quota.minValue}}"
- class="form-control" [formControlName]="quota.value" [ngClass]="{ 'is-invalid': submitted && f[quota.value].errors }" required>
+ <input placeholder="{{'COUNT' | translate}}" type="number"
+ class="form-control" [formControlName]="quota.value" [ngClass]="{ 'is-invalid': submitted && f[quota.value].errors }">
</div>
</div>
</div>
diff --git a/src/app/projects/project-create-update/ProjectCreateUpdateComponent.ts b/src/app/projects/project-create-update/ProjectCreateUpdateComponent.ts
index 01f963e..5eb2d5d 100644
--- a/src/app/projects/project-create-update/ProjectCreateUpdateComponent.ts
+++ b/src/app/projects/project-create-update/ProjectCreateUpdateComponent.ts
@@ -197,11 +197,11 @@
public checkQuota(): void {
if (this.getFormControl('enable_quota').value) {
this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
- this.projectForm.addControl(quotaItem.value, new FormControl(quotaItem.minValue, Validators.required));
+ this.projectForm.addControl(quotaItem.value, new FormControl(''));
});
} else {
this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
- this.getFormControl(quotaItem.value).setValue(quotaItem.minValue);
+ this.getFormControl(quotaItem.value).setValue('');
});
}
}
@@ -247,8 +247,13 @@
if (this.getFormControl('enable_quota').value) {
payload.quotas = {};
this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
- payload.quotas[quotaItem.value] = this.getFormControl(quotaItem.value).value;
+ if (this.getFormControl(quotaItem.value).value !== '') {
+ payload.quotas[quotaItem.value] = this.getFormControl(quotaItem.value).value;
+ }
});
+ if (Object.keys(payload.quotas).length === 0) {
+ delete payload.quotas;
+ }
}
}
@@ -259,16 +264,15 @@
this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
if (!isNullOrUndefined(quotaRef[quotaItem.value])) {
this.projectForm.addControl(quotaItem.value, new FormControl(quotaRef[quotaItem.value],
- [Validators.required, Validators.min(quotaItem.minValue), Validators.max(quotaItem.maxValue)]));
+ [Validators.max(quotaItem.maxValue)]));
} else {
- this.projectForm.addControl(quotaItem.value, new FormControl(quotaItem.minValue, [Validators.required,
- Validators.min(quotaItem.minValue), Validators.max(quotaItem.maxValue)]));
+ this.projectForm.addControl(quotaItem.value, new FormControl('', [Validators.max(quotaItem.maxValue)]));
}
});
} else {
this.quotaItems.forEach((quotaItem: QUOTAITEM): void => {
- this.projectForm.addControl(quotaItem.value, new FormControl(quotaItem.minValue, [Validators.required,
- Validators.min(quotaItem.minValue), Validators.max(quotaItem.maxValue)]));
+ this.projectForm.addControl(quotaItem.value, new FormControl('', [Validators.min(quotaItem.minValue),
+ Validators.max(quotaItem.maxValue)]));
});
}
}