104 lines
3.4 KiB
TypeScript
Raw Normal View History

2016-09-12 13:12:25 -04:00
/// <reference path="../../types.ts" />
2016-09-12 18:13:56 -04:00
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;
}
2016-09-12 13:12:25 -04:00
@Component({
2016-09-12 18:13:56 -04:00
templateUrl: "build/pages/search/search.html",
providers: [BibleService, StrongsService],
directives: [DclWrapper],
pipes: [ReversePipe]
})
2016-09-12 18:13:56 -04:00
export class SearchPage
{
searchQuery: string = "";
items: any[];
2016-09-12 13:12:25 -04:00
last: number;
2016-09-12 18:13:56 -04:00
constructor(private strongsService: StrongsService, private bibleService: BibleService, public loadingCtrl: LoadingController)
{
this.initializeItems();
}
2016-09-12 18:13:56 -04:00
initializeItems()
{
this.items = [];
2016-09-12 13:12:25 -04:00
this.last = 0;
}
2016-09-12 18:13:56 -04:00
setQuery(searchbar)
{
2016-09-12 13:12:25 -04:00
this.searchQuery = searchbar.target.value;
}
2016-09-12 18:13:56 -04:00
removeItem(item)
{
2016-09-12 13:12:25 -04:00
let idx = this.items.indexOf(item);
this.items.splice(idx, 1);
}
2016-09-12 18:13:56 -04:00
getItems(searchbar)
{
2016-09-12 13:12:25 -04:00
try
{
2016-09-12 18:13:56 -04:00
let loader = this.loadingCtrl.create({
content: "Retrieving passage...",
dismissOnPageChange: true
});
loader.present();
2016-09-12 18:13:56 -04:00
let qs = this.searchQuery.split(";");
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();
}
2016-09-12 18:13:56 -04:00
catch (err)
{
//Util.HandleError(err);
}
}
}