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