Skip to content

Commit

Permalink
Merge pull request #1984 from ProgrammeVitam/13161-update-dua
Browse files Browse the repository at this point in the history
Bug #13161: deactivate controle button on send
  • Loading branch information
laedanrex authored Aug 27, 2024
2 parents b07eb5d + 5a60948 commit b4aac74
Showing 1 changed file with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ export class UpdateUnitRulesComponent implements OnDestroy {
submit() {
this.disabledControl = true;
this.showText = true;
this.isLoading = !this.isLoading;

this.isLoading = true;
const rule: RuleAction = {
rule: this.ruleDetailsForm.get('newRule').value,
startDate: this.ruleDetailsForm.get('startDate').value,
Expand All @@ -288,7 +287,6 @@ export class UpdateUnitRulesComponent implements OnDestroy {
this.managementRules = data;
}),
);

if (
this.managementRules.findIndex(
(managementRule) => managementRule.category === this.ruleCategory && managementRule.actionType === RuleActionsEnum.UPDATE_RULES,
Expand Down Expand Up @@ -319,9 +317,8 @@ export class UpdateUnitRulesComponent implements OnDestroy {
};
this.managementRules.push(managementRule);
}

this.managementRulesSharedDataService.emitManagementRules(this.managementRules);
this.addRuleToQuery();
this.addRuleToQueryAndMakeRequest();
this.confirmStep.emit();
this.lastRuleId = this.ruleDetailsForm.get('oldRule').value;
}
Expand Down Expand Up @@ -381,57 +378,51 @@ export class UpdateUnitRulesComponent implements OnDestroy {
);
}

addRuleToQuery() {
addRuleToQueryAndMakeRequest() {
this.isLoading = true;
this.initDSLQuery();

const onlyManagementRules: SearchCriteriaEltDto = {
category: this.updateUnitManagementRuleService.getRuleManagementCategory(this.ruleCategory),
criteria: ORIGIN_HAS_AT_LEAST_ONE,
dataType: CriteriaDataType.STRING,
operator: CriteriaOperator.EQ,
values: [{ id: 'true', value: 'true' }],
};

const criteriaWithId: SearchCriteriaEltDto = {
criteria: MANAGEMENT_RULE_IDENTIFIER,
values: [{ id: this.ruleDetailsForm.get('oldRule').value, value: this.ruleDetailsForm.get('oldRule').value }],
category: this.updateUnitManagementRuleService.getRuleManagementCategory(this.ruleCategory),
operator: CriteriaOperator.EQ,
dataType: CriteriaDataType.STRING,
};

this.criteriaSearchDSLQuery.criteriaList.push(criteriaWithId);
this.criteriaSearchDSLQuery.criteriaList.push(onlyManagementRules);

this.ruleDetailsForm.markAsUntouched();
if (this.hasExactCount) {
this.archiveService.getTotalTrackHitsByCriteria(this.criteriaSearchDSLQuery.criteriaList).subscribe(
(resultsNumber) => {
this.archiveService.getTotalTrackHitsByCriteria(this.criteriaSearchDSLQuery.criteriaList).subscribe({
next: (resultsNumber) => {
this.itemsWithSameRule = resultsNumber.toString();
this.itemsToUpdate = (this.selectedItem - resultsNumber).toString();
this.isLoading = false;
},
(_error) => {
this.isLoading = false;
},
);
error: (e) => console.error(e),
complete: () => (this.isLoading = false),
});
} else {
this.archiveService.searchArchiveUnitsByCriteria(this.criteriaSearchDSLQuery).subscribe(
(data) => {
this.archiveService.searchArchiveUnitsByCriteria(this.criteriaSearchDSLQuery).subscribe({
next: (data) => {
this.itemsWithSameRule = data.totalResults.toString();
this.itemsToUpdate =
data.totalResults === ArchiveSearchConstsEnum.RESULTS_MAX_NUMBER
? this.resultNumberToShow
: this.selectedItem === ArchiveSearchConstsEnum.RESULTS_MAX_NUMBER
? this.resultNumberToShow
: (this.selectedItem - data.totalResults).toString();

this.isLoading = false;
if (
data.totalResults === ArchiveSearchConstsEnum.RESULTS_MAX_NUMBER ||
this.selectedItem === ArchiveSearchConstsEnum.RESULTS_MAX_NUMBER
) {
this.itemsToUpdate = this.resultNumberToShow;
} else {
this.itemsToUpdate = (this.selectedItem - data.totalResults).toString();
}
},
(_error) => {
this.isLoading = false;
},
);
error: (e) => console.error(e),
complete: () => (this.isLoading = false),
});
}
}

Expand Down

0 comments on commit b4aac74

Please sign in to comment.