FEATURE: Added Strongs back in in part

This commit is contained in:
jason.wall 2016-09-12 18:13:56 -04:00
parent aba7058e17
commit 1ff43d7dc0
13 changed files with 365 additions and 113 deletions

View File

@ -28,19 +28,19 @@ export class Reference {
this.Section = { this.Section = {
start: { start: {
book: -1, book: -1,
bookname: '', bookname: "",
longbookname: '', longbookname: "",
lastchapter: -1, lastchapter: -1,
chapter: '', chapter: "",
verse: '' verse: ""
}, },
end: { end: {
book: -1, book: -1,
bookname: '', bookname: "",
longbookname: '', longbookname: "",
lastchapter: -1, lastchapter: -1,
chapter: '', chapter: "",
verse: '' verse: ""
} }
}; };
this.ref = reference.toLowerCase().trim(); this.ref = reference.toLowerCase().trim();
@ -53,14 +53,14 @@ export class Reference {
this.Section.end.lastchapter = this.Section.start.lastchapter; this.Section.end.lastchapter = this.Section.start.lastchapter;
} }
if (this.Section.end.chapter == '') this.Section.end.chapter = this.Section.start.chapter; if (this.Section.end.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.start.book == this.Section.end.book this.Section.start.book == this.Section.end.book
) this.Section.end.verse = this.Section.start.verse; ) this.Section.end.verse = this.Section.start.verse;
if (this.Section.start.verse == '') this.Section.start.verse = '1'; if (this.Section.start.verse == "") this.Section.start.verse = "1";
if (this.Section.end.verse == '') this.Section.end.verse = '*'; if (this.Section.end.verse == "") this.Section.end.verse = "*";
} }
private parseReference() { private parseReference() {
@ -522,8 +522,8 @@ export class Reference {
this.ref = this.ref.slice(1); this.ref = this.ref.slice(1);
} }
this.ref = StringUtils.ltrim(this.ref.toLowerCase()); this.ref = StringUtils.ltrim(this.ref.toLowerCase());
if (this.ref[0] == '*') { if (this.ref[0] == "*") {
thing.verse = '*'; thing.verse = "*";
this.ref = this.ref.slice(1); this.ref = this.ref.slice(1);
return; return;
} }

View File

@ -1,11 +1,11 @@
import {Component, ViewChild} from '@angular/core'; import {Component, ViewChild} from "@angular/core";
import {ionicBootstrap, Platform, MenuController, Nav} from 'ionic-angular'; import {ionicBootstrap, Platform, MenuController, Nav} from "ionic-angular";
import {StatusBar} from 'ionic-native'; import {StatusBar} from "ionic-native";
import {SearchPage} from './pages/search/search'; import {SearchPage} from "./pages/search/search";
@Component({ @Component({
templateUrl: 'build/app.html' templateUrl: "build/app.html"
}) })
class MyApp class MyApp
{ {

View File

@ -1,8 +1,8 @@
/// <reference path="../typings/browser/ambient/jquery/index.d.ts" /> /// <reference path="../typings/browser/ambient/jquery/index.d.ts" />
/// <reference path="types.ts" /> /// <reference path="types.ts" />
import { Injectable } from '@angular/core'; import { Injectable } from "@angular/core";
import { Observable } from 'rxjs/Observable'; import { Observable } from "rxjs/Observable";
import { Http, Response } from '@angular/http'; import { Http, Response } from "@angular/http";
@Injectable() @Injectable()
export class BibleService export class BibleService
@ -24,14 +24,12 @@ export class BibleService
this.result = { this.result = {
cs: [], cs: [],
testament: "", testament: "",
ref: "", ref: ""
id: 0
}; };
this.count = Number(section.end.chapter) - Number(section.start.chapter) + 1; this.count = Number(section.end.chapter) - Number(section.start.chapter) + 1;
for (let i = Number(section.start.chapter); i <= Number(section.end.chapter); i++) for (let i = Number(section.start.chapter); i <= Number(section.end.chapter); i++) {
{ const url = "data/bibles/kjv_strongs/" + section.start.book + "-" + i + ".json";
let url = "data/bibles/kjv_strongs/" + section.start.book + "-" + i + ".json";
jQuery.ajax({ jQuery.ajax({
async: false, async: false,
type: "GET", type: "GET",
@ -50,21 +48,21 @@ export class BibleService
for (let j = 0; j < this.chapters.length; j++) for (let j = 0; j < this.chapters.length; j++)
{ {
let vss: BibleVerse[] = []; const vss: BibleVerse[] = [];
let start; let start: number;
let end; let end;
// figure out the start verse. // figure out the start verse.
if (j == 0) if (j === 0)
{ {
start = section.start.verse; start = parseInt(section.start.verse);
} else } else
{ {
start = 1; start = 1;
} }
// figure out the end verse // figure out the end verse
if ((j + 1) == this.chapters.length) if ((j + 1) === this.chapters.length)
{ {
end = section.end.verse; end = section.end.verse;
} else } else
@ -73,8 +71,8 @@ export class BibleService
} }
// get the verses requested. // get the verses requested.
let tvs = this.chapters[j].vss.length; const tvs = this.chapters[j].vss.length;
if (end == "*" || end > tvs) if (end == "*" || parseInt(end) > tvs)
{ {
end = tvs; end = tvs;
} }

View File

@ -0,0 +1,54 @@
import {ComponentFactory, Component, ComponentRef, Input, ViewContainerRef, ComponentResolver, ViewChild} from "@angular/core"
@Component({
selector: "dcl-wrapper",
template: `<div #target></div>`
})
export class DclWrapper
{
@ViewChild("target", { read: ViewContainerRef }) target;
@Input() type;
@Input() data;
cmpRef: ComponentRef<any>;
private isViewInitialized: boolean = false;
constructor(private resolver: ComponentResolver) { }
updateComponent()
{
if (!this.isViewInitialized)
{
return;
}
if (this.cmpRef)
{
this.cmpRef.destroy();
}
this.resolver.resolveComponent(this.type).then((factory: ComponentFactory<any>) =>
{
this.cmpRef = this.target.createComponent(factory);
//to access the created instance use
this.cmpRef.instance.item = this.data;
});
}
ngOnChanges()
{
this.updateComponent();
}
ngAfterViewInit()
{
this.isViewInitialized = true;
this.updateComponent();
}
ngOnDestroy()
{
if (this.cmpRef)
{
this.cmpRef.destroy();
}
}
}

View File

@ -0,0 +1,8 @@
<ion-card-title class="title" padding>{{item.ref}}</ion-card-title>
<ion-card-content>
<div *ngFor="let ch of item.cs">
<br>
<h2 *ngIf="item.cs.length > 1"><b>Chapter {{ch.ch}}</b></h2>
<span *ngFor="let vs of ch.vss"><b>{{vs.v}}.</b> <span *ngFor="let w of vs.w">{{w.t}}</span><br></span>
</div>
</ion-card-content>

View File

@ -0,0 +1,10 @@
import { Component } from "@angular/core";
@Component({
selector: "passage",
templateUrl: "build/components/passage/passage.html"
})
export class Passage {
private item: BiblePassageResult;
constructor() {
}
}

View File

@ -0,0 +1,4 @@
<ion-card-title class="title" padding>{{item.prefix}}{{item.sn}}</ion-card-title>
<ion-card-content>
<b>{{item.def.tr}} ({{item.def.sn}})</b> - {{item.def.p}} - {{item.def.lemma}} - <span [innerHTML]="item.def.de"></span><br />
</ion-card-content>

View File

@ -0,0 +1,13 @@
import { Component } from "@angular/core";
@Component({
selector: "strongs",
templateUrl: "build/components/strongs/strongs.html"
})
export class Strongs {
private item: StrongsResult;
constructor() {
}
}

View File

@ -8,14 +8,7 @@
</ion-header> </ion-header>
<ion-content padding class="search-card"> <ion-content padding class="search-card">
<ion-card *ngFor="let item of items" (swipe)="removeItem(item)"> <ion-card *ngFor="let item of items" (swipe)="removeItem(item)">
<ion-card-title class="title" padding>{{item.ref}}</ion-card-title> <dcl-wrapper [data]="item.data" [type]="item.type"></dcl-wrapper>
<ion-card-content>
<div *ngFor="let ch of item.cs">
<br>
<h2 *ngIf="item.cs.length > 1"><b>Chapter {{ch.ch}}</b></h2>
<span *ngFor="let vs of ch.vss"><b>{{vs.v}}.</b> <span *ngFor="let w of vs.w">{{w.t}}</span><br></span>
</div>
</ion-card-content>
<ion-item> <ion-item>
<button primary clear item-left (click)="removeItem(item)"> <button primary clear item-left (click)="removeItem(item)">
<ion-icon name="close-circle"></ion-icon> <ion-icon name="close-circle"></ion-icon>

View File

@ -1,35 +1,55 @@
/// <reference path="../../types.ts" /> /// <reference path="../../types.ts" />
import {Injectable} from '@angular/core'; import {Injectable, Type} from "@angular/core";
import {Reference} from '../../Reference'; import {Reference} from "../../Reference";
import {BibleService} from '../../bible-service'; import {BibleService} from "../../bible-service";
import {Component} from '@angular/core'; import {Component} from "@angular/core";
import { LoadingController } from 'ionic-angular'; import {LoadingController} from "ionic-angular";
import {Passage} from "../../components/passage/passage.ts";
import {DclWrapper} from "../../components/dcl-wrapper/dcl-wrapper.ts";
import {StrongsService} from "../../strongs-service";
import {Strongs} from "../../components/strongs/strongs";
import {ReversePipe} from "../../pipes/reverse-pipe.ts";
class Item
{
id: number;
data: any;
type: Type;
}
@Component({ @Component({
templateUrl: 'build/pages/search/search.html', templateUrl: "build/pages/search/search.html",
providers: [BibleService] providers: [BibleService, StrongsService],
directives: [DclWrapper],
pipes: [ReversePipe]
}) })
export class SearchPage { export class SearchPage
searchQuery: string = ''; {
items: BiblePassageResult[]; searchQuery: string = "";
items: any[];
last: number; last: number;
constructor(private bibleService: BibleService, public loadingCtrl: LoadingController) { constructor(private strongsService: StrongsService, private bibleService: BibleService, public loadingCtrl: LoadingController)
{
this.initializeItems(); this.initializeItems();
} }
initializeItems() { initializeItems()
{
this.items = []; this.items = [];
this.last = 0; this.last = 0;
} }
setQuery(searchbar) { setQuery(searchbar)
{
this.searchQuery = searchbar.target.value; this.searchQuery = searchbar.target.value;
} }
removeItem(item) { removeItem(item)
{
let idx = this.items.indexOf(item); let idx = this.items.indexOf(item);
this.items.splice(idx, 1); this.items.splice(idx, 1);
} }
getItems(searchbar) { getItems(searchbar)
{
try try
{ {
let loader = this.loadingCtrl.create({ let loader = this.loadingCtrl.create({
@ -40,56 +60,44 @@ export class SearchPage {
let qs = this.searchQuery.split(";"); let qs = this.searchQuery.split(";");
for (let x in qs) { for (let x in qs) {
if (qs.hasOwnProperty(x)) {
let q = qs[x].trim(); let q = qs[x].trim();
if (q != "") { if (q !== "") {
// its a search term. // its a search term.
if (q.search(/[0-9]/i) == -1) { if (q.search(/[0-9]/i) === -1) {
// get new results. // get new results.
//Words.FindReferences(q); //Words.FindReferences(q);
//$("#searchpanel").panel("open"); //$("#searchpanel").panel("open");
} else if (q.search(/(H|G)[0-9]/i) != -1) { } else if (q.search(/(H|G)[0-9]/i) !== -1) {
let original_q = q;
// its a strongs lookup // its a strongs lookup
let dict = q.substring(0, 1); let dict = q.substring(0, 1);
let store = true;
if (dict.search(/h/i) != -1) { if (dict.search(/h/i) !== -1) {
dict = "heb"; dict = "heb";
if (parseInt(q.substring(1)) > 8674) store = false;
} else { } else {
dict = "grk"; dict = "grk";
if (parseInt(q.substring(1)) > 5624) store = false;
} }
q = q.substring(1, q.length); q = q.substring(1, q.length);
let Ss = q.split(' '); let result = this.strongsService.getStrongs(parseInt(q), dict);
this.items.unshift({ id: this.last++, data: result, type: Strongs });
let results = [];
for (let s in Ss) {
//results.push(Strongs.GetStrongs(Ss[s], dict));
}
for (let result in results) {
//Strongs.DisplayStrongs(results[result]);
}
//if (store) CurrentReferences[original_q.toString().toLowerCase()] = true;
} else { } else {
// its a verse reference. // its a verse reference.
if (q.trim() != "") { if (q.trim() !== "") {
let myref = new Reference(q.trim()); let myref = new Reference(q.trim());
let r = this.bibleService.getPassage(myref.Section); let r = this.bibleService.getPassage(myref.Section);
r.ref = myref.toString(); r.ref = myref.toString();
r.id = this.last++; this.items.unshift({ id: this.last++, data: r, type: Passage });
this.items.push(r); }
//CurrentReferences[myref.toString().toLowerCase()] = true; }
}
} }
} }
loader.dismiss(); loader.dismiss();
}
}
//Settings.SaveResults(); //Settings.SaveResults();
} }
catch (err) { catch (err)
{
//Util.HandleError(err); //Util.HandleError(err);
} }
} }

View File

@ -0,0 +1,12 @@
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "reverse"
})
export class ReversePipe implements PipeTransform
{
transform(value: any[]) : any[]
{
return value.slice().reverse();
}
}

View File

@ -0,0 +1,125 @@
/// <reference path="../typings/browser/ambient/jquery/index.d.ts" />
/// <reference path="types.ts" />
import { Injectable } from "@angular/core";
import { Observable } from "rxjs/Observable";
import { Http, Response } from "@angular/http";
@Injectable()
export class StrongsService
{
result: StrongsResult;
count = 0;
constructor(private http: Http)
{
}
getStrongs(sn: number, dict: string): StrongsResult
{
try
{
const self = this;
this.result = {
prefix: "",
sn: -1,
strongs: [],
def: null,
rmac: [],
crossrefs: [],
rmaccode: ""
};
let url = dict + Math.ceil(sn / 100) + ".json";
if (dict === "grk")
{
self.result.prefix = "G";
if (sn > 5624) return this.result;
} else
{
self.result.prefix = "H";
if (sn > 8674) return this.result;
}
this.result.sn = sn;
$.ajax({
async: false,
type: "GET",
url: `data/strongs/${url}`,
dataType: "json",
success: function (d: StrongsDefinition[], t, x)
{
self.result.strongs = d;
},
error: function (request, status, error)
{
//Util.HandleError(error);
}
});
self.result.def = self.result.strongs.find(el => (el.i === this.result.prefix + this.result.sn));
self.result.strongs = [];
$.ajax({
async: false,
type: "GET",
url: `data/strongscr/cr${url}`,
dataType: "json",
success: function (d: StrongsCrossReference[], t, x)
{
self.result.crossrefs = d;
},
error: function (request, status, error)
{
//Util.HandleError(error);
}
});
if (dict === "grk")
{
url = `data/rmac/rs${Math.ceil(sn / 1000)}.json`;
let rmac_cross_references: RMACCrossReference[];
// rmac is a two get process.
$.ajax({
async: false,
type: "GET",
url: url,
dataType: "json",
success: function (d: RMACCrossReference[], t, x)
{
rmac_cross_references = d;
},
error: function (request, status, error)
{
//Util.HandleError(error);
}
});
// deal with RMAC
this.result.rmaccode = $.grep<RMACCrossReference>(rmac_cross_references, (el, i) => { if (el.i == sn + "") { return true; } else { return false; } })[0].r;
if (this.result.rmaccode != undefined)
{
url = `data/rmac/r-${this.result.rmaccode.substring(0, 1)}.json`;
$.ajax({
async: false,
type: "GET",
url: url,
dataType: "json",
success: function (d: RMACDefinition[], t, x)
{
self.result.rmac = d;
},
error: function (request, status, error)
{
//Util.HandleError(error);
}
});
}
}
return this.result;
} catch (err)
{
//Util.HandleError(err);
}
return null;
}
}

View File

@ -16,11 +16,38 @@ type BibleVerse = {
type BiblePassageResult = { type BiblePassageResult = {
cs: BiblePassage[], cs: BiblePassage[],
testament: string, testament: string,
ref: string, ref: string
id: number
} }
type StrongsDefinition = { n: number, i: string, tr: string, de: string, lemma: string, p: string }
type StrongsCrossReference =
{
id: string, // strongs id H1|G1
t: string, // strongs testament grk|heb
d: string, // strongs word/data Aaron {ah-ar-ohn'}
ss: [
{
w: string,
rs: [
{ r: string }
]
}
]
}
type RMACDefinition = { id: string, d: string[] }
type RMACCrossReference = { i: string, r: string }
type StrongsResult =
{
prefix: string,
sn: number,
strongs: StrongsDefinition[],
def: StrongsDefinition,
rmac: RMACDefinition[],
crossrefs: StrongsCrossReference[],
rmaccode: string,
};
type Section = { type Section = {
start: { start: {
book: number, book: number,