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';
|
2018-01-06 01:30:06 -05:00
|
|
|
import { BiblePassageResult, BibleService, BiblePassage, BibleVerse, HashTable, Paragraph } from '../../services/bible-service';
|
2017-01-24 16:43:58 -05:00
|
|
|
import { Reference } from '../../libs/Reference';
|
2018-01-19 23:48:51 -05:00
|
|
|
import { ProfileService } from '../../services/profile-service';
|
2018-12-25 09:30:28 -06:00
|
|
|
import { ActionSheetController, GestureController, GESTURE_ITEM_SWIPE, AlertController } from 'ionic-angular';
|
|
|
|
import { PagesService } from '../../services/pages-service';
|
|
|
|
import { GESTURE_PRIORITY_SLIDING_ITEM } from 'ionic-angular/umd/gestures/gesture-controller';
|
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
|
|
|
})
|
2018-12-25 09:30:28 -06:00
|
|
|
export class Passage implements OnInit {
|
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
|
|
|
|
|
|
|
data: BiblePassageResult;
|
2018-03-03 21:13:51 -05:00
|
|
|
withParas: BibleParaPassage[];
|
2017-08-07 16:16:15 -04:00
|
|
|
ref: Reference;
|
2018-12-25 09:30:28 -06:00
|
|
|
private gesture;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private bibleService: BibleService,
|
|
|
|
private elementRef: ElementRef,
|
|
|
|
private profileService: ProfileService,
|
|
|
|
private actionSheet: ActionSheetController,
|
|
|
|
private pagesSvc: PagesService,
|
|
|
|
private alertCtrl: AlertController
|
|
|
|
) {
|
2016-12-01 10:39:04 -05:00
|
|
|
}
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2017-08-07 16:16:15 -04:00
|
|
|
this.ref = new Reference(this.cardItem.qry);
|
2018-12-25 09:30:28 -06:00
|
|
|
this.bibleService.getResultAsPromise(this.ref.Section).then(data => {
|
2018-03-03 21:13:51 -05:00
|
|
|
this.setData(data);
|
|
|
|
});
|
2018-12-25 09:30:28 -06:00
|
|
|
|
2018-03-03 21:13:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
setData(data: BiblePassageResult) {
|
2018-03-03 21:13:51 -05:00
|
|
|
this.data = data;
|
|
|
|
this.withParas = this.getParaPassages(data.cs);
|
2017-01-24 16:43:58 -05:00
|
|
|
}
|
2018-01-06 01:30:06 -05:00
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
contextMenu() {
|
|
|
|
const actions = this.actionSheet.create({
|
|
|
|
title: 'Passage Actions',
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
text: 'Add to a Saved Page',
|
|
|
|
icon: 'add-circle',
|
|
|
|
handler: () => {
|
|
|
|
let btns = this.pagesSvc.getSavedPages().map(p => {
|
|
|
|
return {
|
|
|
|
text: p.title,
|
|
|
|
icon: 'bookmark',
|
|
|
|
handler: () => {
|
|
|
|
const page = this.profileService.profile().saved_pages.find(
|
|
|
|
i => i.title === p.title
|
|
|
|
);
|
|
|
|
page.queries.push(this.cardItem);
|
|
|
|
this.profileService.save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
btns.push({
|
|
|
|
text: 'Add to New Page',
|
|
|
|
icon: 'create',
|
|
|
|
handler: () => {
|
|
|
|
const alert = this.alertCtrl.create({
|
|
|
|
title: 'Save Passage as Page',
|
|
|
|
inputs: [
|
|
|
|
{
|
|
|
|
name: 'title',
|
|
|
|
placeholder: 'Page Title'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
text: 'Cancel',
|
|
|
|
role: 'cancel',
|
|
|
|
handler: (): void => {
|
|
|
|
console.log('Cancel clicked');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Save',
|
|
|
|
handler: data => {
|
|
|
|
const p = { queries: this.profileService.profile().items.slice(), title: data.title };
|
|
|
|
this.profileService.profile().saved_pages.push(p);
|
|
|
|
this.profileService.save();
|
|
|
|
this.pagesSvc.addPage(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
alert.present();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.actionSheet.create({
|
|
|
|
title: 'Saved Pages',
|
|
|
|
buttons: btns
|
|
|
|
}).present();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
if (this.profileService.isOnSearchPage()) {
|
|
|
|
actions.addButton({
|
|
|
|
text: 'Remove from ' + this.profileService.title,
|
|
|
|
icon: 'remove-circle',
|
|
|
|
handler: () => {
|
|
|
|
const page = this.profileService.profile().saved_pages.find(
|
|
|
|
i =>
|
|
|
|
i.title === this.profileService.title
|
|
|
|
);
|
|
|
|
const idx = this.profileService.profile().items.indexOf(this.cardItem);
|
|
|
|
this.profileService.profile().items.splice(idx, 1);
|
|
|
|
|
|
|
|
page.queries = this.profileService.profile().items.slice();
|
|
|
|
this.profileService.save();
|
|
|
|
this.pagesSvc.initializePages(this.profileService.profile().saved_pages);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
actions.present();
|
|
|
|
}
|
|
|
|
|
|
|
|
close(ev) {
|
|
|
|
let translate = 'translate3d(110%, 0, 0)';
|
|
|
|
if (ev != null && ev.direction === 2) {
|
|
|
|
translate = 'translate3d(-110%, 0, 0)';
|
|
|
|
}
|
2017-08-11 16:01:33 -04:00
|
|
|
let d = 250;
|
2017-01-28 11:42:48 -05:00
|
|
|
this.elementRef.nativeElement.parentElement.animate({
|
2018-12-25 09:30:28 -06:00
|
|
|
transform: ['none', translate]
|
2017-01-28 11:42:48 -05:00
|
|
|
}, {
|
|
|
|
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
|
|
|
});
|
2018-12-25 09:30:28 -06:00
|
|
|
setTimeout(() => {
|
2017-01-28 11:42:48 -05:00
|
|
|
this.onClose.emit(this.cardItem);
|
|
|
|
}, d);
|
2016-12-01 10:39:04 -05:00
|
|
|
}
|
2017-01-20 18:57:02 -05:00
|
|
|
|
2018-12-25 09:30:28 -06: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 = '*';
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
this.bibleService.getResultAsPromise(this.ref.Section).then(data => {
|
2018-03-03 21:13:51 -05:00
|
|
|
this.setData(data);
|
2017-08-07 16:16:15 -04:00
|
|
|
this.cardItem.qry = data.ref;
|
|
|
|
this.ref = new Reference(data.ref);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
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 = '*';
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
this.bibleService.getResultAsPromise(this.ref.Section).then(data => {
|
2018-03-03 21:13:51 -05:00
|
|
|
this.setData(data);
|
2017-08-07 16:16:15 -04:00
|
|
|
this.cardItem.qry = data.ref;
|
|
|
|
this.ref = new Reference(data.ref);
|
|
|
|
});
|
|
|
|
}
|
2018-01-06 01:30:06 -05:00
|
|
|
|
2018-12-25 09:30:28 -06: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
|
2018-12-25 09:30:28 -06: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));
|
2018-12-25 09:30:28 -06:00
|
|
|
if (this.ref.Section.start.chapter === '0') {
|
2017-08-07 16:16:15 -04:00
|
|
|
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
|
2018-12-25 09:30:28 -06: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
|
|
|
|
2018-12-25 09:30:28 -06: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();
|
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';
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
this.bibleService.getResultAsPromise(this.ref.Section).then(data => {
|
2018-03-03 21:13:51 -05:00
|
|
|
this.setData(data);
|
2017-08-07 16:16:15 -04:00
|
|
|
this.cardItem.qry = data.ref;
|
|
|
|
this.ref = new Reference(data.ref);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-25 09:30:28 -06: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
|
|
|
}
|
2018-01-06 01:30:06 -05:00
|
|
|
|
2018-12-25 09:30:28 -06: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
|
|
|
}
|
2018-01-06 01:30:06 -05:00
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
hasHeader(p: Paragraph) {
|
2018-01-06 01:30:06 -05:00
|
|
|
if (p === undefined)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return p.h.length > 0;
|
|
|
|
}
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
isPara(vs: BibleVerse) {
|
|
|
|
return this.getRefKey(this.ref.Section.start.chapter, vs) in BibleService.paragraphs;
|
2018-01-06 01:30:06 -05:00
|
|
|
}
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
getRefKey(ch: string, vs: BibleVerse) {
|
|
|
|
return this.ref.Section.start.book.book_number + ';' + ch + ';' + vs.v;
|
2018-01-06 01:30:06 -05:00
|
|
|
}
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
getParaPassages(chapters: BiblePassage[]) {
|
2018-03-03 21:13:51 -05:00
|
|
|
let passages: BibleParaPassage[] = [];
|
2018-12-25 09:30:28 -06:00
|
|
|
for (let ch of chapters) {
|
2018-03-03 21:13:51 -05:00
|
|
|
let para = {
|
|
|
|
ch: ch.ch,
|
|
|
|
paras: this.getParas(ch)
|
|
|
|
};
|
|
|
|
|
|
|
|
passages.push(para);
|
|
|
|
}
|
|
|
|
return passages;
|
|
|
|
}
|
|
|
|
|
2018-12-25 09:30:28 -06:00
|
|
|
getParas(ch: BiblePassage) {
|
2018-01-06 01:30:06 -05:00
|
|
|
// group the verses into paragraphs.
|
2018-03-03 21:13:51 -05:00
|
|
|
|
2018-01-06 01:30:06 -05:00
|
|
|
// create an initial paragraph to hold verses that might come before a paragraph.
|
|
|
|
let para: BiblePara = { p: { h: '', p: 0 }, vss: [] };
|
|
|
|
let paras: BiblePara[] = [];
|
|
|
|
|
|
|
|
// for each verse in the chapter, break them into paragraphs.
|
2018-12-25 09:30:28 -06:00
|
|
|
for (let v of ch.vss) {
|
|
|
|
if (this.isPara(v)) {
|
2018-01-06 01:30:06 -05:00
|
|
|
paras.push(para);
|
2018-12-25 09:30:28 -06:00
|
|
|
para = { p: BibleService.paragraphs[this.getRefKey(ch.ch.toString(), v)], vss: [v] };
|
2018-01-06 01:30:06 -05:00
|
|
|
if (para.p === undefined)
|
|
|
|
para.p = { h: '', p: 0 }; // just in case you can't find a paragraph.
|
|
|
|
}
|
2018-12-25 09:30:28 -06:00
|
|
|
else {
|
2018-01-06 01:30:06 -05:00
|
|
|
para.vss.push(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the final paragraph if it has verses.
|
|
|
|
if (para.vss.length > 0)
|
|
|
|
paras.push(para);
|
|
|
|
|
|
|
|
return paras;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type BiblePara = {
|
|
|
|
p: Paragraph,
|
|
|
|
vss: BibleVerse[],
|
2017-08-11 16:01:33 -04:00
|
|
|
}
|
2018-03-03 21:13:51 -05:00
|
|
|
|
|
|
|
type BibleParaPassage = {
|
|
|
|
ch: number;
|
|
|
|
paras: BiblePara[];
|
|
|
|
}
|