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

Commit 5c875bf

Browse files
authored
Merge pull request #7 from qjon/develop
v2.1.0
2 parents 6f20069 + c39a6e4 commit 5c875bf

35 files changed

+1349
-149
lines changed

.angular-cli.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
33
"project": {
4-
"version": "1.0.0-beta.32.3",
4+
"version": "2.1.0",
55
"name": "angular2-tree"
66
},
77
"apps": [

README.md

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## Usage
99

10-
Include _TreeModule_ in your application module and create Store
10+
Include _TreeModule_ in your application module and create Store
1111

1212
import {TreeModule} from '@rign/angular2-tree/main';
1313

@@ -22,6 +22,22 @@ Include _TreeModule_ in your application module and create Store
2222
]
2323
})
2424

25+
You need also init translations module, because Tree needs it to translate all labels.
26+
27+
@NgModule({
28+
declarations: [
29+
...
30+
],
31+
imports: [
32+
...
33+
TranslationModule.forRoot(),
34+
TreeModule,
35+
StoreModule.provideStore({trees: treeReducer})
36+
]
37+
})
38+
39+
More information about translations you can find below in section _Translation_.
40+
2541
In any html file put
2642

2743
<rign-tree [treeModel]="treeModel"></rign-tree>
@@ -53,7 +69,8 @@ In component where you create tree, you should register _tree store_, create _Tr
5369
disableMoveNodes: false,
5470
treeId: 'tree3',
5571
dragZone: 'tree3',
56-
dropZone: ['tree3']
72+
dropZone: ['tree3'],
73+
isAnimation: true // add animation to action "expand" and "collapse"
5774
};
5875

5976
public treeModel: TreeModel;
@@ -102,7 +119,7 @@ and _newItem.component.html_
102119
ri-draggable
103120
[dragZone]="treeModel.configuration.dragZone"
104121
[dropConfig]="{dropAllowedCssClass: 'drop-enabled', dropZone: treeModel.configuration.dropZone}"
105-
[node]="node"
122+
[data]="node"
106123
>
107124
<div class="col-sm-8">
108125
<i *ngIf="!isExpanded" (click)="expand()" class="fa fa-plus pointer"></i>
@@ -124,8 +141,10 @@ and _newItem.component.html_
124141
</span>
125142
</div>
126143
</div>
127-
<div class="tree" *ngIf="isExpanded">
128-
<new-tree-item *ngFor="let child of children$ | async" [node]="child" [treeModel]="treeModel" [contextMenu]="contextMenu"></new-tree-item>
144+
<div class="tree" [@isExpanded]="animationState" (@isExpanded.done)="onAnimationDone($event)">
145+
<div *ngIf="isExpanded">
146+
<new-tree-item *ngFor="let child of children$ | async" [node]="child" [treeModel]="treeModel" [contextMenu]="contextMenu"></new-tree-item>
147+
</div>
129148
</div>
130149

131150

@@ -157,9 +176,61 @@ Using _ngrx/store_ you can listen on below actions and do whatever you want:
157176
TreeActionsService.TREE_MOVE_NODE_ERROR
158177
TreeActionsService.TREE_REGISTER
159178

179+
## Translation
180+
181+
Tree module has configured translation for english (default language) and polish. You can add translations for other languages as it is described in [Translate Module](https://github.com/ngx-translate/core/blob/master/README.md) documentation.
182+
In _Tree Module_ you are able to set following labels:
183+
184+
* RI_TREE_LBL_ADD_NODE - Add node
185+
* RI_TREE_LBL_EDIT_NODE - Edit node
186+
* RI_TREE_LBL_REMOVE_NODE - Delete node
187+
* RI_TREE_LBL_DROP_ZONE - Drop here to move node to root level
188+
189+
To change language to polish you have to add these lines to your app module:
190+
191+
export class AppModule {
192+
public constructor(translate: TranslateService) {
193+
translate.use('pl');
194+
}
195+
}
196+
197+
## Drop elements on tree node
198+
199+
Now you have new possibilities to move different elements to the tree (files or other data). To do that, you have to use _ri-draggable_ directive in following way
200+
201+
<div ri-draggable [dragZone]="treeModel.configuration.dragZone" [data]="your_data" [sourceType]="'YOUR_SOURCE_TYPE'">Drag element</div>
202+
203+
where:
204+
* _your_data_ - is any object
205+
* _YOUR_SOURCE_TYPE_ - is any type of string which allow you to filter drop effect
206+
207+
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.
208+
209+
@Effect() move$ = this.actions$
210+
.ofType(TreeActionsService.TREE_MOVE_NODE)
211+
.filter((action: ITreeAction) => {
212+
return action.payload.sourceOfDroppedData === DragAndDrop.DROP_DATA_TYPE;
213+
})
214+
...
215+
216+
but you have to replace
217+
218+
.ofType(TreeActionsService.TREE_MOVE_NODE)
219+
220+
to
221+
222+
.ofType('YOUR_SOURCE_TYPE')
223+
224+
At the end do not forget to add this effects to your app.
160225

161226
## Changes
162227

228+
### v2.1.0
229+
* add translation module
230+
* drop elements on tree nodes
231+
* update and lock of some npm package versions
232+
* add possibility to animate action _collapse_ and _expand_ nodes of tree, using in configuration property _isAnimation: true_
233+
163234
### v2.0.1
164235
* add [MIT LICENSE](https://github.com/qjon/angular2-tree/blob/master/LICENSE)
165236

@@ -210,11 +281,6 @@ Using _ngrx/store_ you can listen on below actions and do whatever you want:
210281
* primary version with all features described below.
211282

212283

213-
## Demo
214-
215-
Working demo with _local storage_ you can find [here](https://qjon.github.io/angular2-tree/).
216-
217-
218284
## Demo
219285

220286
Working demo with _local storage_ you can find [here](https://qjon.github.io/angular2-tree/).

demo/src/app/app.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {TreeTwoModule} from './treeTwo/treeTwo.module';
88
import {StoreModule} from '@ngrx/store';
99
import {treeReducer} from '../../../main';
1010
import {StoreDevtoolsModule} from '@ngrx/store-devtools';
11+
import {TranslateModule, TranslateService} from '@ngx-translate/core';
1112

1213
@NgModule({
1314
declarations: [
@@ -19,6 +20,7 @@ import {StoreDevtoolsModule} from '@ngrx/store-devtools';
1920
HttpModule,
2021
TreeTwoModule,
2122
TreeOneModule,
23+
TranslateModule.forRoot(),
2224
StoreModule.provideStore({trees: treeReducer}),
2325
StoreDevtoolsModule.instrumentOnlyWithExtension({})
2426
],
@@ -27,4 +29,7 @@ import {StoreDevtoolsModule} from '@ngrx/store-devtools';
2729
})
2830
export class AppModule {
2931

32+
public constructor(translate: TranslateService) {
33+
translate.use('en');
34+
}
3035
}

demo/src/app/treeOne/treeOne.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export class TreeOneComponent implements OnInit {
1818
disableMoveNodes: false,
1919
treeId: 'tree3',
2020
dragZone: 'tree3',
21-
dropZone: ['tree3']
21+
dropZone: ['tree3'],
22+
isAnimation: true
2223
};
2324

2425
public treeModel: TreeModel;

demo/src/app/treeTwo/newItem.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ri-draggable
55
[dragZone]="treeModel.configuration.dragZone"
66
[dropConfig]="{dropAllowedCssClass: 'drop-enabled', dropZone: treeModel.configuration.dropZone}"
7-
[node]="node"
7+
[data]="node"
88
>
99
<div class="col-sm-8">
1010
<i *ngIf="!isExpanded" (click)="expand()" class="fa fa-plus pointer"></i>

karma.conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = function (config) {
66
basePath: '',
77
frameworks: ['jasmine', '@angular/cli'],
88
plugins: [
9+
require('karma-jasmine-diff-reporter'),
910
require('karma-jasmine'),
1011
require('karma-chrome-launcher'),
1112
require('karma-jasmine-html-reporter'),
@@ -22,7 +23,7 @@ module.exports = function (config) {
2223
angularCli: {
2324
environment: 'dev'
2425
},
25-
reporters: ['progress', 'kjhtml'],
26+
reporters: ['progress', 'kjhtml', 'jasmine-diff'],
2627
port: 9876,
2728
colors: true,
2829
logLevel: config.LOG_INFO,

main.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ import {ITreeState, ITreeData, ITreeAction} from './src/store/ITreeState';
1515
import {treeReducer} from './src/store/treeReducer';
1616
export {
1717
IApiConfig,
18-
TreeModule,
19-
TreeComponent,
20-
ItemComponent,
21-
NodeService,
22-
NodeDispatcherService,
23-
TreeModel,
2418
IAppConfig,
2519
IConfiguration,
2620
IContextMenu,
2721
IOuterNode,
22+
ItemComponent,
23+
ITreeAction,
2824
ITreeData,
2925
ITreeState,
30-
ITreeAction,
26+
NodeService,
27+
NodeDispatcherService,
3128
TreeActionsService,
29+
TreeComponent,
3230
TreeEffectsService,
33-
treeReducer
31+
treeReducer,
32+
TreeModel,
33+
TreeModule,
3434
}

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rign/angular2-tree",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"license": "MIT",
55
"angular-cli": {},
66
"scripts": {
@@ -9,7 +9,7 @@
99
"lint": "ng lint",
1010
"e2e": "ng e2e",
1111
"test": "./node_modules/.bin/karma --config karma.conf.js start",
12-
"gh-pages" : "ng build --env=prod --base-href \"https://qjon.github.io/angular2-tree/\" && ./node_modules/.bin/angular-cli-ghpages -b gh-pages --name=\"Rafał Ignaszewski\" --email=\"[email protected]\" --no-silent"
12+
"gh-pages": "ng build --env=prod --base-href \"https://qjon.github.io/angular2-tree/\" && ./node_modules/.bin/angular-cli-ghpages -b gh-pages --name=\"Rafał Ignaszewski\" --email=\"[email protected]\" --no-silent"
1313
},
1414
"repository": {
1515
"type": "git",
@@ -27,20 +27,21 @@
2727
"@angular/platform-browser": "^4.0.0",
2828
"@angular/platform-browser-dynamic": "^4.0.0",
2929
"@angular/router": "^4.0.0",
30-
"zone.js": "^0.8.4",
3130
"@ngrx/core": "^1.2.0",
3231
"@ngrx/effects": "^2.0.3",
33-
"core-js": "^2.4.1",
3432
"@ngrx/store": "^2.2.2",
33+
"@ngx-translate/core": "^8.0.0",
3534
"angular2-contextmenu": "^0.7.7",
3635
"angular2-uuid": "^1.1.1",
3736
"bootstrap": "^3.3.7",
37+
"core-js": "^2.4.1",
3838
"font-awesome": "^4.6.3",
3939
"ng2-dnd": "^2.2.2",
40-
"rxjs": "^5.1.0"
40+
"rxjs": "^5.1.0",
41+
"zone.js": "^0.8.4"
4142
},
4243
"devDependencies": {
43-
"@angular/cli": "1.2.0",
44+
"@angular/cli": "1.4.4",
4445
"@angular/compiler-cli": "^4.0.0",
4546
"@angular/language-service": "^4.0.0",
4647
"@ngrx/store-devtools": "^3.2.4",
@@ -56,10 +57,11 @@
5657
"karma-cli": "~1.0.1",
5758
"karma-coverage-istanbul-reporter": "^1.2.1",
5859
"karma-jasmine": "~1.1.0",
60+
"karma-jasmine-diff-reporter": "^1.1.1",
5961
"karma-jasmine-html-reporter": "^0.2.2",
6062
"protractor": "~5.1.2",
6163
"ts-node": "~3.0.4",
62-
"tslint": "~5.3.2",
63-
"typescript": "~2.3.3"
64+
"tslint": "~5.7.0",
65+
"typescript": "~2.5.2"
6466
}
6567
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import {DragAndDrop} from './dragAndDrop.service';
2+
import {IDragElement, IDropElement} from '../interfaces/IDragAndDrop';
3+
4+
describe('DragAndDrop', () => {
5+
let service: DragAndDrop;
6+
let dragElement: IDragElement;
7+
let dropElement: IDropElement;
8+
9+
beforeEach(() => {
10+
service = new DragAndDrop();
11+
12+
dragElement = {
13+
zoneId: 'tree',
14+
data: {some: 'data'},
15+
type: DragAndDrop.DROP_DATA_TYPE
16+
};
17+
18+
dropElement = {
19+
zones: ['tree'],
20+
data: {id: 'data-id'}
21+
};
22+
});
23+
24+
describe('static data', () => {
25+
it('DROP_DATA_TYPE should be set to "TREE_NODE"', () => {
26+
expect(DragAndDrop.DROP_DATA_TYPE).toBe('TREE_NODE');
27+
});
28+
});
29+
30+
describe('dragStart', () => {
31+
it('should emit new drag element', () => {
32+
const handler = jasmine.createSpy('handler');
33+
34+
service.getDragStream()
35+
.subscribe(handler);
36+
37+
service.dragStart(dragElement);
38+
39+
expect(handler).toHaveBeenCalledWith(dragElement);
40+
});
41+
});
42+
43+
describe('dragEnd', () => {
44+
it('should emit drop element', () => {
45+
const handler = jasmine.createSpy('handler');
46+
47+
service.drop$
48+
.subscribe(handler);
49+
50+
service.dragStart(dragElement);
51+
service.dragEnd(dropElement);
52+
53+
expect(handler).toHaveBeenCalledWith({
54+
dragNode: dragElement,
55+
dropNode: dropElement,
56+
type: DragAndDrop.DROP_DATA_TYPE
57+
});
58+
});
59+
});
60+
61+
describe('getLastDragElement', () => {
62+
it('should return last dragged element', () => {
63+
service.dragStart(dragElement);
64+
65+
expect(service.getLastDragElement()).toEqual(dragElement);
66+
});
67+
});
68+
69+
});

0 commit comments

Comments
 (0)