Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
feat: implement config root node name
Browse files Browse the repository at this point in the history
  • Loading branch information
artemnih committed Oct 31, 2022
1 parent 7074673 commit d415650
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Directive, Inject, OnDestroy } from '@angular/core';
import { BehaviorSubject, Subscription } from 'rxjs';
import { INode } from '../../common/types';
import { FILTER_STRING } from '../../injection-tokens/current-view.token';
import { INode } from '../../shared/types';
import { FILTER_STRING } from '../../injection-tokens/tokens';
import { ExplorerService } from '../../services/explorer.service';
import { HelperService } from '../../services/helper.service';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, OnDestroy, ViewEncapsulation } from '@angular/core';
import { Subscription } from 'rxjs';
import { INode } from '../../common/types';
import { INode } from '../../shared/types';
import { ExplorerService } from '../../services/explorer.service';
import { HelperService } from '../../services/helper.service';
import { ConfigProvider } from '../../services/config.provider';

interface Breadcrumb {
node: INode;
Expand All @@ -19,12 +20,12 @@ export class BreadcrumbsComponent implements OnDestroy {
public breadcrumbs: Breadcrumb[] = [];
private sub = new Subscription();

constructor(private explorerService: ExplorerService, private helperService: HelperService) {
constructor(private explorerService: ExplorerService, private helperService: HelperService, private config: ConfigProvider) {
this.sub.add(this.explorerService.breadcrumbs.subscribe(n => this.buildBreadcrumbs(n)));
}

private buildBreadcrumbs(nodes: INode[]) {
this.breadcrumbs = nodes.map(n => ({ name: this.helperService.getName(n.data) || 'Files', node: n }));
this.breadcrumbs = nodes.map(n => ({ name: this.helperService.getName(n.data) || this.config.config.homeNodeName, node: n }));
}

public click(crumb: Breadcrumb) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Inject, OnDestroy, ViewEncapsulation } from '@angular/core';
import { BehaviorSubject, Subscription } from 'rxjs';
import { AvialableView } from '../../common/types';
import { CURRENT_VIEW } from '../../injection-tokens/current-view.token';
import { AvialableView } from '../../shared/types';
import { CURRENT_VIEW } from '../../injection-tokens/tokens';

@Component({
selector: 'nxe-explorer',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, ElementRef, Inject, OnDestroy, ViewChild } from '@angular/core';
import { BehaviorSubject, Subscription } from 'rxjs';
import { FILTER_STRING } from '../../injection-tokens/current-view.token';
import { FILTER_STRING } from '../../injection-tokens/tokens';
import { ExplorerService } from '../../services/explorer.service';

@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Inject, ViewEncapsulation } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { FILTER_STRING } from '../../injection-tokens/current-view.token';
import { FILTER_STRING } from '../../injection-tokens/tokens';
import { ExplorerService } from '../../services/explorer.service';
import { HelperService } from '../../services/helper.service';
import { BaseView } from '../base-view/base-view.directive';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Inject, ViewEncapsulation } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { FILTER_STRING } from '../../injection-tokens/current-view.token';
import { FILTER_STRING } from '../../injection-tokens/tokens';
import { ExplorerService } from '../../services/explorer.service';
import { HelperService } from '../../services/helper.service';
import { BaseView } from '../base-view/base-view.directive';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, ElementRef, OnDestroy, ViewChild, ViewEncapsulation } from '@angular/core';
import { Subscription } from 'rxjs';
import { INode } from '../../common/types';
import { INode } from '../../shared/types';
import { ExplorerService } from '../../services/explorer.service';
import { HelperService } from '../../services/helper.service';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExplorerService } from '../../services/explorer.service';
import { filter } from 'rxjs/operators';
import { HelperService } from '../../services/helper.service';
import { Subscription } from 'rxjs';
import { INode } from '../../common/types';
import { INode } from '../../shared/types';

interface TreeNode extends INode {
children: TreeNode[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Inject, ViewEncapsulation } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { AvialableView } from '../../common/types';
import { CURRENT_VIEW } from '../../injection-tokens/current-view.token';
import { AvialableView } from '../../shared/types';
import { CURRENT_VIEW } from '../../injection-tokens/tokens';

@Component({
selector: 'nxe-view-switcher',
Expand Down
10 changes: 0 additions & 10 deletions projects/ngx-explorer/src/lib/injection-tokens/config.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InjectionToken } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { AvialableView } from '../common/types';
import { AvialableView } from '../shared/types';

export const CURRENT_VIEW = new InjectionToken<BehaviorSubject<AvialableView>>('CURRENT_VIEW', {
providedIn: 'root',
Expand Down
7 changes: 7 additions & 0 deletions projects/ngx-explorer/src/lib/ngx-explorer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ViewSwitcherComponent } from './components/view-switcher/view-switcher.
import { TreeComponent } from './components/tree/tree.component';
import { FilterComponent } from './components/filter/filter.component';
import { DragDropDirective } from './directives/drag-drop.directive';
import { Config } from './shared/default-config';

@NgModule({
declarations: [
Expand Down Expand Up @@ -37,6 +38,12 @@ import { DragDropDirective } from './directives/drag-drop.directive';
ViewSwitcherComponent,
TreeComponent,
FilterComponent
],
providers: [
{
provide: Config,
useValue: Config
}
]
})
export class NgxExplorerModule { }
5 changes: 5 additions & 0 deletions projects/ngx-explorer/src/lib/services/config.provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { NgeExplorerConfig } from '../shared/types';

export class ConfigProvider {
constructor(public config: NgeExplorerConfig) {}
}
2 changes: 1 addition & 1 deletion projects/ngx-explorer/src/lib/services/data.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { IDataService } from '../common/types';
import { IDataService } from '../shared/types';

@Injectable({
providedIn: 'root'
Expand Down
5 changes: 2 additions & 3 deletions projects/ngx-explorer/src/lib/services/explorer.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject, forkJoin, of } from 'rxjs';
import { tap } from 'rxjs/operators';
import { INode, Dictionary, NodeContent } from '../common/types';
import { INode, Dictionary, NodeContent } from '../shared/types';
import { Utils } from '../shared/utils';
import { DataService } from './data.service';
import { HelperService } from './helper.service';

@Injectable({
providedIn: 'root'
Expand All @@ -23,7 +22,7 @@ export class ExplorerService {
public readonly breadcrumbs = this.breadcrumbs$.asObservable();
public readonly tree = this.tree$.asObservable();

constructor(private dataService: DataService, private helper: HelperService) {
constructor(private dataService: DataService) {
this.openNode(this.internalTree.id);
}

Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-explorer/src/lib/services/helper.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { IHelperService } from '../common/types';
import { IHelperService } from '../shared/types';

@Injectable({
providedIn: 'root'
Expand Down
5 changes: 5 additions & 0 deletions projects/ngx-explorer/src/lib/shared/default-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { NgeExplorerConfig } from './types';

export const Config: NgeExplorerConfig = {
homeNodeName: 'Files'
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export enum AvialableView {
Icon = 'Icon',
}

export interface NgxExplorerConfig {
test?: number;
export interface NgeExplorerConfig {
homeNodeName: string;
}
2 changes: 1 addition & 1 deletion projects/ngx-explorer/src/lib/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INode, Dictionary } from '../common/types';
import { INode, Dictionary } from './types';

export class Utils {

Expand Down
7 changes: 4 additions & 3 deletions projects/ngx-explorer/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Public API Surface of ngx-explorer
*/

export * from './lib/common/types';
export * from './lib/shared/types';
export * from './lib/ngx-explorer.module';
export * from './lib/services/data.service';
export * from './lib/services/explorer.service';
export * from './lib/services/helper.service';
export * from './lib/injection-tokens/current-view.token';
export * from './lib/injection-tokens/config';
export * from './lib/services/config.provider';
export * from './lib/injection-tokens/tokens';
export * from './lib/components/icons/icons.component';
export * from './lib/components/explorer/explorer.component';
export * from './lib/components/menu-bar/menu-bar.component';
Expand All @@ -21,3 +21,4 @@ export * from './lib/components/tree/tree.component';
export * from './lib/components/list/list.component';
export * from './lib/components/filter/filter.component';
export * from './lib/shared/utils';
export * from './lib/shared/default-config';
8 changes: 6 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NgxExplorerModule, DataService } from 'ngx-explorer';
import { NgxExplorerModule, DataService, NgeExplorerConfig, ConfigProvider } from 'ngx-explorer';
import { ExampleDataService } from './data.service';

@NgModule({
Expand All @@ -14,7 +14,11 @@ import { ExampleDataService } from './data.service';
],
providers: [
{ provide: DataService, useClass: ExampleDataService },
// { provide: NGX_EXPLORER_CONFIG, useValue: { test: 123 } }
{
provide: ConfigProvider, useValue: new ConfigProvider({
homeNodeName: 'Home'
} as NgeExplorerConfig)
}
// { provide: NxeExplorerHelpers, useClass: LittleHelpers }
],
bootstrap: [AppComponent]
Expand Down

0 comments on commit d415650

Please sign in to comment.