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

Commit b9e31e2

Browse files
authored
Merge pull request #23 from qjon/develop
v3.1.0
2 parents 9fffc34 + 68bb632 commit b9e31e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1821
-1528
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ proxy.config.json
4444

4545
.rpt2_cache
4646
/e2e/screenshots/
47+
backend/node_modules

.travis.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ dist: trusty
33
addons:
44
apt:
55
sources:
6-
- google-chrome
6+
- google-chrome
77
packages:
8-
- google-chrome-stable
8+
- google-chrome-stable
99
language: node_js
1010
node_js:
11-
- 6
11+
- 6
1212
before_script:
13-
- export DISPLAY=:99.0
14-
- sh -e /etc/init.d/xvfb start
13+
- export DISPLAY=:99.0
14+
- sh -e /etc/init.d/xvfb start
1515
install:
16-
- npm install
16+
- npm install
1717
script:
18-
- ./node_modules/.bin/webdriver-manager update
19-
- npm run ci
18+
- ./node_modules/.bin/webdriver-manager update
19+
- npm run ci

README.md

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ You need also init translations and animations module, because Tree needs it to
5959
...
6060
BrowserAnimationsModule,
6161
TranslateModule.forRoot(),
62-
TreeModule.forRoot(AppNodeService)
62+
TreeModule.forRoot()
6363
]
6464
})
6565

@@ -69,7 +69,7 @@ In any html file put
6969

7070
<ri-tree [treeModel]="treeModel"></ri-tree>
7171

72-
In component where you create tree, you should initialize _TreeModel_, remember that in configuration object, parameter _treeId_ should be the same as in _AppNodeService_ it allows to use proper API service in each instance of node.
72+
In component where you create tree, you should create _TreeModel_ passing _configuration_ and _AppNodeService_.
7373

7474
export class MyTreeComponent implements OnInit {
7575
public folders: Observable<ITreeData>;
@@ -88,15 +88,18 @@ In component where you create tree, you should initialize _TreeModel_, remember
8888
public treeModel: TreeModel;
8989

9090

91-
public constructor(private treeModelGenerator: TreeModelGeneratorService) {
91+
public constructor(private treeInitializerService: TreeInitializerService,
92+
private appNodeService: AppNodeService) {
9293
}
9394

94-
public ngOnInit() {
95-
this.treeModel = this.treeModelGenerator.createTreeModel(this.treeConfiguration);
95+
public ngOnInit(): void {
96+
const nodes: IOuterNode[] = JSON.parse(localStorage.getItem('treeOne')) || [];
97+
98+
this.treeModel = this.treeInitializerService.init(this.treeConfiguration, this.appNodeService, nodes);
9699
}
97100
}
98101

99-
If function _createTreeModel_ has got second parameter - array of nodes, then the tree will be marked as fully loaded. It will not use _load API_ function to get new subnodes it will use only passed nodes.
102+
If function _init_ has got third parameter - array of nodes, then the tree will be marked as fully loaded. It will not use _load API_ function to get new subnodes it will use only passed nodes.
100103

101104
### CSS Styles
102105

@@ -155,17 +158,24 @@ and _newItem.component.html_
155158
</span>
156159
</div>
157160
</div>
158-
<div class="tree" [@isExpanded]="animationState" (@isExpanded.done)="onAnimationDone($event)">
159-
<div *ngIf="isExpanded">
160-
<new-tree-item *ngFor="let child of children$ | async" [node]="child" [treeModel]="treeModel" [contextMenu]="contextMenu"></new-tree-item>
161-
</div>
161+
<div class="tree" *ngIf="isExpanded" [@expand]>
162+
<ri-tree-item *ngFor="let child of children$ | async" [node]="child; trackBy: trackByFn"
163+
[treeModel]="treeModel"
164+
[isExpanded]="treeModel.isExpanded(child)"
165+
[isSelected]="treeModel.isSelected(child)"
166+
[contextMenu]="contextMenu"></ri-tree-item>
162167
</div>
163168

164169

165170
Then when you create tree component in your application use such construction
166171

167172
<rign-tree [treeModel]="treeModel">
168-
<new-tree-item *ngFor="let node of treeModel.getRootNodes() | async" [node]="node" [treeModel]="treeModel" [contextMenu]="contextMenu"></new-tree-item>
173+
<new-tree-item *ngFor="let node of treeModel.getRootNodes() | async; trackBy: trackByFn"
174+
[node]="node"
175+
[treeModel]="treeModel"
176+
[isSelected]="treeModel.isSelected(node)"
177+
[isExpanded]="treeModel.isExpanded(node)"
178+
[contextMenu]="contextMenu"></new-tree-item>
169179
</rign-tree>
170180

171181
and that is all. Please see Demo where is such example.
@@ -190,24 +200,24 @@ The _treeModel_ value is the same object that is used in _ri-tree_.
190200

191201
Using _ngrx/store_ you can listen on below actions and do whatever you want:
192202

193-
TreeActionsService.TREE_SAVE_NODE
194-
TreeActionsService.TREE_SAVE_NODE_ERROR
195-
TreeActionsService.TREE_SAVE_NODE_SUCCESS
196-
TreeActionsService.TREE_DELETE_NODE
197-
TreeActionsService.TREE_DELETE_NODE_ERROR
198-
TreeActionsService.TREE_DELETE_NODE_SUCCESS
199-
TreeActionsService.TREE_EDIT_NODE_START
200-
TreeActionsService.TREE_EXPAND_NODE
201-
TreeActionsService.TREE_LOAD
202-
TreeActionsService.TREE_LOAD_ERROR
203-
TreeActionsService.TREE_LOAD_SUCCESS
204-
TreeActionsService.TREE_LOAD_PATH
205-
TreeActionsService.TREE_MOVE_NODE
206-
TreeActionsService.TREE_MOVE_NODE_ERROR
207-
TreeActionsService.TREE_MOVE_NODE_SUCCESS
208-
TreeActionsService.TREE_REGISTER
209-
TreeActionsService.TREE_SET_ALL_NODES
210-
TreeActionsService.TREE_SELECT_NODE
203+
TreeActionTypes.TREE_SAVE_NODE
204+
TreeActionTypes.TREE_SAVE_NODE_ERROR
205+
TreeActionTypes.TREE_SAVE_NODE_SUCCESS
206+
TreeActionTypes.TREE_DELETE_NODE
207+
TreeActionTypes.TREE_DELETE_NODE_ERROR
208+
TreeActionTypes.TREE_DELETE_NODE_SUCCESS
209+
TreeActionTypes.TREE_EDIT_NODE_START
210+
TreeActionTypes.TREE_EXPAND_NODE
211+
TreeActionTypes.TREE_LOAD
212+
TreeActionTypes.TREE_LOAD_ERROR
213+
TreeActionTypes.TREE_LOAD_SUCCESS
214+
TreeActionTypes.TREE_LOAD_PATH
215+
TreeActionTypes.TREE_MOVE_NODE
216+
TreeActionTypes.TREE_MOVE_NODE_ERROR
217+
TreeActionTypes.TREE_MOVE_NODE_SUCCESS
218+
TreeActionTypes.TREE_REGISTER
219+
TreeActionTypes.TREE_SET_ALL_NODES
220+
TreeActionTypes.TREE_SELECT_NODE
211221

212222
## Translation
213223

@@ -240,7 +250,7 @@ where:
240250
Then you have to create _@Effects_ similar to that one in _[treeEffects.service](src/store/treeEffects.service.ts)_or create only Observable and subscribe to it.
241251

242252
@Effect() move$ = this.actions$
243-
.ofType(TreeActionsService.TREE_MOVE_NODE)
253+
.ofType(TreeActionTypes.TREE_MOVE_NODE)
244254
.pipe(
245255
filter((action: ITreeAction) => {
246256
return action.payload.sourceOfDroppedData === DragAndDrop.DROP_DATA_TYPE;
@@ -250,7 +260,7 @@ Then you have to create _@Effects_ similar to that one in _[treeEffects.service]
250260
251261
but you have to replace
252262

253-
.ofType(TreeActionsService.TREE_MOVE_NODE)
263+
.ofType(TreeActionTypes.TREE_MOVE_NODE)
254264

255265
to
256266

@@ -260,6 +270,19 @@ At the end do not forget to add this effects to your app.
260270

261271
## Changes
262272

273+
### v3.1.0
274+
* change tree model initialize and injecting NodeService
275+
* add NestJS server with new _TreeTwoNodeBackendService_ angular service to show how Tree works with real backend (details in _Demo_ section)
276+
* actions and reducer
277+
* change events from TreeActionService to TreeActionTypes (the first one will be removed in 4.0.0)
278+
* rewrite actions from one class to many simpler classes
279+
* create one type _TreeAction_ which cover all tree actions
280+
* rewrite _TreeItemComponent_ - improved performance and reduce code
281+
* move information about expanded nodes from _TreeItemComponent_ to _store_, these cause that _isExpanded_ is now _@Input()_ property for _TreeItemComponent_
282+
* _TreeItemComponent_ has new _@Input()_ property _isSelected_
283+
* small changes in expand animation
284+
* fix issue - when add new node parent node was expanded but not loaded
285+
263286
### v3.0.2
264287
* small fixes with interfaces
265288
* fix export CSS styles
@@ -346,6 +369,18 @@ Working demo with _local storage_ you can find [here](https://qjon.github.io/ang
346369
To run Demo locally clone this repository and run
347370

348371
npm start
372+
373+
If you would like to use demo with real API then you have to make small change.
374+
In _demo/srx/app/treeTwo.component.ts_ change injection from _TreeTwoNodeService_ to _TreeTwoNodeBackendService_.
375+
Then run real backend written in NestJS
376+
377+
cd backend
378+
npm install
379+
npm start
380+
381+
and in second terminal run tree application
382+
383+
npm start
349384

350385
## License
351386

backend/.nestcli.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"language": "ts",
3+
"collection": "@nestjs/schematics"
4+
}

backend/.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

backend/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# backend
2+
3+
## Description
4+
5+
Backend for @angular2-tree
6+
7+
## Installation
8+
9+
```bash
10+
$ npm install
11+
```
12+
13+
## Running the app
14+
15+
```bash
16+
# development
17+
$ npm run start
18+
19+
# watch mode
20+
$ npm run start:dev
21+
22+
# production mode
23+
npm run start:prod
24+
```
25+
26+
## Test
27+
28+
```bash
29+
# unit tests
30+
$ npm run test
31+
32+
# e2e tests
33+
$ npm run test:e2e
34+
35+
# test coverage
36+
$ npm run test:cov
37+
```
38+

backend/nodemon.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"watch": [
3+
"src"
4+
],
5+
"ext": "ts",
6+
"ignore": [
7+
"src/**/*.spec.ts"
8+
],
9+
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
10+
}

backend/package.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "backend",
3+
"version": "1.0.0",
4+
"description": "Backend for @angular2-tree",
5+
"author": "Rafał Ignaszewski",
6+
"license": "MIT",
7+
"scripts": {
8+
"format": "prettier --write \"**/*.ts\"",
9+
"start": "ts-node -r tsconfig-paths/register src/main.ts",
10+
"start:dev": "nodemon",
11+
"prestart:prod": "rm -rf dist && tsc",
12+
"start:prod": "node dist/main.js",
13+
"start:hmr": "node dist/server",
14+
"test": "jest",
15+
"test:cov": "jest --coverage",
16+
"test:e2e": "jest --config ./test/jest-e2e.json",
17+
"webpack": "webpack --config webpack.config.js"
18+
},
19+
"dependencies": {
20+
"@nestjs/common": "^5.0.0",
21+
"@nestjs/core": "^5.0.0",
22+
"fastify-formbody": "^2.0.0",
23+
"reflect-metadata": "^0.1.12",
24+
"rxjs": "^6.0.0",
25+
"typescript": "^2.6.2"
26+
},
27+
"devDependencies": {
28+
"@nestjs/testing": "^5.0.0",
29+
"@types/express": "^4.0.39",
30+
"@types/jest": "^21.1.8",
31+
"@types/node": "^9.3.0",
32+
"@types/supertest": "^2.0.4",
33+
"jest": "^21.2.1",
34+
"nodemon": "^1.14.1",
35+
"prettier": "^1.11.1",
36+
"supertest": "^3.0.0",
37+
"ts-jest": "^21.2.4",
38+
"ts-loader": "^4.1.0",
39+
"ts-node": "^4.1.0",
40+
"tsconfig-paths": "^3.1.1",
41+
"tslint": "5.3.2",
42+
"webpack": "^4.2.0",
43+
"webpack-cli": "^2.0.13",
44+
"webpack-node-externals": "^1.6.0"
45+
},
46+
"jest": {
47+
"moduleFileExtensions": [
48+
"js",
49+
"json",
50+
"ts"
51+
],
52+
"rootDir": "src",
53+
"testRegex": ".spec.ts$",
54+
"transform": {
55+
"^.+\\.(t|j)s$": "ts-jest"
56+
},
57+
"coverageDirectory": "../coverage"
58+
}
59+
}

backend/src/app.module.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Module} from '@nestjs/common';
2+
import {TreeModule} from './tree/tree.module';
3+
4+
@Module({
5+
imports: [TreeModule],
6+
controllers: [],
7+
providers: [],
8+
})
9+
export class AppModule {
10+
}

backend/src/app.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Injectable } from '@nestjs/common';
2+
3+
@Injectable()
4+
export class AppService {
5+
root(): string {
6+
return 'Hello World!';
7+
}
8+
}

backend/src/main.hmr.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NestFactory } from '@nestjs/core';
2+
import { AppModule } from './app.module';
3+
4+
declare const module: any;
5+
6+
async function bootstrap() {
7+
const app = await NestFactory.create(AppModule);
8+
await app.listen(3000);
9+
10+
if (module.hot) {
11+
module.hot.accept();
12+
module.hot.dispose(() => app.close());
13+
}
14+
}
15+
bootstrap();

backend/src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NestFactory } from '@nestjs/core';
2+
import { AppModule } from './app.module';
3+
4+
async function bootstrap() {
5+
const app = await NestFactory.create(AppModule);
6+
await app.listen(3000);
7+
}
8+
bootstrap();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { TreeDataService } from './tree-data.service';
3+
4+
describe('TreeDataService', () => {
5+
let service: TreeDataService;
6+
beforeAll(async () => {
7+
const module: TestingModule = await Test.createTestingModule({
8+
providers: [TreeDataService],
9+
}).compile();
10+
service = module.get<TreeDataService>(TreeDataService);
11+
});
12+
it('should be defined', () => {
13+
expect(service).toBeDefined();
14+
});
15+
});

0 commit comments

Comments
 (0)