File tree Expand file tree Collapse file tree 24 files changed +20903
-20234
lines changed Expand file tree Collapse file tree 24 files changed +20903
-20234
lines changed Original file line number Diff line number Diff line change 1
1
import Component from '@glimmer/component' ;
2
2
import { inject as service } from '@ember/service' ;
3
3
import { action , set , get } from '@ember/object' ;
4
+ import $ from 'jquery' ;
4
5
5
6
export default class NavBarComponent extends Component {
6
7
@service data ;
7
8
@service userPreference ;
8
9
10
+ // constructor(){
11
+ // super(...arguments);
12
+ // fetch('/libraries/4/books').then(r=>r.json()).then(d=>{
13
+ // console.log(d);
14
+ // });
15
+
16
+ // }
17
+
9
18
get libraryReq ( ) {
10
19
return this . data . libraryReq ;
11
20
}
Original file line number Diff line number Diff line change
1
+ import Model , { belongsTo } from '@ember-data/model' ;
2
+
3
+ export default class BookModel extends Model {
4
+ @belongsTo ( 'library' , { async : true , inverse : 'library' } ) library ;
5
+ }
6
+
Original file line number Diff line number Diff line change
1
+ import Model , { attr , hasMany } from '@ember-data/model' ;
2
+
3
+ export default class LibraryModel extends Model {
4
+ @attr name ;
5
+ @attr location ;
6
+ @attr timing ;
7
+ @hasMany ( 'book' , { async : true , inverse : 'book' } ) books ;
8
+ }
Original file line number Diff line number Diff line change @@ -7,12 +7,12 @@ export default class LibraryDetailsRoute extends Route {
7
7
8
8
async model ( { library_id } ) {
9
9
let url = '/libraries/' + library_id ;
10
- let lib = await this . data . getData ( url ) ;
10
+ let data = await this . data . getData ( url ) ;
11
11
12
- if ( ! lib ) {
12
+ if ( ! data ) {
13
13
this . router . transitionTo ( 'not-found' , 'notFound' ) ;
14
14
}
15
- return lib ;
15
+ return data . library ;
16
16
}
17
17
}
18
18
@@ -23,4 +23,4 @@ export default class LibraryDetailsRoute extends Route {
23
23
// }
24
24
// });
25
25
26
- // let lib = fetch(`/libraries/${library_id}`).then((response)=>response.json()).then((r)=> r.data)
26
+ // let lib = fetch(`/libraries/${library_id}`).then((response)=>response.json()).then((r)=> r.data)
Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ export default class LibraryDetailsBooksBookRoute extends Route {
8
8
async model ( { book_id } ) {
9
9
let library_id = this . paramsFor ( 'library.details' ) . library_id ;
10
10
let url = `/libraries/${ library_id } /books/${ book_id } ` ;
11
- let book = await this . data . getData ( url ) ;
12
- if ( ! book ) {
11
+ let data = await this . data . getData ( url ) ;
12
+ if ( ! data ) {
13
13
this . router . transitionTo ( 'not-found' , 'notfound' ) ;
14
14
}
15
- return book ;
15
+ return data . book ;
16
16
}
17
17
}
18
18
Original file line number Diff line number Diff line change @@ -14,13 +14,13 @@ export default class LibraryDetailsBooksIndexRoute extends Route {
14
14
let s = params . sort ;
15
15
let library_id = this . paramsFor ( 'library.details' ) . library_id ;
16
16
let url = '/libraries/' + library_id + '/books' ;
17
- let books = await this . data . getData ( url ) ;
17
+ let data = await this . data . getData ( url ) ;
18
18
19
- return books . sort ( ( a , b ) => {
19
+ return data . books . sort ( ( a , b ) => {
20
20
if ( s === 'asc' ) {
21
- return a . attributes . name . localeCompare ( b . attributes . name ) ;
21
+ return a . name . localeCompare ( b . name ) ;
22
22
} else if ( s === 'desc' ) {
23
- return b . attributes . name . localeCompare ( a . attributes . name ) ;
23
+ return b . name . localeCompare ( a . name ) ;
24
24
} else {
25
25
return 0 ;
26
26
}
@@ -32,4 +32,4 @@ export default class LibraryDetailsBooksIndexRoute extends Route {
32
32
// else if(s === 'desc') return books.sortBy('name').reverse();
33
33
// else return books;
34
34
// let books = await fetch(`/libraries/${library_id}/books`).then((response)=>response.json()).then((r)=>r.data);
35
- // let books = this.modelFor('library.details').books.data.slice();
35
+ // let books = this.modelFor('library.details').books.data.slice();
Original file line number Diff line number Diff line change @@ -22,23 +22,22 @@ export default class LibraryDetailsReadBookRoute extends Route {
22
22
async model ( { readbook_id } ) {
23
23
let library_id = this . paramsFor ( 'library.details' ) . library_id ;
24
24
let url = `/libraries/${ library_id } /books/${ readbook_id } ` ;
25
- let book = this . data . getData ( url ) ;
25
+ let data = await this . data . getData ( url ) ;
26
26
27
- if ( ! book ) {
27
+ if ( ! data ) {
28
28
this . router . transitionTo ( 'not-found' , 'notfound' ) ;
29
29
}
30
- return book ;
30
+ return data . book ;
31
31
}
32
32
}
33
33
34
+ // let book;
35
+ // let library = this.modelFor('library.details');
36
+ // library.books.forEach(element => {
37
+ // if (element.id == readbook_id) {
38
+ // book = element;
39
+ // return
40
+ // }
41
+ // });
34
42
35
- // let book;
36
- // let library = this.modelFor('library.details');
37
- // library.books.forEach(element => {
38
- // if (element.id == readbook_id) {
39
- // book = element;
40
- // return
41
- // }
42
- // });
43
-
44
- // let book = await fetch(`/books/${readbook_id}`).then((response)=>response.json()).then((r)=>r.data);
43
+ // let book = await fetch(`/books/${readbook_id}`).then((response)=>response.json()).then((r)=>r.data);
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ export default class LibraryIndexRoute extends Route {
4
4
model ( ) {
5
5
let data = fetch ( '/libraries' )
6
6
. then ( ( response ) => response . json ( ) )
7
- . then ( ( r ) => r . data ) ;
7
+ . then ( ( r ) => r . libraries ) ;
8
8
return data ;
9
9
}
10
10
}
Original file line number Diff line number Diff line change @@ -2,25 +2,30 @@ import Service from '@ember/service';
2
2
import { tracked } from '@glimmer/tracking' ;
3
3
4
4
export default class DataService extends Service {
5
- @tracked booksReq = 0 ;
6
- @tracked libraryReq = 0 ;
5
+ @tracked booksReq = 0 ;
6
+ @tracked libraryReq = 0 ;
7
7
8
- async getData ( url ) {
9
- let data = await fetch ( url )
10
- . then ( ( response ) => response . json ( ) )
11
- . then ( ( r ) => r . data ) ;
12
-
13
- if ( data ) {
14
- if ( data . type == 'libraries' ) {
15
- this . libraryReq ++ ;
16
- }
17
- else if ( data . type == 'books' ) {
18
- this . booksReq ++ ;
19
- }
20
- }
21
- return data ;
8
+ async getData ( url ) {
9
+ let data = await fetch ( url )
10
+ . then ( ( response ) => {
11
+ if ( response . ok ) return response . json ( ) ;
12
+ } ) ;
13
+
14
+ if ( data ) {
15
+ if ( data . library ) {
16
+ this . libraryReq ++ ;
17
+ } else if ( data . book ) {
18
+ this . booksReq ++ ;
19
+ }
22
20
}
21
+ return data ;
22
+ }
23
23
}
24
+ // if (data.type == 'libraries') {
25
+ // this.libraryReq++;
26
+ // } else if (data.type == 'books') {
27
+ // this.booksReq++;
28
+ // }
24
29
25
30
// let book;
26
31
// lib.books.forEach(element => {
@@ -38,7 +43,6 @@ export default class DataService extends Service {
38
43
// }
39
44
// });
40
45
41
-
42
46
// async getData(url) {
43
47
// let arr = url.split('/');
44
48
@@ -70,4 +74,4 @@ export default class DataService extends Service {
70
74
// if (lib) this.libraryReq++;
71
75
// return lib;
72
76
// }
73
- // }
77
+ // }
Original file line number Diff line number Diff line change 1
1
<div align =" center" >
2
2
<div class =" box-view" >
3
- <h2 >{{ this.model.attributes. name }} </h2 >
4
- <p >Location : {{ this.model.attributes. location }} </p >
5
- <p >Timing : {{ this.model.attributes. timing }} </p >
3
+ <h2 >{{ this.model.name }} </h2 >
4
+ <p >Location : {{ this.model.location }} </p >
5
+ <p >Timing : {{ this.model.timing }} </p >
6
6
<LinkTo @route =" library.details.books" @replace ={{ true }} >Books Available</LinkTo >
7
7
</div >
8
8
</div >
Original file line number Diff line number Diff line change 1
1
{{ page-title " Book" }}
2
2
3
3
<div align =" center" >
4
- <h3 >{{ this.model.attributes. name }} </h3 >
4
+ <h3 >{{ this.model.name }} </h3 >
5
5
<h4 ><u >DESCRIPTION</u ></h4 >
6
- <p >Author : {{ this.model.attributes. author }} </p >
7
- <p >Publisher : {{ this.model.attributes. publisher }} </p >
8
- <p >Date of Publication : {{ get this.model.attributes " published-date " }} </p >
6
+ <p >Author : {{ this.model.author }} </p >
7
+ <p >Publisher : {{ this.model.publisher }} </p >
8
+ <p >Date of Publication : {{ this.model.publishedDate }} </p >
9
9
<LinkTo @route =" library.details.read-book" @model ={{ this.model.id }} >Read book</LinkTo >
10
10
</div >
Original file line number Diff line number Diff line change 5
5
<LinkTo @route =" library.details.books" @query ={{ hash sort =" desc" }} >Descending</LinkTo >
6
6
</div >
7
7
</div >
8
- {{ log this.model }}
9
8
<div style =" text-align: center;" >
10
9
<ul class =" myUL" >
11
10
{{ #each this.model as |book |}}
12
11
<div style =" padding:15px" >
13
12
<li >
14
- <LinkTo @route =" library.details.books.book" @model ={{ book.id }} >{{ book.attributes. name }} </LinkTo >
13
+ <LinkTo @route =" library.details.books.book" @model ={{ book.id }} >{{ book.name }} </LinkTo >
15
14
</li >
16
15
</div >
17
16
{{ /each }}
Original file line number Diff line number Diff line change 1
1
{{ page-title " ReadBook" }}
2
2
3
3
<div align =" center" >
4
- <h3 >{{ this.model.attributes. name }} </h3 >
4
+ <h3 >{{ this.model.name }} </h3 >
5
5
6
6
<label for =" name" >Name</label >
7
7
<Input id =" name" @value ={{ this.name }} @type =" text" /><br ><br >
Original file line number Diff line number Diff line change 1
1
{{ page-title " Index" }}
2
- {{ log this.model }}
3
2
<div align =" center" >
4
3
<h1 >Libraries</h1 >
5
4
{{ #each this.model as |lib |}}
6
5
<div style =" padding:10px" >
7
- <LinkTo @route =" library.details" @model ={{ lib.id }} >{{ lib.attributes. name }} </LinkTo >
6
+ <LinkTo @route =" library.details" @model ={{ lib.id }} >{{ lib.name }} </LinkTo >
8
7
</div >
9
8
{{ /each }}
10
9
</div >
Original file line number Diff line number Diff line change 2
2
discoverEmberDataModels ,
3
3
// applyEmberDataSerializers,
4
4
} from 'ember-cli-mirage' ;
5
- import { createServer } from 'miragejs' ;
5
+ import { Response , createServer } from 'miragejs' ;
6
6
7
7
export default function ( config ) {
8
8
let finalConfig = {
@@ -29,20 +29,24 @@ function routes() {
29
29
let id = request . params . id ;
30
30
let bookIds = schema . libraries . find ( id ) . attrs . bookIds ;
31
31
let books = schema . books . find ( bookIds ) ;
32
-
33
- return this . serialize ( books ) ;
32
+ return books ;
34
33
} ) ;
35
34
36
35
this . get ( '/libraries/:id/books/:book_id' , function ( schema , request ) {
37
36
let id = request . params . id ;
38
37
let book_id = request . params . book_id ;
39
38
let bookIds = schema . libraries . find ( id ) . attrs . bookIds ;
39
+
40
40
let book ;
41
- bookIds . forEach ( bookId => {
42
- if ( bookId == book_id ) {
43
- book = schema . books . find ( book_id ) ;
41
+ bookIds . forEach ( ( bookId ) => {
42
+ if ( bookId == book_id ) {
43
+ book = schema . books . find ( book_id ) ;
44
44
}
45
45
} ) ;
46
+
47
+ if ( ! book ) {
48
+ return new Response ( 500 , { } , { error : 'Book not found' } ) ;
49
+ }
46
50
return book ;
47
51
} ) ;
48
52
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- import { JSONAPISerializer } from 'miragejs' ;
1
+ import { RestSerializer } from 'miragejs' ;
2
2
3
- export default JSONAPISerializer . extend ( {
4
- } ) ;
3
+ export default RestSerializer . extend ( { } ) ;
Original file line number Diff line number Diff line change 1
1
import ApplicationSerializer from './application' ;
2
2
3
3
export default ApplicationSerializer . extend ( {
4
- include : [ 'library' ] ,
4
+ // include: ['library'],
5
5
} ) ;
Original file line number Diff line number Diff line change 1
1
import ApplicationSerializer from './application' ;
2
2
3
3
export default ApplicationSerializer . extend ( {
4
- include : [ 'books' ] ,
4
+ // include: ['books'],
5
+
6
+ // serialize(library, request) {
7
+ // // console.log(library);
8
+ // let data = {
9
+ // data: {
10
+ // id: library.id,
11
+ // location: library.location,
12
+ // name: library.name,
13
+ // timing: library.timing
14
+ // }
15
+ // }
16
+ // return data;
17
+ // }
5
18
} ) ;
You can’t perform that action at this time.
0 commit comments