-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1307 from UUDigitalHumanitieslab/feature/results-…
…model Feature/results model
- Loading branch information
Showing
23 changed files
with
584 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
frontend/src/app/document/document-popup/document-popup.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<ng-container *ngIf="document"> | ||
<p-dialog [(visible)]="visible" width="100%" | ||
[responsive]="true" [maximizable]="true" [dismissableMask]="true" [draggable]="true" [resizable]="false" [blockScroll]="true" | ||
header="Document {{document.position}} of {{page.total}}"> | ||
|
||
<ia-document-view [document]="document" [queryModel]="queryModel" [corpus]="document.corpus" [view]="view"></ia-document-view> | ||
|
||
<ng-template pTemplate="footer"> | ||
<div class="columns" style="text-align:left"> | ||
<div class="column"> | ||
<a *ngIf="document.position > 1" | ||
iaBalloon="view previous document" iaBalloonPosition="right" | ||
(click)="page.focusPrevious(document)" (keydown.enter)="page.focusPrevious(document)" | ||
role="button" tabindex="0"> | ||
<span class="icon"><fa-icon [icon]="faArrowLeft">previous</fa-icon></span> | ||
</a> | ||
</div> | ||
<div class="column" style="text-align:center"> | ||
<a [routerLink]="documentPageLink" | ||
iaBalloon="view this document on its own page" autofocus | ||
tabindex="0"> | ||
<span class="icon"> | ||
<fa-icon [icon]="linkIcon"></fa-icon> | ||
</span> | ||
<span>Link</span> | ||
</a> | ||
| ||
<a *ngIf="document.hasContext" | ||
[routerLink]="['/search', document.corpus.name]" [queryParams]="document.contextQueryParams" | ||
iaBalloon="view all documents from this {{contextDisplayName}}" | ||
tabindex="0"> | ||
<span class="icon"> | ||
<fa-icon [icon]="contextIcon"></fa-icon> | ||
</span> | ||
<span>View {{contextDisplayName}}</span> | ||
</a> | ||
</div> | ||
<div class="column" style="text-align:right"> | ||
<a *ngIf="document.position < page.documents.length" | ||
iaBalloon="view next document" iaBalloonPosition="left" | ||
(click)="page.focusNext(document)" (keydown.enter)="page.focusNext(document)" | ||
role="button" tabindex="0"> | ||
<span class="icon"><fa-icon [icon]="faArrowRight">next</fa-icon></span> | ||
</a> | ||
</div> | ||
</div> | ||
</ng-template> | ||
</p-dialog> | ||
</ng-container> |
Empty file.
25 changes: 25 additions & 0 deletions
25
frontend/src/app/document/document-popup/document-popup.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { DocumentPopupComponent } from './document-popup.component'; | ||
|
||
describe('DocumentPopupComponent', () => { | ||
let component: DocumentPopupComponent; | ||
let fixture: ComponentFixture<DocumentPopupComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [DocumentPopupComponent] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DocumentPopupComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
frontend/src/app/document/document-popup/document-popup.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Component, Input, OnChanges, OnDestroy, SimpleChanges } from '@angular/core'; | ||
import { DocumentFocus, DocumentPage, DocumentView } from '../../models/document-page'; | ||
import { filter, takeUntil } from 'rxjs/operators'; | ||
import * as _ from 'lodash'; | ||
import { faArrowLeft, faArrowRight, faBookOpen, faLink } from '@fortawesome/free-solid-svg-icons'; | ||
import { FoundDocument, QueryModel } from '../../models'; | ||
import { Subject } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'ia-document-popup', | ||
templateUrl: './document-popup.component.html', | ||
styleUrls: ['./document-popup.component.scss'] | ||
}) | ||
export class DocumentPopupComponent implements OnChanges, OnDestroy { | ||
@Input() page: DocumentPage; | ||
@Input() queryModel: QueryModel; | ||
|
||
document: FoundDocument; | ||
view: DocumentView; | ||
|
||
visible = true; | ||
|
||
faArrowLeft = faArrowLeft; | ||
faArrowRight = faArrowRight; | ||
linkIcon = faLink; | ||
contextIcon = faBookOpen; | ||
|
||
private refresh$ = new Subject<void>(); | ||
|
||
get documentPageLink(): string[] { | ||
if (this.document) { | ||
return ['/document', this.document.corpus.name, this.document.id]; | ||
} | ||
} | ||
|
||
get contextDisplayName(): string { | ||
if (this.document.corpus.documentContext) { | ||
return this.document.corpus.documentContext.displayName; | ||
} | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges): void { | ||
if (changes.page) { | ||
this.refresh$.next(); | ||
|
||
this.page.focus$.pipe( | ||
takeUntil(this.refresh$), | ||
).subscribe(this.focusUpdate.bind(this)); | ||
} | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.refresh$.next(); | ||
this.refresh$.complete(); | ||
} | ||
|
||
focusUpdate(focus?: DocumentFocus): void { | ||
if (focus) { | ||
this.document = focus.document; | ||
this.view = focus.view; | ||
this.visible = true; | ||
} else { | ||
this.document = undefined; | ||
this.visible = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Subject } from 'rxjs'; | ||
import { FoundDocument } from './found-document'; | ||
import { CorpusField } from './corpus'; | ||
import * as _ from 'lodash'; | ||
|
||
export type DocumentView = 'content' | 'scan'; | ||
|
||
export interface DocumentFocus { | ||
document: FoundDocument; | ||
view: DocumentView; | ||
} | ||
|
||
export class DocumentPage { | ||
focus$ = new Subject<DocumentFocus>(); | ||
|
||
constructor( | ||
public documents: FoundDocument[], | ||
public total: number, | ||
public fields?: CorpusField[] | ||
) { | ||
this.documents.forEach((d, i) => d.position = i + 1); | ||
} | ||
|
||
focus(document: FoundDocument, view: DocumentView = 'content') { | ||
this.focus$.next({ document, view }); | ||
} | ||
|
||
focusNext(document: FoundDocument) { | ||
this.focusShift(document, 1); | ||
} | ||
|
||
focusPrevious(document: FoundDocument) { | ||
this.focusShift(document, -1); | ||
} | ||
|
||
blur() { | ||
this.focus$.next(undefined); | ||
} | ||
|
||
/** set focus to a position relative to the given document */ | ||
private focusShift(document: FoundDocument, shift: number) { | ||
this.focusPosition(document.position + shift); | ||
} | ||
|
||
/** focus on the document at the given position in the page */ | ||
private focusPosition(position: number) { | ||
const index = _.clamp(position - 1, 0, this.documents.length - 1); | ||
this.focus(this.documents[index]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Observable, combineLatest, from, of } from 'rxjs'; | ||
import { QueryModel } from './query'; | ||
import { map } from 'rxjs/operators'; | ||
import { SearchService } from '../services'; | ||
import { SearchResults } from './search-results'; | ||
import { Results } from './results'; | ||
import { DocumentPage } from './document-page'; | ||
|
||
export const RESULTS_PER_PAGE = 20; | ||
|
||
export interface PageResultsParameters { | ||
from: number; | ||
size: number; | ||
} | ||
|
||
const resultsToPage = (results: SearchResults): DocumentPage => | ||
new DocumentPage(results.documents, results.total.value, results.fields); | ||
|
||
export class PageResults extends Results<PageResultsParameters, DocumentPage> { | ||
from$: Observable<number>; | ||
to$: Observable<number>; | ||
|
||
constructor( | ||
private searchService: SearchService, | ||
query: QueryModel, | ||
) { | ||
super(query, { | ||
from: 0, | ||
size: RESULTS_PER_PAGE, | ||
}); | ||
this.from$ = this.parameters$.pipe( | ||
map(parameters => parameters.from + 1) | ||
); | ||
this.to$ = combineLatest([this.parameters$, this.result$]).pipe( | ||
map(this.highestDocumentIndex) | ||
); | ||
} | ||
|
||
/** Parameters to re-assign when the query model is updated. */ | ||
assignOnQueryUpdate(): Partial<PageResultsParameters> { | ||
return { | ||
from: 0 | ||
}; | ||
} | ||
|
||
fetch(params: PageResultsParameters): Observable<DocumentPage> { | ||
return from(this.searchService.loadResults( | ||
this.query, params.from, params.size | ||
)).pipe( | ||
map(resultsToPage) | ||
); | ||
} | ||
|
||
private highestDocumentIndex([parameters, result]: [PageResultsParameters, DocumentPage]): number { | ||
const limit = parameters.from + parameters.size; | ||
return Math.min(limit, result.total); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.