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

Commit c7ee27c

Browse files
authored
Merge pull request #16 from reyesoft/feature/mergin_relationships
Feature/mergin relationships
2 parents 8857657 + f01d28f commit c7ee27c

33 files changed

+607
-517
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-angular-jsonapi",
3-
"version": "0.4.15",
3+
"version": "0.5.12",
44
"description": "JSONAPI library developed for AngularJS in Typescript",
55
"repository": {
66
"type": "git",
@@ -51,7 +51,6 @@
5151
"gulp-typescript": "^2.13.6",
5252
"gulp-util": "^3.0.7",
5353
"html-webpack-plugin": "^2.9.0",
54-
"isparta-loader": "^2.0.0",
5554
"jasmine": "^2.4.1",
5655
"json-loader": "^0.5.4",
5756
"karma": "^0.13.14",

src/demo/authors/authors.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
export class AuthorsService extends Jsonapi.Resource {
5+
export class AuthorsService extends Jsonapi.Service {
66
type = 'authors';
77
public schema: Jsonapi.ISchema = {
88
attributes: {

src/demo/books/books.component.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ class BooksController {
3232
},
3333
success => {
3434
console.log('success books controller', success, this.books);
35+
36+
// TEST 1
37+
// this test merge data with cache (this not include author or photos)
38+
console.log('BooksRequest#1 received (author data from server)',
39+
(<Jsonapi.IResource>this.books[2].relationships.author.data).attributes
40+
);
41+
42+
console.log('BooksRequest#2 requested');
43+
let books2 = this.BooksService.all(
44+
success => {
45+
console.log('BooksRequest#2 received (author data from cache)',
46+
(<Jsonapi.IResource>books2[1].relationships.author.data)
47+
);
48+
}
49+
);
50+
51+
// TEST 2
52+
console.log('BookRequest#3 requested');
53+
let book1 = this.BooksService.get(1,
54+
success => {
55+
console.log('BookRequest#3 received (author data from cache)',
56+
(<Jsonapi.IResource>book1.relationships.author.data).attributes
57+
);
58+
});
3559
},
3660
error => {
3761
console.log('error books controller', error);

src/demo/books/books.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
export class BooksService extends Jsonapi.Resource {
5+
export class BooksService extends Jsonapi.Service {
66
type = 'books';
77
public schema: Jsonapi.ISchema = {
88
attributes: {

src/demo/photos/photos.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
export class PhotosService extends Jsonapi.Resource {
5+
export class PhotosService extends Jsonapi.Service {
66
type = 'photos';
77
public schema: Jsonapi.ISchema = {
88
attributes: {

src/library/core.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
1-
/// <reference path="./index.d.ts" />
2-
31
import './services/core-services.service';
4-
import { ICore, IResource } from './interfaces';
2+
import { ICore, IService } from './interfaces';
53

64
export class Core implements ICore {
7-
public rootPath: string = 'http://url/';
8-
public resources: Object = {};
5+
private resourceServices: Object = {};
96

107
public loadingsCounter: number = 0;
118
public loadingsStart = () => {};
129
public loadingsDone = () => {};
1310
public loadingsError = () => {};
1411
public loadingsOffline = () => {};
1512

16-
public static Me: ICore = null;
17-
public static Services: any = null;
13+
public static me: ICore;
14+
public static injectedServices: any;
1815

1916
/** @ngInject */
2017
public constructor(
2118
protected rsJsonapiConfig,
2219
protected JsonapiCoreServices
2320
) {
24-
Core.Me = this;
25-
Core.Services = JsonapiCoreServices;
21+
Core.me = this;
22+
Core.injectedServices = JsonapiCoreServices;
2623
}
2724

28-
public _register(clase: IResource): boolean {
29-
if (clase.type in this.resources) {
25+
public _register(clase: IService): boolean {
26+
if (clase.type in this.resourceServices) {
3027
return false;
3128
}
32-
this.resources[clase.type] = clase;
29+
this.resourceServices[clase.type] = clase;
3330
return true;
3431
}
3532

36-
public getResource(type: string): IResource {
37-
return this.resources[type];
33+
public getResourceService(type: string): IService {
34+
return this.resourceServices[type];
3835
}
3936

4037
public refreshLoadings(factor: number): void {
@@ -46,4 +43,5 @@ export class Core implements ICore {
4643
}
4744
}
4845
}
46+
4947
angular.module('Jsonapi.services').service('JsonapiCore', Core);

src/library/index.ts

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

@@ -26,12 +24,15 @@ angular.module('rsJsonapi', [
2624
]);
2725

2826
import { Core } from './core';
27+
import { Service } from './service';
2928
import { Resource } from './resource';
3029

3130
// just for bootstrap this library on demo.
3231
// On dist version, all is exported inside a Jsonapi module
3332
export { Core };
3433
export { Resource };
34+
export { Service };
35+
3536
export * from './interfaces';
3637
import { IResource } from './interfaces';
3738
import { IService } from './interfaces';
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
export interface IAttributes {
2-
[value: string]: boolean | string | number;
2+
// problem with lines like
3+
/*
4+
this._receipt_number = order.attributes.receipt_number;
5+
this.transaction.attributes._due_date_with_format = new Date(this.transaction.attributes.due_date);
6+
*/
7+
// [value: string]: boolean | string | number;
8+
[value: string]: any;
39
}

src/library/interfaces/cache.d.ts

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

33
export interface ICache {
44
// collections: Object;
@@ -8,7 +8,10 @@ export interface ICache {
88
isCollectionLive(url: string, ttl: number): boolean;
99
getCollection(url: string): ICollection;
1010
setCollection(url: string, collection: ICollection): void;
11-
clearAllCollections(): void;
11+
clearAllCollections(): boolean;
12+
isResourceLive(id: string, ttl: number): boolean;
13+
setResource(resource: IResource): void;
14+
getCollection(url: string): ICollection;
1215

1316
removeResource(id: string): void;
1417
}

src/library/interfaces/collection.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IResource } from './resource';
22
import { IPage } from './page';
3+
import { IDataResource } from './data-resource';
34

45
export interface ICollection extends Array<IResource> {
56
$length: number;

0 commit comments

Comments
 (0)