fix reference refactor build issues

This commit is contained in:
Jason Wall 2020-08-07 08:42:08 -04:00
parent d30f3736cb
commit 0e2b2273c1
3 changed files with 118 additions and 127 deletions

View File

@ -27,7 +27,7 @@ export enum Overlap {
export class BibleReference { export class BibleReference {
constructor(reference: string) { constructor(reference: string) {
this.Section = { this.section = {
book: null, book: null,
start: { start: {
chapter: 0, chapter: 0,
@ -41,20 +41,22 @@ export class BibleReference {
this.ref = reference.toLowerCase().trim(); this.ref = reference.toLowerCase().trim();
this.parseReference(); this.parseReference();
if (this.Section.end.chapter === 0) { if (this.section.end.chapter === 0) {
this.Section.end.chapter = this.Section.start.chapter; this.section.end.chapter = this.section.start.chapter;
} }
if ( if (
Number(this.Section.start.verse) > Number(this.Section.end.verse) && Number(this.section.start.verse) > Number(this.section.end.verse) &&
this.Section.start.chapter === this.Section.end.chapter this.section.start.chapter === this.section.end.chapter
) { ) {
this.Section.end.verse = this.Section.start.verse; this.section.end.verse = this.section.start.verse;
} }
if (this.Section.start.verse === 0) { if (this.section.start.verse === 0) {
this.Section.start.verse = 1; this.section.start.verse = 1;
} }
if (this.Section.end.verse === 0) { if (this.section.end.verse === 0) {
this.Section.end.verse = this.Section.book.chapters[this.Section.end.chapter]; this.section.end.verse = this.section.book.chapters[
this.section.end.chapter
];
} }
} }
@ -1611,7 +1613,7 @@ export class BibleReference {
]; ];
private ref: string; private ref: string;
Section: Section; section: Section;
errAcc: string; errAcc: string;
public static parseBook(fbook: string): Book { public static parseBook(fbook: string): Book {
@ -1917,30 +1919,29 @@ export class BibleReference {
return new BibleReference(`${book} ${keyArray[1]}:${keyArray[2]}`); return new BibleReference(`${book} ${keyArray[1]}:${keyArray[2]}`);
} }
public static overlap(leftRef: BibleReference, rightRef: BibleReference): Overlap { public static overlap(
if (leftRef.Section.book !== rightRef.Section.book) { leftRef: BibleReference,
rightRef: BibleReference
): Overlap {
if (leftRef.section.book !== rightRef.section.book) {
// either of the above means we are not overlapping // either of the above means we are not overlapping
console.log("Not same book");
return Overlap.None; return Overlap.None;
} }
if (leftRef.Section.end.chapter === rightRef.Section.start.chapter) { if (leftRef.section.end.chapter === rightRef.section.start.chapter) {
console.log("Same chapter"); if (
console.log("Left Section", leftRef.Section); leftRef.section.end.verse > rightRef.section.start.verse ||
console.log("Right Section", rightRef.Section); rightRef.section.end.verse > leftRef.section.start.verse
if ((leftRef.Section.end.verse > rightRef.Section.start.verse) ) {
|| (rightRef.Section.end.verse > leftRef.Section.start.verse)) {
console.log("Overlap detected");
return Overlap.Intersect; return Overlap.Intersect;
} }
} }
console.log("Default case");
return Overlap.None; return Overlap.None;
} }
public static mergeReference(ref1: BibleReference, ref2: BibleReference) { public static mergeReference(ref1: BibleReference, ref2: BibleReference) {
// eliminate based on book first. // eliminate based on book first.
if (ref1.Section.book != ref2.Section.book) { if (ref1.section.book !== ref2.section.book) {
// either of the above mean we are not overlapping // either of the above mean we are not overlapping
return null; return null;
} }
@ -1974,15 +1975,15 @@ export class BibleReference {
const parts = this.ref.split(':'); const parts = this.ref.split(':');
if (this.ref.match(/\d+:\d+:\d+/) !== null) { if (this.ref.match(/\d+:\d+:\d+/) !== null) {
const fbook = BibleReference.bookName(parseInt(parts[0], 10)); const fbook = BibleReference.bookName(parseInt(parts[0], 10));
this.Section.book = fbook; this.section.book = fbook;
const fch = parts[1]; const fch = parts[1];
this.Section.end.chapter = parseInt(fch, 10); this.section.end.chapter = parseInt(fch, 10);
this.Section.start.chapter = parseInt(fch, 10); this.section.start.chapter = parseInt(fch, 10);
const fv = parts[2]; const fv = parts[2];
this.Section.end.verse = parseInt(fv, 10); this.section.end.verse = parseInt(fv, 10);
this.Section.start.verse = parseInt(fv, 10); this.section.start.verse = parseInt(fv, 10);
this.ref = ''; this.ref = '';
} }
@ -1996,13 +1997,13 @@ export class BibleReference {
fbook = this.ref; fbook = this.ref;
} }
this.ref = this.ref.slice(this.ref.search(/\w\s+\d/i) + 1); this.ref = this.ref.slice(this.ref.search(/\w\s+\d/i) + 1);
this.Section.book = BibleReference.parseBook(fbook); this.section.book = BibleReference.parseBook(fbook);
} }
private parseChapter(isEnd: boolean) { private parseChapter(isEnd: boolean) {
let thing = this.Section.start; let thing = this.section.start;
if (isEnd) { if (isEnd) {
thing = this.Section.end; thing = this.section.end;
} }
this.ref = StringUtils.ltrim(this.ref); this.ref = StringUtils.ltrim(this.ref);
@ -2030,9 +2031,9 @@ export class BibleReference {
} }
private parseVerse(skipColon?: boolean, isEnd?: boolean) { private parseVerse(skipColon?: boolean, isEnd?: boolean) {
let thing = this.Section.start; let thing = this.section.start;
if (isEnd) { if (isEnd) {
thing = this.Section.end; thing = this.section.end;
} }
this.ref = StringUtils.ltrim(this.ref.toLowerCase()); this.ref = StringUtils.ltrim(this.ref.toLowerCase());
@ -2112,7 +2113,7 @@ export class BibleReference {
public toString() { public toString() {
// get the starting book, chapter, verse // get the starting book, chapter, verse
return BibleReference.toString(this.Section); return BibleReference.toString(this.section);
} }
} }

View File

@ -54,101 +54,91 @@ export class PassageCardComponent extends CardComponent implements OnInit {
} }
next() { next() {
const lastVerseForEnd = this.ref.Section.end.book.chapters[ const lastVerseForEnd = this.ref.section.book.chapters[
parseInt(this.ref.Section.end.chapter, 10) this.ref.section.end.chapter
].toString(); ];
if ( if (
this.ref.Section.end.verse !== '*' && this.ref.section.end.verse !== 0 &&
this.ref.Section.end.verse !== lastVerseForEnd this.ref.section.end.verse !== lastVerseForEnd
) { ) {
this.ref.Section.end.chapter = this.ref.Section.end.chapter; this.ref.section.end.chapter = this.ref.section.end.chapter;
} else { } else {
this.ref.Section.end.chapter = ( this.ref.section.end.chapter = this.ref.section.end.chapter + 1;
parseInt(this.ref.Section.end.chapter, 10) + 1
).toString();
} }
this.ref.Section.start.chapter = this.ref.Section.end.chapter; this.ref.section.start.chapter = this.ref.section.end.chapter;
this.ref.Section.start.verse = '1'; this.ref.section.start.verse = 1;
this.ref.Section.end.verse = '*'; this.ref.section.end.verse = this.ref.section.book.chapters[
this.ref.section.end.chapter
];
this.appService.updatePassage(this.cardItem, this.ref); this.appService.updatePassage(this.cardItem, this.ref);
} }
prev() { prev() {
if (this.ref.Section.start.verse !== '1') { if (this.ref.section.start.verse !== 1) {
this.ref.Section.start.chapter = this.ref.Section.start.chapter; this.ref.section.start.chapter = this.ref.section.start.chapter;
} else { } else {
this.ref.Section.start.chapter = ( this.ref.section.start.chapter = this.ref.section.start.chapter - 1;
parseInt(this.ref.Section.start.chapter, 10) - 1
).toString();
} }
this.ref.Section.end.chapter = this.ref.Section.start.chapter; this.ref.section.end.chapter = this.ref.section.start.chapter;
this.ref.Section.start.verse = '1'; this.ref.section.start.verse = 1;
this.ref.Section.end.verse = '*'; this.ref.section.end.verse = this.ref.section.book.chapters[
this.ref.section.end.chapter
];
this.appService.updatePassage(this.cardItem, this.ref); this.appService.updatePassage(this.cardItem, this.ref);
} }
expand() { expand() {
const lastVerseForEnd = this.ref.Section.end.book.chapters[ const lastVerseForEnd = this.ref.section.book.chapters[
parseInt(this.ref.Section.end.chapter, 10) this.ref.section.end.chapter
]; ];
// if your verse is at the beginning, to go the prev chapter and add 3 verses from that // 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, 10) < 4) { if (this.ref.section.start.verse < 4) {
this.ref.Section.start.chapter = ( this.ref.section.start.chapter = this.ref.section.start.chapter - 1;
parseInt(this.ref.Section.start.chapter, 10) - 1 this.ref.section.start.verse =
).toString(); this.ref.section.book.chapters[this.ref.section.start.chapter] -
this.ref.Section.start.verse = (3 - this.ref.section.start.verse);
'*-' + (3 - parseInt(this.ref.Section.start.verse, 10)); if (this.ref.section.start.chapter === 0) {
if (this.ref.Section.start.chapter === '0') { this.ref.section.start.chapter = 1;
this.ref.Section.start.chapter = '1'; this.ref.section.start.verse = 1;
this.ref.Section.start.verse = '1';
} }
} else { } else {
// or go back 3 verses // or go back 3 verses
this.ref.Section.start.verse = ( this.ref.section.start.verse = this.ref.section.start.verse - 3;
parseInt(this.ref.Section.start.verse, 10) - 3
).toString();
} }
// if your verse is at the end, go to the next chapter // if your verse is at the end, go to the next chapter
if ( if (
this.ref.Section.end.verse === '*' || this.ref.section.end.verse === 0 ||
parseInt(this.ref.Section.end.verse, 10) + 3 > lastVerseForEnd this.ref.section.end.verse + 3 > lastVerseForEnd
) { ) {
this.ref.Section.end.chapter = ( this.ref.section.end.chapter = this.ref.section.end.chapter + 1;
parseInt(this.ref.Section.end.chapter, 10) + 1 if (this.ref.section.end.verse === 0) {
).toString(); this.ref.section.end.verse = 3;
if (this.ref.Section.end.verse === '*') {
this.ref.Section.end.verse = '3';
} else { } else {
this.ref.Section.end.verse = ( this.ref.section.end.verse =
parseInt(this.ref.Section.end.verse, 10) + this.ref.section.end.verse + 3 - lastVerseForEnd;
3 -
lastVerseForEnd
).toString();
} }
if ( if (
this.ref.Section.end.chapter === this.ref.section.end.chapter ===
(this.ref.Section.end.book.lastChapter + 1).toString() this.ref.section.book.lastChapter + 1
) { ) {
this.ref.Section.end.chapter = this.ref.Section.end.book.lastChapter.toString(); this.ref.section.end.chapter = this.ref.section.book.lastChapter;
this.ref.Section.end.verse = lastVerseForEnd.toString(); this.ref.section.end.verse = lastVerseForEnd;
} }
} else { } else {
// or add 3 verses // or add 3 verses
this.ref.Section.end.verse = ( this.ref.section.end.verse = this.ref.section.end.verse + 3;
parseInt(this.ref.Section.end.verse, 10) + 3
).toString();
} }
if (this.ref.Section.start.verse === '0') { if (this.ref.section.start.verse === 0) {
this.ref.Section.start.verse = '1'; this.ref.section.start.verse = 1;
} }
this.appService.updatePassage(this.cardItem, this.ref); this.appService.updatePassage(this.cardItem, this.ref);

View File

@ -75,9 +75,9 @@ const initialState: AppState = {
type AppAction = type AppAction =
| { | {
type: 'GET_SAVED_PAGE'; type: 'GET_SAVED_PAGE';
pageId: string; pageId: string;
} }
| { | {
type: 'SAVE_PAGE'; type: 'SAVE_PAGE';
title: string; title: string;
@ -86,48 +86,48 @@ type AppAction =
type: 'UPDATE_CURRENT_PAGE'; type: 'UPDATE_CURRENT_PAGE';
} }
| { | {
type: 'UPDATE_SAVED_PAGES'; type: 'UPDATE_SAVED_PAGES';
savedPages: SavedPage[]; savedPages: SavedPage[];
} }
| { | {
type: 'ADD_CARD_TO_SAVED_PAGE'; type: 'ADD_CARD_TO_SAVED_PAGE';
card: CardItem; card: CardItem;
pageId: string; pageId: string;
} }
| { | {
type: 'ADD_CARD'; type: 'ADD_CARD';
card: CardItem; card: CardItem;
nextToItem: CardItem; nextToItem: CardItem;
} }
| { | {
type: 'UPDATE_CARD'; type: 'UPDATE_CARD';
newCard: CardItem; newCard: CardItem;
oldCard: CardItem; oldCard: CardItem;
} }
| { | {
type: 'REMOVE_CARD'; type: 'REMOVE_CARD';
card: CardItem; card: CardItem;
} }
| { | {
type: 'UPDATE_ERROR'; type: 'UPDATE_ERROR';
error: Error; error: Error;
} }
| { | {
type: 'UPDATE_FONT_SIZE'; type: 'UPDATE_FONT_SIZE';
size: number; size: number;
} }
| { | {
type: 'UPDATE_FONT_FAMILY'; type: 'UPDATE_FONT_FAMILY';
cardFont: string; cardFont: string;
} }
| { | {
type: 'UPDATE_AUTOCOMPLETE'; type: 'UPDATE_AUTOCOMPLETE';
words: string[]; words: string[];
} }
| { | {
type: 'UPDATE_DISPLAY_SETTINGS'; type: 'UPDATE_DISPLAY_SETTINGS';
settings: DisplaySettings; settings: DisplaySettings;
}; };
function reducer(state: AppState, action: AppAction): AppState { function reducer(state: AppState, action: AppAction): AppState {
// somtimes the state is null. lets not complain if that happens. // somtimes the state is null. lets not complain if that happens.
@ -692,10 +692,10 @@ export class AppService extends createStateService(reducer, initialState) {
} }
private async composeBiblePassageCardItem(ref: BibleReference) { private async composeBiblePassageCardItem(ref: BibleReference) {
const result = await this.getPassageFromApi(ref.Section); const result = await this.getPassageFromApi(ref.section);
return { return {
qry: ref.toString(), qry: ref.toString(),
dict: ref.Section.book.bookNumber > 39 ? 'G' : 'H', dict: ref.section.book.bookNumber > 39 ? 'G' : 'H',
type: 'Passage', type: 'Passage',
data: result, data: result,
}; };