Skip to content

Instantly share code, notes, and snippets.

@jxc876
Last active July 25, 2019 21:16
Show Gist options
  • Select an option

  • Save jxc876/12cca8d45302603a04917ecbaf24bf75 to your computer and use it in GitHub Desktop.

Select an option

Save jxc876/12cca8d45302603a04917ecbaf24bf75 to your computer and use it in GitHub Desktop.
Set Approval Request User

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();
  }

Usage 2

 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({});
  }

Usage 3

  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
    }));
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment