4
2
Fork 0

Removed static web urls and fixed some issues

This commit is contained in:
Oh Martin 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 BASE_URL = 'https://getbible.net';
let API_VERSION = 'v2'; let API_VERSION = 'v2';
export { BASE_URL, API_VERSION };
export default { export default {
get_translations(){ get_translations(){

View File

@ -27,6 +27,21 @@ export default {
let db = e.target.result; let db = e.target.result;
db.createObjectStore("saved_translations", { keyPath:'abbreviation' }); db.createObjectStore("saved_translations", { keyPath:'abbreviation' });
db.createObjectStore("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'); // let trans = db.transaction([name],'readonly');
trans.oncomplete = () => { // trans.oncomplete = () => {
resolve(tr); // resolve(tr);
}; // };
let store = trans.objectStore(name); // let store = trans.objectStore(name);
let tr = {}; // let tr = {};
store.openCursor().onsuccess = e => { // store.openCursor().onsuccess = e => {
let cursor = e.target.result; // let cursor = e.target.result;
if (cursor) { // if (cursor) {
if (keyPath == cursor.value.keyPath){ // if (keyPath == cursor.value.keyPath){
tr = cursor.value // tr = cursor.value
for (const book in cursor.value.books) { // for (const book in cursor.value.books) {
for (const chapters in book) { // for (const chapters in book) {
for (const verses in chapters) { // for (const verses in chapters) {
for (const verse in verses) { // for (const verse in verses) {
if(verse.text.includes(keyPath)){ // if(verse.text.includes(keyPath)){
console.log("We found a row with value: " + JSON.stringify(verse.text)); // console.log("We found a row with value: " + JSON.stringify(verse.text));
} // }
} // }
} // }
} // }
} // }
} // }
cursor.continue(); // cursor.continue();
} // }
}; // };
trans.onerror = e => { // trans.onerror = e => {
reject(e) // reject(e)
} // }
trans.onabort = e => { // trans.onabort = e => {
reject(e) // reject(e)
} // }
trans.commit(); // trans.commit();
}); // });
}, // },
} }

View File

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

View File

@ -1,6 +1,6 @@
<template> <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 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> <div v-else>
<ul class="uk-nav-default uk-nav-parent-icon uk-witdth-1-1 " uk-nav="multiple: false" > <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){ t(i){
return this.translations.find(t => t.abbreviation === i) return this.translations.find(t => t.abbreviation === i)
}, },
set_translation(a) { set_translation(a) {
console.log("Hello"); console.log("Hello");
this.$store.dispatch('set_translation', {selected_translation:a}) this.$store.dispatch('set_translation', {selected_translation:a})
}, },
set_book(b){ set_book(b){
this.$store.dispatch('set_book', b) this.$store.dispatch('set_book', b)
}, },
set_chapter(c){ set_chapter(c){
this.$store.dispatch('set_chapter', c) this.$store.dispatch('set_chapter', c)
}, },
open_settings(){ open_settings(){

View File

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