Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<nz-card [nzTitle]="titleTemplateRef">
<ng-template #titleTemplateRef>
<a [routerLink]="routerLink">{{displayName}}</a>
<a [routerLink]="routerLink" [queryParams]="queryParams">{{displayName}}</a>
</ng-template>
<zeppelin-code-editor
[style.height.px]="height"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
OnDestroy,
SimpleChanges
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { NotebookSearchResultItem } from '@zeppelin/interfaces';
import { getKeywordPositions, KeywordPosition } from '@zeppelin/utility/get-keyword-positions';
import { editor, Range } from 'monaco-editor';
Expand All @@ -34,9 +35,9 @@ import IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
})
export class NotebookSearchResultItemComponent implements OnChanges, OnDestroy {
@Input() result: NotebookSearchResultItem;

queryParams = {};
displayName = '';
routerLink = '';
routerLink = [];
mergedStr: string;
keywords: string[] = [];
highlightPositions: KeywordPosition[] = [];
Expand All @@ -54,13 +55,23 @@ export class NotebookSearchResultItemComponent implements OnChanges, OnDestroy {
contextmenu: false
};

constructor(private ngZone: NgZone, private cdr: ChangeDetectorRef) {}
constructor(private ngZone: NgZone, private cdr: ChangeDetectorRef, private router: ActivatedRoute) {}

setDisplayNameAndRouterLink(): void {
const noteId = this.result.id.split('/', 2)[0];
const term = this.router.snapshot.params.queryStr;
const listOfId = this.result.id.split('/');
const [noteId, hasParagraph, paragraph] = listOfId;
if (!hasParagraph) {
this.routerLink = ['/', 'notebook', this.result.id];
this.queryParams = {};
} else {
this.routerLink = ['/', 'notebook', noteId];
this.queryParams = {
paragraph,
term
};
}
this.displayName = this.result.name ? this.result.name : `Note ${noteId}`;

this.routerLink = `/notebook/${noteId}`;
}

setHighlightKeyword(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
*ngFor="let p of note.paragraphs;let first = first; let last = last; index as i"
[nzSpan]="p.config.colWidth * 2"
[select]="p.id === selectId"
[scrolled]="p.id === scrolledId"
[index]="i"
[paragraph]="p"
[note]="note"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { ActivatedRoute, Router } from '@angular/router';
import { isNil } from 'lodash';
import { Subject } from 'rxjs';
import { distinctUntilKeyChanged, takeUntil } from 'rxjs/operators';
import { distinctUntilKeyChanged, map, startWith, takeUntil } from 'rxjs/operators';

import { MessageListener, MessageListenersManager } from '@zeppelin/core';
import { Permissions } from '@zeppelin/interfaces';
Expand Down Expand Up @@ -58,6 +58,7 @@ export class NotebookComponent extends MessageListenersManager implements OnInit
note: Note['note'];
permissions: Permissions;
selectId: string | null = null;
scrolledId: string | null = null;
isOwner = true;
noteRevisions: RevisionListItem[] = [];
currentRevision: string;
Expand Down Expand Up @@ -248,6 +249,10 @@ export class NotebookComponent extends MessageListenersManager implements OnInit
this.selectId = id;
}

onParagraphScrolled(id: string) {
this.scrolledId = id;
}

onSelectAtIndex(index: number) {
const scopeIndex = Math.min(this.note.paragraphs.length, Math.max(0, index));
if (this.note.paragraphs[scopeIndex]) {
Expand Down Expand Up @@ -345,6 +350,16 @@ export class NotebookComponent extends MessageListenersManager implements OnInit
}

ngOnInit() {
this.activatedRoute.queryParamMap
.pipe(
startWith(this.activatedRoute.snapshot.queryParamMap),
takeUntil(this.destroy$),
map(data => data.get('paragraph'))
)
.subscribe(id => {
this.onParagraphSelect(id);
this.onParagraphScrolled(id);
});
this.activatedRoute.params
.pipe(
takeUntil(this.destroy$),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Expand Down Expand Up @@ -62,7 +63,7 @@ type Mode = 'edit' | 'command';
},
changeDetection: ChangeDetectionStrategy.OnPush
})
export class NotebookParagraphComponent extends ParagraphBase implements OnInit, OnChanges, OnDestroy {
export class NotebookParagraphComponent extends ParagraphBase implements OnInit, OnChanges, OnDestroy, AfterViewInit {
@ViewChild(NotebookParagraphCodeEditorComponent, { static: false })
notebookParagraphCodeEditorComponent: NotebookParagraphCodeEditorComponent;
@ViewChildren(NotebookParagraphResultComponent) notebookParagraphResultComponents: QueryList<
Expand All @@ -73,6 +74,7 @@ export class NotebookParagraphComponent extends ParagraphBase implements OnInit,
@Input() looknfeel: string;
@Input() revisionView: boolean;
@Input() select: boolean = false;
@Input() scrolled: boolean = false;
@Input() index: number = -1;
@Input() viewOnly: boolean;
@Input() last: boolean;
Expand Down Expand Up @@ -608,25 +610,36 @@ export class NotebookParagraphComponent extends ParagraphBase implements OnInit,
});
}

scrollIfNeeded(): void {
if (this.scrolled && this.host.nativeElement) {
setTimeout(() => {
this.host.nativeElement.scrollIntoView();
});
}
}
ngOnChanges(changes: SimpleChanges): void {
const { index, select } = changes;
const { index, select, scrolled } = changes;
if (
(index && index.currentValue !== index.previousValue && this.select) ||
(select && select.currentValue === true && select.previousValue !== true)
) {
if (this.host.nativeElement) {
setTimeout(() => {
if (this.mode === 'command') {
(this.host.nativeElement as HTMLElement).focus();
}
});
}
setTimeout(() => {
if (this.mode === 'command' && this.host.nativeElement) {
(this.host.nativeElement as HTMLElement).focus();
}
});
}
if (scrolled) {
this.scrollIfNeeded();
}
}

getElement(): HTMLElement {
return this.host && this.host.nativeElement;
}
ngAfterViewInit(): void {
this.scrollIfNeeded();
}

ngOnDestroy(): void {
super.ngOnDestroy();
Expand Down