ngOnInit()

in zeppelin-web-angular/src/app/pages/workspace/notebook/paragraph/paragraph.component.ts [436:584]


  ngOnInit() {
    const shortcutService = this.shortcutService.forkByElement(this.host.nativeElement);
    const observables: Array<Observable<{
      action: ParagraphActions;
      event: KeyboardEvent;
    }>> = [];
    Object.entries(ShortcutsMap).forEach(([action, keys]) => {
      const keysArr: string[] = Array.isArray(keys) ? keys : [keys];
      keysArr.forEach(key => {
        observables.push(
          shortcutService
            .bindShortcut({
              keybindings: key
            })
            .pipe(
              takeUntil(this.destroy$),
              map(({ event }) => {
                return {
                  event,
                  action: action as ParagraphActions
                };
              })
            )
        );
      });
    });

    merge<{
      action: ParagraphActions;
      event: KeyboardEvent;
    }>(...observables)
      .pipe(takeUntil(this.destroy$))
      .subscribe(({ action, event }) => {
        if (this.mode === 'command') {
          switch (action) {
            case ParagraphActions.InsertAbove:
              this.insertParagraph('above');
              break;
            case ParagraphActions.InsertBelow:
              this.insertParagraph('below');
              break;
            case ParagraphActions.SwitchEditorShow:
              this.setEditorHide(!this.paragraph.config.editorHide);
              this.commitParagraph();
              break;
            case ParagraphActions.SwitchOutputShow:
              this.setTableHide(!this.paragraph.config.tableHide);
              this.commitParagraph();
              break;
            case ParagraphActions.SwitchTitleShow:
              this.paragraph.config.title = !this.paragraph.config.title;
              this.commitParagraph();
              break;
            case ParagraphActions.SwitchLineNumber:
              this.paragraph.config.lineNumbers = !this.paragraph.config.lineNumbers;
              this.commitParagraph();
              break;
            case ParagraphActions.MoveToUp:
              event.preventDefault();
              this.moveUpParagraph();
              break;
            case ParagraphActions.MoveToDown:
              event.preventDefault();
              this.moveDownParagraph();
              break;
            case ParagraphActions.SwitchEnable:
              this.paragraph.config.enabled = !this.paragraph.config.enabled;
              this.commitParagraph();
              break;
            case ParagraphActions.ReduceWidth:
              this.paragraph.config.colWidth = Math.max(1, this.paragraph.config.colWidth - 1);
              this.cdr.markForCheck();
              this.changeColWidth(true);
              break;
            case ParagraphActions.IncreaseWidth:
              this.paragraph.config.colWidth = Math.min(12, this.paragraph.config.colWidth + 1);
              this.cdr.markForCheck();
              this.changeColWidth(true);
              break;
            case ParagraphActions.Delete:
              this.removeParagraph();
              break;
            case ParagraphActions.SelectAbove:
              event.preventDefault();
              this.selectAtIndex.emit(this.index - 1);
              break;
            case ParagraphActions.SelectBelow:
              event.preventDefault();
              this.selectAtIndex.emit(this.index + 1);
              break;
            default:
              break;
          }
        }
        switch (action) {
          case ParagraphActions.Link:
            this.openSingleParagraph(this.paragraph.id);
            break;
          case ParagraphActions.EditMode:
            if (this.mode === 'command') {
              event.preventDefault();
            }
            if (!this.paragraph.config.editorHide) {
              this.switchMode('edit');
            }
            break;
          case ParagraphActions.Run:
            event.preventDefault();
            this.runParagraph();
            break;
          case ParagraphActions.RunBelow:
            this.waitConfirmFromEdit = true;
            this.runAllBelowAndCurrent();
            break;
          case ParagraphActions.Cancel:
            event.preventDefault();
            this.cancelParagraph();
            break;
          default:
            break;
        }
      });
    this.setResults();
    this.originalText = this.paragraph.text;
    this.isEntireNoteRunning = this.noteStatusService.isEntireNoteRunning(this.note);
    this.isParagraphRunning = this.noteStatusService.isParagraphRunning(this.paragraph);
    this.noteVarShareService.set(this.paragraph.id + '_paragraphScope', this);
    this.initializeDefault(this.paragraph.config);
    this.ngZService
      .runParagraphAction()
      .pipe(takeUntil(this.destroy$))
      .subscribe(id => {
        if (id === this.paragraph.id) {
          this.runParagraph();
        }
      });
    this.ngZService
      .contextChanged()
      .pipe(takeUntil(this.destroy$))
      .subscribe(change => {
        if (change.paragraphId === this.paragraph.id && change.emit) {
          if (change.set) {
            this.messageService.angularObjectClientBind(this.note.id, change.key, change.value, change.paragraphId);
          } else {
            this.messageService.angularObjectClientUnbind(this.note.id, change.key, change.paragraphId);
          }
        }
      });
  }