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

included resources are saved on store now #19

Merged
merged 9 commits into from
Jul 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- HttpStorage deprecated: jsons were saved as sent by the server, now we save json with logic (saving ids and resources separately).
- Service with `toServer()` and `fromServer()` functions. They execute before and after http request. Ideal for type conversions.
- `JsonapiCore.duplicateResource(resouce, ...relationtypes)` return a duplication of resource. You can duplicate resources and, optionally, their relationships. (v0.6.16)
- resource save() method return a promise.
- Fix problem with `Possibly unhandled rejection: undefined` with new AngularJs.

## No more declaration file .d.ts

Expand Down
1 change: 1 addition & 0 deletions conf/webpack-dist.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = {
// compress: {unused: true, dead_code: true} // eslint-disable-line camelcase
// })
],
bail: true,
output: {
// https://webpack.github.io/docs/library-and-externals.html
path: path.join(process.cwd(), conf.paths.dist),
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-angular-jsonapi",
"version": "0.6.24",
"version": "0.6.30",
"description": "JSONAPI library developed for AngularJS in Typescript",
"repository": {
"type": "git",
Expand All @@ -10,20 +10,19 @@
"url": "https://github.com/reyesoft/ts-angular-jsonapi/issues"
},
"dependencies": {
"angular": "<1.6.0",
"angular-localforage": "^1.3.0",
"localforage-getitems": "^1.3.0"
"angular": ">=1.4.0",
"angular-localforage": "1.3.7"
},
"devDependencies": {
"@types/angular": "^1.6.6",
"@types/angular": "^1.6.4",
"@types/angular-mocks": "^1.5.9",
"@types/angular-ui-router": "^1.1.36",
"@types/es6-shim": "^0.31.32",
"@types/jasmine": "^2.5.43",
"@types/jquery": "^2.0.40",
"@types/node": "^7.0.5",
"@types/jquery": "^3.2.6",
"@types/node": "^8.0.8",
"angular-mocks": "^1.6.2",
"angular-ui-router": "1.0.0-beta.3",
"angular-ui-router": "1.0.3",
"autoprefixer": "^6.7.3",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.3.2",
Expand All @@ -34,7 +33,7 @@
"declaration-bundler-webpack-plugin": "^1.0.3",
"del": "^2.2.2",
"es6-shim": "^0.35.3",
"eslint": "^3.15.0",
"eslint": "^4.1.1",
"eslint-config-angular": "^0.5.0",
"eslint-config-xo-space": "^0.15.0",
"eslint-loader": "^1.6.1",
Expand Down Expand Up @@ -81,7 +80,7 @@
"ts-loader": "^2.0.0",
"tslint": "^4.4.2",
"tslint-loader": "^3.4.2",
"typescript": "^2.1.0",
"typescript": "^2.4.0",
"webpack": "^2.2.1",
"webpack-fail-plugin": "^1.0.5"
},
Expand Down
27 changes: 12 additions & 15 deletions src/demo/authors/author.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as angular from 'angular';
import 'angular-ui-router';
import * as Jsonapi from '../../library/index';

class AuthorController {
class AuthorController implements ng.IController {
public author: Jsonapi.IResource;
public relatedbooks: Jsonapi.IResource[];

Expand Down Expand Up @@ -31,9 +31,13 @@ class AuthorController {
);
}

/**
public $onInit() {

}

/*
Add a new author
**/
*/
public new() {
let author = this.AuthorsService.new();
author.attributes.name = 'Pablo Reyes';
Expand All @@ -45,9 +49,9 @@ class AuthorController {
// author.save( /* { include: ['book'] } */ );
}

/**
/*
Update name for actual author
**/
*/
public update() {
this.author.attributes.name += 'o';
this.author.save(
Expand All @@ -64,14 +68,7 @@ class AuthorController {
}
}

export const Author = {
templateUrl: 'demo/authors/author.html',
controller: AuthorController
// bindings: {
// completedCount: '<',
// activeCount: '<',
// selectedFilter: '<filter',
// onClearCompleted: '&',
// onShow: '&'
// }
export class Author {
templateUrl = 'demo/authors/author.html';
controller = AuthorController;
};
19 changes: 8 additions & 11 deletions src/demo/authors/authors.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Jsonapi from '../../library/index';

class AuthorsController {
class AuthorsController implements ng.IController {
public authors: Jsonapi.ICollection;

/** @ngInject */
Expand All @@ -19,6 +19,10 @@ class AuthorsController {
);
}

public $onInit() {

}

public delete (author: Jsonapi.IResource) {
console.log('eliminaremos (no soportado en este ejemplo)', author.toObject());
this.AuthorsService.delete(
Expand All @@ -30,14 +34,7 @@ class AuthorsController {
}
}

export const Authors = {
templateUrl: 'demo/authors/authors.html',
controller: AuthorsController
// bindings: {
// completedCount: '<',
// activeCount: '<',
// selectedFilter: '<filter',
// onClearCompleted: '&',
// onShow: '&'
// }
export class Authors {
public templateUrl = 'demo/authors/authors.html';
public controller = AuthorsController;
};
2 changes: 0 additions & 2 deletions src/demo/authors/authors.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="../_all.ts" />

import * as Jsonapi from '../../library/index';

export class AuthorsService extends Jsonapi.Service {
Expand Down
12 changes: 8 additions & 4 deletions src/demo/books/book.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Jsonapi from '../../library/index';

export class BookController {
export class BookController implements ng.IController {
public book: any = null;

/** @ngInject */
Expand All @@ -22,9 +22,13 @@ export class BookController {
}
);
}

public $onInit() {

}
}

export const Book = {
templateUrl: 'demo/books/book.html',
controller: BookController
export class Book {
public templateUrl = 'demo/books/book.html';
public controller = BookController;
};
16 changes: 10 additions & 6 deletions src/demo/books/books.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Jsonapi from '../../library/index';

class BooksController {
class BooksController implements ng.IController {
public books: Jsonapi.ICollection;

/** @ngInject */
Expand All @@ -20,9 +20,9 @@ class BooksController {
this.books = BooksService.all(
{
localfilter: filter,
remotefilter: {
remotefilter: {
date: {
since:'1983-01-01',
since: '1983-01-01',
until: '2010-01-01'
}
},
Expand Down Expand Up @@ -63,12 +63,16 @@ class BooksController {
);
}

public $onInit() {

}

public delete(book: Jsonapi.IResource) {
this.BooksService.delete(book.id);
}
}

export const Books = {
templateUrl: 'demo/books/books.html',
controller: BooksController
export class Books {
public templateUrl = 'demo/books/books.html';
public controller = BooksController;
};
2 changes: 0 additions & 2 deletions src/demo/books/books.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="../_all.ts" />

import * as Jsonapi from '../../library/index';

export class BooksService extends Jsonapi.Service {
Expand Down
20 changes: 14 additions & 6 deletions src/demo/containers/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export class AppController {

class AppController implements ng.IController {
/** @ngInject */
constructor(
protected JsonapiCore,
Expand Down Expand Up @@ -31,10 +30,19 @@ export class AppController {
self.$scope.loading = 'No connection 2!!!';
};
}

public $onInit() {

}
}

export const App = {
templateUrl: 'demo/containers/app.html',
controller: AppController,
transclude: true
export class App implements ng.IComponentOptions {
public templateUrl: string;
public controller: ng.Injectable<ng.IControllerConstructor> = AppController;
public transclude: boolean;

constructor() {
this.templateUrl = 'demo/containers/app.html';
this.transclude = true;
}
};
14 changes: 7 additions & 7 deletions src/demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ angular
.service('AuthorsService', AuthorsService)
.service('BooksService', BooksService)
.service('PhotosService', PhotosService)
.component('app', App)
.component('author', Author)
.component('authors', Authors)
.component('book', Book)
.component('books', Books)
.component('photos', Photos)
.component('noduplicatedcalltests', NoDuplicatedHttpCalls)
.component('app', new App())
.component('author', new Author())
.component('authors', new Authors())
.component('book', new Book())
.component('books', new Books())
.component('photos', new Photos())
.component('noduplicatedcalltests', new NoDuplicatedHttpCalls())
;
12 changes: 8 additions & 4 deletions src/demo/photos/photos.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Jsonapi from '../../library/index';

class PhotosController {
class PhotosController implements ng.IController {
public photos: Jsonapi.ICollection;

/** @ngInject */
Expand All @@ -15,6 +15,10 @@ class PhotosController {
this.makeRequest(5);
}

public $onInit() {

}

public makeRequest(id) {
this.photos = this.PhotosService.all(
succes => {
Expand All @@ -24,7 +28,7 @@ class PhotosController {
}
}

export const Photos = {
templateUrl: 'demo/photos/photos.html',
controller: PhotosController
export class Photos {
public templateUrl = 'demo/photos/photos.html';
public controller = PhotosController;
};
2 changes: 0 additions & 2 deletions src/demo/photos/photos.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="../_all.ts" />

import * as Jsonapi from '../../library/index';

export class PhotosService extends Jsonapi.Service {
Expand Down
12 changes: 8 additions & 4 deletions src/demo/tests/noduplicatedhttpcalls.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Jsonapi from '../../library/index';

class NoDuplicatedHttpCallsComponent {
class NoDuplicatedHttpCallsComponent implements ng.IController {
public authors: Array<Jsonapi.ICollection> = [];

/** @ngInject */
Expand All @@ -19,9 +19,13 @@ class NoDuplicatedHttpCallsComponent {
);
}
}

public $onInit() {

}
}

export const NoDuplicatedHttpCalls = {
templateUrl: 'demo/tests/noduplicatedhttpcalls.html',
controller: NoDuplicatedHttpCallsComponent
export class NoDuplicatedHttpCalls {
public templateUrl = 'demo/tests/noduplicatedhttpcalls.html';
public controller = NoDuplicatedHttpCallsComponent;
};
12 changes: 8 additions & 4 deletions src/library/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import './services/core-services.service';
import { ICore, IResource, ICollection, IService } from './interfaces';

export class Core implements ICore {
private resourceServices: Object = {};
public static me: ICore;
public static injectedServices: {
$q: ng.IQService,
JsonapiStoreService: any,
JsonapiHttp: any,
rsJsonapiConfig: any
};

private resourceServices: Object = {};
public loadingsCounter: number = 0;
public loadingsStart = () => {};
public loadingsDone = () => {};
public loadingsError = () => {};
public loadingsOffline = () => {};

public static me: ICore;
public static injectedServices: any;

/** @ngInject */
public constructor(
protected rsJsonapiConfig,
Expand Down
3 changes: 1 addition & 2 deletions src/library/interfaces/cache.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ICollection, IResource } from '../interfaces';
import { IResource } from '../interfaces';

export interface ICache {
setCollection(url: string, collection: ICollection): void;
setResource(resource: IResource): void;
deprecateCollections(path_start_with: string): boolean;
}
1 change: 1 addition & 0 deletions src/library/interfaces/cachememory.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ICacheMemory extends ICache {

isResourceLive(id: string, ttl: number): boolean;
getOrCreateResource(type: string, id: string): IResource;
setCollection(url: string, collection: ICollection): void;

removeResource(id: string): void;
}
Loading