Page MenuHomec4science

tln-viewer-navigation.component.ts
No OneTemporary

File Metadata

Created
Tue, May 7, 21:44

tln-viewer-navigation.component.ts

import { Component, OnInit, OnDestroy, HostListener, Input, ElementRef } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
import {MatBottomSheet, MatBottomSheetRef} from '@angular/material/bottom-sheet';
import { TlnQueryServiceInterface, Reference, ManuscriptUnity, NavigationPage } from '../models';
import { TlnManuscriptUnity, TlnNavigationPage} from '../datatypes/navigation';
import { DEFAULT_VIEW_OPTION, TLN_VIEWER_ROUTE, TLN_FULLSCREEN_PARAM, TLN_FIND_PARAM, TLN_NAV_BAR_OPEN_STATE_PARAM, TLN_PAGE_PARAM, TLN_MANUSCRIPT_PARAM,
TLN_SELECTED_LINES_PARAM, TLN_SELECTED_WORDS_PARAM, TLN_VIEW_OPTION_PARAM, TLN_ZOOM_PARAM, VIEW_OPTIONS, ONTOLOTY_PREFIX } from '../constants';
import { IsReconstructedKonvolut } from '../datatypes/basic_datatype';
import { TlnLine} from '../datatypes/line';
import { TlnWord} from '../datatypes/word';
import { TlnTextGeneticOrder} from '../datatypes/text_version';
import { Mapping } from '../route-reader';
import { RouteUpdater } from '../route-updater';
import { ComplexKeyIriMapping, DataHandler, KeyIriMapping } from '../data_handler';
import { PageViewService, TlnQueryService } from '../services';
import { TlnInformationComponent, ParentInformation } from '../tln-information/tln-information.component';
import { PageInformation } from '../tln-information/page-information';
@Component({
selector: 'tln-viewer-navigation',
templateUrl: './tln-viewer-navigation.component.html',
styleUrls: ['./tln-viewer-navigation.component.css']
})
export class TlnViewerNavigation extends RouteUpdater implements OnDestroy {
/**
* OPTIONAL pass a queryService with method
* {@link /interfaces/TlnQueryServiceInterface.html#getData|getData}
* to TlnPageViewComponent.
**/
@Input() queryService: TlnQueryServiceInterface;
/**
* whether or not to show page view in fullscreen mode.
**/
fullscreen: boolean = false;
findText: string;
current_iri: string;
current_manuscript_iri: string;
manuscript_unity: ManuscriptUnity;
current_page: NavigationPage;
pageInformation: PageInformation;
previous_page: NavigationPage;
next_page: NavigationPage;
navBarOpenState: boolean;
showArchivalManuscriptUnity: boolean = false;
dataHandler: DataHandler = new DataHandler(this);
geneticOrders: TlnTextGeneticOrder[] = [];
selectedLines: string[] = [];
selectedWords: string[] = [];
private readonly increment: number = 0.333;
private readonly decrement: number = this.increment*-1;
//protected currentRoute: string = TLN_VIEWER_ROUTE;
protected mapping: Mapping = { findText: { param: TLN_FIND_PARAM, type: "string" },
current_iri: { param: TLN_PAGE_PARAM, type: "string" },
navBarOpenState: { param: TLN_NAV_BAR_OPEN_STATE_PARAM, type: "boolean" },
current_manuscript_iri: { param: TLN_MANUSCRIPT_PARAM, type: "string" },
fullscreen: { param: TLN_FULLSCREEN_PARAM, type: "boolean" },
selectedViewOption: { param: TLN_VIEW_OPTION_PARAM, type: "string" },
selectedWords: { param: TLN_SELECTED_WORDS_PARAM, type: "string" },
selectedLines: { param: TLN_SELECTED_LINES_PARAM, type: "string" } }
routerParams: Params;
selectedViewOption: string = DEFAULT_VIEW_OPTION
updating: boolean = false;
viewOptions: string[] = [ VIEW_OPTIONS.TRANSKRIPTION, VIEW_OPTIONS.FAKSIMILE, VIEW_OPTIONS.SYNOPSIS, VIEW_OPTIONS.SYNOPSIS_B ];
subscriptions: any[] = [];
constructor(el: ElementRef, private bottomSheet: MatBottomSheet, private pageViewService: PageViewService, private localQueryService: TlnQueryService, protected router: Router, protected activatedRoute: ActivatedRoute ) {
super(router, activatedRoute);
}
ngOnInit() {
let tlnQueryService = (this.queryService != null) ? this.queryService : this.localQueryService;
this.dataHandler.addHandler('manuscript_unity', { 'handler': TlnManuscriptUnity, 'next_key': 'navigation_page'});
this.dataHandler.addHandler('navigation_page', ['current_page', 'geneticOrders'] );
this.dataHandler.addHandler('current_page', { 'handler': TlnNavigationPage });
this.dataHandler.addHandler('geneticOrders', { 'handler': TlnTextGeneticOrder});
this.dataHandler.setQueryService(tlnQueryService);
this.subscriptions.push(this.dataHandler.start_processing.subscribe(
(started: boolean) =>{ this.updating = true;
}));
this.subscriptions.push(this.dataHandler.processing_finished.subscribe(
(finished: boolean) =>{ this.updating = false;
}));
super.ngOnInit();
this.subscriptions.push(this.pageViewService.reference.subscribe(
(newReference: Reference) => {
this.updatePageToReference(newReference)
}));
this.subscriptions.push(this.pageViewService.onClickedLine.subscribe(
(clickedLine: TlnLine) => {
let index = this.selectedLines.indexOf(clickedLine.id)
if (index > -1){
this.selectedLines.splice(index, 1);
} else {
this.selectedLines.push(clickedLine.id);
}
this.updateParams();
}));
this.subscriptions.push(this.pageViewService.onClickedWord.subscribe(
(clickedWord: TlnWord) => {
this.clickWord(clickedWord)
}));
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
}
private clearFindText() {
this.findText = '';
this.updateParams();
}
private clickWord(clickedWord: TlnWord){
let wordIndex = this.selectedWords.indexOf(clickedWord.id)
let lineIndex = this.selectedLines.indexOf(clickedWord.line)
if (wordIndex > -1){
this.selectedWords.splice(wordIndex, 1);
} else if (lineIndex > -1){
this.selectedLines.splice(lineIndex, 1);
} else {
this.selectedWords.push(clickedWord.id);
}
this.updateParams();
}
private getPageTitle(page?: NavigationPage, numPages?: number): string {
if (page == null){
return '';
}
let indexPrefix = (numPages != null) ? page.index + '/' + numPages : page.index;
return indexPrefix + ': ' + page.title + ' ' + page.number;
}
protected readParams(params: Params){
super.readParams(params);
if (this.dataHandler.ready && (this.current_page == null || this.current_page.id != this.current_iri)){
this.dataHandler.resetData('navigation_page')
if(this.current_manuscript_iri != null){
//this.dataHandler.debug = true;
/*this.dataHandler.conditionalAddHandler(IsReconstructedKonvolut.getQuery(this.current_manuscript_iri),
'current_page',{ handler: TlnNavigationPage}, { handler: TlnNavigationPage});*/
this.dataHandler.getData('manuscript_unity', this.current_manuscript_iri, this.current_iri);
} else {
this.dataHandler.getData('current_page', this.current_iri);
}
}
}
private setCurrentIri(pageIri: string, manuscriptIir?: string){
this.dataHandler.stop_processing.emit(true);
this.current_iri = pageIri;
this.updateParams();
}
private showInformation() {
let parentData: ParentInformation = {
geneticOrders: this.geneticOrders,
page: this.current_page,
manuscript_iri: this.current_manuscript_iri,
parentActivatedRoute: this.activatedRoute.parent
}
this.bottomSheet.open(TlnInformationComponent, {
data: parentData
});
}
private updatePageToReference(reference: Reference){
this.current_iri = <string>reference.page.id;
this.selectedLines = [ <string>reference.line.id ]
this.updateParams();
}
}

Event Timeline