2016-09-12 13:12:25 -04:00
|
|
|
/// <reference path="../../types.ts" />
|
2016-12-01 10:39:04 -05:00
|
|
|
import {Type, Component} from "@angular/core";
|
|
|
|
import {Reference} from "../../Reference";
|
2016-09-12 18:13:56 -04:00
|
|
|
import {BibleService} from "../../bible-service";
|
2016-12-01 13:40:04 -05:00
|
|
|
import {LoadingController, ModalController } from "ionic-angular";
|
2016-09-12 18:13:56 -04:00
|
|
|
import {StrongsService} from "../../strongs-service";
|
|
|
|
import {Strongs} from "../../components/strongs/strongs";
|
2016-12-01 10:39:04 -05:00
|
|
|
import {Passage} from "../../components/passage/passage.ts";
|
2016-12-01 13:40:04 -05:00
|
|
|
import {StrongsModal} from "../../components/strongs-modal/strongs-modal.ts";
|
2016-12-01 15:21:07 -05:00
|
|
|
import {Storage} from '@ionic/storage';
|
2016-09-12 18:13:56 -04:00
|
|
|
|
2016-12-01 10:39:04 -05:00
|
|
|
class Item {
|
2016-09-12 18:13:56 -04:00
|
|
|
id: number;
|
|
|
|
data: any;
|
2016-12-01 10:39:04 -05:00
|
|
|
type: Type<any>;
|
|
|
|
dict: string;
|
2016-09-12 18:13:56 -04:00
|
|
|
}
|
2016-09-12 13:12:25 -04:00
|
|
|
|
2016-12-01 10:39:04 -05:00
|
|
|
@Component({
|
|
|
|
templateUrl: "search.html",
|
|
|
|
providers: [BibleService, StrongsService],
|
|
|
|
})
|
|
|
|
export class SearchPage {
|
|
|
|
searchQuery: string = "";
|
2016-12-01 15:21:07 -05:00
|
|
|
items: CardItem[];
|
2016-12-01 10:39:04 -05:00
|
|
|
last: number;
|
2016-12-01 15:21:07 -05:00
|
|
|
user: User = { strongs_modal: true };
|
2016-12-01 10:39:04 -05:00
|
|
|
|
2016-12-01 13:40:04 -05:00
|
|
|
constructor(
|
2016-12-01 15:21:07 -05:00
|
|
|
private strongsService: StrongsService
|
2016-12-01 13:40:04 -05:00
|
|
|
, private bibleService: BibleService
|
|
|
|
, public loadingCtrl: LoadingController
|
2016-12-01 15:21:07 -05:00
|
|
|
, public modalCtrl: ModalController
|
|
|
|
, public local: Storage) {
|
2016-12-01 10:39:04 -05:00
|
|
|
this.initializeItems();
|
2016-12-01 15:21:07 -05:00
|
|
|
// Check if there is a profile saved in local storage
|
|
|
|
this.local.get('profile').then(profile => {
|
|
|
|
if (profile === null) {
|
|
|
|
this.local.set('profile', JSON.stringify(this.user));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.user = JSON.parse(profile);
|
|
|
|
}).catch(error => {
|
|
|
|
console.log(error);
|
|
|
|
});
|
2016-12-01 10:39:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
initializeItems() {
|
|
|
|
this.items = [];
|
|
|
|
this.last = 0;
|
|
|
|
}
|
2016-12-01 13:40:04 -05:00
|
|
|
|
|
|
|
presentStrongsModal(strongs: StrongsResult) {
|
2016-12-01 15:21:07 -05:00
|
|
|
let modal = this.modalCtrl.create(StrongsModal, { strongsid: strongs });
|
2016-12-01 13:40:04 -05:00
|
|
|
modal.present();
|
|
|
|
}
|
|
|
|
|
2016-12-01 10:39:04 -05:00
|
|
|
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);
|
2016-12-01 10:39:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2016-12-01 10:39:04 -05:00
|
|
|
|
|
|
|
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);
|
2016-12-01 15:21:07 -05:00
|
|
|
if (this.user.strongs_modal)
|
|
|
|
this.presentStrongsModal(result);
|
|
|
|
else
|
|
|
|
this.items.unshift({ id: this.last++, data: result, type: Strongs, dict: "na" });
|
2016-09-12 18:13:56 -04:00
|
|
|
} 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-12-01 15:21:07 -05:00
|
|
|
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();
|
|
|
|
|
2016-12-01 10:39:04 -05:00
|
|
|
//Settings.SaveResults();
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//Util.HandleError(err);
|
|
|
|
}
|
|
|
|
}
|
2016-05-18 17:15:23 -04:00
|
|
|
}
|