155 lines
5.2 KiB
TypeScript
Raw Normal View History

import { Component, EventEmitter, Output, Input, OnInit, ElementRef } from '@angular/core';
import { OpenData, CardItem } from '../../pages/search/search';
import { BiblePassageResult, BibleService } from '../../services/bible-service';
import { Reference } from '../../libs/Reference';
@Component({
selector: 'passage',
templateUrl: 'passage.html',
providers: [BibleService]
})
export class Passage implements OnInit
{
@Output()
onItemClicked = new EventEmitter<OpenData>();
@Output()
onClose = new EventEmitter<CardItem>();
@Input()
cardItem: CardItem;
@Input()
versesOnNewLine: boolean;
data: BiblePassageResult;
ref: Reference;
constructor(private bibleService: BibleService, private elementRef: ElementRef)
{
}
ngOnInit(): void
{
this.ref = new Reference(this.cardItem.qry);
this.bibleService.getResultAsPromise(this.ref.Section).then(data => this.data = data);
}
close()
{
let d = 250;
this.elementRef.nativeElement.parentElement.animate({
transform: ['none', 'translate3d(110%, 0, 0)']
}, {
fill: 'forwards',
duration: d,
iterations: 1,
easing: 'ease-in-out'
});
setTimeout(() =>
{
this.onClose.emit(this.cardItem);
}, d);
}
next()
{
let last_verse_for_end = this.ref.Section.end.book.chapters[parseInt(this.ref.Section.end.chapter)].toString();
if (this.ref.Section.end.verse !== '*' && this.ref.Section.end.verse !== last_verse_for_end)
this.ref.Section.end.chapter = this.ref.Section.end.chapter;
else
this.ref.Section.end.chapter = (parseInt(this.ref.Section.end.chapter) + 1).toString();
this.ref.Section.start.chapter = this.ref.Section.end.chapter;
this.ref.Section.start.verse = '1';
this.ref.Section.end.verse = '*';
this.bibleService.getResultAsPromise(this.ref.Section).then(data =>
{
this.data = data;
this.cardItem.qry = data.ref;
this.ref = new Reference(data.ref);
});
}
prev()
{
if (this.ref.Section.start.verse !== '1')
this.ref.Section.start.chapter = this.ref.Section.start.chapter;
else
this.ref.Section.start.chapter = (parseInt(this.ref.Section.start.chapter) - 1).toString();
this.ref.Section.end.chapter = this.ref.Section.start.chapter;
this.ref.Section.start.verse = '1';
this.ref.Section.end.verse = '*';
this.bibleService.getResultAsPromise(this.ref.Section).then(data =>
{
this.data = data;
this.cardItem.qry = data.ref;
this.ref = new Reference(data.ref);
});
}
expand()
{
let last_verse_for_end = this.ref.Section.end.book.chapters[parseInt(this.ref.Section.end.chapter)];
// if your verse is at the beginning, to go the prev chapter and add 3 verses from that
if (parseInt(this.ref.Section.start.verse) < 4)
{
this.ref.Section.start.chapter = (parseInt(this.ref.Section.start.chapter) - 1).toString();
this.ref.Section.start.verse = '*-' + (3 - parseInt(this.ref.Section.start.verse));
if (this.ref.Section.start.chapter === '0')
{
this.ref.Section.start.chapter = '1';
this.ref.Section.start.verse = '1';
}
}
else // or go back 3 verses
this.ref.Section.start.verse = (parseInt(this.ref.Section.start.verse) - 3).toString();
// if your verse is at the end, go to the next chapter
if (this.ref.Section.end.verse === '*' || parseInt(this.ref.Section.end.verse) + 3 > last_verse_for_end)
{
this.ref.Section.end.chapter = (parseInt(this.ref.Section.end.chapter) + 1).toString();
if (this.ref.Section.end.verse === '*')
this.ref.Section.end.verse = '3';
else
this.ref.Section.end.verse = (parseInt(this.ref.Section.end.verse) + 3 - last_verse_for_end).toString();
2017-08-23 17:53:03 -04:00
if (this.ref.Section.end.chapter === (this.ref.Section.end.book.last_chapter + 1).toString())
{
2017-08-23 17:53:03 -04:00
this.ref.Section.end.chapter = this.ref.Section.end.book.last_chapter.toString();
this.ref.Section.end.verse = last_verse_for_end.toString();
}
}
else // or add 3 verses
this.ref.Section.end.verse = (parseInt(this.ref.Section.end.verse) + 3).toString();
if (this.ref.Section.start.verse === '0')
this.ref.Section.start.verse = '1';
this.bibleService.getResultAsPromise(this.ref.Section).then(data =>
{
this.data = data;
this.cardItem.qry = data.ref;
this.ref = new Reference(data.ref);
});
}
openStrongs(strongs: string)
{
this.onItemClicked.emit({ card: this.cardItem, qry: this.cardItem.dict + strongs, from_search_bar: false });
}
openMenu(strongs: string)
{
2017-01-04 17:17:56 -05:00
}
isPunct(c: string)
{
return new RegExp('^[\.\,\;\:\?\!]$').test(c);
}
}