Skip to content

Commit

Permalink
Merge pull request #34 from Zicrael/dev-branch
Browse files Browse the repository at this point in the history
init v2.5.0
  • Loading branch information
Zicrael authored Jan 15, 2019
2 parents 6d6a1ad + 6742c84 commit 6b372a8
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 21 deletions.
46 changes: 42 additions & 4 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -317,24 +317,61 @@ in you component file:
}
```

### onremoveitem()
Trigger removing action item
### onStartDeleteItem()
Trigger start Deleting action item

#### example

in you template file:

```xml
<lib-ngx-tree-component [treeData]='youTree' (onremoveitem)='onRemoveItem($event)'> </lib-ngx-tree-component>
<lib-ngx-tree-component [treeData]='youTree' (onStartDeleteItem)='onStartDeleteItem($event)'> </lib-ngx-tree-component>
```
in you component file:

```typescript
onRemoveItem(event) {
onStartDeleteItem(event) {
console.log(event);
}
```

### onFinishDeleteItem()
Trigger start Deleting action item

#### example

in you template file:

```xml
<lib-ngx-tree-component [treeData]='youTree' (onFinishDeleteItem)='onFinishDeleteItem($event)'> </lib-ngx-tree-component>
```
in you component file:

```typescript
onFinishDeleteItem(event) {
console.log(event);
}
```

### onCancelDeleteItem()
Trigger start Deleting action item

#### example

in you template file:

```xml
<lib-ngx-tree-component [treeData]='youTree' (onCancelDeleteItem)='onCancelDeleteItem($event)'> </lib-ngx-tree-component>
```
in you component file:

```typescript
onCancelDeleteItem(event) {
console.log(event);
}
```


### 3. Config

You can enable/disable and set some elements on tree by write simple config:
Expand All @@ -354,6 +391,7 @@ in you component file:
showAddButtons: true, // show/hide add button for all elements
showRenameButtons: true, // show/hide rename buttons for all elements
showDeleteButtons: true, // show/hide delete buttons for all elements
showRootActionButtons: true, // shlow/hide root action bottons
enableExpandButtons: true, // // show/hide expand buttons for all elements
enableDragging: true, // enable/disable dragging
rootTitle: 'Root', // Tree titile name
Expand Down
46 changes: 42 additions & 4 deletions projects/ngx-tree-dnd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,24 +317,61 @@ in you component file:
}
```

### onremoveitem()
Trigger removing action item
### onStartDeleteItem()
Trigger start Deleting action item

#### example

in you template file:

```xml
<lib-ngx-tree-component [treeData]='youTree' (onremoveitem)='onRemoveItem($event)'> </lib-ngx-tree-component>
<lib-ngx-tree-component [treeData]='youTree' (onStartDeleteItem)='onStartDelete($event)'> </lib-ngx-tree-component>
```
in you component file:

```typescript
onRemoveItem(event) {
onStartDelete(event) {
console.log(event);
}
```

### onFinishDeleteItem()
Trigger finish deleting action item

#### example

in you template file:

```xml
<lib-ngx-tree-component [treeData]='youTree' (onFinishDeleteItem)='onFinishDelete($event)'> </lib-ngx-tree-component>
```
in you component file:

```typescript
onFinishDelete(event) {
console.log(event);
}
```

### onCancelDeleteItem()
Trigger cancel deleting action item

#### example

in you template file:

```xml
<lib-ngx-tree-component [treeData]='youTree' (onCancelDeleteItem)='onCancelDelete($event)'> </lib-ngx-tree-component>
```
in you component file:

```typescript
onCancelDelete(event) {
console.log(event);
}
```


### 3. Config

You can enable/disable and set some elements on tree by write simple config:
Expand All @@ -354,6 +391,7 @@ in you component file:
showAddButtons: true, // show/hide add button for all elements
showRenameButtons: true, // show/hide rename buttons for all elements
showDeleteButtons: true, // show/hide delete buttons for all elements
showRootActionButtons: true, // shlow/hide root action bottons
enableExpandButtons: true, // // show/hide expand buttons for all elements
enableDragging: true, // enable/disable dragging
rootTitle: 'Root', // Tree titile name
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-tree-dnd/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-tree-dnd",
"version": "2.4.3",
"version": "2.5.0",
"repository": {
"type": "git",
"url": "https://github.com/Zicrael/ngx-tree-dnd"
Expand Down
1 change: 1 addition & 0 deletions projects/ngx-tree-dnd/src/lib/models/tree-view.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface TreeConfig {
showRenameButtons?: boolean;
showDeleteButtons?: boolean;
enableExpandButtons?: boolean;
showRootActionButtons?: boolean;
// actions
enableDragging?: boolean;
rootTitle?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ export class NgxTreeChildrenComponent implements AfterViewInit {
}

/*
Event: onremoveitem;
Events:
onStartDeleteItem,
onFinishDeleteItem,
onCancelDeleteItem.
Check is item edit, then if name empty delete item.
Call deleteItem() from tree service.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{userConfig.rootTitle}}
</div>

<div class='d-flex buttons-bar' *ngIf="userConfig.showActionButtons">
<div class='d-flex buttons-bar' *ngIf="userConfig.showActionButtons && userConfig.showRootActionButtons">
<div class='d-flex'>
<button class="tree-btn add-btn" *ngIf="userConfig.showAddButtons" (click)="submitAdd(null)">
<fa-icon icon="plus" [style.font-size.px]='userConfig.setIconSize'></fa-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class NgxTreeParentComponent implements AfterViewInit {
showAddButtons: true,
showRenameButtons: true,
showDeleteButtons: true,
showRootActionButtons: true,
enableExpandButtons: true,
enableDragging: true,
rootTitle: 'Root',
Expand All @@ -43,7 +44,9 @@ export class NgxTreeParentComponent implements AfterViewInit {
@Output() onadditem: EventEmitter<any> = new EventEmitter();
@Output() onStartRenameItem: EventEmitter<any> = new EventEmitter();
@Output() onFinishRenameItem: EventEmitter<any> = new EventEmitter();
@Output() onremoveitem: EventEmitter<any> = new EventEmitter();
@Output() onStartDeleteItem: EventEmitter<any> = new EventEmitter();
@Output() onFinishDeleteItem: EventEmitter<any> = new EventEmitter();
@Output() onCancelDeleteItem: EventEmitter<any> = new EventEmitter();

@Input()
set config(config: TreeConfig) {
Expand Down Expand Up @@ -122,9 +125,19 @@ export class NgxTreeParentComponent implements AfterViewInit {
this.onFinishRenameItem.emit(event);
}
);
this.treeService.onRemoveItem.subscribe(
this.treeService.onStartDeleteItem.subscribe(
(event) => {
this.onremoveitem.emit(event);
this.onStartDeleteItem.emit(event);
}
);
this.treeService.onFinishDeleteItem.subscribe(
(event) => {
this.onFinishDeleteItem.emit(event);
}
);
this.treeService.onCancelDeleteItem.subscribe(
(event) => {
this.onCancelDeleteItem.emit(event);
}
);
this.treeService.onDragEnter.subscribe(
Expand Down
26 changes: 21 additions & 5 deletions projects/ngx-tree-dnd/src/lib/ngx-tree-dnd.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export class NgxTreeService {
onRenameItem = new Subject<any>();
onStartRenameItem = new Subject<any>();
onFinishRenameItem = new Subject<any>();
onRemoveItem = new Subject<any>();
onStartDeleteItem = new Subject<any>();
onFinishDeleteItem = new Subject<any>();
onCancelDeleteItem = new Subject<any>();
config = new BehaviorSubject<any>(null);
defaulConfig: TreeConfig;

Expand All @@ -42,6 +44,7 @@ export class NgxTreeService {
showAddButtons: true,
showRenameButtons: true,
showDeleteButtons: true,
showRootActionButtons: true,
enableExpandButtons: true,
enableDragging: true,
rootTitle: 'Root',
Expand Down Expand Up @@ -155,17 +158,30 @@ export class NgxTreeService {
/*
Delete element.
It`s accepts 'id' for find item on tree.
Emit onRemoveItem Subject.
Emit onStartDeleteItem Subject before delete.
Emit onFinishDeleteItem Subject after submit delete.
Emit onCancelDeleteItem Subject after on cancel delete.
*/
public deleteItem(id) {
this.elementFinder(this.treeStorage, id);
const eventEmit = {
element: this.findingResults.foundItem,
parent: this.findingResults.parentItem || 'root'
};
this.onRemoveItem.next(eventEmit);
const i = this.findingResults.itemsList.indexOf(this.findingResults.foundItem);
this.findingResults.itemsList.splice(i, 1);
this.onStartDeleteItem.next(eventEmit);
let text: string;
if( this.findingResults.foundItem.name ) {
text = `Do you really want to delete '${this.findingResults.foundItem.name}'?`;
} else {
text = `Cancel creating a new item?`;
}
if(confirm(text)) {
this.onFinishDeleteItem.next(eventEmit);
const i = this.findingResults.itemsList.indexOf(this.findingResults.foundItem);
this.findingResults.itemsList.splice(i, 1);
} else {
this.onCancelDeleteItem.next(eventEmit);
}
this.clearAction();
this.checkTreeLength();
}
Expand Down
11 changes: 10 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<!--The content below is only a placeholder and can be replaced.-->
<div>
<lib-ngx-tree-component [treeData]='myTree' (ondrop)='onDrop($event)' (onStartRenameItem)="onStartRenameItem($event)" (onFinishRenameItem)='onFinishRenameItem($event)' (onremoveitem)='onDelete($event)' (onadditem)='onadditem($event)' [config]='config'>
<lib-ngx-tree-component
[treeData]='myTree'
(ondrop)='onDrop($event)'
(onStartRenameItem)="onStartRenameItem($event)"
(onFinishRenameItem)='onFinishRenameItem($event)'
(onStartDeleteItem)='onStartDelete($event)'
(onFinishDeleteItem)='onFinishDelete($event)'
(onCancelDeleteItem)='onCancelDelete($event)'
(onadditem)='onadditem($event)'
[config]='config'>
</lib-ngx-tree-component>
<div id='eventInfo'></div>
</div>
Expand Down
14 changes: 13 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class AppComponent {
showAddButtons: true,
showRenameButtons: true,
showDeleteButtons: true,
showRootActionButtons: true,
enableExpandButtons: true,
enableDragging: true,
rootTitle: 'My Tree',
Expand Down Expand Up @@ -76,7 +77,18 @@ export class AppComponent {
console.log(this.myTree);
console.log(event);
}
onDelete(event) {
onStartDelete(event) {
console.log('on start delete item');
console.log(this.myTree);
console.log(event);
}
onFinishDelete(event) {
console.log('on finish delete item');
console.log(this.myTree);
console.log(event);
}
onCancelDelete(event) {
console.log('on cancel delete item');
console.log(this.myTree);
console.log(event);
}
Expand Down

0 comments on commit 6b372a8

Please sign in to comment.