en_btr_frontend/app/components/scripture-nav-bar.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-10-04 21:58:28 +00:00
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from "@glimmer/tracking";
import { books } from "../data/book-chapter-verse";
2020-10-05 04:06:09 +00:00
import { inject as service } from '@ember/service';
2020-10-04 21:58:28 +00:00
export default class ScriptureNavBarComponent extends Component {
2020-10-05 04:06:09 +00:00
@service router;
2020-10-06 22:05:33 +00:00
@service store;
2020-10-05 04:06:09 +00:00
2020-10-04 21:58:28 +00:00
@tracked chaptersVisible = false;
@tracked versesVisible = false;
@tracked currentBook = null;
@tracked currentChapter = null;
2020-10-06 22:05:33 +00:00
@tracked books = [];
2020-10-04 21:58:28 +00:00
constructor(...args) {
super(...args);
this.books = this.getBooks();
2020-10-06 22:05:33 +00:00
}
// get only the books that we have backend data for
async getBooks()
2020-10-06 22:05:33 +00:00
{
const results = await this.store.findAll('book');
this.books = results.map((book) => {
let foundValue = books.find(function(value) {
return value['name'] == book.id
});
if(foundValue) {
return foundValue;
} else {
console.log("Could not find: " + book.id);
}
2020-10-06 22:05:33 +00:00
});
2020-10-04 21:58:28 +00:00
}
@action
showChapters(book) {
this.chaptersVisible = true;
this.versesVisible = false;
this.currentBook = book;
}
@action
showVerses(book, chapter) {
this.versesVisible = true;
this.currentChapter = chapter;
}
@action
verseSelected(book, chapter, verse) {
2020-10-06 14:46:24 +00:00
// Load the DOM with verse page
2020-10-07 16:33:20 +00:00
// console.log('[verseSelected] called: ' + book + ' ' + chapter.chapter + ':' + verse);
// console.log(chapter);
2020-10-06 14:46:24 +00:00
this.router.transitionTo('verse', book + '-' + chapter.chapter + '-' + verse);
2020-10-04 21:58:28 +00:00
}
}