Usage 1 - triggered by publish button
< button (click) ="publish() "... >
{{ smartRotation.approvalRequestUser | smartRotationPublishText }}
</ button >
public publish ( ) : void {
const approvalRequestUser : string = < string > _.get(this.smartRotationState.getCurrentStateAsSmartRotation(), 'approvalRequestUser');
_.isNil(approvalRequestUser) ? this.modalPublishToViero()
: _.isEqual(approvalRequestUser, this.currentUserId)? this.modalPublishToViero() : this.doPublish();
}
publish() {
const approvalRequestUser: ...
_.isNil(approvalRequestUser) ? this.modalPublishToViero()
: _.isEqual(approvalRequestUser, this.currentUserId)
? this.modalPublishToViero() : this.doPublish();
}
doPublish() {
const dialogRef: MatDialogRef<DialogConfirmComponent> = this.dialog.open(DialogConfirmComponent, {
maxHeight: '260px',
width: '800px',
data: {
title: 'Smart Rotation Publish',
message: 'Please confirm that you wish to publish this Smart Rotation.',
positiveLabel: 'CONFIRM',
negativeLabel: 'CANCEL'
}
});
dialogRef.componentInstance.onPositive
..
concatMap(() => this.setStatusToPublish()),
}
public setStatusToPublish(): Observable<object> {
this.smartRotationState.setStatusInSmartRotation('PUBLISHING');
this.smartRotationState.setApprovalRequestUserInSmartRotation(null); <---
return of({});
}
public modalPublishToViero(): void {
!_.isNil(this.currentUserState.user) && this.authorizeUsers();
const dialogRef: MatDialogRef<DialogConfirmCheckboxFooterComponent> = this.dialog.open(DialogConfirmCheckboxFooterComponent, {
maxHeight: '260px',
width: '800px',
data: {
title: 'Request approval',
message: 'This smart rotation needs to be approved before it can be published.',
checkboxLabel: 'No Approval Required',
approvalRequired: this.unAuthorizedUser,
positiveLabel: 'PUBLISH',
negativeLabel: 'CANCEL'
}
});
dialogRef.componentInstance.onPositiveChecked
.pipe(
tap(() => dialogRef.close()),
concatMap(() => this.loadingIndicator.toggle(true)),
concatMap(() => this.setStatusToPublish())
)
.subscribe(
() => this.publishData(),
(err: Error | Response) => {
this.logger.error(`${this.constructorName}.modalPublishToViero(): Publish to Viero without Approval Failure`, err);
this.notifications.show(`Error for Saving before to Publish Smart Rotation to Viero without Approval`);
}
);
dialogRef.componentInstance.onPositiveUnchecked
.pipe(
tap(() => dialogRef.close()),
concatMap(() => this.loadingIndicator.toggle(true)),
concatMap(() => this.smartRotationFacade.requestApproval(this.smartRotationState.getCurrentStateAsSmartRotation())),
finalize(() => this.loadingIndicator.toggle(false))
)
.subscribe(
() => {
this.activityLogHelper.requestApprovalSmartRotation();
this.smartRotationState.setStatusInSmartRotation('IN_PROGRESS');
this.smartRotationState.setApprovalRequestUserInSmartRotation(this.currentUserId);
this.notifications.show(`Success for Approval Requesting of Smart Rotation to Viero`);
},
(err: Error | Response) => {
this.logger.error(`${this.constructorName}.modalPublishToViero(): Publish to Viero Failure`, err);
this.notifications.show(`Error for Approval Requesting of Smart Rotation to Viero`);
}
);
dialogRef.afterClosed()
.subscribe(() => this.loadingIndicator.toggle(false));
}
public setApprovalRequestUserInSmartRotation(user: string): void {
this.updateState(_.assign({}, this._state.getValue(), {
approvalRequestUser: user
}));
}