Page MenuHomec4science

tln-fulltext.component.ts
No OneTemporary

File Metadata

Created
Fri, Nov 15, 10:25

tln-fulltext.component.ts

import { Component, OnInit, ViewChild } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
import {PageEvent} from '@angular/material/paginator';
import { TLN_CROSSREF_ROUTE, TLN_SEARCH_ROUTE, TLN_MANUSCRIPT_ROUTE, TLN_VIEWER_ROUTE, TLN_CONTEXT_VIEW_PARAM, TLN_FULLSCREEN_PARAM, TLN_FIND_PARAM, TLN_PAGE_PARAM, TLN_MANUSCRIPT_PARAM,
TLN_RESULT_INDEX_PARAM,TLN_SELECTED_LINES_PARAM, TLN_TEXT_GENETIC_ORDER_PARAM, TLN_VIEW_OPTION_PARAM, TLN_ZOOM_PARAM, VIEW_OPTIONS, ONTOLOTY_PREFIX } from '../constants';
import { DataHandler } from '../data_handler';
import { FoundPage} from '../datatypes/search';
import { Mapping } from '../route-reader';
import { RouteUpdater } from '../route-updater';
import { TlnQueryService } from '../services';
import { ResultRange } from './page-result-filter.pipe';
//TODO: german language support for paginator, see: https://github.com/ngx-translate/core
@Component({
selector: 'tln-fulltext',
templateUrl: './tln-fulltext.component.html',
styleUrls: ['./tln-fulltext.component.css']
})
export class TlnFulltextComponent extends RouteUpdater implements OnInit {
protected currentRoute: string = TLN_SEARCH_ROUTE;
current_page_iri: string;
current_manuscript_unity: string;
dataHandler: DataHandler = new DataHandler(this);
fullscreen: boolean;
max_width: number = -1;
max_height: number = -1;
searchTerm: string;
resultIndex: number = 0;
resultLength: number = 5;
resultRange: ResultRange = { start: 0, end: 4 };
resultsReceived: boolean = false;
selectedViewOption: string = VIEW_OPTIONS.TRANSKRIPTION
startSearch: boolean = false;
protected mapping: Mapping = {
current_page_iri: { param: TLN_PAGE_PARAM, type: "string" },
resultIndex: { param: TLN_RESULT_INDEX_PARAM, type: "number" },
searchTerm: { param: TLN_FIND_PARAM, type: "string" },
current_manuscript_unity: { param: TLN_MANUSCRIPT_PARAM, type: "string" },
fullscreen: { param: TLN_FULLSCREEN_PARAM, type: "boolean" },
}
pages: FoundPage[] = [];
private readonly margin_width: number = 280;
private readonly initialPreviewWidth : number = 300;
previewWidth: number = this.initialPreviewWidth;
constructor(private tlnQueryService: TlnQueryService, protected router: Router, protected activatedRoute: ActivatedRoute ) {
super(router, activatedRoute);
}
ngOnInit() {
if (screen.availWidth - this.initialPreviewWidth - this.margin_width > 1000){
this.previewWidth = screen.availWidth - this.initialPreviewWidth - 1000;
}
this.max_width = screen.availWidth - this.previewWidth - this.margin_width;
this.max_height = screen.availHeight - 200;
this.dataHandler.addHandler('pages', { 'handler': FoundPage});
this.dataHandler['pages']['service'] = this
this.dataHandler.setQueryService(this.tlnQueryService);
this.dataHandler.start_processing.subscribe(
(started: boolean) =>{
this.resultsReceived = false;
this.startSearch = true;
});
this.dataHandler.processing_finished.subscribe(
(finished: boolean) =>{
this.resultsReceived = true;
this.startSearch = false;
});
super.ngOnInit();
}
private clearFindText() {
this.searchTerm = '';
this.pages = [];
this.resultIndex = 0;
super.updateParams();
}
private search(){
this.resultIndex = 0;
this.updateResultRange();
super.updateParams();
if (this.searchTerm != undefined && this.searchTerm != null && this.searchTerm != ''){
this.dataHandler.resetData('pages');
this.dataHandler.getData('pages', this.searchTerm);
}
}
protected readParams(params: Params){
let oldSearchTerm = this.searchTerm;
let oldResultIndex = this.resultIndex;
super.readParams(params);
if (this.searchTerm != undefined && this.searchTerm != null && this.searchTerm != '' && this.searchTerm != oldSearchTerm){
this.resultIndex = 0;
this.dataHandler.getData('pages', this.searchTerm);
}
if(oldResultIndex != this.resultIndex){
this.updateResultRange();
}
}
getSearchTerms(): string[] {
return this.searchTerm.split(' ');
}
showResults(event: PageEvent){
this.resultIndex = event.pageIndex;
this.updateResultRange();
this.updateParams()
}
private updateResultRange(){
let newStart = this.resultIndex*this.resultLength
let newEnd = newStart+this.resultLength;
this.resultRange = { start: newStart, end: newEnd };
}
}

Event Timeline