2020-10-04 21:58:28 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { action } from '@ember/object';
|
2020-12-18 18:16:05 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-10-04 21:58:28 +00:00
|
|
|
|
|
|
|
export default class BookComponent extends Component {
|
2020-12-18 18:16:05 +00:00
|
|
|
@service('nav-state') navState;
|
|
|
|
|
2020-10-04 21:58:28 +00:00
|
|
|
get bookTitle() {
|
2021-05-04 17:03:15 +00:00
|
|
|
if (typeof this.args.book == 'undefined') {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2020-10-04 21:58:28 +00:00
|
|
|
let string = this.args.book.name.toLowerCase();
|
|
|
|
if (this.isNumber(string.charAt(0))) {
|
2021-05-04 17:01:59 +00:00
|
|
|
return string.slice(0,1) + ' ' + string.charAt(2).toUpperCase() + string.slice(3);
|
2020-10-04 21:58:28 +00:00
|
|
|
} else {
|
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
selectBook() {
|
|
|
|
this.args.showChapters(this.args.book);
|
2020-12-18 18:16:05 +00:00
|
|
|
this.navState.setBook(this.args.book);
|
2020-10-04 21:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isNumber(char) {
|
|
|
|
var number = /^[0-9]+$/;
|
|
|
|
let string = char;
|
|
|
|
|
|
|
|
if(string.match(number)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 18:16:05 +00:00
|
|
|
|
|
|
|
get
|
|
|
|
selected() {
|
|
|
|
if(this.navState.isCurrentBook(this.args.book)) {
|
|
|
|
return "selected";
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2020-10-04 21:58:28 +00:00
|
|
|
}
|