105 lines
3.5 KiB
TypeScript
Raw Normal View History

2016-09-12 13:12:25 -04:00
/// <reference path="../../types.ts" />
import {Type, Component} from "@angular/core";
import {Reference} from "../../Reference";
2016-09-12 18:13:56 -04:00
import {BibleService} from "../../bible-service";
import {LoadingController} from "ionic-angular";
import {StrongsService} from "../../strongs-service";
import {Strongs} from "../../components/strongs/strongs";
import {Passage} from "../../components/passage/passage.ts";
import {ComponentLoader} from "../../components/component-loader/component-loader.ts";
2016-09-12 18:13:56 -04:00
class Item {
2016-09-12 18:13:56 -04:00
id: number;
data: any;
type: Type<any>;
dict: string;
2016-09-12 18:13:56 -04:00
}
2016-09-12 13:12:25 -04:00
@Component({
templateUrl: "search.html",
providers: [BibleService, StrongsService],
})
export class SearchPage {
searchQuery: string = "";
items: any[];
last: number;
constructor(private strongsService: StrongsService, private bibleService: BibleService, public loadingCtrl: LoadingController) {
this.initializeItems();
}
initializeItems() {
this.items = [];
this.last = 0;
}
setQuery(searchbar) {
this.searchQuery = searchbar.target.value;
}
getQuery(searchbar) {
this.getItems(this.searchQuery);
}
removeItem(item) {
2016-09-12 13:12:25 -04:00
let idx = this.items.indexOf(item);
this.items.splice(idx, 1);
}
isPassage(t: Type<any>) {
return t == Passage;
}
isStrongs(t: Type<any>) {
return t == Strongs;
}
getItems(search) {
try {
2016-09-12 18:13:56 -04:00
let loader = this.loadingCtrl.create({
content: "Retrieving passage...",
dismissOnPageChange: true
});
loader.present();
let qs = search.split(";");
2016-09-12 18:13:56 -04:00
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, dict: r.testament == 'new' ? "G":"H" });
2016-09-12 18:13:56 -04:00
}
}
}
}
}
loader.dismiss();
//Settings.SaveResults();
}
catch (err) {
//Util.HandleError(err);
}
}
}