Skip to content
This repository was archived by the owner on Aug 18, 2018. It is now read-only.

Commit 70c4cfc

Browse files
authored
Merge pull request #19 from reyesoft/feature/include_resources_now_are_saved
included resources are saved on store now
2 parents a02bcc7 + b41d65f commit 70c4cfc

35 files changed

+7800
-290
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- HttpStorage deprecated: jsons were saved as sent by the server, now we save json with logic (saving ids and resources separately).
1212
- Service with `toServer()` and `fromServer()` functions. They execute before and after http request. Ideal for type conversions.
1313
- `JsonapiCore.duplicateResource(resouce, ...relationtypes)` return a duplication of resource. You can duplicate resources and, optionally, their relationships. (v0.6.16)
14+
- resource save() method return a promise.
15+
- Fix problem with `Possibly unhandled rejection: undefined` with new AngularJs.
1416

1517
## No more declaration file .d.ts
1618

conf/webpack-dist.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module.exports = {
5757
// compress: {unused: true, dead_code: true} // eslint-disable-line camelcase
5858
// })
5959
],
60+
bail: true,
6061
output: {
6162
// https://webpack.github.io/docs/library-and-externals.html
6263
path: path.join(process.cwd(), conf.paths.dist),

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-angular-jsonapi",
3-
"version": "0.6.24",
3+
"version": "0.6.30",
44
"description": "JSONAPI library developed for AngularJS in Typescript",
55
"repository": {
66
"type": "git",
@@ -10,20 +10,19 @@
1010
"url": "https://github.com/reyesoft/ts-angular-jsonapi/issues"
1111
},
1212
"dependencies": {
13-
"angular": "<1.6.0",
14-
"angular-localforage": "^1.3.0",
15-
"localforage-getitems": "^1.3.0"
13+
"angular": ">=1.4.0",
14+
"angular-localforage": "1.3.7"
1615
},
1716
"devDependencies": {
18-
"@types/angular": "^1.6.6",
17+
"@types/angular": "^1.6.4",
1918
"@types/angular-mocks": "^1.5.9",
2019
"@types/angular-ui-router": "^1.1.36",
2120
"@types/es6-shim": "^0.31.32",
2221
"@types/jasmine": "^2.5.43",
23-
"@types/jquery": "^2.0.40",
24-
"@types/node": "^7.0.5",
22+
"@types/jquery": "^3.2.6",
23+
"@types/node": "^8.0.8",
2524
"angular-mocks": "^1.6.2",
26-
"angular-ui-router": "1.0.0-beta.3",
25+
"angular-ui-router": "1.0.3",
2726
"autoprefixer": "^6.7.3",
2827
"babel-eslint": "^7.1.1",
2928
"babel-loader": "^6.3.2",
@@ -34,7 +33,7 @@
3433
"declaration-bundler-webpack-plugin": "^1.0.3",
3534
"del": "^2.2.2",
3635
"es6-shim": "^0.35.3",
37-
"eslint": "^3.15.0",
36+
"eslint": "^4.1.1",
3837
"eslint-config-angular": "^0.5.0",
3938
"eslint-config-xo-space": "^0.15.0",
4039
"eslint-loader": "^1.6.1",
@@ -81,7 +80,7 @@
8180
"ts-loader": "^2.0.0",
8281
"tslint": "^4.4.2",
8382
"tslint-loader": "^3.4.2",
84-
"typescript": "^2.1.0",
83+
"typescript": "^2.4.0",
8584
"webpack": "^2.2.1",
8685
"webpack-fail-plugin": "^1.0.5"
8786
},

src/demo/authors/author.component.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as angular from 'angular';
22
import 'angular-ui-router';
33
import * as Jsonapi from '../../library/index';
44

5-
class AuthorController {
5+
class AuthorController implements ng.IController {
66
public author: Jsonapi.IResource;
77
public relatedbooks: Jsonapi.IResource[];
88

@@ -31,9 +31,13 @@ class AuthorController {
3131
);
3232
}
3333

34-
/**
34+
public $onInit() {
35+
36+
}
37+
38+
/*
3539
Add a new author
36-
**/
40+
*/
3741
public new() {
3842
let author = this.AuthorsService.new();
3943
author.attributes.name = 'Pablo Reyes';
@@ -45,9 +49,9 @@ class AuthorController {
4549
// author.save( /* { include: ['book'] } */ );
4650
}
4751

48-
/**
52+
/*
4953
Update name for actual author
50-
**/
54+
*/
5155
public update() {
5256
this.author.attributes.name += 'o';
5357
this.author.save(
@@ -64,14 +68,7 @@ class AuthorController {
6468
}
6569
}
6670

67-
export const Author = {
68-
templateUrl: 'demo/authors/author.html',
69-
controller: AuthorController
70-
// bindings: {
71-
// completedCount: '<',
72-
// activeCount: '<',
73-
// selectedFilter: '<filter',
74-
// onClearCompleted: '&',
75-
// onShow: '&'
76-
// }
71+
export class Author {
72+
templateUrl = 'demo/authors/author.html';
73+
controller = AuthorController;
7774
};

src/demo/authors/authors.component.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Jsonapi from '../../library/index';
22

3-
class AuthorsController {
3+
class AuthorsController implements ng.IController {
44
public authors: Jsonapi.ICollection;
55

66
/** @ngInject */
@@ -19,6 +19,10 @@ class AuthorsController {
1919
);
2020
}
2121

22+
public $onInit() {
23+
24+
}
25+
2226
public delete (author: Jsonapi.IResource) {
2327
console.log('eliminaremos (no soportado en este ejemplo)', author.toObject());
2428
this.AuthorsService.delete(
@@ -30,14 +34,7 @@ class AuthorsController {
3034
}
3135
}
3236

33-
export const Authors = {
34-
templateUrl: 'demo/authors/authors.html',
35-
controller: AuthorsController
36-
// bindings: {
37-
// completedCount: '<',
38-
// activeCount: '<',
39-
// selectedFilter: '<filter',
40-
// onClearCompleted: '&',
41-
// onShow: '&'
42-
// }
37+
export class Authors {
38+
public templateUrl = 'demo/authors/authors.html';
39+
public controller = AuthorsController;
4340
};

src/demo/authors/authors.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference path="../_all.ts" />
2-
31
import * as Jsonapi from '../../library/index';
42

53
export class AuthorsService extends Jsonapi.Service {

src/demo/books/book.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Jsonapi from '../../library/index';
22

3-
export class BookController {
3+
export class BookController implements ng.IController {
44
public book: any = null;
55

66
/** @ngInject */
@@ -22,9 +22,13 @@ export class BookController {
2222
}
2323
);
2424
}
25+
26+
public $onInit() {
27+
28+
}
2529
}
2630

27-
export const Book = {
28-
templateUrl: 'demo/books/book.html',
29-
controller: BookController
31+
export class Book {
32+
public templateUrl = 'demo/books/book.html';
33+
public controller = BookController;
3034
};

src/demo/books/books.component.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Jsonapi from '../../library/index';
22

3-
class BooksController {
3+
class BooksController implements ng.IController {
44
public books: Jsonapi.ICollection;
55

66
/** @ngInject */
@@ -20,9 +20,9 @@ class BooksController {
2020
this.books = BooksService.all(
2121
{
2222
localfilter: filter,
23-
remotefilter: {
23+
remotefilter: {
2424
date: {
25-
since:'1983-01-01',
25+
since: '1983-01-01',
2626
until: '2010-01-01'
2727
}
2828
},
@@ -63,12 +63,16 @@ class BooksController {
6363
);
6464
}
6565

66+
public $onInit() {
67+
68+
}
69+
6670
public delete(book: Jsonapi.IResource) {
6771
this.BooksService.delete(book.id);
6872
}
6973
}
7074

71-
export const Books = {
72-
templateUrl: 'demo/books/books.html',
73-
controller: BooksController
75+
export class Books {
76+
public templateUrl = 'demo/books/books.html';
77+
public controller = BooksController;
7478
};

src/demo/books/books.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference path="../_all.ts" />
2-
31
import * as Jsonapi from '../../library/index';
42

53
export class BooksService extends Jsonapi.Service {

src/demo/containers/app.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
export class AppController {
2-
1+
class AppController implements ng.IController {
32
/** @ngInject */
43
constructor(
54
protected JsonapiCore,
@@ -31,10 +30,19 @@ export class AppController {
3130
self.$scope.loading = 'No connection 2!!!';
3231
};
3332
}
33+
34+
public $onInit() {
35+
36+
}
3437
}
3538

36-
export const App = {
37-
templateUrl: 'demo/containers/app.html',
38-
controller: AppController,
39-
transclude: true
39+
export class App implements ng.IComponentOptions {
40+
public templateUrl: string;
41+
public controller: ng.Injectable<ng.IControllerConstructor> = AppController;
42+
public transclude: boolean;
43+
44+
constructor() {
45+
this.templateUrl = 'demo/containers/app.html';
46+
this.transclude = true;
47+
}
4048
};

src/demo/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ angular
3333
.service('AuthorsService', AuthorsService)
3434
.service('BooksService', BooksService)
3535
.service('PhotosService', PhotosService)
36-
.component('app', App)
37-
.component('author', Author)
38-
.component('authors', Authors)
39-
.component('book', Book)
40-
.component('books', Books)
41-
.component('photos', Photos)
42-
.component('noduplicatedcalltests', NoDuplicatedHttpCalls)
36+
.component('app', new App())
37+
.component('author', new Author())
38+
.component('authors', new Authors())
39+
.component('book', new Book())
40+
.component('books', new Books())
41+
.component('photos', new Photos())
42+
.component('noduplicatedcalltests', new NoDuplicatedHttpCalls())
4343
;

src/demo/photos/photos.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Jsonapi from '../../library/index';
22

3-
class PhotosController {
3+
class PhotosController implements ng.IController {
44
public photos: Jsonapi.ICollection;
55

66
/** @ngInject */
@@ -15,6 +15,10 @@ class PhotosController {
1515
this.makeRequest(5);
1616
}
1717

18+
public $onInit() {
19+
20+
}
21+
1822
public makeRequest(id) {
1923
this.photos = this.PhotosService.all(
2024
succes => {
@@ -24,7 +28,7 @@ class PhotosController {
2428
}
2529
}
2630

27-
export const Photos = {
28-
templateUrl: 'demo/photos/photos.html',
29-
controller: PhotosController
31+
export class Photos {
32+
public templateUrl = 'demo/photos/photos.html';
33+
public controller = PhotosController;
3034
};

src/demo/photos/photos.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference path="../_all.ts" />
2-
31
import * as Jsonapi from '../../library/index';
42

53
export class PhotosService extends Jsonapi.Service {

src/demo/tests/noduplicatedhttpcalls.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Jsonapi from '../../library/index';
22

3-
class NoDuplicatedHttpCallsComponent {
3+
class NoDuplicatedHttpCallsComponent implements ng.IController {
44
public authors: Array<Jsonapi.ICollection> = [];
55

66
/** @ngInject */
@@ -19,9 +19,13 @@ class NoDuplicatedHttpCallsComponent {
1919
);
2020
}
2121
}
22+
23+
public $onInit() {
24+
25+
}
2226
}
2327

24-
export const NoDuplicatedHttpCalls = {
25-
templateUrl: 'demo/tests/noduplicatedhttpcalls.html',
26-
controller: NoDuplicatedHttpCallsComponent
28+
export class NoDuplicatedHttpCalls {
29+
public templateUrl = 'demo/tests/noduplicatedhttpcalls.html';
30+
public controller = NoDuplicatedHttpCallsComponent;
2731
};

src/library/core.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@ import './services/core-services.service';
33
import { ICore, IResource, ICollection, IService } from './interfaces';
44

55
export class Core implements ICore {
6-
private resourceServices: Object = {};
6+
public static me: ICore;
7+
public static injectedServices: {
8+
$q: ng.IQService,
9+
JsonapiStoreService: any,
10+
JsonapiHttp: any,
11+
rsJsonapiConfig: any
12+
};
713

14+
private resourceServices: Object = {};
815
public loadingsCounter: number = 0;
916
public loadingsStart = () => {};
1017
public loadingsDone = () => {};
1118
public loadingsError = () => {};
1219
public loadingsOffline = () => {};
1320

14-
public static me: ICore;
15-
public static injectedServices: any;
16-
1721
/** @ngInject */
1822
public constructor(
1923
protected rsJsonapiConfig,

src/library/interfaces/cache.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { ICollection, IResource } from '../interfaces';
1+
import { IResource } from '../interfaces';
22

33
export interface ICache {
4-
setCollection(url: string, collection: ICollection): void;
54
setResource(resource: IResource): void;
65
deprecateCollections(path_start_with: string): boolean;
76
}

src/library/interfaces/cachememory.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface ICacheMemory extends ICache {
1010

1111
isResourceLive(id: string, ttl: number): boolean;
1212
getOrCreateResource(type: string, id: string): IResource;
13+
setCollection(url: string, collection: ICollection): void;
1314

1415
removeResource(id: string): void;
1516
}

0 commit comments

Comments
 (0)