Skip to content

Commit

Permalink
view scan
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed Nov 2, 2023
1 parent 4777390 commit f74e3d5
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<div class="column is-7">
<div class="box">
<ia-tabs>
<ia-tabs [activeTab]="activeTab">
<ng-template iaTabPanel *ngFor="let field of contentFields" [id]="field.name" [title]="field.displayName" [icon]="tabIcons.text">
<div class="content" [innerHtml]="highlightedInnerHtml(field)"></div>
</ng-template>
Expand Down
17 changes: 14 additions & 3 deletions frontend/src/app/document-view/document-view.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Component, Input } from '@angular/core';
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';

import { CorpusField, FoundDocument, Corpus, QueryModel } from '../models/index';
import { faBook, faImage } from '@fortawesome/free-solid-svg-icons';
import { DocumentView } from '../models/document-page';

@Component({
selector: 'ia-document-view',
templateUrl: './document-view.component.html',
styleUrls: ['./document-view.component.scss']
})
export class DocumentViewComponent {
export class DocumentViewComponent implements OnChanges {

@Input()
public document: FoundDocument;
Expand All @@ -20,14 +21,16 @@ export class DocumentViewComponent {
public corpus: Corpus;

@Input()
public documentTabIndex: number;
public view: DocumentView;


tabIcons = {
text: faBook,
scan: faImage,
};

activeTab: 'scan' | undefined;

public imgNotFound: boolean;
public imgPath: string;
public media: string[];
Expand All @@ -48,6 +51,14 @@ export class DocumentViewComponent {
return !!this.corpus.scan_image_type;
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.view) {
if (this.view === 'scan' && this.showScanTab) {
this.activeTab = 'scan';
}
}
}

isUrlField(field: CorpusField) {
return field.name === 'url' || field.name.startsWith('url_');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<ng-container *ngIf="page?.focus$ | async as document">
<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" [documentTabIndex]="0"></ia-document-view>
<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()" (keydown.enter)="page.focusPrevious()"
(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>
Expand Down Expand Up @@ -38,7 +38,7 @@
<div class="column" style="text-align:right">
<a *ngIf="document.position < page.documents.length - 1"
iaBalloon="view next document" iaBalloonPosition="left"
(click)="page.focusNext()" (keydown.enter)="page.focusNext()"
(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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { DocumentPage } from '../../models/document-page';
import { DocumentPage, DocumentView } from '../../models/document-page';
import { filter } from 'rxjs/operators';
import * as _ from 'lodash';
import { faArrowLeft, faArrowRight, faBookOpen, faLink } from '@fortawesome/free-solid-svg-icons';
Expand All @@ -14,6 +14,9 @@ export class DocumentPopupComponent implements OnChanges {
@Input() page: DocumentPage;
@Input() queryModel: QueryModel;

document: FoundDocument;
view: DocumentView;

visible = true;

faArrowLeft = faArrowLeft;
Expand All @@ -22,28 +25,26 @@ export class DocumentPopupComponent implements OnChanges {
contextIcon = faBookOpen;

get documentPageLink(): string[] {
if (this.focusedDocument) {
return ['/document', this.focusedDocument.corpus.name, this.focusedDocument.id];
if (this.document) {
return ['/document', this.document.corpus.name, this.document.id];
}
}

get contextDisplayName(): string {
if (this.focusedDocument.corpus.documentContext) {
return this.focusedDocument.corpus.documentContext.displayName;
if (this.document.corpus.documentContext) {
return this.document.corpus.documentContext.displayName;
}
}

private get focusedDocument(): FoundDocument {
return this.page?.focus$.value;
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.page) {
this.page.focus$.pipe(
filter(focus => !!focus),
).subscribe(() =>
this.visible = true
);
).subscribe(focus => {
this.document = focus.document;
this.view = focus.view;
this.visible = true;
});
}
}
}
29 changes: 16 additions & 13 deletions frontend/src/app/models/document-page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { BehaviorSubject } from 'rxjs';
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 BehaviorSubject<FoundDocument>(undefined);
focus$ = new Subject<DocumentFocus>();

constructor(
public documents: FoundDocument[],
Expand All @@ -15,27 +21,24 @@ export class DocumentPage {
this.documents.forEach((d, i) => d.position = i + 1);
}

focus(document: FoundDocument) {
this.focus$.next(document);
focus(document: FoundDocument, view: DocumentView = 'content') {
this.focus$.next({ document, view });
}

focusNext() {
this.focusShift(1);
focusNext(document: FoundDocument) {
this.focusShift(document, 1);
}

focusPrevious() {
this.focusShift(-1);
focusPrevious(document: FoundDocument) {
this.focusShift(document, -1);
}

blur() {
this.focus$.next(undefined);
}

private focusShift(shift: number) {
const document = this.focus$.value;
if (document) {
this.focusPosition(document.position + shift);
}
private focusShift(document: FoundDocument, shift: number) {
this.focusPosition(document.position + shift);
}

private focusPosition(position: number) {
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/app/search/search-results.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ <h2 class="subtitle" *ngIf="page.total > 5">
</div>
<search-relevance [value]="document.relevance"></search-relevance>
</ng-container>
<button *ngIf="document.fieldValues.image_path" class="button scan-button is-primary is-inverted" iaBalloon="View Scan" (click)="goToScan(document, $event)">
<button *ngIf="document.fieldValues.image_path" class="button scan-button is-primary is-inverted"
iaBalloon="View Scan" aria-label="view scan"
(click)="goToScan(page, document, $event)">
<span class="icon">
<i class="fa fa-newspaper-o fa-3x" aria-hidden="true"></i>
</span>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app/search/search-results.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ShowError } from '../error/error.component';
import { PageResultsParameters, PageResults } from '../models/page-results';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { DocumentPage } from '../models/document-page';

const MAXIMUM_DISPLAYED = 10000;

Expand Down Expand Up @@ -69,6 +70,11 @@ export class SearchResultsComponent implements OnChanges {
return Math.min(totalResults, MAXIMUM_DISPLAYED);
}

goToScan(page: DocumentPage, document: FoundDocument, event: Event) {
page.focus(document, 'scan');
event.stopPropagation();
};

@HostListener('window:scroll', [])
onWindowScroll() {
// mark that the search results were scrolled down beyond 68 pixels from top (position underneath sticky search bar)
Expand Down

0 comments on commit f74e3d5

Please sign in to comment.