diff --git a/.hgignore b/.hgignore index 28ac244d..9741c469 100644 --- a/.hgignore +++ b/.hgignore @@ -26,6 +26,7 @@ DynamicBibleIonic/nbproject DynamicBibleIonic/obj DynamicBibleIonic/bin DynamicBibleIonic/.vscode +DynamicBibleIonic/www/assets/ DynamicBibleUtility/.vs DynamicBibleIonic/platforms/android/release-signing.properties DynamicBibleIonic/platforms/android/build diff --git a/DynamicBibleIonic/src/app/app.component.ts b/DynamicBibleIonic/src/app/app.component.ts index 10d49ddc..4c62ec1c 100644 --- a/DynamicBibleIonic/src/app/app.component.ts +++ b/DynamicBibleIonic/src/app/app.component.ts @@ -42,18 +42,18 @@ export class MyApp { // close the menu when clicking a link from the menu this.menu.close('pages'); - - // because the actions menu is on a Page component, and you swap the SearchPage out, - // the menu get registered multiple times. to avoid some pages not opening the menu because - // multiple menus with the same id exist and the first one in the list is returned (which happens - // be disabled when another of the same id is added) it won't show. because not enabled. - // --- - // unregistering the actions menu whenever a new page is opened fixes the problem, because the menu - // will get reregistered when SearchPage loads. Also, if you go to a non SearchPage, the actions - // menu won't be there, but the unregister function doesn't fail if a non existent id is given, + + // because the actions menu is on a Page component, and you swap the SearchPage out, + // the menu get registered multiple times. to avoid some pages not opening the menu because + // multiple menus with the same id exist and the first one in the list is returned (which happens + // be disabled when another of the same id is added) it won't show. because not enabled. + // --- + // unregistering the actions menu whenever a new page is opened fixes the problem, because the menu + // will get reregistered when SearchPage loads. Also, if you go to a non SearchPage, the actions + // menu won't be there, but the unregister function doesn't fail if a non existent id is given, // so thats ok. this.menu._unregister(this.menu.get('actions')); - + // navigate to the new page if it is not the current page this.nav.setRoot(page.component, page.params); } diff --git a/DynamicBibleIonic/src/app/app.module.ts b/DynamicBibleIonic/src/app/app.module.ts index 565f4292..91fa6193 100644 --- a/DynamicBibleIonic/src/app/app.module.ts +++ b/DynamicBibleIonic/src/app/app.module.ts @@ -1,3 +1,4 @@ +import { ProfileService } from './../services/profile-service'; import { NgModule, ErrorHandler } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpModule } from '@angular/http'; @@ -24,6 +25,8 @@ import { ErrorMessage } from '../components/error-message/error-message'; import { VersePickerModal } from '../components/verse-picker/verse-picker'; import {AngularFireModule } from 'angularfire2'; +import { AngularFireAuthModule } from 'angularfire2/auth'; +import { AngularFireDatabaseModule } from 'angularfire2/database'; export const firebaseConfig = { apiKey: 'AIzaSyA3UV4s56CV2EumgvZmyJBTyU-vhv0xhc8', @@ -55,7 +58,9 @@ export const firebaseConfig = { IonicStorageModule.forRoot(), BrowserModule, HttpModule, - AngularFireModule.initializeApp(firebaseConfig) + AngularFireModule.initializeApp(firebaseConfig), + AngularFireAuthModule, + AngularFireDatabaseModule, ], bootstrap: [IonicApp], entryComponents: [ @@ -71,6 +76,6 @@ export const firebaseConfig = { Error, ErrorMessage ], - providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }, StatusBar, SplashScreen] + providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }, StatusBar, SplashScreen, ProfileService] }) export class AppModule { } diff --git a/DynamicBibleIonic/src/libs/UserProfile.ts b/DynamicBibleIonic/src/libs/UserProfile.ts deleted file mode 100644 index 68ce32a2..00000000 --- a/DynamicBibleIonic/src/libs/UserProfile.ts +++ /dev/null @@ -1,93 +0,0 @@ -/// -import { Storage } from '@ionic/storage'; -import { CardItem } from '../pages/search/search'; - -export class UserProfile -{ - user: User; - - constructor(u: User) - { - this.user = u; - } - - public textSizeChanged() - { - $('html').css('font-size', this.user.font_size + 'px'); - } - - public update(t: UserProfile, local: Storage) - { - let updated = false; - let k; - const user = this.user; - for (k in user) - { - if (user.hasOwnProperty(k)) - { - if (t[k] === undefined) - { - t[k] = user[k]; - updated = true; - } - } - } - - for (k in user) - if (user.hasOwnProperty(k)) - user[k] = t[k]; - - if (updated) - this.save(local); - - this.textSizeChanged(); - } - - save(local: Storage) - { - local.set('profile', JSON.stringify(this.user)); - } - - reset(local: Storage) - { - this.user.strongs_modal = true; - this.user.clear_search_after_query = false; - this.user.items = []; - this.user.append_to_bottom = false; - this.user.insert_next_to_item = false; - this.user.font_size = 10; - this.user.saved_pages = []; - this.user.verses_on_new_line = true; - this.save(local); - } - - public static createDefaultUser(): User - { - return { - strongs_modal: true, - clear_search_after_query: false, - items: [], - append_to_bottom: false, - insert_next_to_item: false, - font_size: 10, - saved_pages: [], - verses_on_new_line: true - }; - } -} - -export type User = { - strongs_modal: boolean, - clear_search_after_query: boolean, - items: CardItem[], - append_to_bottom: boolean, - insert_next_to_item: boolean, - font_size: number, - saved_pages: SavedPage[], - verses_on_new_line: boolean, -} - -export type SavedPage = { - queries: CardItem[], - title: string, -} diff --git a/DynamicBibleIonic/src/pages/search/search.html b/DynamicBibleIonic/src/pages/search/search.html index 10e586c7..7feeea28 100644 --- a/DynamicBibleIonic/src/pages/search/search.html +++ b/DynamicBibleIonic/src/pages/search/search.html @@ -22,28 +22,28 @@ Search Settings Show Strongs as Modal - + Clear Search after Query - + Append Results Below - + Insert Result Next to Item - + Each Verse on New Line - + Adjust Text - + A A @@ -70,10 +70,10 @@ - + - + diff --git a/DynamicBibleIonic/src/pages/search/search.ts b/DynamicBibleIonic/src/pages/search/search.ts index 7fee9e62..ecbdd1e8 100644 --- a/DynamicBibleIonic/src/pages/search/search.ts +++ b/DynamicBibleIonic/src/pages/search/search.ts @@ -5,7 +5,7 @@ import { Storage } from '@ionic/storage'; import { StrongsModal } from '../../components/strongs-modal/strongs-modal'; import { PagesService } from '../../services/pages-service'; -import { UserProfile } from '../../libs/UserProfile'; +import { ProfileService, User } from './../../services/profile-service'; import { Reference } from '../../libs/Reference'; import { VersePickerModal } from '../../components/verse-picker/verse-picker'; @@ -15,7 +15,6 @@ import { VersePickerModal } from '../../components/verse-picker/verse-picker'; export class SearchPage implements OnInit { searchQuery = ''; - userProfile: UserProfile; last: CardItem; loader: Loading; title: string; @@ -26,57 +25,44 @@ export class SearchPage implements OnInit , private menu: MenuController , public loadingCtrl: LoadingController , public modalCtrl: ModalController - , public local: Storage + , public profileService: ProfileService , public params: NavParams ) { - this.userProfile = new UserProfile(UserProfile.createDefaultUser()); } - ngOnInit(): void - { + ngOnInit(): void + { + let t = this.profileService.profile(); // Check if there is a profile saved in local storage - this.local.get('profile').then(profile => - { - let t = this.userProfile; + this.loader = this.loadingCtrl.create({ content: 'Loading Page...' }); + this.loader.present().then(() => + { + this.initializeItems(t); - if (profile !== null) - t = JSON.parse(profile); - - this.loader = this.loadingCtrl.create({ content: 'Loading Page...' }); - this.loader.present().then( - () => - { - this.userProfile.update(t, this.local); - - this.initializeItems(this.userProfile); - - this.loader.dismiss(); - }); - }).catch(error => - { - console.log(error); - }); - } - initializeItems(u: UserProfile) + this.loader.dismiss(); + }); + } + + initializeItems(u: User) { // migrate old way of storing card items to the new. let has_migrated = false; - for (let i in u.user.items) + for (let i in u.items) { - if (u.user.items.hasOwnProperty(i)) + if (u.items.hasOwnProperty(i)) { - let ci = u.user.items[i]; + let ci = u.items[i]; if (ci['data'] !== undefined) { if (ci['data'].qry !== undefined) - u.user.items[i] = { qry: ci['data'].qry, dict: ci.dict, type: ci.type }; + u.items[i] = { qry: ci['data'].qry, dict: ci.dict, type: ci.type }; else if (ci['data'].ref !== undefined) - u.user.items[i] = { qry: ci['data'].ref, dict: ci.dict, type: ci.type }; + u.items[i] = { qry: ci['data'].ref, dict: ci.dict, type: ci.type }; else if (ci['data'].word !== undefined) - u.user.items[i] = { qry: ci['data'].word, dict: ci.dict, type: ci.type }; + u.items[i] = { qry: ci['data'].word, dict: ci.dict, type: ci.type }; else if (ci['data'].sn !== undefined) - u.user.items[i] = { + u.items[i] = { qry: ci['data'].sn, dict: ci['prefix'] === 'G' ? 'grk' : 'heb', type: ci.type @@ -87,7 +73,7 @@ export class SearchPage implements OnInit } } - for (let pg of u.user.saved_pages) + for (let pg of u.saved_pages) { for (let i in pg.queries) { @@ -116,32 +102,33 @@ 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; + this.pagesService.initializePages(u.saved_pages); - if (has_migrated) - this.userProfile.save(this.local); + if (this.params.data.queries !== undefined) + this.profileService.profile().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) + this.profileService.save(); } save() { - this.userProfile.save(this.local); + this.profileService.save(); } textSizeChanged() { - this.userProfile.textSizeChanged(); + this.profileService.textSizeChanged(); this.save(); - } - actionsMenu() - { - this.menu.open('actions'); + } + + actionsMenu() + { + this.menu.open('actions'); } addPage() @@ -167,9 +154,9 @@ export class SearchPage implements OnInit text: 'Save', handler: data => { - const p = { queries: this.userProfile.user.items.slice(), title: data.title }; - this.userProfile.user.saved_pages.push(p); - this.userProfile.save(this.local); + const p = { queries: this.profileService.profile().items.slice(), title: data.title }; + this.profileService.profile().saved_pages.push(p); + this.profileService.save(); this.pagesService.addPage(p); } } @@ -178,14 +165,14 @@ export class SearchPage implements OnInit alert.present(); } - updatePage() + updatePage() { - const page = this.userProfile.user.saved_pages.find( + const page = this.profileService.profile().saved_pages.find( i => i.title === this.params.data.title ); - page.queries = this.userProfile.user.items.slice(); - this.userProfile.save(this.local); + page.queries = this.profileService.profile().items.slice(); + this.profileService.save(); } setQuery(searchbar) @@ -222,31 +209,31 @@ export class SearchPage implements OnInit removeItem(item) { - const idx = this.userProfile.user.items.indexOf(item); - this.userProfile.user.items.splice(idx, 1); + const idx = this.profileService.profile().items.indexOf(item); + this.profileService.profile().items.splice(idx, 1); // save the users settings. - this.userProfile.save(this.local); + this.profileService.save(); } addItemToList(item: CardItem) { - if (this.userProfile.user.append_to_bottom) + if (this.profileService.profile().append_to_bottom) { - if (this.last != null && this.userProfile.user.insert_next_to_item) + if (this.last != null && this.profileService.profile().insert_next_to_item) { - const idx = this.userProfile.user.items.indexOf(this.last); - this.userProfile.user.items.splice(idx + 1, 0, item); + const idx = this.profileService.profile().items.indexOf(this.last); + this.profileService.profile().items.splice(idx + 1, 0, item); } else - this.userProfile.user.items.push(item); + this.profileService.profile().items.push(item); } else { - if (this.last != null && this.userProfile.user.insert_next_to_item) + if (this.last != null && this.profileService.profile().insert_next_to_item) { - const idx = this.userProfile.user.items.indexOf(this.last); - this.userProfile.user.items.splice(idx, 0, item); + const idx = this.profileService.profile().items.indexOf(this.last); + this.profileService.profile().items.splice(idx, 0, item); } else - this.userProfile.user.items.unshift(item); + this.profileService.profile().items.unshift(item); } this.last = null; } @@ -258,7 +245,7 @@ export class SearchPage implements OnInit getItemList(search: string): Promise { - return new Promise((resolve) => + return new Promise((resolve) => { const list: CardItem[] = []; @@ -300,10 +287,10 @@ export class SearchPage implements OnInit } } } - if (this.userProfile.user.clear_search_after_query) + if (this.profileService.profile().clear_search_after_query) $('.searchbar-input').val(''); - this.userProfile.save(this.local); + this.profileService.save(); } catch (error) { @@ -317,7 +304,7 @@ export class SearchPage implements OnInit updateUIwithItems(search: string, from_search_bar: boolean) { - this.getItemList(search).then(lst => + this.getItemList(search).then(lst => { this.loader = this.loadingCtrl.create({ content: 'Looking up Query...' }); this.loader.present().then( @@ -325,7 +312,7 @@ export class SearchPage implements OnInit { for (let item of lst) { - if (item.type === 'Strongs' && this.userProfile.user.strongs_modal && !from_search_bar) + if (item.type === 'Strongs' && this.profileService.profile().strongs_modal && !from_search_bar) { const modal = this.modalCtrl.create(StrongsModal, { sn: parseInt(item.qry), dict: item.dict, onItemClicked: this }); modal.present(); @@ -340,7 +327,7 @@ export class SearchPage implements OnInit } export type OpenData = { card: CardItem, qry: string, from_search_bar: boolean } - + export type CardItem = { qry: string, type: string, dict: string } class Item diff --git a/DynamicBibleIonic/src/pages/settings/settings.html b/DynamicBibleIonic/src/pages/settings/settings.html index aacb688b..2ff83075 100644 --- a/DynamicBibleIonic/src/pages/settings/settings.html +++ b/DynamicBibleIonic/src/pages/settings/settings.html @@ -7,37 +7,47 @@ - +

Search Settings

- + + + + + + + + + + + Show Strongs as Modal - + Clear Search after Query - + Append Results Below - + Insert Result Next to Item - + Each Verse on New Line - +

Adjust Text

- + A A @@ -46,7 +56,7 @@

Manage Pages

- + {{p.title}}