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

View File

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

View File

@ -1,8 +1,8 @@
/// <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';
import { Injectable } from "@angular/core";
import { Observable } from "rxjs/Observable";
import { Http, Response } from "@angular/http";
@Injectable()
export class BibleService
@ -24,14 +24,12 @@ export class BibleService
this.result = {
cs: [],
testament: "",
ref: "",
id: 0
ref: ""
};
this.count = Number(section.end.chapter) - Number(section.start.chapter) + 1;
for (let i = Number(section.start.chapter); i <= Number(section.end.chapter); i++)
{
let url = "data/bibles/kjv_strongs/" + section.start.book + "-" + i + ".json";
for (let i = Number(section.start.chapter); i <= Number(section.end.chapter); i++) {
const url = "data/bibles/kjv_strongs/" + section.start.book + "-" + i + ".json";
jQuery.ajax({
async: false,
type: "GET",
@ -50,21 +48,21 @@ export class BibleService
for (let j = 0; j < this.chapters.length; j++)
{
let vss: BibleVerse[] = [];
let start;
const vss: BibleVerse[] = [];
let start: number;
let end;
// figure out the start verse.
if (j == 0)
if (j === 0)
{
start = section.start.verse;
start = parseInt(section.start.verse);
} else
{
start = 1;
}
// figure out the end verse
if ((j + 1) == this.chapters.length)
if ((j + 1) === this.chapters.length)
{
end = section.end.verse;
} else
@ -73,8 +71,8 @@ export class BibleService
}
// get the verses requested.
let tvs = this.chapters[j].vss.length;
if (end == "*" || end > tvs)
const tvs = this.chapters[j].vss.length;
if (end == "*" || parseInt(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-content padding class="search-card">
<ion-card *ngFor="let item of items" (swipe)="removeItem(item)">
<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>
<dcl-wrapper [data]="item.data" [type]="item.type"></dcl-wrapper>
<ion-item>
<button primary clear item-left (click)="removeItem(item)">
<ion-icon name="close-circle"></ion-icon>

View File

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