mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-26 08:49:49 -04:00
FEATURE/PERF: move more things into promises, so the menu closes immediately.
* only load strongs into modals if you're clicking on a link * change size of strongs cross refs dynamically
This commit is contained in:
parent
e4044838c5
commit
7aa83dbd20
@ -40,7 +40,7 @@ export class Passage implements OnInit
|
|||||||
|
|
||||||
openStrongs(strongs: string)
|
openStrongs(strongs: string)
|
||||||
{
|
{
|
||||||
this.onItemClicked.emit({ card: this.cardItem, qry: this.cardItem.dict + strongs });
|
this.onItemClicked.emit({ card: this.cardItem, qry: this.cardItem.dict + strongs, from_search_bar: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
openMenu(strongs: string)
|
openMenu(strongs: string)
|
||||||
|
@ -5,7 +5,8 @@ import { StrongsResult, StrongsService } from '../../services/strongs-service';
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "strongs-modal",
|
selector: "strongs-modal",
|
||||||
templateUrl: "strongs-modal.html"
|
templateUrl: "strongs-modal.html",
|
||||||
|
providers: [StrongsService]
|
||||||
})
|
})
|
||||||
export class StrongsModal implements OnInit
|
export class StrongsModal implements OnInit
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { EventEmitter, Component, Input, Output, OnInit } from "@angular/core";
|
import { HostListener, EventEmitter, Component, Input, Output, OnInit, AfterViewChecked } from "@angular/core";
|
||||||
import { Reference } from '../../libs/Reference';
|
import { Reference } from '../../libs/Reference';
|
||||||
import { OpenData, CardItem } from "../../pages/search/search";
|
import { OpenData, CardItem } from "../../pages/search/search";
|
||||||
import { StrongsResult, StrongsService } from '../../services/strongs-service';
|
import { StrongsResult, StrongsService } from '../../services/strongs-service';
|
||||||
@ -8,7 +8,7 @@ import { StrongsResult, StrongsService } from '../../services/strongs-service';
|
|||||||
templateUrl: "strongs.html",
|
templateUrl: "strongs.html",
|
||||||
providers: [StrongsService]
|
providers: [StrongsService]
|
||||||
})
|
})
|
||||||
export class Strongs implements OnInit
|
export class Strongs implements AfterViewChecked, OnInit
|
||||||
{
|
{
|
||||||
@Output()
|
@Output()
|
||||||
onClose = new EventEmitter<CardItem>();
|
onClose = new EventEmitter<CardItem>();
|
||||||
@ -25,12 +25,30 @@ export class Strongs implements OnInit
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HostListener('window:resize', ['$event'])
|
||||||
|
onResize(evt)
|
||||||
|
{
|
||||||
|
$("strongs ion-scroll").each((i, el) =>
|
||||||
|
{
|
||||||
|
let len = $(el).find(".scroll-content .scroll-zoom-wrapper dl span").length;
|
||||||
|
len += $(el).find(".scroll-content .scroll-zoom-wrapper dl dd").length;
|
||||||
|
|
||||||
|
if (len < 20)
|
||||||
|
$(el).css("height", Math.ceil(len / 3) * 30 + 30);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngAfterViewChecked(): void
|
||||||
|
{
|
||||||
|
this.onResize(null);
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void
|
ngOnInit(): void
|
||||||
{
|
{
|
||||||
this.strongsService.getResultAsPromise(parseInt(this.cardItem.qry), this.cardItem.dict)
|
this.strongsService.getResultAsPromise(parseInt(this.cardItem.qry), this.cardItem.dict)
|
||||||
.then(data =>
|
.then(data =>
|
||||||
this.data = data
|
this.data = data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
close()
|
close()
|
||||||
@ -40,7 +58,7 @@ export class Strongs implements OnInit
|
|||||||
|
|
||||||
openItem(p: string)
|
openItem(p: string)
|
||||||
{
|
{
|
||||||
this.onItemClicked.emit({ card: this.cardItem, qry: p });
|
this.onItemClicked.emit({ card: this.cardItem, qry: p, from_search_bar: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
makePassage(p: string)
|
makePassage(p: string)
|
||||||
@ -51,6 +69,6 @@ export class Strongs implements OnInit
|
|||||||
openPassage(p: string)
|
openPassage(p: string)
|
||||||
{
|
{
|
||||||
let ref = this.makePassage(p);
|
let ref = this.makePassage(p);
|
||||||
this.onItemClicked.emit({ card: this.cardItem, qry: ref });
|
this.onItemClicked.emit({ card: this.cardItem, qry: ref, from_search_bar: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -103,6 +103,6 @@ export class Words implements AfterViewChecked, OnInit
|
|||||||
openPassage(p: string)
|
openPassage(p: string)
|
||||||
{
|
{
|
||||||
let ref = this.makePassage(p);
|
let ref = this.makePassage(p);
|
||||||
this.onItemClicked.emit({ card: this.cardItem, qry: ref });
|
this.onItemClicked.emit({ card: this.cardItem, qry: ref, from_search_bar: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -42,77 +42,23 @@ export class SearchPage implements OnInit
|
|||||||
if (profile !== null)
|
if (profile !== null)
|
||||||
t = JSON.parse(profile);
|
t = JSON.parse(profile);
|
||||||
|
|
||||||
this.userProfile.update(t, this.local);
|
this.loader = this.loadingCtrl.create({ content: 'Loading Page...' });
|
||||||
|
this.loader.present().then(
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
this.userProfile.update(t, this.local);
|
||||||
|
|
||||||
this.initializeItems(this.userProfile);
|
this.initializeItems(this.userProfile);
|
||||||
|
|
||||||
|
this.loader.dismiss();
|
||||||
|
});
|
||||||
}).catch(error =>
|
}).catch(error =>
|
||||||
{
|
{
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
actionsMenu()
|
|
||||||
{
|
|
||||||
this.menu.open('actions');
|
|
||||||
}
|
|
||||||
|
|
||||||
addPage()
|
|
||||||
{
|
|
||||||
let alert = this.alertCtrl.create({
|
|
||||||
title: 'Save Search as Page',
|
|
||||||
inputs: [
|
|
||||||
{
|
|
||||||
name: 'title',
|
|
||||||
placeholder: 'Page Title'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
buttons: [
|
|
||||||
{
|
|
||||||
text: 'Cancel',
|
|
||||||
role: 'cancel',
|
|
||||||
handler: data =>
|
|
||||||
{
|
|
||||||
console.log('Cancel clicked');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: 'Save',
|
|
||||||
handler: data =>
|
|
||||||
{
|
|
||||||
let p = { queries: this.userProfile.user.items.slice(), title: data.title };
|
|
||||||
this.userProfile.user.saved_pages.push(p);
|
|
||||||
this.userProfile.save(this.local);
|
|
||||||
this.pagesService.addPage(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
alert.present();
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePage()
|
|
||||||
{
|
|
||||||
let page = this.userProfile.user.saved_pages.find(
|
|
||||||
i =>
|
|
||||||
i.title == this.params.data.title
|
|
||||||
);
|
|
||||||
page.queries = this.userProfile.user.items.slice();
|
|
||||||
this.userProfile.save(this.local);
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeItems(u: UserProfile)
|
initializeItems(u: UserProfile)
|
||||||
{
|
{
|
||||||
this.userProfile = u;
|
|
||||||
|
|
||||||
// initialize the pages.
|
|
||||||
this.pagesService.initializePages(u.user.saved_pages);
|
|
||||||
if (this.params.data.queries !== undefined)
|
|
||||||
this.userProfile.user.items = this.params.data.queries.slice();
|
|
||||||
if (this.params.data.title === undefined)
|
|
||||||
this.title = "Search";
|
|
||||||
else
|
|
||||||
this.title = this.params.data.title;
|
|
||||||
|
|
||||||
// migrate old way of storing card items to the new.
|
// migrate old way of storing card items to the new.
|
||||||
let has_migrated = false;
|
let has_migrated = false;
|
||||||
for (let i in u.user.items)
|
for (let i in u.user.items)
|
||||||
@ -153,9 +99,65 @@ export class SearchPage implements OnInit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// initialize the pages.
|
||||||
|
this.pagesService.initializePages(u.user.saved_pages);
|
||||||
|
if (this.params.data.queries !== undefined)
|
||||||
|
this.userProfile.user.items = this.params.data.queries.slice();
|
||||||
|
if (this.params.data.title === undefined)
|
||||||
|
this.title = "Search";
|
||||||
|
else
|
||||||
|
this.title = this.params.data.title;
|
||||||
|
|
||||||
if (has_migrated)
|
if (has_migrated)
|
||||||
this.userProfile.save(this.local);
|
this.userProfile.save(this.local);
|
||||||
|
}
|
||||||
|
|
||||||
|
actionsMenu()
|
||||||
|
{
|
||||||
|
this.menu.open('actions');
|
||||||
|
}
|
||||||
|
|
||||||
|
addPage()
|
||||||
|
{
|
||||||
|
let alert = this.alertCtrl.create({
|
||||||
|
title: 'Save Search as Page',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'title',
|
||||||
|
placeholder: 'Page Title'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
text: 'Cancel',
|
||||||
|
role: 'cancel',
|
||||||
|
handler: data =>
|
||||||
|
{
|
||||||
|
console.log('Cancel clicked');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Save',
|
||||||
|
handler: data =>
|
||||||
|
{
|
||||||
|
let p = { queries: this.userProfile.user.items.slice(), title: data.title };
|
||||||
|
this.userProfile.user.saved_pages.push(p);
|
||||||
|
this.userProfile.save(this.local);
|
||||||
|
this.pagesService.addPage(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
alert.present();
|
||||||
|
}
|
||||||
|
updatePage()
|
||||||
|
{
|
||||||
|
let page = this.userProfile.user.saved_pages.find(
|
||||||
|
i =>
|
||||||
|
i.title == this.params.data.title
|
||||||
|
);
|
||||||
|
page.queries = this.userProfile.user.items.slice();
|
||||||
|
this.userProfile.save(this.local);
|
||||||
}
|
}
|
||||||
|
|
||||||
setQuery(searchbar)
|
setQuery(searchbar)
|
||||||
@ -164,16 +166,7 @@ export class SearchPage implements OnInit
|
|||||||
}
|
}
|
||||||
getQuery(searchbar)
|
getQuery(searchbar)
|
||||||
{
|
{
|
||||||
this.getItems(this.searchQuery);
|
this.getItems(this.searchQuery, true);
|
||||||
}
|
|
||||||
|
|
||||||
removeItem(item)
|
|
||||||
{
|
|
||||||
let idx = this.userProfile.user.items.indexOf(item);
|
|
||||||
this.userProfile.user.items.splice(idx, 1);
|
|
||||||
|
|
||||||
// save the users settings.
|
|
||||||
this.userProfile.save(this.local);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isError(t: string)
|
isError(t: string)
|
||||||
@ -193,6 +186,14 @@ export class SearchPage implements OnInit
|
|||||||
return t === 'Words';
|
return t === 'Words';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeItem(item)
|
||||||
|
{
|
||||||
|
let idx = this.userProfile.user.items.indexOf(item);
|
||||||
|
this.userProfile.user.items.splice(idx, 1);
|
||||||
|
|
||||||
|
// save the users settings.
|
||||||
|
this.userProfile.save(this.local);
|
||||||
|
}
|
||||||
addItemToList(item: CardItem)
|
addItemToList(item: CardItem)
|
||||||
{
|
{
|
||||||
if (this.userProfile.user.append_to_bottom)
|
if (this.userProfile.user.append_to_bottom)
|
||||||
@ -217,83 +218,97 @@ export class SearchPage implements OnInit
|
|||||||
}
|
}
|
||||||
this.last = null;
|
this.last = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getItemsNextToCard(data: OpenData)
|
getItemsNextToCard(data: OpenData)
|
||||||
{
|
{
|
||||||
this.last = data.card;
|
this.last = data.card;
|
||||||
this.getItems(data.qry);
|
this.getItems(data.qry, data.from_search_bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
getItems(search)
|
getItemsList(search: string): Promise<CardItem[]>
|
||||||
{
|
{
|
||||||
this.loader = this.loadingCtrl.create({ content: 'Looking up query...' });
|
return new Promise((resolve, reject) =>
|
||||||
this.loader.present().then(
|
{
|
||||||
() =>
|
let list: CardItem[] = [];
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
let qs = search.split(';');
|
||||||
|
for (let x in qs)
|
||||||
{
|
{
|
||||||
let qs = search.split(';');
|
if (qs.hasOwnProperty(x))
|
||||||
for (let x in qs)
|
|
||||||
{
|
{
|
||||||
if (qs.hasOwnProperty(x))
|
let q = qs[x].trim();
|
||||||
|
if (q !== '')
|
||||||
{
|
{
|
||||||
let q = qs[x].trim();
|
// its a search term.
|
||||||
if (q !== '')
|
if (q.search(/[0-9]/i) === -1)
|
||||||
|
list.push({ qry: q, dict: 'na', type: 'Words' });
|
||||||
|
else if (q.search(/(H|G)[0-9]/i) !== -1)
|
||||||
{
|
{
|
||||||
// its a search term.
|
// its a strongs lookup
|
||||||
if (q.search(/[0-9]/i) === -1)
|
let dict = q.substring(0, 1);
|
||||||
this.addItemToList({ qry: q, dict: 'na', type: 'Words' });
|
|
||||||
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)
|
if (dict.search(/h/i) !== -1)
|
||||||
dict = 'heb';
|
dict = 'heb';
|
||||||
else
|
|
||||||
dict = 'grk';
|
|
||||||
|
|
||||||
q = q.substring(1, q.length);
|
|
||||||
if (this.userProfile.user.strongs_modal)
|
|
||||||
{
|
|
||||||
let modal = this.modalCtrl.create(StrongsModal, { sn: parseInt(q), dict: dict, onItemClicked: this });
|
|
||||||
modal.present();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this.addItemToList({ qry: q, dict: dict, type: 'Strongs' });
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
dict = 'grk';
|
||||||
|
|
||||||
|
q = q.substring(1, q.length);
|
||||||
|
list.push({ qry: q, dict: dict, type: 'Strongs' });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// its a verse reference.
|
||||||
|
if (q.trim() !== '')
|
||||||
{
|
{
|
||||||
// its a verse reference.
|
let myref = new Reference(q.trim());
|
||||||
if (q.trim() !== '')
|
list.push({ qry: myref.toString(), dict: myref.Section.start.book > 39 ? 'G' : 'H', type: 'Passage' });
|
||||||
{
|
|
||||||
let myref = new Reference(q.trim());
|
|
||||||
this.addItemToList({ qry: myref.toString(), dict: myref.Section.start.book > 39 ? 'G' : 'H', type: 'Passage' });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.userProfile.user.clear_search_after_query)
|
}
|
||||||
$('.searchbar-input').val('');
|
if (this.userProfile.user.clear_search_after_query)
|
||||||
|
$('.searchbar-input').val('');
|
||||||
|
|
||||||
this.userProfile.save(this.local);
|
this.userProfile.save(this.local);
|
||||||
}
|
}
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
this.addItemToList({ qry: error, type: 'Error', dict: 'na' });
|
list.push({ qry: error, type: 'Error', dict: 'na' });
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
|
resolve(list);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getItems(search: string, from_search_bar: boolean)
|
||||||
|
{
|
||||||
|
this.getItemsList(search).then(lst =>
|
||||||
|
{
|
||||||
|
this.loader = this.loadingCtrl.create({ content: 'Looking up Query...' });
|
||||||
|
this.loader.present().then(
|
||||||
|
() =>
|
||||||
{
|
{
|
||||||
|
for (let item of lst)
|
||||||
|
{
|
||||||
|
if (item.type == "Strongs" && this.userProfile.user.strongs_modal && !from_search_bar)
|
||||||
|
{
|
||||||
|
let modal = this.modalCtrl.create(StrongsModal, { sn: parseInt(item.qry), dict: item.dict, onItemClicked: this });
|
||||||
|
modal.present();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.addItemToList(item);
|
||||||
|
}
|
||||||
this.loader.dismiss();
|
this.loader.dismiss();
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type OpenData = { card: CardItem, qry: string }
|
export type OpenData = { card: CardItem, qry: string, from_search_bar: boolean }
|
||||||
|
|
||||||
export type CardItem = { qry: string, type: string, dict: string }
|
export type CardItem = { qry: string, type: string, dict: string }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user