-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
272 additions
and
39 deletions.
There are no files selected for viewing
36 changes: 22 additions & 14 deletions
36
projects/ngx-explorer/src/lib/components/explorer/explorer.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
<div class="nxe-explorer-container"> | ||
<nxe-menu-bar></nxe-menu-bar> | ||
<nxe-second-menu-bar></nxe-second-menu-bar> | ||
<div class="nxe-explorer-view-container"> | ||
|
||
<ng-container *ngIf="view === avialableView.Icon"> | ||
<nxe-icons></nxe-icons> | ||
</ng-container> | ||
|
||
<ng-container *ngIf="view === avialableView.List"> | ||
<nxe-list></nxe-list> | ||
</ng-container> | ||
|
||
<div class="nxe-explorer"> | ||
<div class="nxe-eplorer-menu"> | ||
<nxe-menu-bar></nxe-menu-bar> | ||
</div> | ||
</div> | ||
<div class="nxe-explorer-containers"> | ||
<div class="nxe-explorer-left-container"> | ||
<nxe-tree></nxe-tree> | ||
</div> | ||
<div class="nxe-explorer-right-container"> | ||
<div class="nxe-explorer-right-menu"> | ||
<nxe-second-menu-bar></nxe-second-menu-bar> | ||
</div> | ||
<div class="nxe-explorer-right-content"> | ||
<ng-container *ngIf="view === avialableView.Icon"> | ||
<nxe-icons></nxe-icons> | ||
</ng-container> | ||
<ng-container *ngIf="view === avialableView.List"> | ||
<nxe-list></nxe-list> | ||
</ng-container> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
34 changes: 31 additions & 3 deletions
34
projects/ngx-explorer/src/lib/components/explorer/explorer.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
.nxe-explorer-container { | ||
.nxe-explorer { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
border: 1px solid #ccc; | ||
} | ||
|
||
.nxe-eplorer-menu { | ||
border-bottom: 1px solid #ccc; | ||
} | ||
|
||
.nxe-explorer-containers { | ||
display: flex; | ||
flex-wrap: wrap; | ||
height: 100%; | ||
} | ||
|
||
.nxe-explorer-left-container { | ||
flex-basis: 20rem; | ||
flex-grow: 1; | ||
border-right: 1px solid #ccc; | ||
} | ||
|
||
.nxe-explorer-right-container { | ||
display: flex; | ||
flex-direction: column; | ||
flex-basis: 0; | ||
flex-grow: 999; | ||
} | ||
|
||
.nxe-explorer-right-menu { | ||
border-bottom: 1px solid #ccc; | ||
} | ||
|
||
.nxe-explorer-view-container { | ||
.nxe-explorer-right-content { | ||
flex-grow: 1; | ||
overflow: auto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
projects/ngx-explorer/src/lib/components/menu-bar/menu-bar.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
projects/ngx-explorer/src/lib/components/second-menu-bar/second-menu-bar.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
projects/ngx-explorer/src/lib/components/tree/tree.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="nxe-tree"> | ||
<ng-container *ngTemplateOutlet="tree;context:{nodes:treeNodes}"> | ||
</ng-container> | ||
</div> | ||
|
||
<ng-template #tree let-nodes="nodes"> | ||
<ul *ngIf="nodes && nodes.length > 0"> | ||
<li *ngFor="let node of nodes"> | ||
<div class="chevron" *ngIf="!node.expanded" (click)="expand(node)"><i class="fa fa-angle-right" aria-hidden="true"></i></div> | ||
<div class="chevron" *ngIf="node.expanded" (click)="collapse(node)"><i class="fa fa-angle-down" aria-hidden="true"></i></div> | ||
|
||
<div class="item" (dblclick)="open(node)"> | ||
<div class="folder-icon"><i class="fa fa-folder-o" aria-hidden="true"></i></div> | ||
<div class="grow" [innerText]="getName(node.data)"></div> | ||
<!-- <div class="ellipsis-icon"><i class="fa fa-ellipsis-v" aria-hidden="true"></i></div> --> | ||
<div class="highlighter"></div> | ||
</div> | ||
|
||
<ng-container *ngTemplateOutlet="tree;context:{nodes:node.children}"> | ||
</ng-container> | ||
</li> | ||
</ul> | ||
</ng-template> |
46 changes: 46 additions & 0 deletions
46
projects/ngx-explorer/src/lib/components/tree/tree.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
$item-spacing: 10px; | ||
|
||
.nxe-tree { | ||
ul { | ||
list-style-position: inside; | ||
padding: 0; | ||
margin: 0; | ||
margin-left: 20px; | ||
} | ||
|
||
li { | ||
list-style-type: none; | ||
position: relative; | ||
padding: 0; | ||
} | ||
|
||
.chevron { | ||
position: absolute; | ||
cursor: pointer; | ||
text-align: center; | ||
color: #333; | ||
width: 21px; | ||
top: 1px; | ||
left: -20px; | ||
font-size: 1.3rem; | ||
} | ||
|
||
.item { | ||
display: flex; | ||
cursor: pointer; | ||
padding: 5px 5px; | ||
border-radius: 5px; | ||
|
||
.folder-icon { | ||
margin-right: 5px; | ||
} | ||
|
||
.grow { | ||
flex: 1; | ||
} | ||
|
||
&:hover { | ||
background-color: #d7edff; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
projects/ngx-explorer/src/lib/components/tree/tree.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { TreeComponent } from './tree.component'; | ||
|
||
describe('TreeComponent', () => { | ||
let component: TreeComponent; | ||
let fixture: ComponentFixture<TreeComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ TreeComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TreeComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
85 changes: 85 additions & 0 deletions
85
projects/ngx-explorer/src/lib/components/tree/tree.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Component, OnDestroy, ViewEncapsulation } from '@angular/core'; | ||
import { XNode } from 'ngx-explorer'; | ||
import { ExplorerService } from '../../services/explorer.service'; | ||
import { filter } from 'rxjs/operators'; | ||
import { HelperService } from '../../services/helper.service'; | ||
import { Subscription } from 'rxjs'; | ||
|
||
interface TreeNode extends XNode { | ||
children: TreeNode[]; | ||
expanded: boolean; | ||
} | ||
|
||
@Component({ | ||
selector: 'nxe-tree', | ||
templateUrl: './tree.component.html', | ||
styleUrls: ['./tree.component.scss'], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class TreeComponent implements OnDestroy { | ||
public treeNodes: any = []; | ||
private expandedIds: string[] = []; | ||
private sub = new Subscription(); | ||
|
||
constructor(private explorerService: ExplorerService, private helperService: HelperService) { | ||
this.sub.add(this.explorerService.tree.pipe(filter(x => !!x)).subscribe(node => { | ||
this.addExpandedNode(node.id); // always expand root | ||
this.treeNodes = this.buildTree(node).children; | ||
})); | ||
} | ||
|
||
open(node: XNode) { | ||
this.addExpandedNode(node.id); | ||
this.explorerService.openNode(node.id); | ||
} | ||
|
||
expand(node: XNode) { | ||
this.addExpandedNode(node.id); | ||
this.explorerService.expandNode(node.id); | ||
} | ||
|
||
collapse(node: XNode) { | ||
this.removeExpandedNode(node.id); | ||
let nodes: XNode; | ||
this.explorerService.tree.pipe(filter(x => !!x)).subscribe(x => nodes = x); | ||
this.treeNodes = this.buildTree(nodes).children; | ||
} | ||
|
||
getName(node: XNode) { | ||
return this.helperService.getName(node); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.sub.unsubscribe(); | ||
} | ||
|
||
private buildTree(node: XNode): TreeNode { | ||
const treeNode = { | ||
id: node.id, | ||
parentId: node.parentId, | ||
data: node.data, | ||
isLeaf: node.isLeaf, | ||
children: [], | ||
expanded: false | ||
} as TreeNode; | ||
|
||
treeNode.expanded = this.expandedIds.indexOf(node.id) > -1; | ||
if (treeNode.expanded) { | ||
treeNode.children = node.children.filter(x => !x.isLeaf).map(x => this.buildTree(x)); | ||
} | ||
return treeNode; | ||
} | ||
|
||
private addExpandedNode(id: string) { | ||
const index = this.expandedIds.indexOf(id); | ||
if (index === -1) { | ||
this.expandedIds.push(id); | ||
} | ||
} | ||
|
||
private removeExpandedNode(id: string) { | ||
const index = this.expandedIds.indexOf(id); | ||
this.expandedIds.splice(index, 1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.