2016-09-12 13:12:25 -04:00
|
|
|
/// <reference path="../../types.ts" />
|
|
|
|
import {Injectable} from '@angular/core';
|
2016-05-18 17:15:23 -04:00
|
|
|
import {Reference} from '../../Reference';
|
2016-09-12 13:12:25 -04:00
|
|
|
import {BibleService} from '../../bible-service';
|
|
|
|
import {Component} from '@angular/core';
|
|
|
|
import { LoadingController } from 'ionic-angular';
|
|
|
|
|
|
|
|
@Component({
|
2016-05-18 17:15:23 -04:00
|
|
|
templateUrl: 'build/pages/search/search.html',
|
|
|
|
providers: [BibleService]
|
|
|
|
})
|
|
|
|
export class SearchPage {
|
|
|
|
searchQuery: string = '';
|
|
|
|
items: BiblePassageResult[];
|
2016-09-12 13:12:25 -04:00
|
|
|
last: number;
|
2016-05-18 17:15:23 -04:00
|
|
|
|
2016-09-12 13:12:25 -04:00
|
|
|
constructor(private bibleService: BibleService, public loadingCtrl: LoadingController) {
|
2016-05-18 17:15:23 -04:00
|
|
|
this.initializeItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
initializeItems() {
|
|
|
|
this.items = [];
|
2016-09-12 13:12:25 -04:00
|
|
|
this.last = 0;
|
2016-05-18 17:15:23 -04:00
|
|
|
}
|
|
|
|
setQuery(searchbar) {
|
2016-09-12 13:12:25 -04:00
|
|
|
this.searchQuery = searchbar.target.value;
|
|
|
|
}
|
|
|
|
removeItem(item) {
|
|
|
|
let idx = this.items.indexOf(item);
|
|
|
|
this.items.splice(idx, 1);
|
2016-05-18 17:15:23 -04:00
|
|
|
}
|
|
|
|
getItems(searchbar) {
|
2016-09-12 13:12:25 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
let loader = this.loadingCtrl.create({
|
|
|
|
content: "Retrieving passage...",
|
|
|
|
dismissOnPageChange: true
|
|
|
|
});
|
|
|
|
loader.present();
|
|
|
|
|
2016-05-18 17:15:23 -04:00
|
|
|
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();
|
2016-09-12 13:12:25 -04:00
|
|
|
r.id = this.last++;
|
|
|
|
this.items.push(r);
|
2016-05-18 17:15:23 -04:00
|
|
|
//CurrentReferences[myref.toString().toLowerCase()] = true;
|
|
|
|
}
|
|
|
|
}
|
2016-09-12 13:12:25 -04:00
|
|
|
loader.dismiss();
|
2016-05-18 17:15:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Settings.SaveResults();
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//Util.HandleError(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|