/// import {Type, Component} from "@angular/core"; import {Reference} from "../../Reference"; import {BibleService} from "../../bible-service"; import {LoadingController, ModalController } from "ionic-angular"; import {StrongsService} from "../../strongs-service"; import {Strongs} from "../../components/strongs/strongs"; import {Passage} from "../../components/passage/passage.ts"; import {StrongsModal} from "../../components/strongs-modal/strongs-modal.ts"; import {Storage} from '@ionic/storage'; class Item { id: number; data: any; type: Type; dict: string; } @Component({ templateUrl: "search.html", providers: [BibleService, StrongsService], }) export class SearchPage { searchQuery: string = ""; items: CardItem[]; last: number; user: User = { strongs_modal: true }; constructor( private strongsService: StrongsService , private bibleService: BibleService , public loadingCtrl: LoadingController , public modalCtrl: ModalController , public local: Storage) { this.initializeItems(); // 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); }); } initializeItems() { this.items = []; this.last = 0; } presentStrongsModal(strongs: StrongsResult) { let modal = this.modalCtrl.create(StrongsModal, { strongsid: strongs }); modal.present(); } 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); if (this.user.strongs_modal) this.presentStrongsModal(result); else this.items.unshift({ id: this.last++, data: result, type: Strongs, dict: "na" }); } 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); } } }