4
2
mirror of https://github.com/getbible/app.git synced 2024-12-21 23:48:53 +00:00

Removed static web urls and fixed some issues

This commit is contained in:
Oh 2021-01-07 14:47:51 +02:00
parent 195eec66b1
commit 10c4e1e6c5
No known key found for this signature in database
GPG Key ID: D2FA7AE034066270
5 changed files with 165 additions and 171 deletions

View File

@ -4,6 +4,8 @@
let BASE_URL = 'https://getbible.net';
let API_VERSION = 'v2';
export { BASE_URL, API_VERSION };
export default {
get_translations(){

View File

@ -27,6 +27,21 @@ export default {
let db = e.target.result;
db.createObjectStore("saved_translations", { keyPath:'abbreviation' });
db.createObjectStore("translations", { keyPath:'abbreviation' });
// let index = translations.createIndex('book_idx', 'name');
// let transaction = db.transaction("books"); // readonly
// let books = transaction.objectStore("books");
// let bookIndex = translations.index("book_idx");
// let request = bookIndex.getAll("Genesis");
// request.onsuccess = function() {
// if (request.result !== undefined) {
// console.log("Books", request.result); // array of books with name="Genesis"
// } else {
// console.log("No such books");
// }
// }
};
});
},
@ -134,50 +149,50 @@ export default {
});
},
async search(name, keyPath) {
// async search(name, keyPath) {
let db = await this.getDb();
// let db = await this.getDb();
return new Promise((resolve, reject) => {
// return new Promise((resolve, reject) => {
let trans = db.transaction([name],'readonly');
trans.oncomplete = () => {
resolve(tr);
};
// let trans = db.transaction([name],'readonly');
// trans.oncomplete = () => {
// resolve(tr);
// };
let store = trans.objectStore(name);
let tr = {};
// let store = trans.objectStore(name);
// let tr = {};
store.openCursor().onsuccess = e => {
let cursor = e.target.result;
if (cursor) {
if (keyPath == cursor.value.keyPath){
tr = cursor.value
for (const book in cursor.value.books) {
for (const chapters in book) {
for (const verses in chapters) {
for (const verse in verses) {
if(verse.text.includes(keyPath)){
console.log("We found a row with value: " + JSON.stringify(verse.text));
}
}
}
}
}
// store.openCursor().onsuccess = e => {
// let cursor = e.target.result;
// if (cursor) {
// if (keyPath == cursor.value.keyPath){
// tr = cursor.value
// for (const book in cursor.value.books) {
// for (const chapters in book) {
// for (const verses in chapters) {
// for (const verse in verses) {
// if(verse.text.includes(keyPath)){
// console.log("We found a row with value: " + JSON.stringify(verse.text));
// }
// }
// }
// }
// }
}
cursor.continue();
}
};
trans.onerror = e => {
reject(e)
}
trans.onabort = e => {
reject(e)
}
trans.commit();
// }
// cursor.continue();
// }
// };
// trans.onerror = e => {
// reject(e)
// }
// trans.onabort = e => {
// reject(e)
// }
// trans.commit();
});
},
// });
// },
}

View File

@ -11,126 +11,127 @@
</template>
<script>
import _ from 'lodash';
import {mapGetters} from 'vuex'
import { mapGetters } from 'vuex'
import { BASE_URL, API_VERSION } from '../api/getbible_v2_api'
export default {
components:{
},
data: function(){
},
data: function(){
return {
progress: 0,
loading: false,
}},
computed: {
translations(){
return this.$store.state.saved_translations;
},
saved_translations(){
console.log(this.$store.state.saved_translations);
return this.$store.state.saved_translations
},
...mapGetters(['chapters', 'chapter']),
fchapters: function (){
if(!this.search)
return this.chapter.verses
return this.filteredChapters
},
filteredChapters() {
return _.orderBy(this.chapter.verses.filter((item) =>
item.verse.toString().toLowerCase().includes(this.search.toLowerCase())
|| item.chapter.toString().toLowerCase().includes(this.search.toLowerCase())
|| item.name.toString().toLowerCase().includes(this.search.toLowerCase())
|| item.text.toLowerCase().includes(this.search.toLowerCase())), 'verse');
},
computed: {
translations(){
return this.$store.state.saved_translations;
},
saved_translations(){
console.log(this.$store.state.saved_translations);
return this.$store.state.saved_translations
},
...mapGetters(['chapters', 'chapter']),
fchapters: function (){
if(!this.search)
return this.chapter.verses
return this.filteredChapters
},
filteredChapters() {
return _.orderBy(this.chapter.verses.filter((item) =>
item.verse.toString().toLowerCase().includes(this.search.toLowerCase())
|| item.chapter.toString().toLowerCase().includes(this.search.toLowerCase())
|| item.name.toString().toLowerCase().includes(this.search.toLowerCase())
|| item.text.toLowerCase().includes(this.search.toLowerCase())), 'verse');
},
methods:{
t(i){
return this.translations.find(t => t.abbreviation === i)
},
next(){
if(this.chapter<this.chapters.length)
this.$store.dispatch('set_chapter', this.chapter + 1)
},
prev(){
if(this.chapter>1)
this.$store.dispatch('set_chapter', this.chapter - 1)
},
async update_chapter() {
// this.loading = true
this.progress = 95
let config = {
headers: {'Access-Control-Allow-Origin': '*'}
};
},
methods:{
t(i){
return this.translations.find(t => t.abbreviation === i)
},
next(){
if(this.chapter<this.chapters.length)
this.$store.dispatch('set_chapter', this.chapter + 1)
},
prev(){
if(this.chapter>1)
this.$store.dispatch('set_chapter', this.chapter - 1)
},
async update_chapter() {
// this.loading = true
this.progress = 95
let config = {
headers: {'Access-Control-Allow-Origin': '*'}
};
let url = `${BASE_URL}/${API_VERSION}/${this.translation}/${this.book}/${this.chapter_num}.json`
let url = `https://getbible.net/v2/${this.translation}/${this.book}/${this.chapter_num}.json`
let response = await fetch(url, config).catch(function(err) {
this.chapter = err
this.loading =false
this.message = 'Error'
});
if (!response) return;
this.progress = 99
let data = await response.json().catch(err => {
this.chapter = err
this.loading =false
this.message = 'Error'
})
let response = await fetch(url, config).catch(function(err) {
this.chapter = err
this.loading =false
if (!data) return;
this.message = 'Error'
});
this.chapter = data
this.progress =0
if (!response) return;
},
async update_tr(){
},
async update_bk(){
let config = {
headers: {'Access-Control-Allow-Origin': '*'}
};
this.loading =true
this.progress =25
this.message = 'Loading...'
let url = `https://getbible.net/v2/${this.translation}/books.json`
fetch(url,config)
.then(response => response.json())
.then(data => {
// console.log(data)
this.books = data
this.progress = 60
this.update_ch();
}).catch(function(err) {
this.chapter = err
this.loading =false
this.message = 'Error'
});
this.progress = 99
let data = await response.json().catch(err => {
this.chapter = err
this.loading =false
this.message = 'Error'
})
this.loading =false
},
async update_ch(){
let config = {
headers: {'Access-Control-Allow-Origin': '*'}
};
fetch(`https://getbible.net/v2/${this.translation}/${this.book}/chapters.json`,config)
.then(response => response.json())
.then(data => {
// console.log(data)
this.chapters = data
this.progress = 85
this.update_chapter();
}).catch(function(err) {
this.chapter = err
this.loading =false
this.message = 'Error'
});
}
},
if (!data) return;
this.chapter = data
this.progress =0
},
async update_tr(){
},
async update_bk(){
let config = {
headers: {'Access-Control-Allow-Origin': '*'}
};
this.loading =true
this.progress =25
this.message = 'Loading...'
let url = `${BASE_URL}/${API_VERSION}/${this.translation}/books.json`
fetch(url,config)
.then(response => response.json())
.then(data => {
// console.log(data)
this.books = data
this.progress = 60
this.update_ch();
}).catch(function(err) {
this.chapter = err
this.loading =false
this.message = 'Error'
});
},
async update_ch(){
let config = {
headers: {'Access-Control-Allow-Origin': '*'}
};
fetch(`${BASE_URL}/${API_VERSION}/${this.translation}/${this.book}/chapters.json`,config)
.then(response => response.json())
.then(data => {
// console.log(data)
this.chapters = data
this.progress = 85
this.update_chapter();
}).catch(function(err) {
this.chapter = err
this.loading =false
this.message = 'Error'
});
}
},
}
</script>

View File

@ -1,6 +1,6 @@
<template>
<div id="selection" class="primary text-secondary uk-animation-slide-bottom uk-width-1-1 uk-card uk-card-default uk-card-body rounded" uk-margin>
<div class="" v-if="!saved_translations.length>0">No translation added. <br/>Please click <a @click="open_settings">HERE</a> to Open Settings</div>
<div class="" v-if="!saved_translations.length>0">No translations added. <br/>Please click <a @click="open_settings">HERE</a> to Open Settings</div>
<div v-else>
<ul class="uk-nav-default uk-nav-parent-icon uk-witdth-1-1 " uk-nav="multiple: false" >
@ -73,14 +73,14 @@ export default {
t(i){
return this.translations.find(t => t.abbreviation === i)
},
set_translation(a) {
set_translation(a) {
console.log("Hello");
this.$store.dispatch('set_translation', {selected_translation:a})
},
set_book(b){
this.$store.dispatch('set_book', b)
},
set_chapter(c){
set_chapter(c){
this.$store.dispatch('set_chapter', c)
},
open_settings(){

View File

@ -3,34 +3,10 @@
export default {
add_translation (state, payload ) {
// payload = {
// translation:{
// name: 'translation',
// putObj: {}
// },
// saved_translations:{
// name: 'saved_translation',
// putObj: {}
// }
// }
state.saved_translations.push(payload.saved_translations.putObj)
},
REMOVE_TRANSLATION (state, payload ) {
// payload example
// payload = {
// translation:{
// name: 'translation',
// keyPath: 'aksjv'
// },
// saved_translations:{
// name: 'saved_translation',
// keyPath: "askjv"
// }
// }
const {keyPath} = payload.saved_translations;