Merge pull request #4943 from tsiegleauq/prevent-destructive-bulk
Prevent wrong bulk-change-state operations
This commit is contained in:
commit
0d93c5ecfc
@ -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.
|
* @param message The message to show or an "real" error, which will be passed to the console.
|
||||||
*/
|
*/
|
||||||
protected raiseError = (message: string | Error): void => {
|
protected raiseError = (message: string | Error): void => {
|
||||||
|
let errorNotification: string;
|
||||||
if (message instanceof Error) {
|
if (message instanceof Error) {
|
||||||
console.error(message);
|
if (message.message) {
|
||||||
message = this.translate.instant('A client error occured. Please contact your system administrator.');
|
errorNotification = message.message;
|
||||||
|
} else {
|
||||||
|
errorNotification = this.translate.instant(
|
||||||
|
'A client error occurred. Please contact your system administrator.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.messageSnackBar = this.matSnackBar.open(message as string, this.translate.instant('OK'), {
|
} else {
|
||||||
|
errorNotification = message;
|
||||||
|
}
|
||||||
|
this.messageSnackBar = this.matSnackBar.open(errorNotification, this.translate.instant('OK'), {
|
||||||
duration: 0
|
duration: 0
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -110,6 +110,7 @@ export class MotionMultiselectService {
|
|||||||
* @param motions The motions to change
|
* @param motions The motions to change
|
||||||
*/
|
*/
|
||||||
public async setStateOfMultiple(motions: ViewMotion[]): Promise<void> {
|
public async setStateOfMultiple(motions: ViewMotion[]): Promise<void> {
|
||||||
|
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 title = this.translate.instant('This will set the following state for all selected motions:');
|
||||||
const choices = this.workflowRepo.getWorkflowStatesForMotions(motions).map(workflowState => ({
|
const choices = this.workflowRepo.getWorkflowStatesForMotions(motions).map(workflowState => ({
|
||||||
id: workflowState.id,
|
id: workflowState.id,
|
||||||
@ -120,11 +121,9 @@ export class MotionMultiselectService {
|
|||||||
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
|
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
|
||||||
this.overlayService.setSpinner(true, message);
|
this.overlayService.setSpinner(true, message);
|
||||||
await this.repo.setMultiState(motions, selectedChoice.items as number);
|
await this.repo.setMultiState(motions, selectedChoice.items as number);
|
||||||
// .catch(error => {
|
}
|
||||||
// this.overlayService.setSpinner(false);
|
} else {
|
||||||
// throw error;
|
throw new Error(this.translate.instant('You cannot change the state of motions in different workflows!'));
|
||||||
// });
|
|
||||||
// this.overlayService.setSpinner(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +133,10 @@ export class MotionMultiselectService {
|
|||||||
* @param motions The motions to change
|
* @param motions The motions to change
|
||||||
*/
|
*/
|
||||||
public async setRecommendation(motions: ViewMotion[]): Promise<void> {
|
public async setRecommendation(motions: ViewMotion[]): Promise<void> {
|
||||||
const title = this.translate.instant('This will set the following recommendation for all selected motions:');
|
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
|
const choices = this.workflowRepo
|
||||||
.getWorkflowStatesForMotions(motions)
|
.getWorkflowStatesForMotions(motions)
|
||||||
.filter(workflowState => !!workflowState.recommendation_label)
|
.filter(workflowState => !!workflowState.recommendation_label)
|
||||||
@ -149,17 +151,16 @@ export class MotionMultiselectService {
|
|||||||
id: motion.id,
|
id: motion.id,
|
||||||
recommendation: selectedChoice.action ? 0 : (selectedChoice.items as number)
|
recommendation: selectedChoice.action ? 0 : (selectedChoice.items as number)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
|
const message = `${motions.length} ` + this.translate.instant(this.messageForSpinner);
|
||||||
this.overlayService.setSpinner(true, message);
|
this.overlayService.setSpinner(true, message);
|
||||||
await this.httpService.post('/rest/motions/motion/manage_multiple_recommendation/', {
|
await this.httpService.post('/rest/motions/motion/manage_multiple_recommendation/', {
|
||||||
motions: requestData
|
motions: requestData
|
||||||
});
|
});
|
||||||
// .catch(error => {
|
}
|
||||||
// this.overlayService.setSpinner(false);
|
} else {
|
||||||
// throw error;
|
throw new Error(
|
||||||
// });
|
this.translate.instant('You cannot change the recommendation of motions in different workflows!')
|
||||||
// this.overlayService.setSpinner(false);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user