diff --git a/app/components/nav-bar.hbs b/app/components/nav-bar.hbs index b108073..3a95038 100644 --- a/app/components/nav-bar.hbs +++ b/app/components/nav-bar.hbs @@ -3,8 +3,8 @@ Home Libraries Latest Arrivals -

Books : {{this.booksReq}}

-

Library : {{this.libraryReq}}

+

Books : {{this.booksReq}}

+

Library : {{this.libraryReq}}



diff --git a/app/components/nav-bar.js b/app/components/nav-bar.js index 2ee0d22..72d90ca 100644 --- a/app/components/nav-bar.js +++ b/app/components/nav-bar.js @@ -1,11 +1,20 @@ import Component from '@glimmer/component'; import { inject as service } from '@ember/service'; import { action, set, get } from '@ember/object'; +import $ from 'jquery'; export default class NavBarComponent extends Component { @service data; @service userPreference; + // constructor(){ + // super(...arguments); + // fetch('/library').then(r=>r.json()).then(d=>{ + // console.log(d); + // }); + + // } + get libraryReq() { return this.data.libraryReq; } diff --git a/app/routes/library/details.js b/app/routes/library/details.js index 00b3e2e..092aba6 100644 --- a/app/routes/library/details.js +++ b/app/routes/library/details.js @@ -5,14 +5,14 @@ export default class LibraryDetailsRoute extends Route { @service data; @service router; - model({ library_id }) { + async model({ library_id }) { let url = '/libraries/' + library_id; - let lib = this.data.getData(url); + let data = await this.data.getData(url); - if (!lib) { + if (!data) { this.router.transitionTo('not-found', 'notFound'); } - return lib; + return data.library; } } @@ -23,4 +23,4 @@ export default class LibraryDetailsRoute extends Route { // } // }); -// let lib = fetch(`/libraries/${library_id}`).then((response)=>response.json()).then((r)=> r.data) \ No newline at end of file +// let lib = fetch(`/libraries/${library_id}`).then((response)=>response.json()).then((r)=> r.data) diff --git a/app/routes/library/details/books.js b/app/routes/library/details/books.js index ae0e8e2..81efd13 100644 --- a/app/routes/library/details/books.js +++ b/app/routes/library/details/books.js @@ -1,4 +1,8 @@ import Route from '@ember/routing/route'; - +import { action } from '@ember/object'; export default class LibraryDetailsBooksRoute extends Route { + // @action + // bubbled(){ + // console.log('bubbled from book'); + // } } diff --git a/app/routes/library/details/books/book.js b/app/routes/library/details/books/book.js index aeb840e..3501f93 100644 --- a/app/routes/library/details/books/book.js +++ b/app/routes/library/details/books/book.js @@ -8,18 +8,18 @@ export default class LibraryDetailsBooksBookRoute extends Route { async model({ book_id }) { let library_id = this.paramsFor('library.details').library_id; let url = `/libraries/${library_id}/books/${book_id}`; - let book = await this.data.getData(url); - if (!book) { + let data = await this.data.getData(url); + if (!data) { this.router.transitionTo('not-found', 'notfound'); } - return book; + return data.book; } } - // library.books.forEach(element => { - // if (element.id == book_id) { - // book = element; - // return - // } - // }); - // let book = await fetch(`/books/${book_id}`).then((response) => response.json()).then((r) => r.data); +// library.books.forEach(element => { +// if (element.id == book_id) { +// book = element; +// return +// } +// }); +// let book = await fetch(`/books/${book_id}`).then((response) => response.json()).then((r) => r.data); diff --git a/app/routes/library/details/books/index.js b/app/routes/library/details/books/index.js index 14a5bee..057b472 100644 --- a/app/routes/library/details/books/index.js +++ b/app/routes/library/details/books/index.js @@ -14,13 +14,13 @@ export default class LibraryDetailsBooksIndexRoute extends Route { let s = params.sort; let library_id = this.paramsFor('library.details').library_id; let url = '/libraries/' + library_id + '/books'; - let books = await this.data.getData(url); + let data = await this.data.getData(url); - return books.sort((a, b) => { + return data.books.sort((a, b) => { if (s === 'asc') { - return a.attributes.name.localeCompare(b.attributes.name); + return a.name.localeCompare(b.name); } else if (s === 'desc') { - return b.attributes.name.localeCompare(a.attributes.name); + return b.name.localeCompare(a.name); } else { return 0; } @@ -32,4 +32,4 @@ export default class LibraryDetailsBooksIndexRoute extends Route { // else if(s === 'desc') return books.sortBy('name').reverse(); // else return books; // let books = await fetch(`/libraries/${library_id}/books`).then((response)=>response.json()).then((r)=>r.data); -// let books = this.modelFor('library.details').books.data.slice(); \ No newline at end of file +// let books = this.modelFor('library.details').books.data.slice(); diff --git a/app/routes/library/details/read-book.js b/app/routes/library/details/read-book.js index 337fbb2..c56663d 100644 --- a/app/routes/library/details/read-book.js +++ b/app/routes/library/details/read-book.js @@ -22,23 +22,22 @@ export default class LibraryDetailsReadBookRoute extends Route { async model({ readbook_id }) { let library_id = this.paramsFor('library.details').library_id; let url = `/libraries/${library_id}/books/${readbook_id}`; - let book = this.data.getData(url); + let data = await this.data.getData(url); - if (!book) { + if (!data) { this.router.transitionTo('not-found', 'notfound'); } - return book; + return data.book; } } +// let book; +// let library = this.modelFor('library.details'); +// library.books.forEach(element => { +// if (element.id == readbook_id) { +// book = element; +// return +// } +// }); - // let book; - // let library = this.modelFor('library.details'); - // library.books.forEach(element => { - // if (element.id == readbook_id) { - // book = element; - // return - // } - // }); - - // let book = await fetch(`/books/${readbook_id}`).then((response)=>response.json()).then((r)=>r.data); \ No newline at end of file +// let book = await fetch(`/books/${readbook_id}`).then((response)=>response.json()).then((r)=>r.data); diff --git a/app/routes/library/index.js b/app/routes/library/index.js index 597e51a..0311891 100644 --- a/app/routes/library/index.js +++ b/app/routes/library/index.js @@ -1,13 +1,10 @@ import Route from '@ember/routing/route'; -import { inject as service } from "@ember/service"; export default class LibraryIndexRoute extends Route { - // @service('LibraryData') library; - model() { let data = fetch('/libraries') .then((response) => response.json()) - .then((r) => r.data); + .then((r) => r.libraries); return data; } } diff --git a/app/services/user-preference.js b/app/services/user-preference.js index 9a1b2c9..eb9c6e0 100644 --- a/app/services/user-preference.js +++ b/app/services/user-preference.js @@ -2,37 +2,36 @@ import Service from '@ember/service'; import { tracked } from '@glimmer/tracking'; export default class UserPreferenceService extends Service { + @tracked theme; - @tracked theme; + constructor() { + super(...arguments); + let value = localStorage.getItem('theme'); + this.theme = value ? value : 'light'; + } - constructor(){ - super(...arguments); - let value = localStorage.getItem("theme"); - this.theme = value ? value : 'light'; - } + setTheme(newTheme) { + localStorage.setItem('theme', newTheme); + this.theme = newTheme; - setTheme(newTheme) { - localStorage.setItem("theme",newTheme) - this.theme = newTheme; + // let date = new Date(); + // seetting expiry date of 30 days + // date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000)); + // document.cookie = `theme=${newTheme};expires=${date.toUTCString()}`; + } - // let date = new Date(); - // seetting expiry date of 30 days - // date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000)); - // document.cookie = `theme=${newTheme};expires=${date.toUTCString()}`; - } - - // get theme() { - // // let cookieArr = document.cookie.split('; '); - // // let t = 'light'; - // // if (cookieArr.length > 0) { - // // cookieArr.forEach((cookie) => { - // // let keyValue = cookie.split("="); - // // if (keyValue[0] == 'theme') { - // // t = keyValue[1]; - // // } - // // }) - // // } - // // return t; - // return localStorage.getItem("theme"); - // } + // get theme() { + // // let cookieArr = document.cookie.split('; '); + // // let t = 'light'; + // // if (cookieArr.length > 0) { + // // cookieArr.forEach((cookie) => { + // // let keyValue = cookie.split("="); + // // if (keyValue[0] == 'theme') { + // // t = keyValue[1]; + // // } + // // }) + // // } + // // return t; + // return localStorage.getItem("theme"); + // } } diff --git a/app/styles/app.css b/app/styles/app.css index 708bfb7..2be9cd5 100644 --- a/app/styles/app.css +++ b/app/styles/app.css @@ -26,16 +26,17 @@ text-align: left; } -.buttonMode{ +.buttonMode { border-radius: 12px; padding: 9px; + margin: 10px; width: 100px; } -.buttonMode:hover{ +.buttonMode:hover { cursor: pointer; } -a{ +a { color: #7b0930; -} \ No newline at end of file +} diff --git a/mirage/config.js b/mirage/config.js index 7d036a3..de4b75d 100644 --- a/mirage/config.js +++ b/mirage/config.js @@ -2,11 +2,12 @@ import { discoverEmberDataModels, // applyEmberDataSerializers, } from 'ember-cli-mirage'; -import { createServer } from 'miragejs'; +import { Response, createServer } from 'miragejs'; export default function (config) { let finalConfig = { ...config, + trackRequests: true, // Remove discoverEmberDataModels if you do not want ember-cli-mirage to auto discover the ember models models: { ...discoverEmberDataModels(config.store), @@ -15,6 +16,7 @@ export default function (config) { // uncomment to opt into ember-cli-mirage to auto discover ember serializers // serializers: applyEmberDataSerializers(config.serializers), routes, + // logging:false }; return createServer(finalConfig); @@ -29,24 +31,33 @@ function routes() { let id = request.params.id; let bookIds = schema.libraries.find(id).attrs.bookIds; let books = schema.books.find(bookIds); - - return this.serialize(books); + return books; }); this.get('/libraries/:id/books/:book_id', function (schema, request) { let id = request.params.id; let book_id = request.params.book_id; let bookIds = schema.libraries.find(id).attrs.bookIds; + let book; - bookIds.forEach(bookId => { - if(bookId==book_id){ - book = schema.books.find(book_id); + bookIds.forEach((bookId) => { + if (bookId == book_id) { + book = schema.books.find(book_id); } }); - return this.serialize(book); + + if (!book) { + return new Response(500, {}, { error: 'Book not found' }); + } + return book; }); this.get('books/:id'); this.passthrough('https://www.googleapis.com/books/v1/volumes'); + + // this.passthrough(request=>{ + // // console.log(request); + // return request.statusText != 'OK'; + // }) } diff --git a/tests/acceptance/book-test.js b/tests/acceptance/book-test.js index 48a945a..ea5e9d8 100644 --- a/tests/acceptance/book-test.js +++ b/tests/acceptance/book-test.js @@ -9,6 +9,7 @@ module('Acceptance | book', function (hooks) { await visit('/book'); // logHelper('hello'); // await this.pauseTest(); + assert.strictEqual(currentURL(), '/book'); }); });