/// import {Type, Component} from "@angular/core"; import {Reference} from "../../Reference"; 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"; class Item { id: number; data: any; type: Type; dict: string; } @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) { let idx = this.items.indexOf(item); this.items.splice(idx, 1); } isPassage(t: Type) { return t == Passage; } isStrongs(t: Type) { return t == Strongs; } getItems(search) { try { let loader = this.loadingCtrl.create({ content: "Retrieving passage...", dismissOnPageChange: true }); loader.present(); let qs = search.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, dict: r.testament == 'new' ? "G":"H" }); } } } } } loader.dismiss(); //Settings.SaveResults(); } catch (err) { //Util.HandleError(err); } } }