Prevent wrong bulk-change-state operations

Prevents to change the state of multiple motions, if given motions are
in different workflows
This commit is contained in:
Sean 2019-08-26 17:11:40 +02:00 committed by Sean Engelhardt
parent e3a7cbf935
commit 13e18c82e3
2 changed files with 53 additions and 44 deletions

View File

@ -62,11 +62,19 @@ export abstract class BaseViewComponent extends BaseComponent implements OnDestr
* @param message The message to show or an "real" error, which will be passed to the console.
*/
protected raiseError = (message: string | Error): void => {
let errorNotification: string;
if (message instanceof Error) {
console.error(message);
message = this.translate.instant('A client error occured. Please contact your system administrator.');
if (message.message) {
errorNotification = message.message;
} else {
errorNotification = this.translate.instant(
'A client error occurred. Please contact your system administrator.'
);
}
} else {
errorNotification = message;
}
this.messageSnackBar = this.matSnackBar.open(message as string, this.translate.instant('OK'), {
this.messageSnackBar = this.matSnackBar.open(errorNotification, this.translate.instant('OK'), {
duration: 0
});
};

View File

@ -110,21 +110,20 @@ export class MotionMultiselectService {
* @param motions The motions to change
*/
public async setStateOfMultiple(motions: ViewMotion[]): Promise<void> {
const title = this.translate.instant('This will set the following state for all selected motions:');
const choices = this.workflowRepo.getWorkflowStatesForMotions(motions).map(workflowState => ({
id: workflowState.id,
label: workflowState.name
}));
const selectedChoice = await this.choiceService.open(title, choices);
if (selectedChoice) {
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
this.overlayService.setSpinner(true, message);
await this.repo.setMultiState(motions, selectedChoice.items as number);
// .catch(error => {
// this.overlayService.setSpinner(false);
// throw error;
// });
// this.overlayService.setSpinner(false);
if (motions.every(motion => motion.workflow_id === motions[0].workflow_id)) {
const title = this.translate.instant('This will set the following state for all selected motions:');
const choices = this.workflowRepo.getWorkflowStatesForMotions(motions).map(workflowState => ({
id: workflowState.id,
label: workflowState.name
}));
const selectedChoice = await this.choiceService.open(title, choices);
if (selectedChoice) {
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
this.overlayService.setSpinner(true, message);
await this.repo.setMultiState(motions, selectedChoice.items as number);
}
} else {
throw new Error(this.translate.instant('You cannot change the state of motions in different workflows!'));
}
}
@ -134,32 +133,34 @@ export class MotionMultiselectService {
* @param motions The motions to change
*/
public async setRecommendation(motions: ViewMotion[]): Promise<void> {
const title = this.translate.instant('This will set the following recommendation for all selected motions:');
const choices = this.workflowRepo
.getWorkflowStatesForMotions(motions)
.filter(workflowState => !!workflowState.recommendation_label)
.map(workflowState => ({
id: workflowState.id,
label: workflowState.recommendation_label
}));
const clearChoice = this.translate.instant('Delete recommendation');
const selectedChoice = await this.choiceService.open(title, choices, false, null, clearChoice);
if (selectedChoice) {
const requestData = motions.map(motion => ({
id: motion.id,
recommendation: selectedChoice.action ? 0 : (selectedChoice.items as number)
}));
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
this.overlayService.setSpinner(true, message);
await this.httpService.post('/rest/motions/motion/manage_multiple_recommendation/', {
motions: requestData
});
// .catch(error => {
// this.overlayService.setSpinner(false);
// throw error;
// });
// this.overlayService.setSpinner(false);
if (motions.every(motion => motion.workflow_id === motions[0].workflow_id)) {
const title = this.translate.instant(
'This will set the following recommendation for all selected motions:'
);
const choices = this.workflowRepo
.getWorkflowStatesForMotions(motions)
.filter(workflowState => !!workflowState.recommendation_label)
.map(workflowState => ({
id: workflowState.id,
label: workflowState.recommendation_label
}));
const clearChoice = this.translate.instant('Delete recommendation');
const selectedChoice = await this.choiceService.open(title, choices, false, null, clearChoice);
if (selectedChoice) {
const requestData = motions.map(motion => ({
id: motion.id,
recommendation: selectedChoice.action ? 0 : (selectedChoice.items as number)
}));
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
this.overlayService.setSpinner(true, message);
await this.httpService.post('/rest/motions/motion/manage_multiple_recommendation/', {
motions: requestData
});
}
} else {
throw new Error(
this.translate.instant('You cannot change the recommendation of motions in different workflows!')
);
}
}