Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Restructured code components. Addd tree service to allow node updates…
… to be listened to. Added bootstrap + jquery for style simplicity. Changed tree data from string to object (including target pdf name).
- Loading branch information
Showing
27 changed files
with
221 additions
and
198 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
<div class="container"> | ||
<div class="row"> | ||
<app-tree></app-tree> | ||
</div> | ||
</div> | ||
<app-main></app-main> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
import { BrowserModule } from "@angular/platform-browser"; | ||
import { NgModule } from "@angular/core"; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { AppRoutingModule } from "./app-routing.module"; | ||
import { AppComponent } from "./app.component"; | ||
import { TreeComponent } from "./tree/tree.component"; | ||
import { ButtonModule, MessageService, TreeModule } from "primeng/primeng"; | ||
import { MainComponent } from "./main/main.component"; | ||
import { CenterComponent } from "./center/center.component"; | ||
import { LeftComponent } from "./left/left.component"; | ||
import { HttpClientModule } from "@angular/common/http"; | ||
import { AppRoutingModule } from './app-routing.module'; | ||
import { AppComponent } from './app.component'; | ||
import { ButtonModule, MessageService, TreeModule } from 'primeng/primeng'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { MainComponent } from './main/main.component'; | ||
import { MainCenterComponent } from './main/main-center/main-center.component'; | ||
import { TreeComponent } from './main/tree/tree.component'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent, | ||
TreeComponent, | ||
MainComponent, | ||
CenterComponent, | ||
LeftComponent | ||
], | ||
declarations: [AppComponent, TreeComponent, MainComponent, MainCenterComponent], | ||
imports: [ | ||
BrowserModule, | ||
AppRoutingModule, | ||
TreeModule, | ||
HttpClientModule, | ||
ButtonModule | ||
], | ||
providers: [MessageService], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule {} | ||
export class AppModule { } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,8 @@ | ||
<ng-container *ngIf="this.currentNode != null; else noNode"> | ||
<p>Current node is {{this.currentNode.label}}</p> | ||
<!-- Add pdf container here --> | ||
</ng-container> | ||
|
||
<ng-template #noNode> | ||
<p>No node selected</p> | ||
</ng-template> |
12 changes: 6 additions & 6 deletions
12
src/app/center/center.component.spec.ts → ...main-center/main-center.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
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,49 @@ | ||
import { Component, OnInit, OnDestroy } from '@angular/core'; | ||
import { TreeService } from 'src/app/services/tree.service'; | ||
import { Subscription } from 'rxjs'; | ||
import { TreeNode } from 'primeng/api'; | ||
import { ResourceService } from 'src/app/services/api/resource.service'; | ||
import { HttpErrorResponse } from '@angular/common/http'; | ||
|
||
@Component({ | ||
selector: 'app-main-center', | ||
templateUrl: './main-center.component.html', | ||
styleUrls: ['./main-center.component.css'] | ||
}) | ||
export class MainCenterComponent implements OnInit, OnDestroy { | ||
|
||
private treeSubscription: Subscription; | ||
currentNode: TreeNode; | ||
|
||
constructor( | ||
private treeService: TreeService, | ||
private resourceService: ResourceService | ||
) { } | ||
|
||
ngOnInit() { | ||
this.treeSubscription = this.treeService.node$.subscribe(async (node) => { | ||
if (node == null) { | ||
return; | ||
} | ||
console.log('Selected node is', node); | ||
this.currentNode = node; | ||
const data = node.data as { pdfName: string }; | ||
try { | ||
console.log('I will load', data.pdfName); | ||
const pdfData = await this.resourceService.getResourcePDF(data.pdfName); | ||
// render pdf to screen | ||
|
||
} catch (err) { | ||
console.log(err); | ||
if ((err as HttpErrorResponse).status === 404) { | ||
// handle not found | ||
} | ||
} | ||
|
||
}); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.treeSubscription.unsubscribe(); | ||
} | ||
} |
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 +1,2 @@ | ||
<p>main works!</p> | ||
<app-tree></app-tree> | ||
<app-main-center></app-main-center> |
File renamed without changes.
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 @@ | ||
<p-tree [value]="filesTree" selectionMode="single" (onNodeSelect)="nodeSelect($event)"></p-tree> |
12 changes: 6 additions & 6 deletions
12
src/app/left/left.component.spec.ts → src/app/main/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
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,28 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { TreeNode } from 'primeng/api'; | ||
import { NodeService } from 'src/app/node.service'; | ||
import { TreeService } from 'src/app/services/tree.service'; | ||
|
||
@Component({ | ||
selector: 'app-tree', | ||
templateUrl: './tree.component.html', | ||
styleUrls: ['./tree.component.css'] | ||
}) | ||
export class TreeComponent implements OnInit { | ||
|
||
filesTree: TreeNode[]; | ||
|
||
constructor( | ||
private treeService: TreeService, | ||
private nodeService: NodeService | ||
) { } | ||
|
||
ngOnInit() { | ||
this.nodeService.getFiles().then(files => (this.filesTree = files)); | ||
} | ||
|
||
nodeSelect(event: { node: TreeNode }) { | ||
this.treeService.changeNode(event.node); | ||
} | ||
|
||
} |
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,16 +1,14 @@ | ||
import {HttpClient, HttpClientModule} from '@angular/common/http'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { TreeNode } from 'primeng/api'; | ||
|
||
@Injectable({providedIn: 'root'}) | ||
@Injectable({ providedIn: 'root' }) | ||
export class NodeService { | ||
|
||
constructor(private http: HttpClient) { } | ||
|
||
getFiles() { | ||
return this.http.get<any>('http://localhost:4200/assets/files.json') | ||
.toPromise() | ||
.then(res => res.data as TreeNode[]); | ||
async getFiles() { | ||
return (await this.http.get<any>('http://localhost:4200/assets/files.json').toPromise()).data as TreeNode[]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { TreeNode } from 'primeng/api'; | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TreeService { | ||
|
||
private nodeChange = new BehaviorSubject<TreeNode>(null); | ||
node$ = this.nodeChange.asObservable(); | ||
|
||
changeNode(newNode: TreeNode) { | ||
this.nodeChange.next(newNode); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.